diff options
author | Mitch Curtis <mitch.curtis@digia.com> | 2013-08-23 15:14:33 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-17 07:36:09 +0200 |
commit | e73d503b84be12e7bf28491356b459ca309e7c95 (patch) | |
tree | 854ded45f1d75032b5cc3feb78600acc5483f1f2 | |
parent | 77ee9ab37e81b4e593dec73428d584013d6e8574 (diff) |
Add currentColor property to ColorDialog.
QColorDialog has this property. This patch effectively means that
the color property will be set when the dialog closes, instead of
whenever the current color in the dialog changes, so pressing cancel
will revert the color to what it was before the dialog was opened.
[ChangeLog][QtDeclarative][ColorDialog] Added currentColor property.
Change-Id: I2ef6b32954342cd2469cf1552d53f9e2fbf3420b
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
-rw-r--r-- | src/imports/dialogs/DefaultColorDialog.qml | 27 | ||||
-rw-r--r-- | src/imports/dialogs/qquickabstractcolordialog.cpp | 9 | ||||
-rw-r--r-- | src/imports/dialogs/qquickabstractcolordialog_p.h | 21 | ||||
-rw-r--r-- | src/imports/dialogs/qquickplatformcolordialog.cpp | 19 | ||||
-rw-r--r-- | src/imports/widgets/qquickqcolordialog.cpp | 2 |
5 files changed, 55 insertions, 23 deletions
diff --git a/src/imports/dialogs/DefaultColorDialog.qml b/src/imports/dialogs/DefaultColorDialog.qml index 4068c856fa..1d4c4a704b 100644 --- a/src/imports/dialogs/DefaultColorDialog.qml +++ b/src/imports/dialogs/DefaultColorDialog.qml @@ -48,15 +48,16 @@ AbstractColorDialog { property bool _valueSet: true // guard to prevent binding loops function _setControlsFromColor() { _valueSet = false - hueSlider.value = root.hue - saturationSlider.value = root.saturation - lightnessSlider.value = root.lightness - alphaSlider.value = root.alpha - crosshairs.x = root.lightness * paletteMap.width - crosshairs.y = (1.0 - root.saturation) * paletteMap.height + hueSlider.value = root.currentHue + saturationSlider.value = root.currentSaturation + lightnessSlider.value = root.currentLightness + alphaSlider.value = root.currentAlpha + crosshairs.x = root.currentLightness * paletteMap.width + crosshairs.y = (1.0 - root.currentSaturation) * paletteMap.height _valueSet = true } - onColorChanged: _setControlsFromColor() + onCurrentColorChanged: _setControlsFromColor() + onSelectionAccepted: root.color = root.currentColor Rectangle { id: content @@ -204,7 +205,7 @@ AbstractColorDialog { ColorSlider { id: hueSlider value: 0.5 - onValueChanged: if (_valueSet) root.color = Qt.hsla(hueSlider.value, saturationSlider.value, lightnessSlider.value, alphaSlider.value) + onValueChanged: if (_valueSet) root.currentColor = Qt.hsla(hueSlider.value, saturationSlider.value, lightnessSlider.value, alphaSlider.value) text: qsTr("Hue") trackDelegate: Rectangle { rotation: -90 @@ -225,7 +226,7 @@ AbstractColorDialog { id: saturationSlider visible: !content.usePaletteMap value: 0.5 - onValueChanged: if (_valueSet) root.color = Qt.hsla(hueSlider.value, saturationSlider.value, lightnessSlider.value, alphaSlider.value) + onValueChanged: if (_valueSet) root.currentColor = Qt.hsla(hueSlider.value, saturationSlider.value, lightnessSlider.value, alphaSlider.value) text: qsTr("Saturation") trackDelegate: Rectangle { rotation: -90 @@ -241,7 +242,7 @@ AbstractColorDialog { id: lightnessSlider visible: !content.usePaletteMap value: 0.5 - onValueChanged: if (_valueSet) root.color = Qt.hsla(hueSlider.value, saturationSlider.value, lightnessSlider.value, alphaSlider.value) + onValueChanged: if (_valueSet) root.currentColor = Qt.hsla(hueSlider.value, saturationSlider.value, lightnessSlider.value, alphaSlider.value) text: qsTr("Luminosity") trackDelegate: Rectangle { rotation: -90 @@ -259,7 +260,7 @@ AbstractColorDialog { minimum: 0.0 maximum: 1.0 value: 1.0 - onValueChanged: if (_valueSet) root.color = Qt.hsla(hueSlider.value, saturationSlider.value, lightnessSlider.value, alphaSlider.value) + onValueChanged: if (_valueSet) root.currentColor = Qt.hsla(hueSlider.value, saturationSlider.value, lightnessSlider.value, alphaSlider.value) text: qsTr("Alpha") visible: root.showAlphaChannel trackDelegate: Item { @@ -296,9 +297,9 @@ AbstractColorDialog { spacing: content.spacing TextField { id: colorField - text: root.color.toString() + text: root.currentColor.toString() anchors.verticalCenter: parent.verticalCenter - onAccepted: root.color = text + onAccepted: root.currentColor = text Component.onCompleted: width = implicitWidth + 10 } Image { diff --git a/src/imports/dialogs/qquickabstractcolordialog.cpp b/src/imports/dialogs/qquickabstractcolordialog.cpp index d565352af6..abac997ca6 100644 --- a/src/imports/dialogs/qquickabstractcolordialog.cpp +++ b/src/imports/dialogs/qquickabstractcolordialog.cpp @@ -109,6 +109,15 @@ void QQuickAbstractColorDialog::setColor(QColor arg) m_color = arg; emit colorChanged(); } + setCurrentColor(arg); +} + +void QQuickAbstractColorDialog::setCurrentColor(QColor currentColor) +{ + if (m_currentColor != currentColor) { + m_currentColor = currentColor; + emit currentColorChanged(); + } } void QQuickAbstractColorDialog::setShowAlphaChannel(bool arg) diff --git a/src/imports/dialogs/qquickabstractcolordialog_p.h b/src/imports/dialogs/qquickabstractcolordialog_p.h index bd23e0d1a4..ad2c7ce1ed 100644 --- a/src/imports/dialogs/qquickabstractcolordialog_p.h +++ b/src/imports/dialogs/qquickabstractcolordialog_p.h @@ -66,10 +66,11 @@ class QQuickAbstractColorDialog : public QQuickAbstractDialog Q_OBJECT Q_PROPERTY(bool showAlphaChannel READ showAlphaChannel WRITE setShowAlphaChannel NOTIFY showAlphaChannelChanged) Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) - Q_PROPERTY(qreal hue READ hue NOTIFY colorChanged) - Q_PROPERTY(qreal saturation READ saturation NOTIFY colorChanged) - Q_PROPERTY(qreal lightness READ lightness NOTIFY colorChanged) - Q_PROPERTY(qreal alpha READ alpha NOTIFY colorChanged) + Q_PROPERTY(QColor currentColor READ currentColor WRITE setCurrentColor NOTIFY currentColorChanged) + Q_PROPERTY(qreal currentHue READ currentHue NOTIFY currentColorChanged) + Q_PROPERTY(qreal currentSaturation READ currentSaturation NOTIFY currentColorChanged) + Q_PROPERTY(qreal currentLightness READ currentLightness NOTIFY currentColorChanged) + Q_PROPERTY(qreal currentAlpha READ currentAlpha NOTIFY currentColorChanged) public: QQuickAbstractColorDialog(QObject *parent = 0); @@ -78,27 +79,31 @@ public: virtual QString title() const; bool showAlphaChannel() const; QColor color() const { return m_color; } - qreal hue() const { return m_color.hslHueF(); } - qreal saturation() const { return m_color.hslSaturationF(); } - qreal lightness() const { return m_color.lightnessF(); } - qreal alpha() const { return m_color.alphaF(); } + QColor currentColor() const { return m_currentColor; } + qreal currentHue() const { return m_currentColor.hslHueF(); } + qreal currentSaturation() const { return m_currentColor.hslSaturationF(); } + qreal currentLightness() const { return m_currentColor.lightnessF(); } + qreal currentAlpha() const { return m_currentColor.alphaF(); } public Q_SLOTS: void setVisible(bool v); void setModality(Qt::WindowModality m); void setTitle(const QString &t); void setColor(QColor arg); + void setCurrentColor(QColor currentColor); void setShowAlphaChannel(bool arg); Q_SIGNALS: void showAlphaChannelChanged(); void colorChanged(); + void currentColorChanged(); void selectionAccepted(); protected: QPlatformColorDialogHelper *m_dlgHelper; QSharedPointer<QColorDialogOptions> m_options; QColor m_color; + QColor m_currentColor; Q_DISABLE_COPY(QQuickAbstractColorDialog) }; diff --git a/src/imports/dialogs/qquickplatformcolordialog.cpp b/src/imports/dialogs/qquickplatformcolordialog.cpp index 8dc6d09f2c..9de9b7a553 100644 --- a/src/imports/dialogs/qquickplatformcolordialog.cpp +++ b/src/imports/dialogs/qquickplatformcolordialog.cpp @@ -166,7 +166,7 @@ QPlatformColorDialogHelper *QQuickPlatformColorDialog::helper() return m_dlgHelper; connect(m_dlgHelper, SIGNAL(accept()), this, SLOT(accept())); connect(m_dlgHelper, SIGNAL(reject()), this, SLOT(reject())); - connect(m_dlgHelper, SIGNAL(currentColorChanged(QColor)), this, SLOT(setColor(QColor))); + connect(m_dlgHelper, SIGNAL(currentColorChanged(QColor)), this, SLOT(setCurrentColor(QColor))); connect(m_dlgHelper, SIGNAL(colorSelected(QColor)), this, SLOT(setColor(QColor))); } @@ -232,6 +232,23 @@ QPlatformColorDialogHelper *QQuickPlatformColorDialog::helper() \qmlproperty color ColorDialog::color The color which the user selected. + + \note This color is not always the same as the color held by the + currentColor property since the user can choose different colors before + finally selecting the one to use. + + \sa currentColor +*/ + +/*! + \qmlproperty color ColorDialog::currentColor + + The color which the user has currently selected. + + For the color that is set when the dialog is accepted, use the \l color + property. + + \sa color */ QT_END_NAMESPACE diff --git a/src/imports/widgets/qquickqcolordialog.cpp b/src/imports/widgets/qquickqcolordialog.cpp index d10eacee60..ee27d147e7 100644 --- a/src/imports/widgets/qquickqcolordialog.cpp +++ b/src/imports/widgets/qquickqcolordialog.cpp @@ -163,7 +163,7 @@ QPlatformColorDialogHelper *QQuickQColorDialog::helper() if (!m_dlgHelper) { m_dlgHelper = new QColorDialogHelper(); - connect(m_dlgHelper, SIGNAL(currentColorChanged(const QColor&)), this, SLOT(setColor(QColor))); + connect(m_dlgHelper, SIGNAL(currentColorChanged(const QColor&)), this, SLOT(setCurrentColor(QColor))); connect(m_dlgHelper, SIGNAL(colorSelected(const QColor&)), this, SLOT(setColor(QColor))); connect(m_dlgHelper, SIGNAL(accept()), this, SLOT(accept())); connect(m_dlgHelper, SIGNAL(reject()), this, SLOT(reject())); |