diff options
| author | Liang Qi <liang.qi@digia.com> | 2013-06-04 13:36:18 +0200 |
|---|---|---|
| committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-06-06 17:40:46 +0200 |
| commit | e67d67d0ad0c5c4549047f13be1999c65a9efb42 (patch) | |
| tree | 9cf7d52db90f2acd799a11388446f8ee37411b85 /examples/quick/controls/text/src/documenthandler.cpp | |
| parent | e6ea417c15aa760e8b1a88e5db362f9642d1589e (diff) | |
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 <caroline.chao@digia.com>
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
Diffstat (limited to 'examples/quick/controls/text/src/documenthandler.cpp')
| -rw-r--r-- | examples/quick/controls/text/src/documenthandler.cpp | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/examples/quick/controls/text/src/documenthandler.cpp b/examples/quick/controls/text/src/documenthandler.cpp index 81eb744b6..e0c9610d0 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 |
