summaryrefslogtreecommitdiffstats
path: root/examples/quick/controls/text/src
diff options
context:
space:
mode:
Diffstat (limited to 'examples/quick/controls/text/src')
-rw-r--r--examples/quick/controls/text/src/documenthandler.cpp48
-rw-r--r--examples/quick/controls/text/src/documenthandler.h16
2 files changed, 53 insertions, 11 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
diff --git a/examples/quick/controls/text/src/documenthandler.h b/examples/quick/controls/text/src/documenthandler.h
index c60bc1d51..a759c4033 100644
--- a/examples/quick/controls/text/src/documenthandler.h
+++ b/examples/quick/controls/text/src/documenthandler.h
@@ -63,7 +63,8 @@ class DocumentHandler : public QObject
Q_PROPERTY(int selectionStart READ selectionStart WRITE setSelectionStart NOTIFY selectionStartChanged)
Q_PROPERTY(int selectionEnd READ selectionEnd WRITE setSelectionEnd NOTIFY selectionEndChanged)
- Q_PROPERTY(QFont currentFont READ currentFont NOTIFY currentFontChanged)
+ Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor NOTIFY textColorChanged)
+ Q_PROPERTY(QString fontFamily READ fontFamily WRITE setFontFamily NOTIFY fontFamilyChanged)
Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
Q_PROPERTY(bool bold READ bold WRITE setBold NOTIFY boldChanged)
@@ -93,7 +94,9 @@ public:
int selectionStart() const { return m_selectionStart; }
int selectionEnd() const { return m_selectionEnd; }
- QFont currentFont() const;
+ QString fontFamily() const;
+
+ QColor textColor() const;
Qt::Alignment alignment() const;
void setAlignment(Qt::Alignment a);
@@ -114,6 +117,8 @@ public Q_SLOTS:
void setItalic(bool arg);
void setUnderline(bool arg);
void setFontSize(int arg);
+ void setTextColor(const QColor &arg);
+ void setFontFamily(const QString &arg);
void setFileUrl(const QUrl &arg);
void setText(const QString &arg);
@@ -126,7 +131,8 @@ Q_SIGNALS:
void selectionStartChanged();
void selectionEndChanged();
- void currentFontChanged();
+ void fontFamilyChanged();
+ void textColorChanged();
void alignmentChanged();
void boldChanged();
@@ -142,6 +148,7 @@ Q_SIGNALS:
void documentTitleChanged();
private:
+ void reset();
QTextCursor textCursor() const;
void mergeFormatOnWordOrSelection(const QTextCharFormat &format);
@@ -153,9 +160,6 @@ private:
int m_selectionEnd;
QFont m_font;
- bool m_bold;
- bool m_italic;
- bool m_underline;
int m_fontSize;
QUrl m_fileUrl;
QString m_text;