aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports/platform/qquickplatformfontdialog.cpp
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2016-08-13 13:58:28 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2016-08-14 09:26:00 +0000
commit877ac7226c8ae4ec9b8d1652a7da1f73d78bc5c7 (patch)
tree091e790e60fb5d4c02d3998bd23ae831eb412213 /src/imports/platform/qquickplatformfontdialog.cpp
parentfb05eafac51a602c8c090c76584ece6b7da2034c (diff)
FontDialog: replace fontSelected() with a declarative property
This is consistent with the QML FontDialog from QtQuick Dialogs 1. Change-Id: I14a5a313be5ba9a9e0fb1645fe272cf9c2cdd389 Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'src/imports/platform/qquickplatformfontdialog.cpp')
-rw-r--r--src/imports/platform/qquickplatformfontdialog.cpp61
1 files changed, 48 insertions, 13 deletions
diff --git a/src/imports/platform/qquickplatformfontdialog.cpp b/src/imports/platform/qquickplatformfontdialog.cpp
index 13e35389..cffa5b97 100644
--- a/src/imports/platform/qquickplatformfontdialog.cpp
+++ b/src/imports/platform/qquickplatformfontdialog.cpp
@@ -59,8 +59,10 @@ QT_BEGIN_NAMESPACE
\image qtlabsplatform-fontdialog-gtk.png
To show a font dialog, construct an instance of FontDialog, set the
- desired properties, and call \l {Dialog::}{open()}. FontDialog emits
- the \l fontSelected() signal when the user has selected a font.
+ desired properties, and call \l {Dialog::}{open()}. The \l currentFont
+ property can be used to determine the currently selected font in the
+ dialog. The \l font property is updated only after the final selection
+ has been made by accepting the dialog.
\code
MenuItem {
@@ -70,8 +72,12 @@ QT_BEGIN_NAMESPACE
FontDialog {
id: fontDialog
- currentFont.family: "Sans"
- onFontSelected: document.font = font
+ currentFont.family: document.font
+ }
+
+ MyDocument {
+ id: document
+ font: fontDialog.font
}
\endcode
@@ -89,19 +95,39 @@ QT_BEGIN_NAMESPACE
\labs
*/
+Q_DECLARE_LOGGING_CATEGORY(qtLabsPlatformDialogs)
+
+QQuickPlatformFontDialog::QQuickPlatformFontDialog(QObject *parent)
+ : QQuickPlatformDialog(parent), m_options(QFontDialogOptions::create())
+{
+}
+
/*!
- \qmlsignal void Qt.labs.platform::FontDialog::fontSelected(font font)
+ \qmlproperty font Qt.labs.platform::FontDialog::font
- This signal is emitted just after the user has clicked \uicontrol OK to select a \a font.
+ This property holds the final accepted font.
- \sa currentFont
-*/
+ Unlike the \l currentFont property, the \c font property is not updated
+ while the user is selecting fonts in the dialog, but only after the final
+ selection has been made. That is, when the user has clicked \uicontrol OK
+ to accept a font. Alternatively, the \l {Dialog::}{accepted()} signal
+ can be handled to get the final selection.
-Q_DECLARE_LOGGING_CATEGORY(qtLabsPlatformDialogs)
+ \sa currentFont, {Dialog::}{accepted()}
+*/
+QFont QQuickPlatformFontDialog::font() const
+{
+ return m_font;
+}
-QQuickPlatformFontDialog::QQuickPlatformFontDialog(QObject *parent)
- : QQuickPlatformDialog(parent), m_options(QFontDialogOptions::create())
+void QQuickPlatformFontDialog::setFont(const QFont &font)
{
+ if (m_font == font)
+ return;
+
+ m_font = font;
+ setCurrentFont(font);
+ emit fontChanged();
}
/*!
@@ -109,7 +135,11 @@ QQuickPlatformFontDialog::QQuickPlatformFontDialog(QObject *parent)
This property holds the currently selected font in the dialog.
- \sa fontSelected()
+ Unlike the \l font property, the \c currentFont property is updated
+ while the user is selecting fonts in the dialog, even before the final
+ selection has been made.
+
+ \sa font
*/
QFont QQuickPlatformFontDialog::currentFont() const
{
@@ -167,7 +197,6 @@ QPlatformDialogHelper *QQuickPlatformFontDialog::createHelper()
if (QPlatformFontDialogHelper *fontDialog = qobject_cast<QPlatformFontDialogHelper *>(dialog)) {
connect(fontDialog, &QPlatformFontDialogHelper::currentFontChanged, this, &QQuickPlatformFontDialog::currentFontChanged);
- connect(fontDialog, &QPlatformFontDialogHelper::fontSelected, this, &QQuickPlatformFontDialog::fontSelected);
fontDialog->setOptions(m_options);
}
return dialog;
@@ -178,4 +207,10 @@ void QQuickPlatformFontDialog::applyOptions()
m_options->setWindowTitle(title());
}
+void QQuickPlatformFontDialog::accept()
+{
+ setFont(currentFont());
+ QQuickPlatformDialog::accept();
+}
+
QT_END_NAMESPACE