diff options
Diffstat (limited to 'src/imports/dialogs')
33 files changed, 3427 insertions, 0 deletions
diff --git a/src/imports/dialogs/DefaultColorDialog.qml b/src/imports/dialogs/DefaultColorDialog.qml new file mode 100644 index 0000000000..7322aa18e7 --- /dev/null +++ b/src/imports/dialogs/DefaultColorDialog.qml @@ -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/DefaultFileDialog.qml b/src/imports/dialogs/DefaultFileDialog.qml new file mode 100644 index 0000000000..5542e59cb5 --- /dev/null +++ b/src/imports/dialogs/DefaultFileDialog.qml @@ -0,0 +1,360 @@ +/***************************************************************************** +** +** 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 Qt.labs.folderlistmodel 2.0 +import "qml" + +AbstractFileDialog { + id: root + onVisibleChanged: { + if (visible) { + selectedIndices = [] + lastClickedIdx = -1 + currentPathField.visible = false + } + } + + property bool showFocusHighlight: false + property real textX: 28 + property SystemPalette palette + property var selectedIndices: [] + property int lastClickedIdx: -1 + folder: urlToPath(view.model.folder) + + function dirDown(path) { + view.model.folder = path + lastClickedIdx = -1 + selectedIndices = [] + } + function dirUp() { + view.model.folder = view.model.parentFolder + lastClickedIdx = -1 + selectedIndices = [] + } + function up(extend) { + if (view.currentIndex > 0) + --view.currentIndex + else + view.currentIndex = 0 + if (extend) { + if (selectedIndices.indexOf(view.currentIndex) < 0) { + var selCopy = selectedIndices + selCopy.push(view.currentIndex) + selectedIndices = selCopy + } + } else + selectedIndices = [view.currentIndex] + } + function down(extend) { + if (view.currentIndex < view.model.count - 1) + ++view.currentIndex + else + view.currentIndex = view.model.count - 1 + if (extend) { + if (selectedIndices.indexOf(view.currentIndex) < 0) { + var selCopy = selectedIndices + selCopy.push(view.currentIndex) + selectedIndices = selCopy + } + } else + selectedIndices = [view.currentIndex] + } + function acceptSelection() { + clearSelection() + if (selectFolder && selectedIndices.length == 0) + addSelection(folder) + else { + selectedIndices.map(function(idx) { + if (view.model.isFolder(idx)) { + if (selectFolder) + addSelection(view.model.get(idx, "filePath")) + } else { + if (!selectFolder) + addSelection(view.model.get(idx, "filePath")) + } + }) + } + accept() + } + + Rectangle { + width: 480 // TODO: QTBUG-29817 geometry from AbstractFileDialog + height: 320 + id: window + color: palette.window + anchors.centerIn: Qt.application.supportsMultipleWindows ? null : parent + + SystemPalette { id: palette } + + Component { + id: folderDelegate + Rectangle { + id: wrapper + function launch() { + if (view.model.isFolder(index)) { + dirDown(filePath) + } else { + root.acceptSelection() + } + } + width: window.width + height: nameText.implicitHeight * 1.5 + color: "transparent" + Rectangle { + id: itemHighlight + visible: root.selectedIndices.indexOf(index) >= 0 + anchors.fill: parent + color: palette.highlight + } + Image { + id: icon + source: "images/folder.png" + height: wrapper.height - y * 2; width: height + x: (root.textX - width) / 2 + y: 2 + visible: view.model.isFolder(index) + } + Text { + id: nameText + anchors.fill: parent; verticalAlignment: Text.AlignVCenter + text: fileName + anchors.leftMargin: root.textX + color: itemHighlight.visible ? palette.highlightedText : palette.windowText + elide: Text.ElideRight + } + MouseArea { + id: mouseRegion + anchors.fill: parent + onDoubleClicked: { + selectedIndices = [index] + root.lastClickedIdx = index + launch() + } + onClicked: { + view.currentIndex = index + if (mouse.modifiers & Qt.ControlModifier && root.selectMultiple) { + // modifying the contents of selectedIndices doesn't notify, + // so we have to re-assign the variable + var selCopy = selectedIndices + var existingIdx = selCopy.indexOf(index) + if (existingIdx >= 0) + selCopy.splice(existingIdx, 1) + else + selCopy.push(index) + selectedIndices = selCopy + } else if (mouse.modifiers & Qt.ShiftModifier && root.selectMultiple) { + if (root.lastClickedIdx >= 0) { + var sel = [] + if (index > lastClickedIdx) { + for (var i = root.lastClickedIdx; i <= index; i++) + sel.push(i) + } else { + for (var i = root.lastClickedIdx; i >= index; i--) + sel.push(i) + } + selectedIndices = sel + } + } else { + selectedIndices = [index] + root.lastClickedIdx = index + } + } + } + } + } + + ListView { + id: view + anchors.top: titleBar.bottom + anchors.bottom: bottomBar.top + clip: true + x: 0 + width: parent.width + model: FolderListModel { } + delegate: folderDelegate + highlight: Rectangle { + color: "transparent" + border.color: Qt.darker(palette.window, 1.3) + } + highlightMoveDuration: 0 + highlightMoveVelocity: -1 + focus: !currentPathField.visible + Keys.onPressed: { + event.accepted = true + switch (event.key) { + case Qt.Key_Up: + root.up(event.modifiers & Qt.ShiftModifier && root.selectMultiple) + break + case Qt.Key_Down: + root.down(event.modifiers & Qt.ShiftModifier && root.selectMultiple) + break + case Qt.Key_Left: + root.dirUp() + break + case Qt.Key_Return: + case Qt.Key_Select: + case Qt.Key_Right: + if (view.currentItem) + view.currentItem.launch() + else + root.acceptSelection() + break + default: + // do nothing + event.accepted = false + break + } + } + } + + MouseArea { + anchors.fill: view + enabled: currentPathField.visible + onClicked: currentPathField.visible = false + } + + + Item { + id: titleBar + width: parent.width + height: currentPathField.height * 1.5 + Rectangle { + anchors.fill: parent + color: Qt.darker(palette.window, 1.1) + border.color: Qt.darker(palette.window, 1.3) + } + Rectangle { + id: upButton + width: root.textX + height: titleBar.height + color: "transparent" + + Image { + id: upButtonImage + anchors.centerIn: parent; source: "images/up.png" + } + MouseArea { id: upRegion; anchors.centerIn: parent + width: 56 + height: parent.height + onClicked: if (view.model.parentFolder != "") dirUp() + } + states: [ + State { + name: "pressed" + when: upRegion.pressed + PropertyChanges { target: upButton; color: palette.highlight } + } + ] + } + Text { + id: currentPathText + anchors.left: parent.left; anchors.right: parent.right; anchors.verticalCenter: parent.verticalCenter + anchors.leftMargin: textX; anchors.rightMargin: 4 + text: root.urlToPath(view.model.folder) + color: palette.text + elide: Text.ElideLeft; horizontalAlignment: Text.AlignRight; verticalAlignment: Text.AlignVCenter + MouseArea { + anchors.fill: parent + onClicked: currentPathField.visible = true + } + } + TextField { + id: currentPathField + anchors.left: parent.left; anchors.right: parent.right; anchors.verticalCenter: parent.verticalCenter + anchors.leftMargin: textX; anchors.rightMargin: 4 + visible: false + focus: visible + text: root.urlToPath(view.model.folder) + onAccepted: { + root.clearSelection() + if (root.addSelection(text)) + root.accept() + else + view.model.folder = root.pathFolder(text) + } + onDownPressed: currentPathField.visible = false + } + } + Rectangle { + id: bottomBar + width: parent.width + height: buttonRow.height + buttonRow.spacing * 2 + anchors.bottom: parent.bottom + color: Qt.darker(palette.window, 1.1) + border.color: Qt.darker(palette.window, 1.3) + + Row { + id: buttonRow + anchors.right: parent.right + anchors.rightMargin: spacing + anchors.verticalCenter: parent.verticalCenter + spacing: 4 + TextField { + id: filterField + text: root.selectedNameFilter + visible: !selectFolder + width: bottomBar.width - cancelButton.width - okButton.width - parent.spacing * 5 + anchors.verticalCenter: parent.verticalCenter + onAccepted: { + root.selectNameFilter(text) + view.model.nameFilters = text + } + } + Button { + id: cancelButton + text: "Cancel" + onClicked: root.reject() + } + Button { + id: okButton + text: "OK" + onClicked: { + if (view.model.isFolder(view.currentIndex) && !selectFolder) + dirDown(view.model.get(view.currentIndex, "filePath")) + else + root.acceptSelection() + } + } + } + } + } +} diff --git a/src/imports/dialogs/WidgetColorDialog.qml b/src/imports/dialogs/WidgetColorDialog.qml new file mode 100644 index 0000000000..ed7c7ab77a --- /dev/null +++ b/src/imports/dialogs/WidgetColorDialog.qml @@ -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 { } diff --git a/src/imports/dialogs/WidgetFileDialog.qml b/src/imports/dialogs/WidgetFileDialog.qml new file mode 100644 index 0000000000..c8f59d20a7 --- /dev/null +++ b/src/imports/dialogs/WidgetFileDialog.qml @@ -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 + +QtFileDialog { } diff --git a/src/imports/dialogs/dialogs.pro b/src/imports/dialogs/dialogs.pro new file mode 100644 index 0000000000..b7704dadda --- /dev/null +++ b/src/imports/dialogs/dialogs.pro @@ -0,0 +1,44 @@ +CXX_MODULE = qml +TARGET = dialogplugin +TARGETPATH = QtQuick/Dialogs +IMPORT_VERSION = 1.0 + +SOURCES += \ + qquickabstractfiledialog.cpp \ + qquickplatformfiledialog.cpp \ + qquickfiledialog.cpp \ + qquickabstractcolordialog.cpp \ + qquickplatformcolordialog.cpp \ + qquickcolordialog.cpp \ + qquickabstractdialog.cpp \ + plugin.cpp + +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 + +QT += quick-private gui-private core-private + +load(qml_plugin) diff --git a/src/imports/dialogs/images/checkers.png b/src/imports/dialogs/images/checkers.png Binary files differnew file mode 100644 index 0000000000..458d33de9d --- /dev/null +++ b/src/imports/dialogs/images/checkers.png diff --git a/src/imports/dialogs/images/copy.png b/src/imports/dialogs/images/copy.png Binary files differnew file mode 100644 index 0000000000..2aeb28288f --- /dev/null +++ b/src/imports/dialogs/images/copy.png diff --git a/src/imports/dialogs/images/crosshairs.png b/src/imports/dialogs/images/crosshairs.png Binary files differnew file mode 100644 index 0000000000..9a61946eca --- /dev/null +++ b/src/imports/dialogs/images/crosshairs.png diff --git a/src/imports/dialogs/images/folder.png b/src/imports/dialogs/images/folder.png Binary files differnew file mode 100644 index 0000000000..e53e2ad464 --- /dev/null +++ b/src/imports/dialogs/images/folder.png diff --git a/src/imports/dialogs/images/slider_handle.png b/src/imports/dialogs/images/slider_handle.png Binary files differnew file mode 100644 index 0000000000..e3b9654392 --- /dev/null +++ b/src/imports/dialogs/images/slider_handle.png diff --git a/src/imports/dialogs/images/sunken_frame.png b/src/imports/dialogs/images/sunken_frame.png Binary files differnew file mode 100644 index 0000000000..178c3092d2 --- /dev/null +++ b/src/imports/dialogs/images/sunken_frame.png diff --git a/src/imports/dialogs/images/up.png b/src/imports/dialogs/images/up.png Binary files differnew file mode 100644 index 0000000000..b05f8025d0 --- /dev/null +++ b/src/imports/dialogs/images/up.png diff --git a/src/imports/dialogs/plugin.cpp b/src/imports/dialogs/plugin.cpp new file mode 100644 index 0000000000..67653e5965 --- /dev/null +++ b/src/imports/dialogs/plugin.cpp @@ -0,0 +1,141 @@ +/**************************************************************************** +** +** 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 <QtQml/qqml.h> +#include <QtQml/qqmlextensionplugin.h> +#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 + +#define DIALOGS_MAJOR_MINOR 1, 0 + +QT_BEGIN_NAMESPACE + +/*! + \qmlmodule QtQuick.Dialogs 1 + \title Qt Quick Dialog QML Types + \ingroup qmlmodules + \brief Provides QML types for standard file, color picker and message dialogs + + This QML module contains types for creating and interacting with system dialogs. + + To use the types in this module, import the module with the following line: + + \code + import QtQuick.Dialogs 1.0 + \endcode +*/ + +class QtQuick2DialogsPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface/1.0") + +public: + QtQuick2DialogsPlugin() : QQmlExtensionPlugin() { } + + virtual void registerTypes(const char *uri) { + Q_ASSERT(QLatin1String(uri) == QLatin1String("QtQuick.Dialogs")); + QDir qmlDir(baseUrl().toLocalFile()); + QDir widgetsDir(baseUrl().toLocalFile()); + // TODO: find the directory by searching rather than assuming a relative path + widgetsDir.cd("../PrivateWidgets"); + + // Prefer the QPA dialog helpers if the platform supports them. + // Else if there is a QWidget-based implementation, check whether it's + // possible to instantiate it from Qt Quick. + // Otherwise fall back to a pure-QML implementation. + + // FileDialog +#ifndef PURE_QML_ONLY + if (QGuiApplicationPrivate::platformTheme()->usePlatformNativeDialog(QPlatformTheme::FileDialog)) + qmlRegisterType<QQuickPlatformFileDialog>(uri, DIALOGS_MAJOR_MINOR, "FileDialog"); + else +#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: + template <class WrapperType> + void registerWidgetOrQmlImplementation(QDir widgetsDir, QString widgetQmlFile, + QDir qmlDir, QString qmlFile, const char *qmlName, const char *uri) { + bool needQml = true; +#ifndef PURE_QML_ONLY + // If there is a qmldir and we have a QApplication instance (as opposed to a + // widget-free QGuiApplication), assume that the widget-based dialog will work. + if (widgetsDir.exists("qmldir") && !widgetQmlFile.isEmpty() && + !qstrcmp(QCoreApplication::instance()->metaObject()->className(), "QApplication")) { + QString dialogQmlPath = qmlDir.filePath(widgetQmlFile); + if (qmlRegisterType(QUrl::fromLocalFile(dialogQmlPath), uri, DIALOGS_MAJOR_MINOR, qmlName) >= 0) + needQml = false; + // qDebug() << "registering" << qmlName << " as " << dialogQmlPath << "success?" << needQml; + } +#endif + if (needQml) { + QString dialogQmlPath = qmlDir.filePath(qmlFile); + QByteArray abstractTypeName = QByteArray("Abstract") + qmlName; + qmlRegisterType<WrapperType>(uri, DIALOGS_MAJOR_MINOR, abstractTypeName); // implementation wrapper + // qDebug() << "registering" << qmlName << " as " << dialogQmlPath << "success?" << + qmlRegisterType(QUrl::fromLocalFile(dialogQmlPath), uri, DIALOGS_MAJOR_MINOR, qmlName); + } + } + +}; + +QT_END_NAMESPACE + +#include "plugin.moc" diff --git a/src/imports/dialogs/plugins.qmltypes b/src/imports/dialogs/plugins.qmltypes new file mode 100644 index 0000000000..faf68de909 --- /dev/null +++ b/src/imports/dialogs/plugins.qmltypes @@ -0,0 +1,72 @@ +import QtQuick.tooling 1.1 + +// This file describes the plugin-supplied types contained in the library. +// It is used for QML tooling purposes only. +// +// This file was auto-generated with the command 'qmlplugindump QtQuick.Dialogs 1.0'. + +Module { + Component { + name: "QQuickAbstractFileDialog" + prototype: "QObject" + Property { name: "visible"; type: "bool" } + Property { name: "modality"; type: "Qt::WindowModality" } + Property { name: "title"; type: "string" } + Property { name: "selectExisting"; type: "bool" } + Property { name: "selectMultiple"; type: "bool" } + Property { name: "selectFolder"; type: "bool" } + Property { name: "folder"; type: "string" } + Property { name: "nameFilters"; type: "QStringList" } + Property { name: "selectedNameFilter"; type: "string" } + Property { name: "filePath"; type: "string"; isReadonly: true } + Property { name: "filePaths"; type: "QStringList"; isReadonly: true } + Signal { name: "visibilityChanged" } + Signal { name: "filterSelected" } + Signal { name: "fileModeChanged" } + Signal { name: "accepted" } + Signal { name: "rejected" } + Method { name: "open" } + Method { name: "close" } + Method { + name: "setVisible" + Parameter { name: "v"; type: "bool" } + } + Method { + name: "setModality" + Parameter { name: "m"; type: "Qt::WindowModality" } + } + Method { + name: "setTitle" + Parameter { name: "t"; type: "string" } + } + Method { + name: "setSelectExisting" + Parameter { name: "s"; type: "bool" } + } + Method { + name: "setSelectMultiple" + Parameter { name: "s"; type: "bool" } + } + Method { + name: "setSelectFolder" + Parameter { name: "s"; type: "bool" } + } + Method { + name: "setFolder" + Parameter { name: "f"; type: "string" } + } + Method { + name: "setNameFilters" + Parameter { name: "f"; type: "QStringList" } + } + Method { + name: "selectNameFilter" + Parameter { name: "f"; type: "string" } + } + } + Component { + name: "QQuickQFileDialog" + prototype: "QQuickAbstractFileDialog" + exports: ["QtQuick.PrivateWidgets/QtFileDialog 1.0"] + } +} diff --git a/src/imports/dialogs/qml/Button.qml b/src/imports/dialogs/qml/Button.qml new file mode 100644 index 0000000000..491dc2e251 --- /dev/null +++ b/src/imports/dialogs/qml/Button.qml @@ -0,0 +1,87 @@ +/***************************************************************************** +** +** 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 + +Item { + id: container + + property alias text: buttonLabel.text + property alias label: buttonLabel + signal clicked + property alias containsMouse: mouseArea.containsMouse + property alias pressed: mouseArea.pressed + implicitHeight: buttonLabel.implicitHeight + implicitWidth: buttonLabel.implicitWidth + height: buttonLabel.implicitHeight + 12 + width: Math.max(80, implicitWidth + 8) + + SystemPalette { id: palette } + + Rectangle { + id: frame + anchors.fill: parent + color: palette.button + gradient: Gradient { + GradientStop { position: 0.0; color: mouseArea.pressed ? Qt.darker(palette.button, 1.3) : palette.button } + GradientStop { position: 1.0; color: Qt.darker(palette.button, 1.3) } + } + antialiasing: true + radius: 5 + border.color: Qt.darker(palette.button, 1.5) + border.width: 1 + } + + MouseArea { + id: mouseArea + anchors.fill: parent + onClicked: container.clicked() + hoverEnabled: true + } + + Text { + id: buttonLabel + width: parent.width + horizontalAlignment: Text.Center + text: container.text + color: palette.buttonText + anchors.verticalCenter: parent.verticalCenter + } +} diff --git a/src/imports/dialogs/qml/ColorSlider.qml b/src/imports/dialogs/qml/ColorSlider.qml new file mode 100755 index 0000000000..8fc9717380 --- /dev/null +++ b/src/imports/dialogs/qml/ColorSlider.qml @@ -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; + } + } + } + } + } +} diff --git a/src/imports/dialogs/qml/TextField.qml b/src/imports/dialogs/qml/TextField.qml new file mode 100644 index 0000000000..baa469caa9 --- /dev/null +++ b/src/imports/dialogs/qml/TextField.qml @@ -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: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: root + + 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 + 8 + clip: true + + Rectangle { + id: rect + anchors.fill: parent + radius: height / 4 + color: palette.button + border.color: Qt.darker(palette.button, 1.5) + } + + TextInput { + 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() + } +} diff --git a/src/imports/dialogs/qml/qmldir b/src/imports/dialogs/qml/qmldir new file mode 100644 index 0000000000..c475502cf1 --- /dev/null +++ b/src/imports/dialogs/qml/qmldir @@ -0,0 +1,3 @@ +Button 1.0 Button.qml +ColorSlider 1.0 ColorSlider.qml +TextField 1.0 TextField.qml diff --git a/src/imports/dialogs/qmldir b/src/imports/dialogs/qmldir new file mode 100644 index 0000000000..df9a035ade --- /dev/null +++ b/src/imports/dialogs/qmldir @@ -0,0 +1,3 @@ +module QtQuick.Dialogs +plugin dialogplugin +typeinfo plugins.qmltypes diff --git a/src/imports/dialogs/qquickabstractcolordialog.cpp b/src/imports/dialogs/qquickabstractcolordialog.cpp new file mode 100644 index 0000000000..9a9f3bc11b --- /dev/null +++ b/src/imports/dialogs/qquickabstractcolordialog.cpp @@ -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 index 0000000000..3301605c86 --- /dev/null +++ b/src/imports/dialogs/qquickabstractcolordialog_p.h @@ -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/qquickabstractdialog.cpp b/src/imports/dialogs/qquickabstractdialog.cpp new file mode 100644 index 0000000000..abdc9e067c --- /dev/null +++ b/src/imports/dialogs/qquickabstractdialog.cpp @@ -0,0 +1,248 @@ +/**************************************************************************** +** +** 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 "qquickabstractdialog_p.h" +#include "qquickitem.h" + +#include <private/qguiapplication_p.h> +#include <QWindow> +#include <QQuickWindow> +#include <qpa/qplatformintegration.h> + +QT_BEGIN_NAMESPACE + +QQuickAbstractDialog::QQuickAbstractDialog(QObject *parent) + : QObject(parent) + , m_parentWindow(0) + , m_visible(false) + , m_modality(Qt::WindowModal) + , m_qmlImplementation(0) + , m_dialogWindow(0) +{ +} + +QQuickAbstractDialog::~QQuickAbstractDialog() +{ +} + +void QQuickAbstractDialog::setVisible(bool v) +{ + if (m_visible == v) return; + m_visible = v; + if (helper()) { + if (v) { + Qt::WindowFlags flags = Qt::Dialog; + if (!title().isEmpty()) + flags |= Qt::WindowTitleHint; + m_visible = helper()->show(flags, m_modality, parentWindow()); + } else { + helper()->hide(); + } + } else { + // For a pure QML implementation, there is no helper. + // But m_implementation is probably either an Item or a Window at this point. + if (!m_dialogWindow) { + m_dialogWindow = qobject_cast<QWindow *>(m_qmlImplementation); + if (!m_dialogWindow) { + QQuickItem *dlgItem = qobject_cast<QQuickItem *>(m_qmlImplementation); + if (dlgItem) { + m_dialogWindow = dlgItem->window(); + // An Item-based dialog implementation doesn't come with a window, so + // we have to instantiate one iff the platform allows it. + if (!m_dialogWindow && QGuiApplicationPrivate::platformIntegration()-> + hasCapability(QPlatformIntegration::MultipleWindows)) { + QQuickWindow *win = new QQuickWindow; + ((QObject *)win)->setParent(this); // memory management only + m_dialogWindow = win; + dlgItem->setParentItem(win->contentItem()); + m_dialogWindow->setMinimumSize(QSize(dlgItem->width(), dlgItem->height())); + connect(win, SIGNAL(widthChanged(int)), this, SLOT(windowGeometryChanged())); + connect(win, SIGNAL(heightChanged(int)), this, SLOT(windowGeometryChanged())); + } + + QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent()); + // qDebug() << "item implementation" << dlgItem << "has window" << m_dialogWindow << "and parent" << parentItem; + + // If the platform does not support multiple windows, but the dialog is + // implemented as an Item, then just reparent it and make it visible. + // TODO QTBUG-29818: put it into a fake Item-based window, when we have a reusable self-decorated one. + if (parentItem && !m_dialogWindow) + dlgItem->setParentItem(parentItem); + } + } + if (m_dialogWindow) + connect(m_dialogWindow, SIGNAL(visibleChanged(bool)), this, SLOT(visibleChanged(bool))); + } + if (m_dialogWindow) { + if (v) { + m_dialogWindow->setTransientParent(parentWindow()); + m_dialogWindow->setTitle(title()); + m_dialogWindow->setModality(m_modality); + } + m_dialogWindow->setVisible(v); + } + } + + emit visibilityChanged(); +} + +void QQuickAbstractDialog::setModality(Qt::WindowModality m) +{ + if (m_modality == m) return; + m_modality = m; + emit modalityChanged(); +} + +void QQuickAbstractDialog::accept() +{ + setVisible(false); + emit accepted(); +} + +void QQuickAbstractDialog::reject() +{ + setVisible(false); + emit rejected(); +} + +void QQuickAbstractDialog::visibleChanged(bool v) +{ + m_visible = v; + emit visibilityChanged(); +} + +void QQuickAbstractDialog::windowGeometryChanged() +{ + QQuickItem *content = qobject_cast<QQuickItem*>(m_qmlImplementation); +qDebug() << Q_FUNC_INFO << m_dialogWindow << content; + if (m_dialogWindow && content) { + content->setWidth(m_dialogWindow->width()); + content->setHeight(m_dialogWindow->height()); + } +} + +QQuickWindow *QQuickAbstractDialog::parentWindow() +{ + QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent()); + if (parentItem) + m_parentWindow = parentItem->window(); + return m_parentWindow; +} + +void QQuickAbstractDialog::setQmlImplementation(QObject *obj) +{ + m_qmlImplementation = obj; + if (m_dialogWindow) { + disconnect(this, SLOT(visibleChanged(bool))); + // Can't necessarily delete because m_dialogWindow might have been provided by the QML. + m_dialogWindow = 0; + } +} + +int QQuickAbstractDialog::x() const +{ + if (m_dialogWindow) + return m_dialogWindow->x(); + return -1; +} + +int QQuickAbstractDialog::y() const +{ + if (m_dialogWindow) + return m_dialogWindow->y(); + return -1; +} + +int QQuickAbstractDialog::width() const +{ + if (m_dialogWindow) + return m_dialogWindow->width(); + return -1; +} + +int QQuickAbstractDialog::height() const +{ + if (m_dialogWindow) + return m_dialogWindow->height(); + return -1; +} + +void QQuickAbstractDialog::setX(int arg) +{ + if (helper()) { + // TODO + } else if (m_dialogWindow) { + m_dialogWindow->setX(arg); + } + emit geometryChanged(); +} + +void QQuickAbstractDialog::setY(int arg) +{ + if (helper()) { + // TODO + } else if (m_dialogWindow) { + m_dialogWindow->setY(arg); + } + emit geometryChanged(); +} + +void QQuickAbstractDialog::setWidth(int arg) +{ + if (helper()) { + // TODO + } else if (m_dialogWindow) { + m_dialogWindow->setWidth(arg); + } + emit geometryChanged(); +} + +void QQuickAbstractDialog::setHeight(int arg) +{ + if (helper()) { + // TODO + } else if (m_dialogWindow) { + m_dialogWindow->setHeight(arg); + } + emit geometryChanged(); +} + +QT_END_NAMESPACE diff --git a/src/imports/dialogs/qquickabstractdialog_p.h b/src/imports/dialogs/qquickabstractdialog_p.h new file mode 100644 index 0000000000..2ad24f98e0 --- /dev/null +++ b/src/imports/dialogs/qquickabstractdialog_p.h @@ -0,0 +1,133 @@ +/**************************************************************************** +** +** 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 QQUICKABSTRACTDIALOG_P_H +#define QQUICKABSTRACTDIALOG_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> + +QT_BEGIN_NAMESPACE + +class QQuickAbstractDialog : public QObject +{ + Q_OBJECT + Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibilityChanged) + Q_PROPERTY(Qt::WindowModality modality READ modality WRITE setModality NOTIFY modalityChanged) + Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) + Q_PROPERTY(int x READ x WRITE setX NOTIFY geometryChanged) + Q_PROPERTY(int y READ y WRITE setY NOTIFY geometryChanged) + Q_PROPERTY(int width READ width WRITE setWidth NOTIFY geometryChanged) + Q_PROPERTY(int height READ height WRITE setHeight NOTIFY geometryChanged) + +public: + QQuickAbstractDialog(QObject *parent = 0); + virtual ~QQuickAbstractDialog(); + + bool isVisible() const { return m_visible; } + Qt::WindowModality modality() const { return m_modality; } + virtual QString title() const = 0; + QObject* qmlImplementation() { return m_qmlImplementation; } + + int x() const; + int y() const; + int width() const; + int height() const; + + virtual void setVisible(bool v); + virtual void setModality(Qt::WindowModality m); + virtual void setTitle(QString t) = 0; + void setQmlImplementation(QObject* obj); + void setX(int arg); + void setY(int arg); + void setWidth(int arg); + void setHeight(int arg); + +public Q_SLOTS: + void open() { setVisible(true); } + void close() { setVisible(false); } + +Q_SIGNALS: + void visibilityChanged(); + void geometryChanged(); + void modalityChanged(); + void titleChanged(); + void accepted(); + void rejected(); + +protected Q_SLOTS: + void accept(); + void reject(); + void visibleChanged(bool v); + void windowGeometryChanged(); + +protected: + virtual QPlatformDialogHelper *helper() = 0; + QQuickWindow *parentWindow(); + +protected: + QQuickWindow *m_parentWindow; + bool m_visible; + Qt::WindowModality m_modality; + +protected: // variables for pure-QML implementations only + QObject *m_qmlImplementation; + QWindow *m_dialogWindow; + + Q_DISABLE_COPY(QQuickAbstractDialog) +}; + +QT_END_NAMESPACE + +#endif // QQUICKABSTRACTDIALOG_P_H diff --git a/src/imports/dialogs/qquickabstractfiledialog.cpp b/src/imports/dialogs/qquickabstractfiledialog.cpp new file mode 100644 index 0000000000..32442de41f --- /dev/null +++ b/src/imports/dialogs/qquickabstractfiledialog.cpp @@ -0,0 +1,195 @@ +/**************************************************************************** +** +** 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 "qquickabstractfiledialog_p.h" +#include "qquickitem.h" + +#include <private/qguiapplication_p.h> +#include <QWindow> +#include <QQuickWindow> + +QT_BEGIN_NAMESPACE + +QQuickAbstractFileDialog::QQuickAbstractFileDialog(QObject *parent) + : QQuickAbstractDialog(parent) + , m_dlgHelper(0) + , m_options(QSharedPointer<QFileDialogOptions>(new QFileDialogOptions())) + , m_selectExisting(true) + , m_selectMultiple(false) + , m_selectFolder(false) +{ + connect(this, SIGNAL(accepted()), this, SIGNAL(selectionAccepted())); +} + +QQuickAbstractFileDialog::~QQuickAbstractFileDialog() +{ +} + +void QQuickAbstractFileDialog::setVisible(bool v) +{ + if (helper() && v) { + m_dlgHelper->setOptions(m_options); + m_dlgHelper->setFilter(); + emit filterSelected(); + } + QQuickAbstractDialog::setVisible(v); +} + +QString QQuickAbstractFileDialog::title() const +{ + return m_options->windowTitle(); +} + +void QQuickAbstractFileDialog::setTitle(QString t) +{ + if (m_options->windowTitle() == t) return; + m_options->setWindowTitle(t); + emit titleChanged(); +} + +void QQuickAbstractFileDialog::setSelectExisting(bool selectExisting) +{ + if (selectExisting == m_selectExisting) return; + m_selectExisting = selectExisting; + updateModes(); +} + +void QQuickAbstractFileDialog::setSelectMultiple(bool selectMultiple) +{ + if (selectMultiple == m_selectMultiple) return; + m_selectMultiple = selectMultiple; + updateModes(); +} + +void QQuickAbstractFileDialog::setSelectFolder(bool selectFolder) +{ + if (selectFolder == m_selectFolder) return; + m_selectFolder = selectFolder; + updateModes(); +} + +QString QQuickAbstractFileDialog::folder() +{ + if (m_dlgHelper && !m_dlgHelper->directory().isEmpty()) + return m_dlgHelper->directory(); + return m_options->initialDirectory(); +} + +void QQuickAbstractFileDialog::setFolder(QString f) +{ + if (m_dlgHelper) + m_dlgHelper->setDirectory(f); + m_options->setInitialDirectory(f); + emit folderChanged(); +} + +void QQuickAbstractFileDialog::setNameFilters(const QStringList &f) +{ + m_options->setNameFilters(f); + if (f.isEmpty()) + selectNameFilter(QString()); + else if (!f.contains(selectedNameFilter())) + selectNameFilter(f.first()); + emit nameFiltersChanged(); +} + +QString QQuickAbstractFileDialog::selectedNameFilter() +{ + QString ret; + if (m_dlgHelper) + ret = m_dlgHelper->selectedNameFilter(); + if (ret.isEmpty()) + return m_options->initiallySelectedNameFilter(); + return ret; +} + +void QQuickAbstractFileDialog::selectNameFilter(QString f) +{ + // This should work whether the dialog is currently being shown already, or ahead of time. + m_options->setInitiallySelectedNameFilter(f); + if (m_dlgHelper) + m_dlgHelper->selectNameFilter(f); + emit filterSelected(); +} + +QUrl QQuickAbstractFileDialog::fileUrl() +{ + QList<QUrl> urls = fileUrls(); + return (urls.count() == 1) ? urls[0] : QUrl(); +} + +QList<QUrl> QQuickAbstractFileDialog::fileUrls() +{ + QList<QUrl> ret; + if (m_dlgHelper) + foreach (QString path, m_dlgHelper->selectedFiles()) + ret << QUrl::fromLocalFile(path); + return ret; +} + +void QQuickAbstractFileDialog::updateModes() +{ + // The 4 possible modes are AnyFile, ExistingFile, Directory, ExistingFiles + // Assume AnyFile until we find a reason to the contrary + QFileDialogOptions::FileMode mode = QFileDialogOptions::AnyFile; + + if (m_selectFolder) { + mode = QFileDialogOptions::Directory; + m_options->setOption(QFileDialogOptions::ShowDirsOnly); + m_selectMultiple = false; + m_selectExisting = true; + setNameFilters(QStringList()); + } else if (m_selectExisting) { + mode = m_selectMultiple ? + QFileDialogOptions::ExistingFiles : QFileDialogOptions::ExistingFile; + m_options->setOption(QFileDialogOptions::ShowDirsOnly, false); + } else if (m_selectMultiple) { + m_selectExisting = true; + } + if (!m_selectExisting) + m_selectMultiple = false; + m_options->setFileMode(mode); + m_options->setAcceptMode(m_selectExisting ? + QFileDialogOptions::AcceptOpen : QFileDialogOptions::AcceptSave); + emit fileModeChanged(); +} + +QT_END_NAMESPACE diff --git a/src/imports/dialogs/qquickabstractfiledialog_p.h b/src/imports/dialogs/qquickabstractfiledialog_p.h new file mode 100644 index 0000000000..965f1a7029 --- /dev/null +++ b/src/imports/dialogs/qquickabstractfiledialog_p.h @@ -0,0 +1,122 @@ +/**************************************************************************** +** +** 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 QQUICKABSTRACTFILEDIALOG_P_H +#define QQUICKABSTRACTFILEDIALOG_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 QQuickAbstractFileDialog : public QQuickAbstractDialog +{ + Q_OBJECT + Q_PROPERTY(bool selectExisting READ selectExisting WRITE setSelectExisting NOTIFY fileModeChanged) + Q_PROPERTY(bool selectMultiple READ selectMultiple WRITE setSelectMultiple NOTIFY fileModeChanged) + Q_PROPERTY(bool selectFolder READ selectFolder WRITE setSelectFolder NOTIFY fileModeChanged) + Q_PROPERTY(QString folder READ folder WRITE setFolder NOTIFY folderChanged) + Q_PROPERTY(QStringList nameFilters READ nameFilters WRITE setNameFilters NOTIFY nameFiltersChanged) + Q_PROPERTY(QString selectedNameFilter READ selectedNameFilter WRITE selectNameFilter NOTIFY filterSelected) + Q_PROPERTY(QUrl fileUrl READ fileUrl NOTIFY selectionAccepted) + Q_PROPERTY(QList<QUrl> fileUrls READ fileUrls NOTIFY selectionAccepted) + +public: + QQuickAbstractFileDialog(QObject *parent = 0); + virtual ~QQuickAbstractFileDialog(); + + virtual QString title() const; + bool selectExisting() const { return m_selectExisting; } + bool selectMultiple() const { return m_selectMultiple; } + bool selectFolder() const { return m_selectFolder; } + QString folder(); + QStringList nameFilters() const { return m_options->nameFilters(); } + QString selectedNameFilter(); + QUrl fileUrl(); + virtual QList<QUrl> fileUrls(); + +public Q_SLOTS: + void setVisible(bool v); + void setTitle(QString t); + void setSelectExisting(bool s); + void setSelectMultiple(bool s); + void setSelectFolder(bool s); + void setFolder(QString f); + void setNameFilters(const QStringList &f); + void selectNameFilter(QString f); + +Q_SIGNALS: + void folderChanged(); + void nameFiltersChanged(); + void filterSelected(); + void fileModeChanged(); + void selectionAccepted(); + +protected: + void updateModes(); + +protected: + QPlatformFileDialogHelper *m_dlgHelper; + QSharedPointer<QFileDialogOptions> m_options; + bool m_selectExisting; + bool m_selectMultiple; + bool m_selectFolder; + + Q_DISABLE_COPY(QQuickAbstractFileDialog) +}; + +QT_END_NAMESPACE + +#endif // QQUICKABSTRACTFILEDIALOG_P_H diff --git a/src/imports/dialogs/qquickcolordialog.cpp b/src/imports/dialogs/qquickcolordialog.cpp new file mode 100644 index 0000000000..39af99770e --- /dev/null +++ b/src/imports/dialogs/qquickcolordialog.cpp @@ -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 index 0000000000..ff6953fc0f --- /dev/null +++ b/src/imports/dialogs/qquickcolordialog_p.h @@ -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/qquickfiledialog.cpp b/src/imports/dialogs/qquickfiledialog.cpp new file mode 100644 index 0000000000..f78e8a6f8d --- /dev/null +++ b/src/imports/dialogs/qquickfiledialog.cpp @@ -0,0 +1,177 @@ +/**************************************************************************** +** +** 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 "qquickfiledialog_p.h" +#include <QQuickItem> +#include <private/qguiapplication_p.h> + +QT_BEGIN_NAMESPACE + +/*! + \qmltype AbstractFileDialog + \instantiates QQuickFileDialog + \inqmlmodule QtQuick.Dialogs 1 + \ingroup qtquick-visual + \brief API wrapper for QML file dialog implementations + \since 5.1 + \internal + + AbstractFileDialog provides only the API for implementing a file 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::AbstractFileDialog::accepted + + The \a accepted signal is emitted by \l accept(). +*/ + +/*! + \qmlsignal QtQuick::Dialogs::AbstractFileDialog::rejected + + The \a accepted signal is emitted by \l reject(). +*/ + +/*! + \class QQuickFileDialog + \inmodule QtQuick.Dialogs + \internal + + The QQuickFileDialog class is a concrete subclass of + \l QQuickAbstractFileDialog, 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. +*/ +QQuickFileDialog::QQuickFileDialog(QObject *parent) + : QQuickAbstractFileDialog(parent) +{ +} + + +/*! + Destroys the file dialog wrapper. +*/ +QQuickFileDialog::~QQuickFileDialog() +{ +} + +QList<QUrl> QQuickFileDialog::fileUrls() +{ + QList<QUrl> ret; + foreach (QString path, m_selections) + ret << QUrl::fromLocalFile(path); + return ret; +} + +/*! + \qmlproperty bool AbstractFileDialog::visible + + This property holds whether the dialog is visible. By default this is false. +*/ + +/*! + \qmlproperty bool AbstractFileDialog::filePaths + + A list of files to be populated as the user chooses. +*/ + +/*! + \brief Clears \l filePaths +*/ +void QQuickFileDialog::clearSelection() +{ + m_selections.clear(); +} + +/*! + \brief Adds one file to \l filePaths + + \l path should be given as an absolute file system path. If it is given as a + file:// URL, it will be converted to a path. Returns true on success, + false if the given path is not valid given the current setting properties. +*/ +bool QQuickFileDialog::addSelection(QString path) +{ + if (path.startsWith("file:")) + path = QUrl(path).toLocalFile(); + QFileInfo info(path); + if (info.exists() && ((info.isDir() && m_selectFolder) || !info.isDir())) { + if (m_selectFolder) + m_selections.append(pathFolder(path).toLocalFile()); + else + m_selections.append(path); + return true; + } + return false; +} + +/*! + \brief get a file's directory as a URL + + If \a path points to a directory, just convert it to a URL. + If \a path points to a file, convert the file's directory to a URL. +*/ +QUrl QQuickFileDialog::pathFolder(const QString &path) +{ + QFileInfo info(path); + if (info.exists() && info.isDir()) + return QUrl::fromLocalFile(path); + return QUrl::fromLocalFile(QFileInfo(path).absolutePath()); +} + +/*! + \qmlproperty QObject AbstractFileDialog::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/qquickfiledialog_p.h b/src/imports/dialogs/qquickfiledialog_p.h new file mode 100644 index 0000000000..93e11f9e3e --- /dev/null +++ b/src/imports/dialogs/qquickfiledialog_p.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** 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 QQUICKFILEDIALOG_P_H +#define QQUICKFILEDIALOG_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 "qquickabstractfiledialog_p.h" + +QT_BEGIN_NAMESPACE + +class QQuickFileDialog : public QQuickAbstractFileDialog +{ + Q_OBJECT + Q_PROPERTY(QObject* implementation READ qmlImplementation WRITE setQmlImplementation DESIGNABLE false) + Q_CLASSINFO("DefaultProperty", "implementation") // AbstractFileDialog in QML can have only one child + +public: + explicit QQuickFileDialog(QObject *parent = 0); + ~QQuickFileDialog(); + virtual QList<QUrl> fileUrls(); + +signals: + +public Q_SLOTS: + void clearSelection(); + bool addSelection(QString path); + +protected: + virtual QPlatformFileDialogHelper *helper() { return 0; } + Q_INVOKABLE QString urlToPath(const QUrl &url) { return url.toLocalFile(); } + Q_INVOKABLE QUrl pathToUrl(const QString &path) { return QUrl::fromLocalFile(path); } + Q_INVOKABLE QUrl pathFolder(const QString &path); + +private: + QStringList m_selections; + + Q_DISABLE_COPY(QQuickFileDialog) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QQuickFileDialog *) + +#endif // QQUICKFILEDIALOG_P_H diff --git a/src/imports/dialogs/qquickplatformcolordialog.cpp b/src/imports/dialogs/qquickplatformcolordialog.cpp new file mode 100644 index 0000000000..491a2e687c --- /dev/null +++ b/src/imports/dialogs/qquickplatformcolordialog.cpp @@ -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 index 0000000000..55d301da8b --- /dev/null +++ b/src/imports/dialogs/qquickplatformcolordialog_p.h @@ -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/dialogs/qquickplatformfiledialog.cpp b/src/imports/dialogs/qquickplatformfiledialog.cpp new file mode 100644 index 0000000000..d767f65499 --- /dev/null +++ b/src/imports/dialogs/qquickplatformfiledialog.cpp @@ -0,0 +1,314 @@ +/**************************************************************************** +** +** 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 "qquickplatformfiledialog_p.h" +#include "qquickitem.h" + +#include <private/qguiapplication_p.h> +#include <QWindow> +#include <QQuickView> +#include <QQuickWindow> + +QT_BEGIN_NAMESPACE + +/*! + \qmltype FileDialog + \instantiates QQuickPlatformFileDialog + \inqmlmodule QtQuick.Dialogs 1 + \ingroup qtquick-visual + \brief Dialog component for choosing files from a local filesystem. + \since Qt 5.1 + + FileDialog provides a basic file chooser: it allows the user to select + existing files and/or directories, or create new filenames. 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 file dialog and exit after the user + chooses a file: + + \qml + import QtQuick 2.1 + import QtQuick.Dialogs 1.0 + + FileDialog { + id: fileDialog + title: "Please choose a file" + onAccepted: { + console.log("You chose: " + fileDialog.filePaths) + Qt.quit() + } + onRejected: { + console.log("Canceled") + Qt.quit() + } + Component.onCompleted: visible = true + } + \endqml + + A FileDialog 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 FileDialog will be a platform file dialog if + possible. If that isn't possible, then it will try to instantiate a + \l QFileDialog. If that also isn't possible, then it will fall back to a QML + implementation, DefaultFileDialog.qml. In that case you can customize the + appearance by editing this file. DefaultFileDialog.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::FileDialog::accepted + + The \a accepted signal is emitted when the user has finished using the + dialog. You can then inspect the \a filePath or \a filePaths properties to + get the selection. + + Example: + + \qml + FileDialog { + onAccepted: { console.log("Selected file: " + filePath) } + } + \endqml +*/ + +/*! + \qmlsignal QtQuick::Dialogs::FileDialog::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 QQuickPlatformFileDialog + \inmodule QtQuick.Dialogs + \internal + + \brief The QQuickPlatformFileDialog class provides a file dialog + + The dialog is implemented via the QPlatformFileDialogHelper when possible; + otherwise it falls back to a QFileDialog or a QML implementation. + + \since 5.1 +*/ + +/*! + Constructs a file dialog with parent window \a parent. +*/ +QQuickPlatformFileDialog::QQuickPlatformFileDialog(QObject *parent) : + QQuickAbstractFileDialog(parent) +{ +} + +/*! + Destroys the file dialog. +*/ +QQuickPlatformFileDialog::~QQuickPlatformFileDialog() +{ + if (m_dlgHelper) + m_dlgHelper->hide(); + delete m_dlgHelper; +} + +QPlatformFileDialogHelper *QQuickPlatformFileDialog::helper() +{ + QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent()); + if (parentItem) + m_parentWindow = parentItem->window(); + + if ( !m_dlgHelper && QGuiApplicationPrivate::platformTheme()-> + usePlatformNativeDialog(QPlatformTheme::FileDialog) ) { + m_dlgHelper = static_cast<QPlatformFileDialogHelper *>(QGuiApplicationPrivate::platformTheme() + ->createPlatformDialogHelper(QPlatformTheme::FileDialog)); + if (!m_dlgHelper) + return m_dlgHelper; + connect(m_dlgHelper, SIGNAL(directoryEntered(QString)), this, SIGNAL(folderChanged())); + connect(m_dlgHelper, SIGNAL(filterSelected(QString)), this, SIGNAL(filterSelected())); + connect(m_dlgHelper, SIGNAL(accept()), this, SLOT(accept())); + connect(m_dlgHelper, SIGNAL(reject()), this, SLOT(reject())); + } + + return m_dlgHelper; +} + +/*! + \qmlproperty bool FileDialog::visible + + This property holds whether the dialog is visible. By default this is + false. + + \sa modality +*/ + +/*! + \qmlproperty Qt::WindowModality FileDialog::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 WindowModal. + + 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. You probably need to write an onAccepted handler + to actually load or save the chosen file. +*/ + +/*! + \qmlmethod void FileDialog::open() + + Shows the dialog to the user. It is equivalent to setting \l visible to + true. +*/ + +/*! + \qmlmethod void FileDialog::close() + + Closes the dialog. +*/ + +/*! + \qmlproperty string FileDialog::title + + The title of the dialog window. +*/ + +/*! + \qmlproperty bool FileDialog::selectExisting + + Whether only existing files or directories can be selected. + + By default, this property is true. This property must be set to the desired + value before opening the dialog. Setting this property to false implies + that the dialog is for naming a file to which to save something, or naming + a folder to be created; therefore \l selectMultiple must be false. +*/ + +/*! + \qmlproperty bool FileDialog::selectMultiple + + Whether more than one filename can be selected. + + By default, this property is false. This property must be set to the + desired value before opening the dialog. Setting this property to true + implies that \l selectExisting must be true. +*/ + +/*! + \qmlproperty bool FileDialog::selectFolder + + Whether the selected item should be a folder. + + By default, this property is false. This property must be set to the + desired value before opening the dialog. Setting this property to true + implies that \l selectMultiple must be false and \l selectExisting must be + true. +*/ + +/*! + \qmlproperty string FileDialog::folder + + The path to the currently selected folder. Setting this property before + invoking open() will cause the file browser to be initially positioned on + the specified folder. + + The value of this property is also updated after the dialog is closed. + + By default, this property is false. +*/ + +/*! + \qmlproperty list<string> FileDialog::nameFilters + + A list of strings to be used as file name filters. Each string can be a + space-separated list of filters; filters may include the ? and * wildcards. + The list of filters can also be enclosed in parentheses and a textual + description of the filter can be provided. + + For example: + + \qml + FileDialog { + nameFilters: [ "Image files (*.jpg *.png)", "All files (*)" ] + } + \endqml + + \note Directories are not excluded by filters. + \sa selectedNameFilter +*/ + +/*! + \qmlproperty string FileDialog::selectedNameFilter + + Which of the \l nameFilters is currently selected. + + This property can be set before the dialog is visible, to set the default + name filter, and can also be set while the dialog is visible to set the + current name filter. It is also updated when the user selects a different + filter. +*/ + +/*! + \qmlproperty string FileDialog::filePath + + The path of the file which was selected by the user. + + \note This property is set only if exactly one file was selected. In all + other cases, it will return an empty string. + + \sa filePaths +*/ + +/*! + \qmlproperty list<string> FileDialog::filePaths + + The list of file paths which were selected by the user. +*/ + +QT_END_NAMESPACE diff --git a/src/imports/dialogs/qquickplatformfiledialog_p.h b/src/imports/dialogs/qquickplatformfiledialog_p.h new file mode 100644 index 0000000000..5431836271 --- /dev/null +++ b/src/imports/dialogs/qquickplatformfiledialog_p.h @@ -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 QQUICKPLATFORMFILEDIALOG_P_H +#define QQUICKPLATFORMFILEDIALOG_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 "qquickabstractfiledialog_p.h" + +QT_BEGIN_NAMESPACE + +class QQuickPlatformFileDialog : public QQuickAbstractFileDialog +{ + Q_OBJECT + +public: + QQuickPlatformFileDialog(QObject *parent = 0); + virtual ~QQuickPlatformFileDialog(); + +protected: + QPlatformFileDialogHelper *helper(); + + Q_DISABLE_COPY(QQuickPlatformFileDialog) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QQuickPlatformFileDialog *) + +#endif // QQUICKPLATFORMFILEDIALOG_P_H |