diff options
author | Shawn Rutledge <shawn.rutledge@digia.com> | 2013-08-26 10:31:54 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-19 13:53:34 +0200 |
commit | a25b1fdf7d642d9f252fbfa1789efaa32e03b994 (patch) | |
tree | e13f4255693049d4133fc96e0e5236fbd3c9f43a /src/imports | |
parent | 607f2db351edf4b0f677c302fa37733596abe024 (diff) |
Adding QtQuick.Dialogs.MessageDialog
Change-Id: Ifa3de21e6f611c24742118d6d178edbe14f243be
Reviewed-by: Liang Qi <liang.qi@digia.com>
Diffstat (limited to 'src/imports')
23 files changed, 1683 insertions, 5 deletions
diff --git a/src/imports/dialogs/DefaultMessageDialog.qml b/src/imports/dialogs/DefaultMessageDialog.qml new file mode 100644 index 0000000000..5dbe727f68 --- /dev/null +++ b/src/imports/dialogs/DefaultMessageDialog.qml @@ -0,0 +1,310 @@ +/***************************************************************************** +** +** 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.Window 2.1 +import QtQuick.Dialogs 1.1 +import "qml" + +AbstractMessageDialog { + id: root + + Rectangle { + id: content + property real spacing: 8 + property real outerSpacing: 12 + property int maxSize: 0.9 * Math.min(Screen.desktopAvailableWidth, Screen.desktopAvailableHeight) + implicitHeight: contentColumn.implicitHeight + outerSpacing * 2 + onImplicitHeightChanged: root.height = implicitHeight + implicitWidth: Math.min(maxSize, Math.max( + mainText.implicitWidth, buttons.implicitWidth) + outerSpacing * 2); + onImplicitWidthChanged: if (implicitWidth > root.width) root.width = implicitWidth + color: palette.window + focus: true + Keys.onEscapePressed: root.reject() + Keys.onEnterPressed: root.accept() + Keys.onReturnPressed: root.accept() + Keys.onPressed: if (event.modifiers === Qt.ControlModifier) + switch (event.key) { + case Qt.Key_A: + detailedText.selectAll(); + break; + case Qt.Key_C: + detailedText.copy(); + break; + } + + Column { + id: contentColumn + spacing: content.spacing + anchors { + top: parent.top + left: parent.left + right: parent.right + margins: content.outerSpacing + } + + SystemPalette { id: palette } + + Item { + width: parent.width + height: Math.max(icon.height, mainText.height + informativeText.height + content.spacing) + Image { + id: icon + source: root.standardIconSource + } + + Text { + id: mainText + anchors { + left: icon.right + leftMargin: content.spacing + right: parent.right + } + text: root.text + font.weight: Font.Bold + wrapMode: Text.WordWrap + } + + Text { + id: informativeText + anchors { + left: icon.right + right: parent.right + top: mainText.bottom + leftMargin: content.spacing + topMargin: content.spacing + } + text: root.informativeText + wrapMode: Text.WordWrap + } + } + + + Row { + id: buttons + spacing: content.spacing + layoutDirection: Qt.RightToLeft + width: parent.width + Button { + id: okButton + text: "OK" + onClicked: root.click(Message.Ok) + visible: root.standardButtons & Message.Ok + } + Button { + id: openButton + text: "Open" + onClicked: root.click(Message.Open) + visible: root.standardButtons & Message.Open + } + Button { + id: saveButton + text: "Save" + onClicked: root.click(Message.Save) + visible: root.standardButtons & Message.Save + } + Button { + id: saveAllButton + text: "Save All" + onClicked: root.click(Message.SaveAll) + visible: root.standardButtons & Message.SaveAll + } + Button { + id: retryButton + text: "Retry" + onClicked: root.click(Message.Retry) + visible: root.standardButtons & Message.Retry + } + Button { + id: ignoreButton + text: "Ignore" + onClicked: root.click(Message.Ignore) + visible: root.standardButtons & Message.Ignore + } + Button { + id: applyButton + text: "Apply" + onClicked: root.click(Message.Apply) + visible: root.standardButtons & Message.Apply + } + Button { + id: yesButton + text: "Yes" + onClicked: root.click(Message.Yes) + visible: root.standardButtons & Message.Yes + } + Button { + id: yesAllButton + text: "Yes to All" + onClicked: root.click(Message.YesToAll) + visible: root.standardButtons & Message.YesToAll + } + Button { + id: noButton + text: "No" + onClicked: root.click(Message.No) + visible: root.standardButtons & Message.No + } + Button { + id: noAllButton + text: "No to All" + onClicked: root.click(Message.NoToAll) + visible: root.standardButtons & Message.NoToAll + } + Button { + id: discardButton + text: "Discard" + onClicked: root.click(Message.Discard) + visible: root.standardButtons & Message.Discard + } + Button { + id: resetButton + text: "Reset" + onClicked: root.click(Message.Reset) + visible: root.standardButtons & Message.Reset + } + Button { + id: restoreDefaultsButton + text: "Restore Defaults" + onClicked: root.click(Message.RestoreDefaults) + visible: root.standardButtons & Message.RestoreDefaults + } + Button { + id: cancelButton + text: "Cancel" + onClicked: root.click(Message.Cancel) + visible: root.standardButtons & Message.Cancel + } + Button { + id: abortButton + text: "Abort" + onClicked: root.click(Message.Abort) + visible: root.standardButtons & Message.Abort + } + Button { + id: closeButton + text: "Close" + onClicked: root.click(Message.Close) + visible: root.standardButtons & Message.Close + } + Button { + id: moreButton + text: "Show Details..." + onClicked: content.state = (content.state === "" ? "expanded" : "") + visible: root.detailedText.length > 0 + } + Button { + id: helpButton + text: "Help" + onClicked: root.click(Message.Help) + visible: root.standardButtons & Message.Help + } + } + } + + Item { + id: details + width: parent.width + implicitHeight: detailedText.implicitHeight + content.spacing + height: 0 + clip: true + + anchors { + left: parent.left + right: parent.right + top: contentColumn.bottom + topMargin: content.spacing + leftMargin: content.outerSpacing + rightMargin: content.outerSpacing + } + + Flickable { + id: flickable + contentHeight: detailedText.height + anchors.fill: parent + anchors.topMargin: content.spacing + anchors.bottomMargin: content.outerSpacing + TextEdit { + id: detailedText + text: root.detailedText + width: details.width + wrapMode: Text.WordWrap + readOnly: true + selectByMouse: true + } + } + + Component { + id: edgeFade + EdgeFade { + fadeColor: palette.window + topThreshold: flickable.atYBeginning ? 0 : content.spacing * 3 + bottomThreshold: flickable.atYEnd ? 0 : content.spacing * 3 + } + } + + Loader { + sourceComponent: flickable.height < flickable.contentHeight ? edgeFade : undefined + anchors.fill: parent + } + + } + + states: [ + State { + name: "expanded" + PropertyChanges { + target: details + height: content.height - contentColumn.height - content.spacing - content.outerSpacing + } + PropertyChanges { + target: content + implicitHeight: contentColumn.implicitHeight + content.spacing * 2 + + detailedText.implicitHeight + content.outerSpacing * 2 + } + PropertyChanges { + target: moreButton + text: "Hide Details" + } + } + ] + } +} diff --git a/src/imports/dialogs/WidgetMessageDialog.qml b/src/imports/dialogs/WidgetMessageDialog.qml new file mode 100644 index 0000000000..8bc3eccfd7 --- /dev/null +++ b/src/imports/dialogs/WidgetMessageDialog.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.1 + +QtMessageDialog { } diff --git a/src/imports/dialogs/dialogs.pro b/src/imports/dialogs/dialogs.pro index c1d7041263..8db3d9ab58 100644 --- a/src/imports/dialogs/dialogs.pro +++ b/src/imports/dialogs/dialogs.pro @@ -6,6 +6,9 @@ IMPORT_VERSION = 1.1 QMAKE_DOCS = $$PWD/doc/qtquickdialogs.qdocconf SOURCES += \ + qquickabstractmessagedialog.cpp \ + qquickplatformmessagedialog.cpp \ + qquickmessagedialog.cpp \ qquickabstractfiledialog.cpp \ qquickplatformfiledialog.cpp \ qquickfiledialog.cpp \ @@ -19,6 +22,10 @@ SOURCES += \ plugin.cpp HEADERS += \ + qquickabstractmessagedialog_p.h \ + qquickplatformmessagedialog_p.h \ + qquickmessagedialog_p.h \ + qquickmessageattached_p.h \ qquickabstractfiledialog_p.h \ qquickplatformfiledialog_p.h \ qquickfiledialog_p.h \ @@ -31,6 +38,8 @@ HEADERS += \ qquickabstractdialog_p.h QML_FILES += \ + DefaultMessageDialog.qml \ + WidgetMessageDialog.qml \ DefaultFileDialog.qml \ WidgetFileDialog.qml \ DefaultColorDialog.qml \ @@ -40,9 +49,14 @@ QML_FILES += \ qml/Button.qml \ qml/CheckBox.qml \ qml/ColorSlider.qml \ + qml/EdgeFade.qml \ qml/DefaultWindowDecoration.qml \ qml/TextField.qml \ qml/qmldir \ + images/critical.png \ + images/information.png \ + images/question.png \ + images/warning.png \ images/checkers.png \ images/checkmark.png \ images/copy.png \ diff --git a/src/imports/dialogs/images/critical.png b/src/imports/dialogs/images/critical.png Binary files differnew file mode 100644 index 0000000000..dc9c5aebf4 --- /dev/null +++ b/src/imports/dialogs/images/critical.png diff --git a/src/imports/dialogs/images/information.png b/src/imports/dialogs/images/information.png Binary files differnew file mode 100644 index 0000000000..0a2eb87d10 --- /dev/null +++ b/src/imports/dialogs/images/information.png diff --git a/src/imports/dialogs/images/question.png b/src/imports/dialogs/images/question.png Binary files differnew file mode 100644 index 0000000000..2dd92fd791 --- /dev/null +++ b/src/imports/dialogs/images/question.png diff --git a/src/imports/dialogs/images/warning.png b/src/imports/dialogs/images/warning.png Binary files differnew file mode 100644 index 0000000000..cba78f6bea --- /dev/null +++ b/src/imports/dialogs/images/warning.png diff --git a/src/imports/dialogs/plugin.cpp b/src/imports/dialogs/plugin.cpp index e8c669cb49..e62e4efa34 100644 --- a/src/imports/dialogs/plugin.cpp +++ b/src/imports/dialogs/plugin.cpp @@ -41,6 +41,10 @@ #include <QtQml/qqml.h> #include <QtQml/qqmlextensionplugin.h> +#include "qquickmessagedialog_p.h" +#include "qquickabstractmessagedialog_p.h" +#include "qquickmessageattached_p.h" +#include "qquickplatformmessagedialog_p.h" #include "qquickfiledialog_p.h" #include "qquickabstractfiledialog_p.h" #include "qquickplatformfiledialog_p.h" @@ -68,7 +72,7 @@ QT_BEGIN_NAMESPACE To use the types in this module, import the module with the following line: \code - import QtQuick.Dialogs 1.0 + import QtQuick.Dialogs 1.1 \endcode */ @@ -101,6 +105,15 @@ public: // possible to instantiate it from Qt Quick. // Otherwise fall back to a pure-QML implementation. + // MessageDialog + qmlRegisterUncreatableType<QQuickMessageAttached>(uri, 1, 1, "Message", QQuickMessageAttached::tr("Message can only be used via the attached property.")); +#ifndef PURE_QML_ONLY + if (QGuiApplicationPrivate::platformTheme()->usePlatformNativeDialog(QPlatformTheme::MessageDialog)) + qmlRegisterType<QQuickPlatformMessageDialog>(uri, 1, 0, "MessageDialog"); + else +#endif + registerWidgetOrQmlImplementation<QQuickMessageDialog>(widgetsDir, qmlDir, "MessageDialog", uri, hasTopLevelWindows, 1, 1); + // FileDialog #ifndef PURE_QML_ONLY if (QGuiApplicationPrivate::platformTheme()->usePlatformNativeDialog(QPlatformTheme::FileDialog)) diff --git a/src/imports/dialogs/qml/Button.qml b/src/imports/dialogs/qml/Button.qml index 26cc23a5be..19ed073484 100644 --- a/src/imports/dialogs/qml/Button.qml +++ b/src/imports/dialogs/qml/Button.qml @@ -50,7 +50,7 @@ Item { property alias containsMouse: mouseArea.containsMouse property alias pressed: mouseArea.pressed implicitHeight: Math.max(Screen.logicalPixelDensity * 7, buttonLabel.implicitHeight * 1.2) - implicitWidth: Math.max(Screen.logicalPixelDensity * 11, buttonLabel.implicitWidth * 1.3) + implicitWidth: visible ? Math.max(Screen.logicalPixelDensity * 11, buttonLabel.implicitWidth * 1.3) : 0 height: implicitHeight width: implicitWidth diff --git a/src/imports/dialogs/qml/EdgeFade.qml b/src/imports/dialogs/qml/EdgeFade.qml new file mode 100644 index 0000000000..376aa151e6 --- /dev/null +++ b/src/imports/dialogs/qml/EdgeFade.qml @@ -0,0 +1,63 @@ +/***************************************************************************** +** +** 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 + +ShaderEffect { + property color fadeColor + property real topThreshold: 10 + property real bottomThreshold: 10 + property real _topRatio: topThreshold / height + property real _bottomRatio: bottomThreshold / height + z: 1 + fragmentShader: " + varying lowp vec2 qt_TexCoord0; + uniform lowp vec4 fadeColor; + uniform highp float _topRatio; + uniform highp float _bottomRatio; + + void main() { + highp float bottomEnd = 1. - _bottomRatio; + gl_FragColor = fadeColor * + (qt_TexCoord0.y < _topRatio ? 1. - qt_TexCoord0.y / _topRatio : + (qt_TexCoord0.y > bottomEnd ? (qt_TexCoord0.y - bottomEnd) / _bottomRatio : 0.)); + } + " +} diff --git a/src/imports/dialogs/qml/qmldir b/src/imports/dialogs/qml/qmldir index 39cbc937e5..9d273b1c4b 100644 --- a/src/imports/dialogs/qml/qmldir +++ b/src/imports/dialogs/qml/qmldir @@ -1,4 +1,5 @@ Button 1.0 Button.qml CheckBox 1.1 CheckBox.qml ColorSlider 1.0 ColorSlider.qml +EdgeFade 1.0 EdgeFade.qml TextField 1.0 TextField.qml diff --git a/src/imports/dialogs/qquickabstractdialog_p.h b/src/imports/dialogs/qquickabstractdialog_p.h index c18df33c6c..8ffa166c5b 100644 --- a/src/imports/dialogs/qquickabstractdialog_p.h +++ b/src/imports/dialogs/qquickabstractdialog_p.h @@ -110,8 +110,8 @@ Q_SIGNALS: protected Q_SLOTS: void decorationLoaded(); - void accept(); - void reject(); + virtual void accept(); + virtual void reject(); void visibleChanged(bool v); void windowGeometryChanged(); diff --git a/src/imports/dialogs/qquickabstractmessagedialog.cpp b/src/imports/dialogs/qquickabstractmessagedialog.cpp new file mode 100644 index 0000000000..cfcf056e6c --- /dev/null +++ b/src/imports/dialogs/qquickabstractmessagedialog.cpp @@ -0,0 +1,142 @@ +/**************************************************************************** +** +** 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 "qquickabstractmessagedialog_p.h" + +QT_BEGIN_NAMESPACE + +QQuickAbstractMessageDialog::QQuickAbstractMessageDialog(QObject *parent) + : QQuickAbstractDialog(parent) + , m_dlgHelper(0) + , m_options(QSharedPointer<QMessageDialogOptions>(new QMessageDialogOptions())) + , m_clickedButton(NoButton) +{ +} + +QQuickAbstractMessageDialog::~QQuickAbstractMessageDialog() +{ +} + +void QQuickAbstractMessageDialog::setVisible(bool v) +{ + if (helper() && v) + m_dlgHelper->setOptions(m_options); + if (v) + m_clickedButton = NoButton; + QQuickAbstractDialog::setVisible(v); +} + +void QQuickAbstractMessageDialog::setTitle(const QString &arg) +{ + if (arg != m_options->windowTitle()) { + m_options->setWindowTitle(arg); + emit titleChanged(); + } +} + +void QQuickAbstractMessageDialog::setText(const QString &arg) +{ + if (arg != m_options->text()) { + m_options->setText(arg); + emit textChanged(); + } +} + +void QQuickAbstractMessageDialog::setInformativeText(const QString &arg) +{ + if (arg != m_options->informativeText()) { + m_options->setInformativeText(arg); + emit informativeTextChanged(); + } +} + +void QQuickAbstractMessageDialog::setDetailedText(const QString &arg) +{ + if (arg != m_options->detailedText()) { + m_options->setDetailedText(arg); + emit detailedTextChanged(); + } +} + +void QQuickAbstractMessageDialog::setIcon(QQuickAbstractMessageDialog::Icon icon) +{ + if (static_cast<int>(icon) != static_cast<int>(m_options->icon())) { + m_options->setIcon(static_cast<QMessageDialogOptions::Icon>(icon)); + emit iconChanged(); + } +} + +QUrl QQuickAbstractMessageDialog::standardIconSource() +{ + switch (m_options->icon()) { + case QMessageDialogOptions::Information: + return QUrl("images/information.png"); + break; + case QMessageDialogOptions::Warning: + return QUrl("images/warning.png"); + break; + case QMessageDialogOptions::Critical: + return QUrl("images/critical.png"); + break; + case QMessageDialogOptions::Question: + return QUrl("images/question.png"); + break; + default: + return QUrl(); + break; + } +} + +void QQuickAbstractMessageDialog::setStandardButtons(StandardButtons buttons) +{ + if (buttons != m_options->standardButtons()) { + m_options->setStandardButtons(static_cast<QMessageDialogOptions::StandardButtons>(static_cast<int>(buttons))); + emit standardButtonsChanged(); + } +} + +void QQuickAbstractMessageDialog::click(QQuickAbstractMessageDialog::StandardButton button) +{ + m_clickedButton = button; + emit buttonClicked(); +} + +QT_END_NAMESPACE diff --git a/src/imports/dialogs/qquickabstractmessagedialog_p.h b/src/imports/dialogs/qquickabstractmessagedialog_p.h new file mode 100644 index 0000000000..3f1b842a96 --- /dev/null +++ b/src/imports/dialogs/qquickabstractmessagedialog_p.h @@ -0,0 +1,164 @@ +/**************************************************************************** +** +** 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 QQUICKABSTRACTMESSAGEDIALOG_P_H +#define QQUICKABSTRACTMESSAGEDIALOG_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 QQuickAbstractMessageDialog : public QQuickAbstractDialog +{ + Q_OBJECT + + Q_ENUMS(Icon) + Q_ENUMS(StandardButton) + Q_FLAGS(StandardButtons) + + Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) + Q_PROPERTY(QString informativeText READ informativeText WRITE setInformativeText NOTIFY informativeTextChanged) + Q_PROPERTY(QString detailedText READ detailedText WRITE setDetailedText NOTIFY detailedTextChanged) + Q_PROPERTY(Icon icon READ icon WRITE setIcon NOTIFY iconChanged) + Q_PROPERTY(QUrl standardIconSource READ standardIconSource NOTIFY iconChanged) + Q_PROPERTY(StandardButtons standardButtons READ standardButtons WRITE setStandardButtons NOTIFY standardButtonsChanged) + Q_PROPERTY(StandardButton clickedButton READ clickedButton NOTIFY buttonClicked) + +public: + QQuickAbstractMessageDialog(QObject *parent = 0); + virtual ~QQuickAbstractMessageDialog(); + + virtual QString title() const { return m_options->windowTitle(); } + QString text() const { return m_options->text(); } + QString informativeText() const { return m_options->informativeText(); } + QString detailedText() const { return m_options->detailedText(); } + + enum Icon { + NoIcon = QMessageDialogOptions::NoIcon, + Information = QMessageDialogOptions::Information, + Warning = QMessageDialogOptions::Warning, + Critical = QMessageDialogOptions::Critical, + Question = QMessageDialogOptions::Question + }; + + Icon icon() const { return static_cast<Icon>(m_options->icon()); } + + QUrl standardIconSource(); + + enum StandardButton { + NoButton = QMessageDialogOptions::NoButton, + Ok = QMessageDialogOptions::Ok, + Save = QMessageDialogOptions::Save, + SaveAll = QMessageDialogOptions::SaveAll, + Open = QMessageDialogOptions::Open, + Yes = QMessageDialogOptions::Yes, + YesToAll = QMessageDialogOptions::YesToAll, + No = QMessageDialogOptions::No, + NoToAll = QMessageDialogOptions::NoToAll, + Abort = QMessageDialogOptions::Abort, + Retry = QMessageDialogOptions::Retry, + Ignore = QMessageDialogOptions::Ignore, + Close = QMessageDialogOptions::Close, + Cancel = QMessageDialogOptions::Cancel, + Discard = QMessageDialogOptions::Discard, + Help = QMessageDialogOptions::Help, + Apply = QMessageDialogOptions::Apply, + Reset = QMessageDialogOptions::Reset, + RestoreDefaults = QMessageDialogOptions::RestoreDefaults + }; + Q_DECLARE_FLAGS(StandardButtons, StandardButton) + + StandardButtons standardButtons() const { return static_cast<StandardButtons>(static_cast<int>(m_options->standardButtons())); } + + StandardButton clickedButton() const { return m_clickedButton; } + +public Q_SLOTS: + virtual void setVisible(bool v); + virtual void setTitle(const QString &arg); + void setText(const QString &arg); + void setInformativeText(const QString &arg); + void setDetailedText(const QString &arg); + void setIcon(Icon icon); + void setStandardButtons(StandardButtons buttons); + void click(StandardButton button); + +Q_SIGNALS: + void textChanged(); + void informativeTextChanged(); + void detailedTextChanged(); + void iconChanged(); + void standardButtonsChanged(); + void buttonClicked(); + void discard(); + void help(); + void yes(); + void no(); + void apply(); + void reset(); + +protected: + QPlatformMessageDialogHelper *m_dlgHelper; + QSharedPointer<QMessageDialogOptions> m_options; + StandardButton m_clickedButton; + + Q_DISABLE_COPY(QQuickAbstractMessageDialog) +}; + +Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickAbstractMessageDialog::StandardButtons) + +QT_END_NAMESPACE + +#endif // QQUICKABSTRACTMESSAGEDIALOG_P_H diff --git a/src/imports/dialogs/qquickmessageattached_p.h b/src/imports/dialogs/qquickmessageattached_p.h new file mode 100644 index 0000000000..c1cb94ae36 --- /dev/null +++ b/src/imports/dialogs/qquickmessageattached_p.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtQml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKMESSAGEATTACHED_H +#define QQUICKMESSAGEATTACHED_H + +#include <private/qtquickglobal_p.h> +#include <QtGui/qpa/qplatformdialoghelper.h> +#include "qquickabstractmessagedialog_p.h" + +QT_BEGIN_NAMESPACE + +class Q_DECL_EXPORT QQuickMessageAttached : public QObject +{ + Q_OBJECT + Q_ENUMS(QQuickAbstractMessageDialog::Icon) + Q_ENUMS(QQuickAbstractMessageDialog::StandardButton) + +public: + static QQuickMessageAttached *qmlAttachedProperties(QObject *obj) { + return new QQuickMessageAttached(obj); } + + QQuickMessageAttached(QObject *parent = 0) : QObject(parent) { } +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QQuickMessageAttached) +QML_DECLARE_TYPEINFO(QQuickMessageAttached, QML_HAS_ATTACHED_PROPERTIES) + +#endif // QQUICKMESSAGEATTACHED_H diff --git a/src/imports/dialogs/qquickmessagedialog.cpp b/src/imports/dialogs/qquickmessagedialog.cpp new file mode 100644 index 0000000000..43b6ca09b4 --- /dev/null +++ b/src/imports/dialogs/qquickmessagedialog.cpp @@ -0,0 +1,181 @@ +/**************************************************************************** +** +** 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 "qquickmessagedialog_p.h" +#include <QQuickItem> +#include <private/qguiapplication_p.h> + +QT_BEGIN_NAMESPACE + +/*! + \qmltype AbstractMessageDialog + \instantiates QQuickMessageDialog + \inqmlmodule QtQuick.Dialogs 1 + \ingroup qtquick-visual + \brief API wrapper for QML message dialog implementations + \since 5.2 + \internal + + AbstractMessageDialog provides only the API for implementing a message 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::AbstractMessageDialog::accepted + + This signal is emitted by \l accept(). +*/ + +/*! + \qmlsignal QtQuick::Dialogs::AbstractMessageDialog::rejected + + This signal is emitted by \l reject(). +*/ + +/*! + \class QQuickMessageDialog + \inmodule QtQuick.Dialogs + \internal + + The QQuickMessageDialog class is a concrete subclass of + \l QQuickAbstractMessageDialog, 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.2 +*/ + +/*! + Constructs a message dialog wrapper with parent window \a parent. +*/ +QQuickMessageDialog::QQuickMessageDialog(QObject *parent) + : QQuickAbstractMessageDialog(parent) +{ + connect(this, SIGNAL(buttonClicked()), this, SLOT(clicked())); +} + + +/*! + Destroys the message dialog wrapper. +*/ +QQuickMessageDialog::~QQuickMessageDialog() +{ +} + +/*! + \qmlproperty bool AbstractMessageDialog::visible + + This property holds whether the dialog is visible. By default this is false. +*/ + +/*! + \qmlproperty QObject AbstractMessageDialog::implementation + + The QML object which implements the actual message dialog. Should be either a + \l Window or an \l Item. +*/ + + +void QQuickMessageDialog::clicked() { + switch (m_clickedButton) { + // This mapping from buttons to roles is the same as + // documented for enum QMessageBox::StandardButton + case Ok: + case Open: + case Save: + case SaveAll: + case Retry: + case Ignore: + accept(); + break; + case Cancel: + case Close: + case Abort: + reject(); + break; + case Discard: + emit discard(); + close(); + break; + case Help: + emit help(); + break; + case Yes: + case YesToAll: + emit yes(); + close(); + break; + case No: + case NoToAll: + emit no(); + close(); + break; + case Apply: + emit apply(); + break; + case Reset: + case RestoreDefaults: + emit reset(); + break; + default: + qWarning("StandardButton %d has no role", m_clickedButton); + } +} + +void QQuickMessageDialog::accept() { + // enter key is treated like OK + if (m_clickedButton == NoButton) + m_clickedButton = Ok; + QQuickAbstractMessageDialog::accept(); +} + +void QQuickMessageDialog::reject() { + // escape key is treated like cancel + if (m_clickedButton == NoButton) + m_clickedButton = Cancel; + QQuickAbstractMessageDialog::reject(); +} + +QT_END_NAMESPACE diff --git a/src/imports/dialogs/qquickmessagedialog_p.h b/src/imports/dialogs/qquickmessagedialog_p.h new file mode 100644 index 0000000000..b21d8cba42 --- /dev/null +++ b/src/imports/dialogs/qquickmessagedialog_p.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** 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 QQUICKMESSAGEDIALOG_P_H +#define QQUICKMESSAGEDIALOG_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 "qquickabstractmessagedialog_p.h" + +QT_BEGIN_NAMESPACE + +class QQuickMessageDialog : public QQuickAbstractMessageDialog +{ + Q_OBJECT + Q_PROPERTY(QObject* implementation READ qmlImplementation WRITE setQmlImplementation DESIGNABLE false) + Q_CLASSINFO("DefaultProperty", "implementation") // AbstractMessageDialog in QML can have only one child + +public: + explicit QQuickMessageDialog(QObject *parent = 0); + ~QQuickMessageDialog(); + +protected: + virtual QPlatformDialogHelper *helper() { return 0; } + +protected Q_SLOTS: + virtual void accept(); + virtual void reject(); + void clicked(); + +private: + Q_DISABLE_COPY(QQuickMessageDialog) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QQuickMessageDialog *) + +#endif // QQUICKMESSAGEDIALOG_P_H diff --git a/src/imports/dialogs/qquickplatformmessagedialog.cpp b/src/imports/dialogs/qquickplatformmessagedialog.cpp new file mode 100644 index 0000000000..0e21212711 --- /dev/null +++ b/src/imports/dialogs/qquickplatformmessagedialog.cpp @@ -0,0 +1,206 @@ +/**************************************************************************** +** +** 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 "qquickplatformmessagedialog_p.h" +#include "qquickitem.h" + +#include <private/qguiapplication_p.h> +#include <QWindow> +#include <QQuickView> +#include <QQuickWindow> + +QT_BEGIN_NAMESPACE + +/*! + \qmltype MessageDialog + \instantiates QQuickPlatformMessageDialog + \inqmlmodule QtQuick.Dialogs 1 + \ingroup dialogs + \brief Dialog component for displaying popup messages. + \since Qt 5.2 + + The most basic use case for a MessageDialog is a popup alert. It also + allows the user to respond in various ways depending on which buttons are + enabled. 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 show an alert and exit after the user + responds: + + \qml + import QtQuick 2.2 + import QtQuick.Dialogs 1.1 + + MessageDialog { + id: messageDialog + title: "May I have your attention please" + text: "It's so cool that you are using Qt Quick." + onAccepted: { + console.log("And of course you could only agree.") + Qt.quit() + } + Component.onCompleted: visible = true + } + \endqml + + A MessageDialog 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 MessageDialog will be a platform message dialog if + possible. If that isn't possible, then it will try to instantiate a + \l QMessageBox. If that also isn't possible, then it will fall back to a QML + implementation, DefaultMessageDialog.qml. In that case you can customize the + appearance by editing this file. DefaultMessageDialog.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::MessageDialog::accepted + + This handler is called when the user has pressed OK. +*/ + +/*! + \qmlsignal QtQuick::Dialogs::MessageDialog::rejected + + This handler is called when the user has dismissed the dialog, + either by closing the dialog window or by pressing the Cancel button. +*/ + +/*! + \class QQuickPlatformMessageDialog + \inmodule QtQuick.Dialogs + \internal + + \brief The QQuickPlatformMessageDialog class provides a message dialog + + The dialog is implemented via the QPlatformMessageDialogHelper when possible; + otherwise it falls back to a QMessageBox or a QML implementation. + + \since 5.2 +*/ + +/*! + Constructs a file dialog with parent window \a parent. +*/ +QQuickPlatformMessageDialog::QQuickPlatformMessageDialog(QObject *parent) : + QQuickAbstractMessageDialog(parent) +{ +} + +/*! + Destroys the file dialog. +*/ +QQuickPlatformMessageDialog::~QQuickPlatformMessageDialog() +{ + if (m_dlgHelper) + m_dlgHelper->hide(); + delete m_dlgHelper; +} + +QPlatformMessageDialogHelper *QQuickPlatformMessageDialog::helper() +{ + QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent()); + if (parentItem) + m_parentWindow = parentItem->window(); + + if ( !m_dlgHelper && QGuiApplicationPrivate::platformTheme()-> + usePlatformNativeDialog(QPlatformTheme::MessageDialog) ) { + m_dlgHelper = static_cast<QPlatformMessageDialogHelper *>(QGuiApplicationPrivate::platformTheme() + ->createPlatformDialogHelper(QPlatformTheme::MessageDialog)); + if (!m_dlgHelper) + return m_dlgHelper; + connect(m_dlgHelper, SIGNAL(accept()), this, SLOT(accept())); + connect(m_dlgHelper, SIGNAL(reject()), this, SLOT(reject())); + } + + return m_dlgHelper; +} + +/*! + \qmlproperty bool MessageDialog::visible + + This property holds whether the dialog is visible. By default this is + false. + + \sa modality +*/ + +/*! + \qmlproperty Qt::WindowModality MessageDialog::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 \c Qt.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. +*/ + +/*! + \qmlmethod void MessageDialog::open() + + Shows the dialog to the user. It is equivalent to setting \l visible to + true. +*/ + +/*! + \qmlmethod void MessageDialog::close() + + Closes the dialog. +*/ + +/*! + \qmlproperty string MessageDialog::title + + The title of the dialog window. +*/ + +QT_END_NAMESPACE diff --git a/src/imports/dialogs/qquickplatformmessagedialog_p.h b/src/imports/dialogs/qquickplatformmessagedialog_p.h new file mode 100644 index 0000000000..61f055bb38 --- /dev/null +++ b/src/imports/dialogs/qquickplatformmessagedialog_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 QQUICKPLATFORMMESSAGEDIALOG_P_H +#define QQUICKPLATFORMMESSAGEDIALOG_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 "qquickabstractmessagedialog_p.h" + +QT_BEGIN_NAMESPACE + +class QQuickPlatformMessageDialog : public QQuickAbstractMessageDialog +{ + Q_OBJECT + +public: + QQuickPlatformMessageDialog(QObject *parent = 0); + virtual ~QQuickPlatformMessageDialog(); + +protected: + QPlatformMessageDialogHelper *helper(); + + Q_DISABLE_COPY(QQuickPlatformMessageDialog) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QQuickPlatformMessageDialog *) + +#endif // QQUICKPLATFORMMESSAGEDIALOG_P_H diff --git a/src/imports/widgets/qquickqmessagebox.cpp b/src/imports/widgets/qquickqmessagebox.cpp new file mode 100644 index 0000000000..2f7c748c7b --- /dev/null +++ b/src/imports/widgets/qquickqmessagebox.cpp @@ -0,0 +1,215 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtQml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickqmessagebox_p.h" +#include "qquickitem.h" + +#include <private/qguiapplication_p.h> +#include <private/qqmlcontext_p.h> +#include <QWindow> +#include <QQuickWindow> +#include <QMessageBox> +#include <QAbstractButton> + +QT_BEGIN_NAMESPACE + +class QMessageBoxHelper : public QPlatformMessageDialogHelper +{ +public: + QMessageBoxHelper() { + connect(&m_dialog, SIGNAL(accepted()), this, SIGNAL(accept())); + connect(&m_dialog, SIGNAL(rejected()), this, SIGNAL(reject())); + } + + virtual void exec() { m_dialog.exec(); } + + virtual bool show(Qt::WindowFlags f, Qt::WindowModality m, QWindow *parent) { + m_dialog.winId(); + QWindow *window = m_dialog.windowHandle(); + Q_ASSERT(window); + window->setTransientParent(parent); + window->setFlags(f); + m_dialog.setWindowModality(m); + m_dialog.setWindowTitle(QPlatformMessageDialogHelper::options()->windowTitle()); + m_dialog.setIcon(static_cast<QMessageBox::Icon>(QPlatformMessageDialogHelper::options()->icon())); + if (!QPlatformMessageDialogHelper::options()->text().isNull()) + m_dialog.setText(QPlatformMessageDialogHelper::options()->text()); + if (!QPlatformMessageDialogHelper::options()->informativeText().isNull()) + m_dialog.setInformativeText(QPlatformMessageDialogHelper::options()->informativeText()); + if (!QPlatformMessageDialogHelper::options()->detailedText().isNull()) + m_dialog.setDetailedText(QPlatformMessageDialogHelper::options()->detailedText()); + m_dialog.setStandardButtons(static_cast<QMessageBox::StandardButtons>(static_cast<int>( + QPlatformMessageDialogHelper::options()->standardButtons()))); + m_dialog.show(); + return m_dialog.isVisible(); + } + + virtual void hide() { m_dialog.hide(); } + + QMessageBox m_dialog; +}; + +/*! + \qmltype QtMessageDialog + \instantiates QQuickQMessageBox + \inqmlmodule QtQuick.PrivateWidgets 1 + \ingroup qtquick-visual + \brief Dialog component for choosing a color. + \since 5.2 + \internal + + QtMessageDialog provides a means to instantiate and manage a QMessageBox. + It is not recommended to be used directly; it is an implementation + detail of \l MessageDialog in the \l QtQuick.Dialogs module. + + To use this type, you will need to import the module with the following line: + \code + import QtQuick.PrivateWidgets 1.1 + \endcode +*/ + +/*! + \qmlsignal QtQuick::Dialogs::MessageDialog::accepted + + The \a accepted signal is emitted when the user has pressed the OK button + on the dialog. + + Example: + + \qml + MessageDialog { + onAccepted: { console.log("accepted") } + } + \endqml +*/ + +/*! + \qmlsignal QtQuick::Dialogs::MessageDialog::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 QQuickQMessageBox + \inmodule QtQuick.PrivateWidgets + \internal + + \brief The QQuickQMessageBox class is a wrapper for a QMessageBox. + + \since 5.2 +*/ + +/*! + Constructs a message dialog with parent window \a parent. +*/ +QQuickQMessageBox::QQuickQMessageBox(QObject *parent) + : QQuickAbstractMessageDialog(parent) +{ +} + +/*! + Destroys the message dialog. +*/ +QQuickQMessageBox::~QQuickQMessageBox() +{ + if (m_dlgHelper) + m_dlgHelper->hide(); + delete m_dlgHelper; +} + +void QQuickQMessageBox::finished(int button) { + click(static_cast<StandardButton>(button)); +} + +void QQuickQMessageBox::clicked(QAbstractButton* button) { + QMessageBox &mb = static_cast<QMessageBoxHelper*>(QQuickAbstractMessageDialog::m_dlgHelper)->m_dialog; + switch (mb.buttonRole(button)) { + case QMessageBox::AcceptRole: + emit accepted(); + break; + case QMessageBox::RejectRole: + emit rejected(); + break; + case QMessageBox::DestructiveRole: + emit discard(); + break; + case QMessageBox::HelpRole: + emit help(); + break; + case QMessageBox::YesRole: + emit yes(); + break; + case QMessageBox::NoRole: + emit no(); + break; + case QMessageBox::ApplyRole: + emit apply(); + break; + case QMessageBox::ResetRole: + emit reset(); + break; + default: + qWarning("unhandled QMessageBox button role %d", mb.buttonRole(button)); + } + if (!mb.isVisible()) + setVisible(false); +} + +QPlatformDialogHelper *QQuickQMessageBox::helper() +{ + QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent()); + if (parentItem) + m_parentWindow = parentItem->window(); + + if (!QQuickAbstractMessageDialog::m_dlgHelper) { + QMessageBoxHelper* helper = new QMessageBoxHelper(); + QQuickAbstractMessageDialog::m_dlgHelper = helper; + connect(helper, SIGNAL(accept()), this, SLOT(accept())); + connect(helper, SIGNAL(reject()), this, SLOT(reject())); + connect(&helper->m_dialog, SIGNAL(finished(int)), this, SLOT(finished(int))); + connect(&helper->m_dialog, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(clicked(QAbstractButton*))); + } + + return QQuickAbstractMessageDialog::m_dlgHelper; +} + +QT_END_NAMESPACE diff --git a/src/imports/widgets/qquickqmessagebox_p.h b/src/imports/widgets/qquickqmessagebox_p.h new file mode 100644 index 0000000000..9c3c1f2dd6 --- /dev/null +++ b/src/imports/widgets/qquickqmessagebox_p.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtQml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKQMESSAGEBOX_P_H +#define QQUICKQMESSAGEBOX_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 <QMessageBox> +#include "../dialogs/qquickabstractmessagedialog_p.h" + +QT_BEGIN_NAMESPACE + +class QAbstractButton; + +class QQuickQMessageBox : public QQuickAbstractMessageDialog +{ + Q_OBJECT + +public: + QQuickQMessageBox(QObject *parent = 0); + virtual ~QQuickQMessageBox(); + +protected slots: + void clicked(QAbstractButton* button); + void finished(int button); + +protected: + virtual QPlatformDialogHelper *helper(); + +protected: + Q_DISABLE_COPY(QQuickQMessageBox) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QQuickQMessageBox *) + +#endif // QQUICKQMESSAGEBOX_P_H diff --git a/src/imports/widgets/widgets.pro b/src/imports/widgets/widgets.pro index 6d40897781..8c075945fd 100644 --- a/src/imports/widgets/widgets.pro +++ b/src/imports/widgets/widgets.pro @@ -4,6 +4,8 @@ TARGETPATH = QtQuick/PrivateWidgets IMPORT_VERSION = 1.1 SOURCES += \ + qquickqmessagebox.cpp \ + ../dialogs/qquickabstractmessagedialog.cpp \ qquickqfiledialog.cpp \ ../dialogs/qquickabstractfiledialog.cpp \ qquickqcolordialog.cpp \ @@ -14,6 +16,8 @@ SOURCES += \ widgetsplugin.cpp HEADERS += \ + qquickqmessagebox_p.h \ + ../dialogs/qquickabstractmessagedialog_p.h \ qquickqfiledialog_p.h \ ../dialogs/qquickabstractfiledialog_p.h \ qquickqcolordialog_p.h \ diff --git a/src/imports/widgets/widgetsplugin.cpp b/src/imports/widgets/widgetsplugin.cpp index 4df0292d8a..05c3a5e86c 100644 --- a/src/imports/widgets/widgetsplugin.cpp +++ b/src/imports/widgets/widgetsplugin.cpp @@ -41,6 +41,7 @@ #include <QtQml/qqmlextensionplugin.h> #include <QtQml/qqml.h> +#include "qquickqmessagebox_p.h" #include "qquickqfiledialog_p.h" #include "qquickqcolordialog_p.h" #include "qquickqfontdialog_p.h" @@ -60,7 +61,7 @@ QT_BEGIN_NAMESPACE and to provide fallback implementations in case they fail to load. \code - import QtQuick.PrivateWidgets 1.0 + import QtQuick.PrivateWidgets 1.1 \endcode \since 5.1 @@ -76,6 +77,7 @@ public: { Q_ASSERT(QLatin1String(uri) == QLatin1String("QtQuick.PrivateWidgets")); + qmlRegisterType<QQuickQMessageBox>(uri, 1, 1, "QtMessageDialog"); qmlRegisterType<QQuickQFileDialog>(uri, 1, 0, "QtFileDialog"); qmlRegisterType<QQuickQColorDialog>(uri, 1, 0, "QtColorDialog"); qmlRegisterType<QQuickQFontDialog>(uri, 1, 1, "QtFontDialog"); |