From 8beda08087effd684cfcb325855c9f4b47186135 Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig Date: Thu, 30 May 2013 16:51:34 +0200 Subject: Cleaning up some examples and removing clutter We want to use more layouts in our examples as it is the recommended way to create tool bars etc. Change-Id: Ib3b1e8e907cc5277d522557a19d2c294a7d251b1 Reviewed-by: J-P Nurmi --- examples/quick/controls/text/src/documenthandler.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'examples/quick/controls/text/src/documenthandler.cpp') diff --git a/examples/quick/controls/text/src/documenthandler.cpp b/examples/quick/controls/text/src/documenthandler.cpp index 48b6d033..81eb744b 100644 --- a/examples/quick/controls/text/src/documenthandler.cpp +++ b/examples/quick/controls/text/src/documenthandler.cpp @@ -166,13 +166,11 @@ void DocumentHandler::mergeFormatOnWordOrSelection(const QTextCharFormat &format void DocumentHandler::setSelectionStart(int position) { m_selectionStart = position; -// emit selectionStartChanged(); } void DocumentHandler::setSelectionEnd(int position) { m_selectionEnd = position; -// emit selectionEndChanged(); } void DocumentHandler::setAlignment(Qt::Alignment a) @@ -188,10 +186,8 @@ void DocumentHandler::setAlignment(Qt::Alignment a) Qt::Alignment DocumentHandler::alignment() const { -// if (!m_doc || m_doc->isEmpty() || m_cursorPosition < 0) -// return Qt::AlignLeft; QTextCursor cursor = textCursor(); - if (cursor.isNull() || cursor.blockNumber() == 0) + if (cursor.isNull()) return Qt::AlignLeft; return textCursor().blockFormat().alignment(); } @@ -199,7 +195,7 @@ Qt::Alignment DocumentHandler::alignment() const bool DocumentHandler::bold() const { QTextCursor cursor = textCursor(); - if (cursor.isNull() || cursor.blockNumber() == 0) + if (cursor.isNull()) return false; return textCursor().charFormat().fontWeight() == QFont::Bold; } @@ -207,7 +203,7 @@ bool DocumentHandler::bold() const bool DocumentHandler::italic() const { QTextCursor cursor = textCursor(); - if (cursor.isNull() || cursor.blockNumber() == 0) + if (cursor.isNull()) return false; return textCursor().charFormat().fontItalic(); } @@ -215,7 +211,7 @@ bool DocumentHandler::italic() const bool DocumentHandler::underline() const { QTextCursor cursor = textCursor(); - if (cursor.isNull() || cursor.blockNumber() == 0) + if (cursor.isNull()) return false; return textCursor().charFormat().fontUnderline(); } -- cgit v1.2.1 From e67d67d0ad0c5c4549047f13be1999c65a9efb42 Mon Sep 17 00:00:00 2001 From: Liang Qi Date: Tue, 4 Jun 2013 13:36:18 +0200 Subject: Examples: several fixes for text * Cut/Copy/Paste works * The initial status for b/i/u and alignment works * Font size and family works * Text color works Task-number: QTBUG-31482 Change-Id: I299931dede9defbb1d3eb927f867e77d20ded5ae Reviewed-by: Caroline Chao Reviewed-by: Gabriel de Dietrich --- .../quick/controls/text/src/documenthandler.cpp | 48 +++++++++++++++++++--- 1 file changed, 43 insertions(+), 5 deletions(-) (limited to 'examples/quick/controls/text/src/documenthandler.cpp') diff --git a/examples/quick/controls/text/src/documenthandler.cpp b/examples/quick/controls/text/src/documenthandler.cpp index 81eb744b..e0c9610d 100644 --- a/examples/quick/controls/text/src/documenthandler.cpp +++ b/examples/quick/controls/text/src/documenthandler.cpp @@ -52,7 +52,6 @@ DocumentHandler::DocumentHandler() , m_selectionStart(0) , m_selectionEnd(0) { - setFileUrl(QUrl("qrc:/example.html")); } void DocumentHandler::setTarget(QQuickItem *target) @@ -91,6 +90,8 @@ void DocumentHandler::setFileUrl(const QUrl &arg) emit textChanged(); emit documentTitleChanged(); + + reset(); } } emit fileUrlChanged(); @@ -135,12 +136,18 @@ void DocumentHandler::setCursorPosition(int position) m_cursorPosition = position; - emit currentFontChanged(); + reset(); +} + +void DocumentHandler::reset() +{ + emit fontFamilyChanged(); emit alignmentChanged(); emit boldChanged(); emit italicChanged(); emit underlineChanged(); emit fontSizeChanged(); + emit textColorChanged(); } QTextCursor DocumentHandler::textCursor() const @@ -260,13 +267,44 @@ void DocumentHandler::setFontSize(int arg) emit fontSizeChanged(); } -QFont DocumentHandler::currentFont() const +QColor DocumentHandler::textColor() const +{ + QTextCursor cursor = textCursor(); + if (cursor.isNull()) + return QColor(Qt::black); + QTextCharFormat format = cursor.charFormat(); + return format.foreground().color(); +} + +void DocumentHandler::setTextColor(const QColor &c) +{ + QTextCursor cursor = textCursor(); + if (cursor.isNull()) + return; + QTextCharFormat format; + format.setForeground(QBrush(c)); + mergeFormatOnWordOrSelection(format); + emit textColorChanged(); +} + +QString DocumentHandler::fontFamily() const { QTextCursor cursor = textCursor(); if (cursor.isNull()) - return QFont(); + return QString(); QTextCharFormat format = cursor.charFormat(); - return format.font(); + return format.font().family(); +} + +void DocumentHandler::setFontFamily(const QString &arg) +{ + QTextCursor cursor = textCursor(); + if (cursor.isNull()) + return; + QTextCharFormat format; + format.setFontFamily(arg); + mergeFormatOnWordOrSelection(format); + emit fontFamilyChanged(); } QStringList DocumentHandler::defaultFontSizes() const -- cgit v1.2.1