aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports/platform
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2016-08-13 13:40:36 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2016-08-14 09:25:52 +0000
commitfb05eafac51a602c8c090c76584ece6b7da2034c (patch)
tree377384baa19b78c6cb6b9e59f6a859a66b231ae0 /src/imports/platform
parent2e09e597ab3df5a13f89e945a0a90724d5c5a3f0 (diff)
ColorDialog: replace colorSelected() with a declarative property
This is consistent with the QML ColorDialog from QtQuick Dialogs 1. Change-Id: I4068a98156494eb36b2d9ecf4c1af90ad173bb97 Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'src/imports/platform')
-rw-r--r--src/imports/platform/plugins.qmltypes5
-rw-r--r--src/imports/platform/qquickplatformcolordialog.cpp61
-rw-r--r--src/imports/platform/qquickplatformcolordialog_p.h10
-rw-r--r--src/imports/platform/qquickplatformdialog_p.h4
-rw-r--r--src/imports/platform/widgets/qwidgetplatformcolordialog.cpp1
5 files changed, 59 insertions, 22 deletions
diff --git a/src/imports/platform/plugins.qmltypes b/src/imports/platform/plugins.qmltypes
index 1a1d929c..9c59d3e5 100644
--- a/src/imports/platform/plugins.qmltypes
+++ b/src/imports/platform/plugins.qmltypes
@@ -72,12 +72,9 @@ Module {
prototype: "QQuickPlatformDialog"
exports: ["Qt.labs.platform/ColorDialog 1.0"]
exportMetaObjectRevisions: [0]
+ Property { name: "color"; type: "QColor" }
Property { name: "currentColor"; type: "QColor" }
Property { name: "options"; type: "QColorDialogOptions::ColorDialogOptions" }
- Signal {
- name: "colorSelected"
- Parameter { name: "color"; type: "QColor" }
- }
}
Component {
name: "QQuickPlatformDialog"
diff --git a/src/imports/platform/qquickplatformcolordialog.cpp b/src/imports/platform/qquickplatformcolordialog.cpp
index b71797f5..5f5905d4 100644
--- a/src/imports/platform/qquickplatformcolordialog.cpp
+++ b/src/imports/platform/qquickplatformcolordialog.cpp
@@ -59,8 +59,10 @@ QT_BEGIN_NAMESPACE
\image qtlabsplatform-colordialog-gtk.png
To show a color dialog, construct an instance of ColorDialog, set the
- desired properties, and call \l {Dialog::}{open()}. ColorDialog emits
- the \l colorSelected() signal when the user has selected a color.
+ desired properties, and call \l {Dialog::}{open()}. The \l currentColor
+ property can be used to determine the currently selected color in the
+ dialog. The \l color property is updated only after the final selection
+ has been made by accepting the dialog.
\code
MenuItem {
@@ -70,8 +72,12 @@ QT_BEGIN_NAMESPACE
ColorDialog {
id: colorDialog
- currentColor: "black"
- onColorSelected: document.brush = color
+ currentColor: document.color
+ }
+
+ MyDocument {
+ id: document
+ color: colorDialog.color
}
\endcode
@@ -89,19 +95,39 @@ QT_BEGIN_NAMESPACE
\labs
*/
+Q_DECLARE_LOGGING_CATEGORY(qtLabsPlatformDialogs)
+
+QQuickPlatformColorDialog::QQuickPlatformColorDialog(QObject *parent)
+ : QQuickPlatformDialog(parent), m_options(QColorDialogOptions::create())
+{
+}
+
/*!
- \qmlsignal void Qt.labs.platform::ColorDialog::colorSelected(color color)
+ \qmlproperty color Qt.labs.platform::ColorDialog::color
- This signal is emitted just after the user has clicked \uicontrol OK to select a \a color.
+ This property holds the final accepted color.
- \sa currentColor
-*/
+ Unlike the \l currentColor property, the \c color property is not updated
+ while the user is selecting colors in the dialog, but only after the final
+ selection has been made. That is, when the user has clicked \uicontrol OK
+ to accept a color. Alternatively, the \l {Dialog::}{accepted()} signal
+ can be handled to get the final selection.
-Q_DECLARE_LOGGING_CATEGORY(qtLabsPlatformDialogs)
+ \sa currentColor, {Dialog::}{accepted()}
+*/
+QColor QQuickPlatformColorDialog::color() const
+{
+ return m_color;
+}
-QQuickPlatformColorDialog::QQuickPlatformColorDialog(QObject *parent)
- : QQuickPlatformDialog(parent), m_options(QColorDialogOptions::create())
+void QQuickPlatformColorDialog::setColor(const QColor &color)
{
+ if (m_color == color)
+ return;
+
+ m_color = color;
+ setCurrentColor(color);
+ emit colorChanged();
}
/*!
@@ -109,7 +135,11 @@ QQuickPlatformColorDialog::QQuickPlatformColorDialog(QObject *parent)
This property holds the currently selected color in the dialog.
- \sa colorSelected()
+ Unlike the \l color property, the \c currentColor property is updated
+ while the user is selecting colors in the dialog, even before the final
+ selection has been made.
+
+ \sa color
*/
QColor QQuickPlatformColorDialog::currentColor() const
{
@@ -164,7 +194,6 @@ QPlatformDialogHelper *QQuickPlatformColorDialog::createHelper()
if (QPlatformColorDialogHelper *colorDialog = qobject_cast<QPlatformColorDialogHelper *>(dialog)) {
connect(colorDialog, &QPlatformColorDialogHelper::currentColorChanged, this, &QQuickPlatformColorDialog::currentColorChanged);
- connect(colorDialog, &QPlatformColorDialogHelper::colorSelected, this, &QQuickPlatformColorDialog::colorSelected);
colorDialog->setOptions(m_options);
}
return dialog;
@@ -175,4 +204,10 @@ void QQuickPlatformColorDialog::applyOptions()
m_options->setWindowTitle(title());
}
+void QQuickPlatformColorDialog::accept()
+{
+ setColor(currentColor());
+ QQuickPlatformDialog::accept();
+}
+
QT_END_NAMESPACE
diff --git a/src/imports/platform/qquickplatformcolordialog_p.h b/src/imports/platform/qquickplatformcolordialog_p.h
index 403582e4..70d913e1 100644
--- a/src/imports/platform/qquickplatformcolordialog_p.h
+++ b/src/imports/platform/qquickplatformcolordialog_p.h
@@ -57,6 +57,7 @@ QT_BEGIN_NAMESPACE
class QQuickPlatformColorDialog : public QQuickPlatformDialog
{
Q_OBJECT
+ Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged FINAL)
Q_PROPERTY(QColor currentColor READ currentColor WRITE setCurrentColor NOTIFY currentColorChanged FINAL)
Q_PROPERTY(QColorDialogOptions::ColorDialogOptions options READ options WRITE setOptions NOTIFY optionsChanged FINAL)
Q_FLAGS(QColorDialogOptions::ColorDialogOptions)
@@ -64,6 +65,9 @@ class QQuickPlatformColorDialog : public QQuickPlatformDialog
public:
explicit QQuickPlatformColorDialog(QObject *parent = nullptr);
+ QColor color() const;
+ void setColor(const QColor &color);
+
QColor currentColor() const;
void setCurrentColor(const QColor &color);
@@ -71,15 +75,17 @@ public:
void setOptions(QColorDialogOptions::ColorDialogOptions options);
Q_SIGNALS:
- void optionsChanged();
+ void colorChanged();
void currentColorChanged();
- void colorSelected(const QColor &color);
+ void optionsChanged();
protected:
QPlatformDialogHelper *createHelper() override;
void applyOptions() override;
+ void accept() override;
private:
+ QColor m_color;
QSharedPointer<QColorDialogOptions> m_options;
};
diff --git a/src/imports/platform/qquickplatformdialog_p.h b/src/imports/platform/qquickplatformdialog_p.h
index 577cec94..fb8d4fb6 100644
--- a/src/imports/platform/qquickplatformdialog_p.h
+++ b/src/imports/platform/qquickplatformdialog_p.h
@@ -97,8 +97,8 @@ public:
public Q_SLOTS:
void open();
void close();
- void accept();
- void reject();
+ virtual void accept();
+ virtual void reject();
Q_SIGNALS:
void accepted();
diff --git a/src/imports/platform/widgets/qwidgetplatformcolordialog.cpp b/src/imports/platform/widgets/qwidgetplatformcolordialog.cpp
index 4dd0895d..68173a1d 100644
--- a/src/imports/platform/widgets/qwidgetplatformcolordialog.cpp
+++ b/src/imports/platform/widgets/qwidgetplatformcolordialog.cpp
@@ -51,7 +51,6 @@ QWidgetPlatformColorDialog::QWidgetPlatformColorDialog(QObject *parent)
m_dialog.reset(new QColorDialog);
connect(m_dialog.data(), &QColorDialog::accepted, this, &QPlatformDialogHelper::accept);
connect(m_dialog.data(), &QColorDialog::rejected, this, &QPlatformDialogHelper::reject);
- connect(m_dialog.data(), &QColorDialog::colorSelected, this, &QPlatformColorDialogHelper::colorSelected);
connect(m_dialog.data(), &QColorDialog::currentColorChanged, this, &QPlatformColorDialogHelper::currentColorChanged);
}
}