Add ColorDialog to QtQuick.Dialogs
authorShawn Rutledge <shawn.rutledge@digia.com>
Mon, 11 Mar 2013 10:05:30 +0000 (11:05 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Mon, 18 Mar 2013 12:44:38 +0000 (13:44 +0100)
As with FileDialog, it tries QPA, then QColorDialog, and falls back to
a QML implementation (which is also provided here) if neither type of
native dialog is available.

Change-Id: I384928e1f7322bb6b867d4618d07c88c70e3cbfe
Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com>
23 files changed:
examples/quick/dialogs/ColorDialogs.qml [new file with mode: 0644]
src/imports/dialogs/DefaultColorDialog.qml [new file with mode: 0644]
src/imports/dialogs/WidgetColorDialog.qml [new file with mode: 0644]
src/imports/dialogs/dialogs.pro
src/imports/dialogs/images/checkers.png [new file with mode: 0644]
src/imports/dialogs/images/copy.png [new file with mode: 0644]
src/imports/dialogs/images/crosshairs.png [new file with mode: 0644]
src/imports/dialogs/images/slider_handle.png [new file with mode: 0644]
src/imports/dialogs/images/sunken_frame.png [new file with mode: 0644]
src/imports/dialogs/plugin.cpp
src/imports/dialogs/qml/ColorSlider.qml [new file with mode: 0755]
src/imports/dialogs/qml/TextField.qml
src/imports/dialogs/qml/qmldir
src/imports/dialogs/qquickabstractcolordialog.cpp [new file with mode: 0644]
src/imports/dialogs/qquickabstractcolordialog_p.h [new file with mode: 0644]
src/imports/dialogs/qquickcolordialog.cpp [new file with mode: 0644]
src/imports/dialogs/qquickcolordialog_p.h [new file with mode: 0644]
src/imports/dialogs/qquickplatformcolordialog.cpp [new file with mode: 0644]
src/imports/dialogs/qquickplatformcolordialog_p.h [new file with mode: 0644]
src/imports/widgets/qquickqcolordialog.cpp [new file with mode: 0644]
src/imports/widgets/qquickqcolordialog_p.h [new file with mode: 0644]
src/imports/widgets/widgets.pro
src/imports/widgets/widgetsplugin.cpp

diff --git a/examples/quick/dialogs/ColorDialogs.qml b/examples/quick/dialogs/ColorDialogs.qml
new file mode 100644 (file)
index 0000000..7817c8e
--- /dev/null
@@ -0,0 +1,109 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+**   * Redistributions of source code must retain the above copyright
+**     notice, this list of conditions and the following disclaimer.
+**   * Redistributions in binary form must reproduce the above copyright
+**     notice, this list of conditions and the following disclaimer in
+**     the documentation and/or other materials provided with the
+**     distribution.
+**   * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+**     of its contributors may be used to endorse or promote products derived
+**     from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+import QtQuick.Dialogs 1.0
+import "../shared"
+
+Rectangle {
+    width: 320
+    height: 200
+    color: palette.window
+
+    SystemPalette { id: palette }
+
+    ColorDialog {
+        id: colorDialog
+        visible: colorDialogVisible.checked
+        modality: colorDialogModal.checked ? Qt.WindowModal : Qt.NonModal
+        title: "Choose a color"
+        color: "green"
+        showAlphaChannel: colorDialogAlpha.checked
+        onAccepted: { console.log("Accepted: " + color) }
+        onRejected: { console.log("Rejected") }
+    }
+
+    Column {
+        anchors.fill: parent
+        anchors.margins: 8
+        spacing: 8
+        Text {
+            font.bold: true
+            text: "Color dialog properties:"
+        }
+        CheckBox {
+            id: colorDialogModal
+            text: "Modal"
+            checked: true
+            Binding on checked { value: colorDialog.modality != Qt.NonModal }
+        }
+        CheckBox {
+            id: colorDialogAlpha
+            text: "Show alpha channel"
+            Binding on checked { value: colorDialog.showAlphaChannel }
+        }
+        CheckBox {
+            id: colorDialogVisible
+            text: "Visible"
+            Binding on checked { value: colorDialog.visible }
+        }
+        Row {
+            id: colorRow
+            spacing: parent.spacing
+            height: colorLabel.implicitHeight * 2.0
+            Rectangle {
+                color: colorDialog.color
+                height: parent.height
+                width: height * 2
+                border.color: "black"
+                MouseArea {
+                    anchors.fill: parent
+                    onClicked: colorDialog.open()
+                }
+            }
+            Text {
+                id: colorLabel
+                color: palette.windowText
+                text: "<b>current color:</b> " + colorDialog.color
+                anchors.verticalCenter: parent.verticalCenter
+            }
+        }
+    }
+}
diff --git a/src/imports/dialogs/DefaultColorDialog.qml b/src/imports/dialogs/DefaultColorDialog.qml
new file mode 100644 (file)
index 0000000..7322aa1
--- /dev/null
@@ -0,0 +1,316 @@
+/*****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtQuick.Dialogs module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+**   * Redistributions of source code must retain the above copyright
+**     notice, this list of conditions and the following disclaimer.
+**   * Redistributions in binary form must reproduce the above copyright
+**     notice, this list of conditions and the following disclaimer in
+**     the documentation and/or other materials provided with the
+**     distribution.
+**   * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+**     of its contributors may be used to endorse or promote products derived
+**     from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+*****************************************************************************/
+
+import QtQuick 2.1
+import QtQuick.Dialogs 1.0
+import "qml"
+
+AbstractColorDialog {
+    id: root
+
+    Rectangle {
+        id: content
+        width: 320
+        height: (usePaletteMap ? width : 0) + bottomMinHeight
+        color: palette.window
+        property real bottomMinHeight: sliders.height + buttonRow.height + outerSpacing * 3
+        property real spacing: 8
+        property real outerSpacing: 12
+        property bool usePaletteMap: true
+        property bool inited: false
+
+        SystemPalette { id: palette }
+
+        Binding {
+            target: root
+            property: "color"
+            value: Qt.hsla(hueSlider.value, saturationSlider.value, lightnessSlider.value, alphaSlider.value)
+        }
+
+        Item {
+            id: paletteFrame
+            visible: content.usePaletteMap
+            anchors {
+                top: parent.top
+                left: parent.left
+                right: parent.right
+                margins: content.outerSpacing
+            }
+            height: Math.min(content.height - content.bottomMinHeight, content.width - content.outerSpacing * 2)
+
+            Image {
+                id: paletteMap
+                x: (parent.width - width) / 2
+                width: height
+                height: parent.height
+                source: "images/checkers.png"
+                fillMode: Image.Tile
+
+                // note we smoothscale the shader from a smaller version to improve performance
+                ShaderEffect {
+                    id: map
+                    width: 64
+                    height: 64
+                    opacity: alphaSlider.value
+                    scale: paletteMap.width / width;
+                    layer.enabled: true
+                    layer.smooth: true
+                    anchors.centerIn: parent
+                    property real hue: hueSlider.value
+
+                    fragmentShader: "
+                    varying mediump vec2 qt_TexCoord0;
+                    uniform highp float qt_Opacity;
+                    uniform highp float hue;
+
+                    highp float hueToIntensity(highp float v1, highp float v2, highp float h) {
+                        h = fract(h);
+                        if (h < 1.0 / 6.0)
+                            return v1 + (v2 - v1) * 6.0 * h;
+                        else if (h < 1.0 / 2.0)
+                            return v2;
+                        else if (h < 2.0 / 3.0)
+                            return v1 + (v2 - v1) * 6.0 * (2.0 / 3.0 - h);
+
+                        return v1;
+                    }
+
+                    highp vec3 HSLtoRGB(highp vec3 color) {
+                        highp float h = color.x;
+                        highp float l = color.z;
+                        highp float s = color.y;
+
+                        if (s < 1.0 / 256.0)
+                            return vec3(l, l, l);
+
+                        highp float v1;
+                        highp float v2;
+                        if (l < 0.5)
+                            v2 = l * (1.0 + s);
+                        else
+                            v2 = (l + s) - (s * l);
+
+                        v1 = 2.0 * l - v2;
+
+                        highp float d = 1.0 / 3.0;
+                        highp float r = hueToIntensity(v1, v2, h + d);
+                        highp float g = hueToIntensity(v1, v2, h);
+                        highp float b = hueToIntensity(v1, v2, h - d);
+                        return vec3(r, g, b);
+                    }
+
+                    void main() {
+                        lowp vec4 c = vec4(1.0);
+                        c.rgb = HSLtoRGB(vec3(hue, 1.0 - qt_TexCoord0.t, qt_TexCoord0.s));
+                        gl_FragColor = c * qt_Opacity;
+                    }
+                    "
+                }
+
+                MouseArea {
+                    id: mapMouseArea
+                    anchors.fill: parent
+                    onPositionChanged: {
+                        if (pressed && containsMouse) {
+                            var xx = Math.max(0, Math.min(mouse.x, parent.width))
+                            var yy = Math.max(0, Math.min(mouse.y, parent.height))
+                            saturationSlider.value = 1.0 - yy / parent.height
+                            lightnessSlider.value = xx / parent.width
+                            // TODO if we constrain the movement here, can avoid the containsMouse test
+                            crosshairs.x = mouse.x - crosshairs.radius
+                            crosshairs.y = mouse.y - crosshairs.radius
+                        }
+                    }
+                    onPressed: positionChanged(mouse)
+                }
+
+                Image {
+                    id: crosshairs
+                    property int radius: width / 2 // truncated to int
+                    source: "images/crosshairs.png"
+                }
+
+                BorderImage {
+                    anchors.fill: parent
+                    anchors.margins: -1
+                    anchors.leftMargin: -2
+                    source: "images/sunken_frame.png"
+                    border.left: 8
+                    border.right: 8
+                    border.top: 8
+                    border.bottom: 8
+                }
+            }
+        }
+
+        Column {
+            id: sliders
+            anchors {
+                top: paletteFrame.bottom
+                left: parent.left
+                right: parent.right
+                margins: content.outerSpacing
+            }
+            spacing: content.spacing
+
+            ColorSlider {
+                id: hueSlider
+                value: 0.5
+                text: qsTr("Hue")
+                trackDelegate: Rectangle {
+                    rotation: -90
+                    transformOrigin: Item.TopLeft
+                    gradient: Gradient {
+                        GradientStop {position: 0.000; color: Qt.rgba(1, 0, 0, 1)}
+                        GradientStop {position: 0.167; color: Qt.rgba(1, 1, 0, 1)}
+                        GradientStop {position: 0.333; color: Qt.rgba(0, 1, 0, 1)}
+                        GradientStop {position: 0.500; color: Qt.rgba(0, 1, 1, 1)}
+                        GradientStop {position: 0.667; color: Qt.rgba(0, 0, 1, 1)}
+                        GradientStop {position: 0.833; color: Qt.rgba(1, 0, 1, 1)}
+                        GradientStop {position: 1.000; color: Qt.rgba(1, 0, 0, 1)}
+                    }
+                }
+            }
+
+            ColorSlider {
+                id: saturationSlider
+                visible: !content.usePaletteMap
+                value: 0.5
+                text: qsTr("Saturation")
+                trackDelegate: Rectangle {
+                    rotation: -90
+                    transformOrigin: Item.TopLeft
+                    gradient: Gradient {
+                        GradientStop { position: 0; color: Qt.hsla(hueSlider.value, 0.0, lightnessSlider.value, 1.0) }
+                        GradientStop { position: 1; color: Qt.hsla(hueSlider.value, 1.0, lightnessSlider.value, 1.0) }
+                    }
+                }
+            }
+
+            ColorSlider {
+                id: lightnessSlider
+                visible: !content.usePaletteMap
+                value: 0.5
+                text: qsTr("Luminosity")
+                trackDelegate: Rectangle {
+                    rotation: -90
+                    transformOrigin: Item.TopLeft
+                    gradient: Gradient {
+                        GradientStop { position: 0; color: "black" }
+                        GradientStop { position: 0.5; color: Qt.hsla(hueSlider.value, saturationSlider.value, 0.5, 1.0) }
+                        GradientStop { position: 1; color: "white" }
+                    }
+                }
+            }
+
+            ColorSlider {
+                id: alphaSlider
+                minimum: 0.0
+                maximum: 1.0
+                value: 1.0
+                text: qsTr("Alpha")
+                visible: root.showAlphaChannel
+                trackDelegate: Item {
+                    rotation: -90
+                    transformOrigin: Item.TopLeft
+                    Image {
+                        anchors {fill: parent}
+                        source: "images/checkers.png"
+                        fillMode: Image.TileVertically
+                    }
+                    Rectangle {
+                        anchors.fill: parent
+                        gradient: Gradient {
+                            GradientStop { position: 0; color: "transparent" }
+                            GradientStop { position: 1; color: Qt.hsla(hueSlider.value,
+                                                                       saturationSlider.value,
+                                                                       lightnessSlider.value, 1.0) }
+                        }                    }
+                }
+            }
+        }
+
+        Item {
+            id: buttonRow
+            height: buttonsOnly.height
+            width: parent.width
+            anchors {
+                left: parent.left
+                right: parent.right
+                bottom: content.bottom
+                margins: content.outerSpacing
+            }
+            Row {
+                spacing: content.spacing
+                TextField {
+                    id: colorField
+                    text: root.color
+                    anchors.verticalCenter: parent.verticalCenter
+                    onAccepted:  root.color = text
+                    Component.onCompleted: width = implicitWidth + 10
+                }
+                Image {
+                    id: copyIcon
+                    anchors.verticalCenter: parent.verticalCenter
+                    source: "images/copy.png"
+                    MouseArea {
+                        anchors.fill: parent
+                        onClicked: colorField.copyAll()
+                    }
+                }
+            }
+            Row {
+                id: buttonsOnly
+                spacing: content.spacing
+                anchors.right: parent.right
+                Button {
+                    id: cancelButton
+                    text: "Cancel"
+                    onClicked: root.reject()
+                }
+                Button {
+                    id: okButton
+                    text: "OK"
+                    onClicked: root.accept()
+                }
+            }
+        }
+    }
+}
diff --git a/src/imports/dialogs/WidgetColorDialog.qml b/src/imports/dialogs/WidgetColorDialog.qml
new file mode 100644 (file)
index 0000000..ed7c7ab
--- /dev/null
@@ -0,0 +1,44 @@
+/*****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtQuick.Dialogs module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+**   * Redistributions of source code must retain the above copyright
+**     notice, this list of conditions and the following disclaimer.
+**   * Redistributions in binary form must reproduce the above copyright
+**     notice, this list of conditions and the following disclaimer in
+**     the documentation and/or other materials provided with the
+**     distribution.
+**   * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+**     of its contributors may be used to endorse or promote products derived
+**     from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+*****************************************************************************/
+
+import QtQuick 2.1
+import QtQuick.PrivateWidgets 1.0
+
+QtColorDialog { }
index ec425c1..b7704da 100644 (file)
@@ -7,6 +7,9 @@ SOURCES += \
     qquickabstractfiledialog.cpp \
     qquickplatformfiledialog.cpp \
     qquickfiledialog.cpp \
+    qquickabstractcolordialog.cpp \
+    qquickplatformcolordialog.cpp \
+    qquickcolordialog.cpp \
     qquickabstractdialog.cpp \
     plugin.cpp
 
@@ -14,14 +17,25 @@ HEADERS += \
     qquickabstractfiledialog_p.h \
     qquickplatformfiledialog_p.h \
     qquickfiledialog_p.h \
+    qquickabstractcolordialog_p.h \
+    qquickplatformcolordialog_p.h \
+    qquickcolordialog_p.h \
     qquickabstractdialog_p.h
 
 QML_FILES += \
     DefaultFileDialog.qml \
     WidgetFileDialog.qml \
+    DefaultColorDialog.qml \
+    WidgetColorDialog.qml \
     qml/Button.qml \
+    qml/ColorSlider.qml \
     qml/TextField.qml \
     qml/qmldir \
+    images/checkers.png \
+    images/copy.png \
+    images/crosshairs.png \
+    images/slider_handle.png \
+    images/sunken_frame.png \
     images/folder.png \
     images/up.png
 
diff --git a/src/imports/dialogs/images/checkers.png b/src/imports/dialogs/images/checkers.png
new file mode 100644 (file)
index 0000000..458d33d
Binary files /dev/null and b/src/imports/dialogs/images/checkers.png differ
diff --git a/src/imports/dialogs/images/copy.png b/src/imports/dialogs/images/copy.png
new file mode 100644 (file)
index 0000000..2aeb282
Binary files /dev/null and b/src/imports/dialogs/images/copy.png differ
diff --git a/src/imports/dialogs/images/crosshairs.png b/src/imports/dialogs/images/crosshairs.png
new file mode 100644 (file)
index 0000000..9a61946
Binary files /dev/null and b/src/imports/dialogs/images/crosshairs.png differ
diff --git a/src/imports/dialogs/images/slider_handle.png b/src/imports/dialogs/images/slider_handle.png
new file mode 100644 (file)
index 0000000..e3b9654
Binary files /dev/null and b/src/imports/dialogs/images/slider_handle.png differ
diff --git a/src/imports/dialogs/images/sunken_frame.png b/src/imports/dialogs/images/sunken_frame.png
new file mode 100644 (file)
index 0000000..178c309
Binary files /dev/null and b/src/imports/dialogs/images/sunken_frame.png differ
index f7d72bf..67653e5 100644 (file)
@@ -44,6 +44,9 @@
 #include "qquickfiledialog_p.h"
 #include "qquickabstractfiledialog_p.h"
 #include "qquickplatformfiledialog_p.h"
+#include "qquickcolordialog_p.h"
+#include "qquickabstractcolordialog_p.h"
+#include "qquickplatformcolordialog_p.h"
 #include <private/qguiapplication_p.h>
 
 //#define PURE_QML_ONLY
@@ -95,6 +98,15 @@ public:
 #endif
             registerWidgetOrQmlImplementation<QQuickFileDialog>(widgetsDir, "WidgetFileDialog.qml",
                 qmlDir, "DefaultFileDialog.qml", "FileDialog", uri);
+
+        // ColorDialog
+#ifndef PURE_QML_ONLY
+        if (QGuiApplicationPrivate::platformTheme()->usePlatformNativeDialog(QPlatformTheme::ColorDialog))
+            qmlRegisterType<QQuickPlatformColorDialog>(uri, DIALOGS_MAJOR_MINOR, "ColorDialog");
+        else
+#endif
+            registerWidgetOrQmlImplementation<QQuickColorDialog>(widgetsDir, "WidgetColorDialog.qml",
+                qmlDir, "DefaultColorDialog.qml", "ColorDialog", uri);
     }
 
 protected:
diff --git a/src/imports/dialogs/qml/ColorSlider.qml b/src/imports/dialogs/qml/ColorSlider.qml
new file mode 100755 (executable)
index 0000000..8fc9717
--- /dev/null
@@ -0,0 +1,138 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Graphical Effects module.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+**   * Redistributions of source code must retain the above copyright
+**     notice, this list of conditions and the following disclaimer.
+**   * Redistributions in binary form must reproduce the above copyright
+**     notice, this list of conditions and the following disclaimer in
+**     the documentation and/or other materials provided with the
+**     distribution.
+**   * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+**     of its contributors may be used to endorse or promote products derived
+**     from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.1
+
+Item {
+    id: colorSlider
+
+    property real value: 1
+    property real maximum: 1
+    property real minimum: 0
+    property string text: ""
+    property bool pressed: mouseArea.pressed
+    property bool integer: false
+    property Component trackDelegate
+    property string handleSource: "../images/slider_handle.png"
+
+    width: parent.width
+    height: handle.height + textText.implicitHeight
+
+    function updatePos() {
+        if (maximum > minimum) {
+            var pos = (track.width - 10) * (value - minimum) / (maximum - minimum) + 5;
+            return Math.min(Math.max(pos, 5), track.width - 5) - 10;
+        } else {
+            return 5;
+        }
+    }
+
+    SystemPalette { id: palette }
+
+    Column {
+        id: column
+        width: parent.width
+        spacing: 12
+        Text {
+            id: textText
+            anchors.horizontalCenter: parent.horizontalCenter
+            text: colorSlider.text
+            anchors.left: parent.left
+            color: palette.windowText
+        }
+
+        Item {
+            id: track
+            height: 8
+            anchors.left: parent.left
+            anchors.right: parent.right
+
+            Loader {
+                sourceComponent: trackDelegate
+                width: parent.height
+                height: parent.width
+                y: width
+            }
+
+            BorderImage {
+                source: "../images/sunken_frame.png"
+                border.left: 8
+                border.right: 8
+                border.top:8
+                border.bottom: 8
+                anchors.fill: track
+                anchors.margins: -1
+                anchors.topMargin: -2
+                anchors.leftMargin: -2
+            }
+
+            Image {
+                id: handle
+                anchors.verticalCenter: parent.verticalCenter
+                smooth: true
+                source: "../images/slider_handle.png"
+                x: updatePos() - 8
+                z: 1
+            }
+
+            MouseArea {
+                id: mouseArea
+                anchors {left: parent.left; right: parent.right; verticalCenter: parent.verticalCenter}
+                height: handle.height
+                width: handle.width
+                preventStealing: true
+
+                onPressed: {
+                    var handleX = Math.max(0, Math.min(mouseX, mouseArea.width))
+                    var realValue = (maximum - minimum) * handleX / mouseArea.width + minimum;
+                    value = colorSlider.integer ? Math.round(realValue) : realValue;
+                }
+
+                onPositionChanged: {
+                    if (pressed) {
+                        var handleX = Math.max(0, Math.min(mouseX, mouseArea.width))
+                        var realValue = (maximum - minimum) * handleX / mouseArea.width + minimum;
+                        value = colorSlider.integer ? Math.round(realValue) : realValue;
+                    }
+                }
+            }
+        }
+    }
+}
index 89487e8..baa469c 100644 (file)
@@ -45,11 +45,20 @@ Item {
 
     property alias textInput: textInput
     property alias text: textInput.text
+    property real implicitWidth: textInput.implicitWidth + rect.radius * 2
+    property real implicitHeight: textInput.implicitHeight + rect.radius * 2
     signal accepted
     signal downPressed
 
+    function copyAll() {
+        textInput.selectAll()
+        textInput.copy()
+    }
+
     SystemPalette { id: palette }
-    height: textInput.implicitHeight + 4
+    height: textInput.implicitHeight + 8
+    clip: true
+
     Rectangle {
         id: rect
         anchors.fill: parent
@@ -62,6 +71,8 @@ Item {
         id: textInput
         color: palette.text
         anchors.fill: parent
+        anchors.leftMargin: rect.radius
+        anchors.rightMargin: rect.radius
         verticalAlignment: Text.AlignVCenter
         onAccepted: root.accepted()
         Keys.onDownPressed: root.downPressed()
index 85575c7..c475502 100644 (file)
@@ -1,2 +1,3 @@
 Button 1.0 Button.qml
+ColorSlider 1.0 ColorSlider.qml
 TextField 1.0 TextField.qml
diff --git a/src/imports/dialogs/qquickabstractcolordialog.cpp b/src/imports/dialogs/qquickabstractcolordialog.cpp
new file mode 100644 (file)
index 0000000..9a9f3bc
--- /dev/null
@@ -0,0 +1,115 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtQuick.Dialogs module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.  For licensing terms and
+** conditions see http://qt.digia.com/licensing.  For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights.  These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qquickabstractcolordialog_p.h"
+#include "qquickitem.h"
+
+#include <private/qguiapplication_p.h>
+#include <QWindow>
+#include <QQuickWindow>
+
+QT_BEGIN_NAMESPACE
+
+QQuickAbstractColorDialog::QQuickAbstractColorDialog(QObject *parent)
+    : QQuickAbstractDialog(parent)
+    , m_dlgHelper(0)
+    , m_options(QSharedPointer<QColorDialogOptions>(new QColorDialogOptions()))
+{
+    // On the Mac, modality doesn't work unless you call exec().  But this is a reasonable default anyway.
+    m_modality = Qt::NonModal;
+    connect(this, SIGNAL(accepted()), this, SIGNAL(selectionAccepted()));
+}
+
+QQuickAbstractColorDialog::~QQuickAbstractColorDialog()
+{
+}
+
+void QQuickAbstractColorDialog::setVisible(bool v)
+{
+    if (helper() && v) {
+        m_dlgHelper->setOptions(m_options);
+    }
+    QQuickAbstractDialog::setVisible(v);
+}
+
+void QQuickAbstractColorDialog::setModality(Qt::WindowModality m)
+{
+#ifdef Q_OS_MAC
+    // On the Mac, modality doesn't work unless you call exec()
+    m_modality = Qt::NonModal;
+    emit modalityChanged();
+    return;
+#endif
+    QQuickAbstractDialog::setModality(m);
+}
+
+QString QQuickAbstractColorDialog::title() const
+{
+    return m_options->windowTitle();
+}
+
+bool QQuickAbstractColorDialog::showAlphaChannel() const
+{
+    return m_options->testOption(QColorDialogOptions::ShowAlphaChannel);
+}
+
+void QQuickAbstractColorDialog::setTitle(QString t)
+{
+    if (m_options->windowTitle() == t) return;
+    m_options->setWindowTitle(t);
+    emit titleChanged();
+}
+
+void QQuickAbstractColorDialog::setColor(QColor arg)
+{
+    if (m_color != arg) {
+        m_color = arg;
+        emit colorChanged();
+    }
+}
+
+void QQuickAbstractColorDialog::setShowAlphaChannel(bool arg)
+{
+    m_options->setOption(QColorDialogOptions::ShowAlphaChannel, arg);
+    emit showAlphaChannelChanged();
+}
+
+QT_END_NAMESPACE
diff --git a/src/imports/dialogs/qquickabstractcolordialog_p.h b/src/imports/dialogs/qquickabstractcolordialog_p.h
new file mode 100644 (file)
index 0000000..3301605
--- /dev/null
@@ -0,0 +1,100 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtQuick.Dialogs module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.  For licensing terms and
+** conditions see http://qt.digia.com/licensing.  For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights.  These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQUICKABSTRACTCOLORDIALOG_P_H
+#define QQUICKABSTRACTCOLORDIALOG_P_H
+
+//
+//  W A R N I N G
+//  -------------
+//
+// This file is not part of the Qt API.  It exists purely as an
+// implementation detail.  This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtQml>
+#include <QQuickView>
+#include <QtGui/qpa/qplatformdialoghelper.h>
+#include <qpa/qplatformtheme.h>
+#include "qquickabstractdialog_p.h"
+
+QT_BEGIN_NAMESPACE
+
+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)
+
+public:
+    QQuickAbstractColorDialog(QObject *parent = 0);
+    virtual ~QQuickAbstractColorDialog();
+
+    virtual QString title() const;
+    bool showAlphaChannel() const;
+    QColor color() const { return m_color; }
+
+public Q_SLOTS:
+    void setVisible(bool v);
+    void setModality(Qt::WindowModality m);
+    void setTitle(QString t);
+    void setColor(QColor arg);
+    void setShowAlphaChannel(bool arg);
+
+Q_SIGNALS:
+    void showAlphaChannelChanged();
+    void colorChanged();
+    void selectionAccepted();
+
+protected:
+    QPlatformColorDialogHelper *m_dlgHelper;
+    QSharedPointer<QColorDialogOptions> m_options;
+    QColor m_color;
+
+    Q_DISABLE_COPY(QQuickAbstractColorDialog)
+};
+
+QT_END_NAMESPACE
+
+#endif // QQUICKABSTRACTCOLORDIALOG_P_H
diff --git a/src/imports/dialogs/qquickcolordialog.cpp b/src/imports/dialogs/qquickcolordialog.cpp
new file mode 100644 (file)
index 0000000..39af997
--- /dev/null
@@ -0,0 +1,125 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtQuick.Dialogs module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.  For licensing terms and
+** conditions see http://qt.digia.com/licensing.  For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights.  These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qquickcolordialog_p.h"
+#include <QQuickItem>
+#include <private/qguiapplication_p.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+    \qmltype AbstractColorDialog
+    \instantiates QQuickColorDialog
+    \inqmlmodule QtQuick.Dialogs 1
+    \ingroup qtquick-visual
+    \brief API wrapper for QML file dialog implementations
+    \since 5.1
+    \internal
+
+    AbstractColorDialog provides only the API for implementing a color dialog.
+    The implementation (e.g. a Window or preferably an Item, in case it is
+    shown on a device that doesn't support multiple windows) can be provided as
+    \l implementation, which is the default property (the only allowed child
+    element).
+*/
+
+/*!
+    \qmlsignal QtQuick::Dialogs::AbstractColorDialog::accepted
+
+    The \a accepted signal is emitted by \l accept().
+*/
+
+/*!
+    \qmlsignal QtQuick::Dialogs::AbstractColorDialog::rejected
+
+    The \a accepted signal is emitted by \l reject().
+*/
+
+/*!
+    \class QQuickColorDialog
+    \inmodule QtQuick.Dialogs
+    \internal
+
+    The QQuickColorDialog class is a concrete subclass of
+    \l QQuickAbstractColorDialog, but it is abstract from the QML perspective
+    because it needs to enclose a graphical implementation. It exists in order
+    to provide accessors and helper functions which the QML implementation will
+    need.
+
+    \since 5.1
+*/
+
+/*!
+    Constructs a file dialog wrapper with parent window \a parent.
+*/
+QQuickColorDialog::QQuickColorDialog(QObject *parent)
+    : QQuickAbstractColorDialog(parent)
+{
+}
+
+
+/*!
+    Destroys the file dialog wrapper.
+*/
+QQuickColorDialog::~QQuickColorDialog()
+{
+}
+
+/*!
+    \qmlproperty bool AbstractColorDialog::visible
+
+    This property holds whether the dialog is visible. By default this is false.
+*/
+
+/*!
+    \qmlproperty bool AbstractColorDialog::filePaths
+
+    A list of files to be populated as the user chooses.
+*/
+
+/*!
+    \qmlproperty QObject AbstractColorDialog::implementation
+
+    The QML object which implements the actual file dialog. Should be either a
+    \l Window or an \l Item.
+*/
+
+QT_END_NAMESPACE
diff --git a/src/imports/dialogs/qquickcolordialog_p.h b/src/imports/dialogs/qquickcolordialog_p.h
new file mode 100644 (file)
index 0000000..ff6953f
--- /dev/null
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtQuick.Dialogs module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.  For licensing terms and
+** conditions see http://qt.digia.com/licensing.  For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights.  These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQUICKCOLORDIALOG_P_H
+#define QQUICKCOLORDIALOG_P_H
+
+//
+//  W A R N I N G
+//  -------------
+//
+// This file is not part of the Qt API.  It exists purely as an
+// implementation detail.  This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qquickabstractcolordialog_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QQuickColorDialog : public QQuickAbstractColorDialog
+{
+    Q_OBJECT
+    Q_PROPERTY(QObject* implementation READ qmlImplementation WRITE setQmlImplementation DESIGNABLE false)
+    Q_CLASSINFO("DefaultProperty", "implementation")    // AbstractColorDialog in QML can have only one child
+
+public:
+    explicit QQuickColorDialog(QObject *parent = 0);
+    ~QQuickColorDialog();
+
+protected:
+    virtual QPlatformColorDialogHelper *helper() { return 0; }
+
+    Q_DISABLE_COPY(QQuickColorDialog)
+};
+
+QT_END_NAMESPACE
+
+QML_DECLARE_TYPE(QQuickColorDialog *)
+
+#endif // QQUICKCOLORDIALOG_P_H
diff --git a/src/imports/dialogs/qquickplatformcolordialog.cpp b/src/imports/dialogs/qquickplatformcolordialog.cpp
new file mode 100644 (file)
index 0000000..491a2e6
--- /dev/null
@@ -0,0 +1,237 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtQuick.Dialogs module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.  For licensing terms and
+** conditions see http://qt.digia.com/licensing.  For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights.  These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qquickplatformcolordialog_p.h"
+#include "qquickitem.h"
+
+#include <private/qguiapplication_p.h>
+#include <QWindow>
+#include <QQuickView>
+#include <QQuickWindow>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+    \qmltype ColorDialog
+    \instantiates QQuickPlatformColorDialog
+    \inqmlmodule QtQuick.Dialogs 1
+    \ingroup qtquick-visual
+    \brief Dialog component for choosing a color.
+    \since Qt 5.1
+
+    ColorDialog allows the user to select a color. The dialog is initially
+    invisible. You need to set the properties as desired first, then set
+    \l visible to true or call \l open().
+
+    Here is a minimal example to open a color dialog and exit after the user
+    chooses a color:
+
+    \qml
+    import QtQuick 2.1
+    import QtQuick.Dialogs 1.0
+
+    ColorDialog {
+        id: colorDialog
+        title: "Please choose a color"
+        onAccepted: {
+            console.log("You chose: " + colorDialog.color)
+            Qt.quit()
+        }
+        onRejected: {
+            console.log("Canceled")
+            Qt.quit()
+        }
+        Component.onCompleted: visible = true
+    }
+    \endqml
+
+    A ColorDialog window is automatically transient for its parent window. So
+    whether you declare the dialog inside an \l Item or inside a \l Window, the
+    dialog will appear centered over the window containing the item, or over
+    the Window that you declared.
+
+    The implementation of ColorDialog will be a platform color dialog if
+    possible. If that isn't possible, then it will try to instantiate a
+    \l QColorDialog. If that also isn't possible, then it will fall back to a QML
+    implementation, DefaultColorDialog.qml. In that case you can customize the
+    appearance by editing this file. DefaultColorDialog.qml contains a Rectangle
+    to hold the dialog's contents, because certain embedded systems do not
+    support multiple top-level windows. When the dialog becomes visible, it
+    will automatically be wrapped in a Window if possible, or simply reparented
+    on top of the main window if there can only be one window.
+*/
+
+/*!
+    \qmlsignal QtQuick::Dialogs::ColorDialog::accepted
+
+    The \a accepted signal is emitted when the user has finished using the
+    dialog. You can then inspect the \a color property to get the selection.
+
+    Example:
+
+    \qml
+    ColorDialog {
+        onAccepted: { console.log("Selected color: " + color) }
+    }
+    \endqml
+*/
+
+/*!
+    \qmlsignal QtQuick::Dialogs::ColorDialog::rejected
+
+    The \a rejected signal is emitted when the user has dismissed the dialog,
+    either by closing the dialog window or by pressing the Cancel button.
+*/
+
+/*!
+    \class QQuickPlatformColorDialog
+    \inmodule QtQuick.Dialogs
+    \internal
+
+    \brief The QQuickPlatformColorDialog class provides a color dialog
+
+    The dialog is implemented via the QPlatformColorDialogHelper when possible;
+    otherwise it falls back to a QColorDialog or a QML implementation.
+
+    \since 5.1
+*/
+
+/*!
+    Constructs a color dialog with parent window \a parent.
+*/
+QQuickPlatformColorDialog::QQuickPlatformColorDialog(QObject *parent) :
+    QQuickAbstractColorDialog(parent)
+{
+}
+
+/*!
+    Destroys the color dialog.
+*/
+QQuickPlatformColorDialog::~QQuickPlatformColorDialog()
+{
+    if (m_dlgHelper)
+        m_dlgHelper->hide();
+    delete m_dlgHelper;
+}
+
+QPlatformColorDialogHelper *QQuickPlatformColorDialog::helper()
+{
+    QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent());
+    if (parentItem)
+        m_parentWindow = parentItem->window();
+
+    if ( !m_dlgHelper && QGuiApplicationPrivate::platformTheme()->
+            usePlatformNativeDialog(QPlatformTheme::ColorDialog) ) {
+        m_dlgHelper = static_cast<QPlatformColorDialogHelper *>(QGuiApplicationPrivate::platformTheme()
+           ->createPlatformDialogHelper(QPlatformTheme::ColorDialog));
+        if (!m_dlgHelper)
+            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(colorSelected(QColor)), this, SLOT(setColor(QColor)));
+    }
+
+    return m_dlgHelper;
+}
+
+/*!
+    \qmlproperty bool ColorDialog::visible
+
+    This property holds whether the dialog is visible. By default this is
+    false.
+
+    \sa modality
+*/
+
+/*!
+    \qmlproperty Qt::WindowModality ColorDialog::modality
+
+    Whether the dialog should be shown modal with respect to the window
+    containing the dialog's parent Item, modal with respect to the whole
+    application, or non-modal.
+
+    By default it is \l NonModal.
+
+    Modality does not mean that there are any blocking calls to wait for the
+    dialog to be accepted or rejected; it's only that the user will be
+    prevented from interacting with the parent window and/or the application
+    windows at the same time.
+
+    On MacOS the color dialog is only allowed to be non-modal.
+*/
+
+/*!
+    \qmlmethod void ColorDialog::open()
+
+    Shows the dialog to the user. It is equivalent to setting \l visible to
+    true.
+*/
+
+/*!
+    \qmlmethod void ColorDialog::close()
+
+    Closes the dialog.
+*/
+
+/*!
+    \qmlproperty string ColorDialog::title
+
+    The title of the dialog window.
+*/
+
+/*!
+    \qmlproperty bool ColorDialog::showAlphaChannel
+
+    Whether the dialog will provide a means of changing the opacity.
+
+    By default, this property is true. This property must be set to the desired
+    value before opening the dialog. Usually the alpha channel is represented
+    by an additional slider control.
+*/
+
+/*!
+    \qmlproperty color ColorDialog::color
+
+    The color which the user selected.
+*/
+
+QT_END_NAMESPACE
diff --git a/src/imports/dialogs/qquickplatformcolordialog_p.h b/src/imports/dialogs/qquickplatformcolordialog_p.h
new file mode 100644 (file)
index 0000000..55d301d
--- /dev/null
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtQuick.Dialogs module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.  For licensing terms and
+** conditions see http://qt.digia.com/licensing.  For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights.  These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQUICKPLATFORMCOLORDIALOG_P_H
+#define QQUICKPLATFORMCOLORDIALOG_P_H
+
+//
+//  W A R N I N G
+//  -------------
+//
+// This file is not part of the Qt API.  It exists purely as an
+// implementation detail.  This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qquickabstractcolordialog_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QQuickPlatformColorDialog : public QQuickAbstractColorDialog
+{
+    Q_OBJECT
+
+public:
+    QQuickPlatformColorDialog(QObject *parent = 0);
+    virtual ~QQuickPlatformColorDialog();
+
+protected:
+    QPlatformColorDialogHelper *helper();
+
+    Q_DISABLE_COPY(QQuickPlatformColorDialog)
+};
+
+QT_END_NAMESPACE
+
+QML_DECLARE_TYPE(QQuickPlatformColorDialog *)
+
+#endif // QQUICKPLATFORMCOLORDIALOG_P_H
diff --git a/src/imports/widgets/qquickqcolordialog.cpp b/src/imports/widgets/qquickqcolordialog.cpp
new file mode 100644 (file)
index 0000000..abe6ffd
--- /dev/null
@@ -0,0 +1,172 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.  For licensing terms and
+** conditions see http://qt.digia.com/licensing.  For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights.  These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qquickqcolordialog_p.h"
+#include "qquickitem.h"
+
+#include <private/qguiapplication_p.h>
+#include <private/qqmlcontext_p.h>
+#include <QWindow>
+#include <QQuickWindow>
+#include <QColorDialog>
+
+QT_BEGIN_NAMESPACE
+
+class QColorDialogHelper : public QPlatformColorDialogHelper
+{
+public:
+    QColorDialogHelper() :
+        QPlatformColorDialogHelper()
+    {
+        connect(&m_dialog, SIGNAL(currentColorChanged(const QColor&)), this, SIGNAL(currentColorChanged(const QColor&)));
+        connect(&m_dialog, SIGNAL(colorSelected(const QColor&)), this, SIGNAL(colorSelected(const QColor&)));
+        connect(&m_dialog, SIGNAL(accepted()), this, SIGNAL(accept()));
+        connect(&m_dialog, SIGNAL(rejected()), this, SIGNAL(reject()));
+    }
+
+    virtual void setCurrentColor(const QColor &c) { m_dialog.setCurrentColor(c); }
+    virtual QColor currentColor() const { return m_dialog.currentColor(); }
+
+    virtual void exec() { m_dialog.exec(); }
+
+    virtual bool show(Qt::WindowFlags f, Qt::WindowModality m, QWindow *parent) {
+        m_dialog.windowHandle()->setTransientParent(parent);
+        m_dialog.windowHandle()->setFlags(f);
+        m_dialog.setWindowModality(m);
+        m_dialog.setWindowTitle(QPlatformColorDialogHelper::options()->windowTitle());
+        m_dialog.setOptions((QColorDialog::ColorDialogOptions)((int)(QPlatformColorDialogHelper::options()->options())));
+        m_dialog.show();
+        return m_dialog.isVisible();
+    }
+
+    virtual void hide() { m_dialog.hide(); }
+
+private:
+    QColorDialog m_dialog;
+};
+
+/*!
+    \qmltype QtColorDialog
+    \instantiates QQuickQColorDialog
+    \inqmlmodule QtQuick.PrivateWidgets 1
+    \ingroup qtquick-visual
+    \brief Dialog component for choosing a color.
+    \since 5.1
+    \internal
+
+    QtColorDialog provides a means to instantiate and manage a QColorDialog.
+    It is not recommended to be used directly; it is an implementation
+    detail of \l ColorDialog in the \l QtQuick.Dialogs module.
+
+    To use this type, you will need to import the module with the following line:
+    \code
+    import QtQuick.PrivateWidgets 1.0
+    \endcode
+*/
+
+/*!
+    \qmlsignal QtQuick::Dialogs::ColorDialog::accepted
+
+    The \a accepted signal is emitted when the user has finished using the
+    dialog. You can then inspect the \a color property to get the selection.
+
+    Example:
+
+    \qml
+    ColorDialog {
+        onAccepted: { console.log("Selected color: " + color) }
+    }
+    \endqml
+*/
+
+/*!
+    \qmlsignal QtQuick::Dialogs::ColorDialog::rejected
+
+    The \a rejected signal is emitted when the user has dismissed the dialog,
+    either by closing the dialog window or by pressing the Cancel button.
+*/
+
+/*!
+    \class QQuickQColorDialog
+    \inmodule QtQuick.PrivateWidgets
+    \internal
+
+    \brief The QQuickQColorDialog class is a wrapper for a QColorDialog.
+
+    \since 5.1
+*/
+
+/*!
+    Constructs a file dialog with parent window \a parent.
+*/
+QQuickQColorDialog::QQuickQColorDialog(QObject *parent)
+    : QQuickAbstractColorDialog(parent)
+{
+}
+
+/*!
+    Destroys the file dialog.
+*/
+QQuickQColorDialog::~QQuickQColorDialog()
+{
+    if (m_dlgHelper)
+        m_dlgHelper->hide();
+    delete m_dlgHelper;
+}
+
+QPlatformColorDialogHelper *QQuickQColorDialog::helper()
+{
+    QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent());
+    if (parentItem)
+        m_parentWindow = parentItem->window();
+
+    if (!m_dlgHelper) {
+        m_dlgHelper = new QColorDialogHelper();
+        connect(m_dlgHelper, SIGNAL(currentColorChanged(const QColor&)), this, SLOT(setColor(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()));
+    }
+
+    return m_dlgHelper;
+}
+
+QT_END_NAMESPACE
diff --git a/src/imports/widgets/qquickqcolordialog_p.h b/src/imports/widgets/qquickqcolordialog_p.h
new file mode 100644 (file)
index 0000000..3fb0476
--- /dev/null
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.  For licensing terms and
+** conditions see http://qt.digia.com/licensing.  For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights.  These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQUICKQCOLORDIALOG_P_H
+#define QQUICKQCOLORDIALOG_P_H
+
+//
+//  W A R N I N G
+//  -------------
+//
+// This file is not part of the Qt API.  It exists purely as an
+// implementation detail.  This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "../dialogs/qquickabstractcolordialog_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QQuickQColorDialog : public QQuickAbstractColorDialog
+{
+    Q_OBJECT
+
+public:
+    QQuickQColorDialog(QObject *parent = 0);
+    virtual ~QQuickQColorDialog();
+
+protected:
+    QPlatformColorDialogHelper *helper();
+
+    Q_DISABLE_COPY(QQuickQColorDialog)
+};
+
+QT_END_NAMESPACE
+
+QML_DECLARE_TYPE(QQuickQColorDialog *)
+
+#endif // QQUICKQCOLORDIALOG_P_H
index 7de5aa6..c444674 100644 (file)
@@ -6,12 +6,16 @@ IMPORT_VERSION = 1.0
 SOURCES += \
     qquickqfiledialog.cpp \
     ../dialogs/qquickabstractfiledialog.cpp \
+    qquickqcolordialog.cpp \
+    ../dialogs/qquickabstractcolordialog.cpp \
     ../dialogs/qquickabstractdialog.cpp \
     widgetsplugin.cpp
 
 HEADERS += \
     qquickqfiledialog_p.h \
     ../dialogs/qquickabstractfiledialog_p.h \
+    qquickqcolordialog_p.h \
+    ../dialogs/qquickabstractcolordialog_p.h \
     ../dialogs/qquickabstractdialog_p.h
 
 QT += quick-private gui-private core-private qml-private v8-private widgets
index 6d3a56c..a29c9b3 100644 (file)
@@ -42,6 +42,7 @@
 #include <QtQml/qqmlextensionplugin.h>
 #include <QtQml/qqml.h>
 #include "qquickqfiledialog_p.h"
+#include "qquickqcolordialog_p.h"
 
 QT_BEGIN_NAMESPACE
 
@@ -75,6 +76,7 @@ public:
         Q_ASSERT(QLatin1String(uri) == QLatin1String("QtQuick.PrivateWidgets"));
 
         qmlRegisterType<QQuickQFileDialog>(uri, 1, 0, "QtFileDialog");
+        qmlRegisterType<QQuickQColorDialog>(uri, 1, 0, "QtColorDialog");
     }
 };