diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2016-08-13 13:58:28 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2016-08-14 09:26:00 +0000 |
commit | 877ac7226c8ae4ec9b8d1652a7da1f73d78bc5c7 (patch) | |
tree | 091e790e60fb5d4c02d3998bd23ae831eb412213 /src/imports | |
parent | fb05eafac51a602c8c090c76584ece6b7da2034c (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')
-rw-r--r-- | src/imports/platform/plugins.qmltypes | 5 | ||||
-rw-r--r-- | src/imports/platform/qquickplatformfontdialog.cpp | 61 | ||||
-rw-r--r-- | src/imports/platform/qquickplatformfontdialog_p.h | 10 | ||||
-rw-r--r-- | src/imports/platform/widgets/qwidgetplatformfontdialog.cpp | 1 |
4 files changed, 57 insertions, 20 deletions
diff --git a/src/imports/platform/plugins.qmltypes b/src/imports/platform/plugins.qmltypes index 9c59d3e5..d751e45f 100644 --- a/src/imports/platform/plugins.qmltypes +++ b/src/imports/platform/plugins.qmltypes @@ -151,12 +151,9 @@ Module { prototype: "QQuickPlatformDialog" exports: ["Qt.labs.platform/FontDialog 1.0"] exportMetaObjectRevisions: [0] + Property { name: "font"; type: "QFont" } Property { name: "currentFont"; type: "QFont" } Property { name: "options"; type: "QFontDialogOptions::FontDialogOptions" } - Signal { - name: "fontSelected" - Parameter { name: "font"; type: "QFont" } - } } Component { name: "QQuickPlatformMenu" 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 diff --git a/src/imports/platform/qquickplatformfontdialog_p.h b/src/imports/platform/qquickplatformfontdialog_p.h index 0c4f64ee..920628ed 100644 --- a/src/imports/platform/qquickplatformfontdialog_p.h +++ b/src/imports/platform/qquickplatformfontdialog_p.h @@ -57,6 +57,7 @@ QT_BEGIN_NAMESPACE class QQuickPlatformFontDialog : public QQuickPlatformDialog { Q_OBJECT + Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged FINAL) Q_PROPERTY(QFont currentFont READ currentFont WRITE setCurrentFont NOTIFY currentFontChanged FINAL) Q_PROPERTY(QFontDialogOptions::FontDialogOptions options READ options WRITE setOptions NOTIFY optionsChanged FINAL) Q_FLAGS(QFontDialogOptions::FontDialogOptions) @@ -64,6 +65,9 @@ class QQuickPlatformFontDialog : public QQuickPlatformDialog public: explicit QQuickPlatformFontDialog(QObject *parent = nullptr); + QFont font() const; + void setFont(const QFont &font); + QFont currentFont() const; void setCurrentFont(const QFont &font); @@ -71,15 +75,17 @@ public: void setOptions(QFontDialogOptions::FontDialogOptions options); Q_SIGNALS: - void optionsChanged(); + void fontChanged(); void currentFontChanged(); - void fontSelected(const QFont &font); + void optionsChanged(); protected: QPlatformDialogHelper *createHelper() override; void applyOptions() override; + void accept() override; private: + QFont m_font; QSharedPointer<QFontDialogOptions> m_options; }; diff --git a/src/imports/platform/widgets/qwidgetplatformfontdialog.cpp b/src/imports/platform/widgets/qwidgetplatformfontdialog.cpp index af335b03..7687b74c 100644 --- a/src/imports/platform/widgets/qwidgetplatformfontdialog.cpp +++ b/src/imports/platform/widgets/qwidgetplatformfontdialog.cpp @@ -51,7 +51,6 @@ QWidgetPlatformFontDialog::QWidgetPlatformFontDialog(QObject *parent) m_dialog.reset(new QFontDialog); connect(m_dialog.data(), &QFontDialog::accepted, this, &QPlatformDialogHelper::accept); connect(m_dialog.data(), &QFontDialog::rejected, this, &QPlatformDialogHelper::reject); - connect(m_dialog.data(), &QFontDialog::fontSelected, this, &QPlatformFontDialogHelper::fontSelected); connect(m_dialog.data(), &QFontDialog::currentFontChanged, this, &QPlatformFontDialogHelper::currentFontChanged); } } |