summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dialogs/DefaultDialogWrapper.qml162
-rw-r--r--src/dialogs/dialogs.pro5
-rw-r--r--src/dialogs/plugin.cpp14
-rw-r--r--src/dialogs/qquickabstractdialog.cpp27
-rw-r--r--src/dialogs/qquickabstractdialog_p.h31
-rw-r--r--src/dialogs/qquickabstractmessagedialog.cpp2
-rw-r--r--src/dialogs/qquickabstractmessagedialog_p.h37
-rw-r--r--src/dialogs/qquickdialog.cpp271
-rw-r--r--src/dialogs/qquickdialog_p.h127
-rw-r--r--src/dialogs/qquickdialogassets_p.h2
10 files changed, 643 insertions, 35 deletions
diff --git a/src/dialogs/DefaultDialogWrapper.qml b/src/dialogs/DefaultDialogWrapper.qml
new file mode 100644
index 000000000..1a30141e6
--- /dev/null
+++ b/src/dialogs/DefaultDialogWrapper.qml
@@ -0,0 +1,162 @@
+/*****************************************************************************
+**
+** Copyright (C) 2014 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.Controls 1.1
+import QtQuick.Dialogs 1.2
+import QtQuick.Layouts 1.1
+import QtQuick.Window 2.1
+import "qml"
+
+AbstractDialog {
+ id: root
+ default property alias data: contentItem.data
+
+ Rectangle {
+ id: content
+ property real spacing: 6
+ property real outerSpacing: 12
+ property real buttonsRowImplicitWidth: minimumWidth
+ property bool buttonsInSingleRow: contentItem.width >= buttonsRowImplicitWidth
+ property real minimumHeight: implicitHeight
+ property real minimumWidth: Screen.pixelDensity * 50
+ implicitHeight: contentItem.implicitHeight + spacing + outerSpacing * 2 +
+ (buttonsInSingleRow ? moreButton.implicitHeight : moreButton.implicitHeight * 2 + spacing)
+ implicitWidth: Math.min(Screen.desktopAvailableWidth * 0.9, Math.max(
+ contentItem.implicitWidth, buttonsRowImplicitWidth, Screen.pixelDensity * 50) + outerSpacing * 2);
+ color: palette.window
+ focus: root.visible
+ Keys.onPressed: {
+ event.accepted = true
+ switch (event.key) {
+ case Qt.Key_Escape:
+ case Qt.Key_Back:
+ reject()
+ break
+ case Qt.Key_Enter:
+ case Qt.Key_Return:
+ accept()
+ break
+ }
+ }
+
+ SystemPalette { id: palette }
+
+ Item {
+ id: contentItem
+ anchors {
+ left: parent.left
+ right: parent.right
+ top: parent.top
+ margins: content.outerSpacing
+ }
+ implicitHeight: childrenRect.height
+ }
+
+ Flow {
+ id: buttonsLeft
+ spacing: content.spacing
+ anchors {
+ left: parent.left
+ bottom: content.buttonsInSingleRow ? parent.bottom : buttonsRight.top
+ margins: content.outerSpacing
+ }
+
+ Repeater {
+ model: standardButtonsLeftModel
+ onCountChanged: calculateImplicitWidth()
+ Button {
+ text: standardButtonsLeftModel[index].text
+ onClicked: root.click(standardButtonsLeftModel[index].standardButton)
+ }
+ }
+
+ Button {
+ id: moreButton
+ text: "Show Details..."
+ visible: false
+ }
+ }
+
+ Flow {
+ id: buttonsRight
+ spacing: content.spacing
+ layoutDirection: Qt.RightToLeft
+ anchors {
+ left: parent.left
+ right: parent.right
+ bottom: parent.bottom
+ margins: content.outerSpacing
+ }
+
+ Repeater {
+ model: standardButtonsRightModel
+ onCountChanged: calculateImplicitWidth()
+ // TODO maybe: insert gaps if the button requires it (destructive buttons only)
+ Button {
+ text: standardButtonsRightModel[index].text
+ onClicked: root.click(standardButtonsRightModel[index].standardButton)
+ }
+ }
+ }
+ }
+ function calculateImplicitWidth() {
+ if (buttonsRight.visibleChildren.length < 2)
+ return;
+ var calcWidth = 0;
+
+ function calculateForButton(i, b) {
+ var buttonWidth = b.implicitWidth;
+ if (buttonWidth > 0) {
+ if (i > 0)
+ buttonWidth += content.spacing
+ calcWidth += buttonWidth
+ }
+ }
+
+ for (var i = 0; i < buttonsRight.visibleChildren.length; ++i)
+ calculateForButton(i, buttonsRight.visibleChildren[i])
+ content.minimumWidth = calcWidth + content.outerSpacing * 2
+ for (i = 0; i < buttonsLeft.visibleChildren.length; ++i)
+ calculateForButton(i, buttonsLeft.visibleChildren[i])
+ content.buttonsRowImplicitWidth = calcWidth + content.spacing
+ }
+ Component.onCompleted: calculateImplicitWidth()
+}
diff --git a/src/dialogs/dialogs.pro b/src/dialogs/dialogs.pro
index dee9fe362..4ad7888f5 100644
--- a/src/dialogs/dialogs.pro
+++ b/src/dialogs/dialogs.pro
@@ -19,6 +19,7 @@ SOURCES += \
qquickplatformfontdialog.cpp \
qquickfontdialog.cpp \
qquickabstractdialog.cpp \
+ qquickdialog.cpp \
plugin.cpp
HEADERS += \
@@ -35,7 +36,8 @@ HEADERS += \
qquickabstractfontdialog_p.h \
qquickplatformfontdialog_p.h \
qquickfontdialog_p.h \
- qquickabstractdialog_p.h
+ qquickabstractdialog_p.h \
+ qquickdialog_p.h
DIALOGS_QML_FILES += \
DefaultMessageDialog.qml \
@@ -46,6 +48,7 @@ DIALOGS_QML_FILES += \
WidgetColorDialog.qml \
DefaultFontDialog.qml \
WidgetFontDialog.qml \
+ DefaultDialogWrapper.qml \
qml/ColorSlider.qml \
qml/DefaultWindowDecoration.qml \
qml/qmldir \
diff --git a/src/dialogs/plugin.cpp b/src/dialogs/plugin.cpp
index 4e4c641e0..7c8c6bea0 100644
--- a/src/dialogs/plugin.cpp
+++ b/src/dialogs/plugin.cpp
@@ -54,6 +54,7 @@
#include "qquickfontdialog_p.h"
#include "qquickabstractfontdialog_p.h"
#include "qquickplatformfontdialog_p.h"
+#include "qquickdialog_p.h"
#include <private/qguiapplication_p.h>
#include <qpa/qplatformintegration.h>
@@ -162,6 +163,19 @@ public:
else
#endif
registerWidgetOrQmlImplementation<QQuickFontDialog>(widgetsDir, qmlDir, "FontDialog", uri, hasTopLevelWindows, 1, 1);
+
+ // Dialog
+ {
+ // @uri QtQuick.Dialogs.AbstractDialog
+ qmlRegisterType<QQuickDialog>(uri, 1, 2, "AbstractDialog"); // implementation wrapper
+ QUrl dialogQmlPath = m_useResources ?
+ QUrl("qrc:/QtQuick/Dialogs/DefaultDialogWrapper.qml") :
+ QUrl::fromLocalFile(qmlDir.filePath("DefaultDialogWrapper.qml"));
+#ifdef DEBUG_REGISTRATION
+ qDebug() << " registering DefaultDialogWrapper.qml as Dialog; success?" <<
+#endif
+ qmlRegisterType(dialogQmlPath, uri, 1, 2, "Dialog");
+ }
}
protected:
diff --git a/src/dialogs/qquickabstractdialog.cpp b/src/dialogs/qquickabstractdialog.cpp
index 9bb238874..92bad9bf9 100644
--- a/src/dialogs/qquickabstractdialog.cpp
+++ b/src/dialogs/qquickabstractdialog.cpp
@@ -103,7 +103,20 @@ void QQuickAbstractDialog::setVisible(bool v)
((QObject *)win)->setParent(this); // memory management only
m_dialogWindow = win;
m_contentItem->setParentItem(win->contentItem());
- m_dialogWindow->setMinimumSize(QSize(m_contentItem->implicitWidth(), m_contentItem->implicitHeight()));
+ QSize minSize = QSize(m_contentItem->implicitWidth(), m_contentItem->implicitHeight());
+ QVariant minHeight = m_contentItem->property("minimumHeight");
+ if (minHeight.isValid()) {
+ if (minHeight.toInt() > minSize.height())
+ minSize.setHeight(minHeight.toDouble());
+ connect(m_contentItem, SIGNAL(minimumHeightChanged()), this, SLOT(minimumHeightChanged()));
+ }
+ QVariant minWidth = m_contentItem->property("minimumWidth");
+ if (minWidth.isValid()) {
+ if (minWidth.toInt() > minSize.width())
+ minSize.setWidth(minWidth.toInt());
+ connect(m_contentItem, SIGNAL(minimumWidthChanged()), this, SLOT(minimumWidthChanged()));
+ }
+ m_dialogWindow->setMinimumSize(minSize);
connect(win, SIGNAL(widthChanged(int)), this, SLOT(windowGeometryChanged()));
connect(win, SIGNAL(heightChanged(int)), this, SLOT(windowGeometryChanged()));
}
@@ -230,6 +243,18 @@ void QQuickAbstractDialog::windowGeometryChanged()
}
}
+void QQuickAbstractDialog::minimumWidthChanged()
+{
+ m_dialogWindow->setMinimumWidth(qMax(m_contentItem->implicitWidth(),
+ m_contentItem->property("minimumWidth").toReal()));
+}
+
+void QQuickAbstractDialog::minimumHeightChanged()
+{
+ m_dialogWindow->setMinimumHeight(qMax(m_contentItem->implicitHeight(),
+ m_contentItem->property("minimumHeight").toReal()));
+}
+
QQuickWindow *QQuickAbstractDialog::parentWindow()
{
QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent());
diff --git a/src/dialogs/qquickabstractdialog_p.h b/src/dialogs/qquickabstractdialog_p.h
index 8ffa166c5..5a408530c 100644
--- a/src/dialogs/qquickabstractdialog_p.h
+++ b/src/dialogs/qquickabstractdialog_p.h
@@ -63,6 +63,9 @@ QT_BEGIN_NAMESPACE
class QQuickAbstractDialog : public QObject
{
Q_OBJECT
+ // TODO move the enum to QQuickDialog at the same time that QQuickMessageDialog inherits from it
+ Q_ENUMS(StandardButton)
+ Q_FLAGS(StandardButtons)
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)
@@ -92,6 +95,30 @@ public:
void setQmlImplementation(QObject* obj);
bool isWindow() const { return m_hasNativeWindows; }
+ enum StandardButton {
+ NoButton = QPlatformDialogHelper::NoButton,
+ Ok = QPlatformDialogHelper::Ok,
+ Save = QPlatformDialogHelper::Save,
+ SaveAll = QPlatformDialogHelper::SaveAll,
+ Open = QPlatformDialogHelper::Open,
+ Yes = QPlatformDialogHelper::Yes,
+ YesToAll = QPlatformDialogHelper::YesToAll,
+ No = QPlatformDialogHelper::No,
+ NoToAll = QPlatformDialogHelper::NoToAll,
+ Abort = QPlatformDialogHelper::Abort,
+ Retry = QPlatformDialogHelper::Retry,
+ Ignore = QPlatformDialogHelper::Ignore,
+ Close = QPlatformDialogHelper::Close,
+ Cancel = QPlatformDialogHelper::Cancel,
+ Discard = QPlatformDialogHelper::Discard,
+ Help = QPlatformDialogHelper::Help,
+ Apply = QPlatformDialogHelper::Apply,
+ Reset = QPlatformDialogHelper::Reset,
+ RestoreDefaults = QPlatformDialogHelper::RestoreDefaults,
+ NButtons
+ };
+ Q_DECLARE_FLAGS(StandardButtons, StandardButton)
+
public Q_SLOTS:
void open() { setVisible(true); }
void close() { setVisible(false); }
@@ -114,6 +141,8 @@ protected Q_SLOTS:
virtual void reject();
void visibleChanged(bool v);
void windowGeometryChanged();
+ void minimumWidthChanged();
+ void minimumHeightChanged();
protected:
virtual QPlatformDialogHelper *helper() = 0;
@@ -140,6 +169,8 @@ protected: // variables for pure-QML implementations only
Q_DISABLE_COPY(QQuickAbstractDialog)
};
+Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickAbstractDialog::StandardButtons)
+
QT_END_NAMESPACE
#endif // QQUICKABSTRACTDIALOG_P_H
diff --git a/src/dialogs/qquickabstractmessagedialog.cpp b/src/dialogs/qquickabstractmessagedialog.cpp
index 2c24c4ba6..ebaed414b 100644
--- a/src/dialogs/qquickabstractmessagedialog.cpp
+++ b/src/dialogs/qquickabstractmessagedialog.cpp
@@ -169,7 +169,7 @@ void QQuickAbstractMessageDialog::click(QPlatformDialogHelper::StandardButton bu
}
}
-void QQuickAbstractMessageDialog::click(QQuickAbstractMessageDialog::StandardButton button)
+void QQuickAbstractMessageDialog::click(QQuickAbstractDialog::StandardButton button)
{
click(static_cast<QPlatformDialogHelper::StandardButton>(button),
static_cast<QPlatformDialogHelper::ButtonRole>(
diff --git a/src/dialogs/qquickabstractmessagedialog_p.h b/src/dialogs/qquickabstractmessagedialog_p.h
index 2afea1dc0..3cf8ee47b 100644
--- a/src/dialogs/qquickabstractmessagedialog_p.h
+++ b/src/dialogs/qquickabstractmessagedialog_p.h
@@ -66,16 +66,14 @@ 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)
+ Q_PROPERTY(QQuickAbstractDialog::StandardButtons standardButtons READ standardButtons WRITE setStandardButtons NOTIFY standardButtonsChanged)
+ Q_PROPERTY(QQuickAbstractDialog::StandardButton clickedButton READ clickedButton NOTIFY buttonClicked)
public:
QQuickAbstractMessageDialog(QObject *parent = 0);
@@ -98,29 +96,6 @@ public:
QUrl standardIconSource();
- enum StandardButton {
- NoButton = QPlatformDialogHelper::NoButton,
- Ok = QPlatformDialogHelper::Ok,
- Save = QPlatformDialogHelper::Save,
- SaveAll = QPlatformDialogHelper::SaveAll,
- Open = QPlatformDialogHelper::Open,
- Yes = QPlatformDialogHelper::Yes,
- YesToAll = QPlatformDialogHelper::YesToAll,
- No = QPlatformDialogHelper::No,
- NoToAll = QPlatformDialogHelper::NoToAll,
- Abort = QPlatformDialogHelper::Abort,
- Retry = QPlatformDialogHelper::Retry,
- Ignore = QPlatformDialogHelper::Ignore,
- Close = QPlatformDialogHelper::Close,
- Cancel = QPlatformDialogHelper::Cancel,
- Discard = QPlatformDialogHelper::Discard,
- Help = QPlatformDialogHelper::Help,
- Apply = QPlatformDialogHelper::Apply,
- Reset = QPlatformDialogHelper::Reset,
- RestoreDefaults = QPlatformDialogHelper::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; }
@@ -133,8 +108,7 @@ public Q_SLOTS:
void setDetailedText(const QString &arg);
void setIcon(Icon icon);
void setStandardButtons(StandardButtons buttons);
- void click(QPlatformDialogHelper::StandardButton button, QPlatformDialogHelper::ButtonRole);
- void click(QQuickAbstractMessageDialog::StandardButton button);
+ void click(QQuickAbstractDialog::StandardButton button);
Q_SIGNALS:
void textChanged();
@@ -151,6 +125,9 @@ Q_SIGNALS:
void reset();
protected:
+ void click(QPlatformDialogHelper::StandardButton button, QPlatformDialogHelper::ButtonRole);
+
+protected:
QPlatformMessageDialogHelper *m_dlgHelper;
QSharedPointer<QMessageDialogOptions> m_options;
StandardButton m_clickedButton;
@@ -158,8 +135,6 @@ protected:
Q_DISABLE_COPY(QQuickAbstractMessageDialog)
};
-Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickAbstractMessageDialog::StandardButtons)
-
QT_END_NAMESPACE
#endif // QQUICKABSTRACTMESSAGEDIALOG_P_H
diff --git a/src/dialogs/qquickdialog.cpp b/src/dialogs/qquickdialog.cpp
new file mode 100644
index 000000000..4d47ab3cf
--- /dev/null
+++ b/src/dialogs/qquickdialog.cpp
@@ -0,0 +1,271 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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 "qquickdialog_p.h"
+#include <QQuickItem>
+#include <private/qguiapplication_p.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \qmltype Dialog
+ \instantiates QQuickDialog
+ \inqmlmodule QtQuick.Dialogs
+ \ingroup qtquick-visual
+ \brief A generic QtQuick dialog wrapper with standard buttons
+ \since 5.3
+
+ Dialog provides an item with a platform-tailored button box for a dialog.
+ The \l implementation Item is the default property (the only allowed child
+ element).
+*/
+
+/*!
+ \qmlsignal QtQuick::Dialogs::Dialog::accepted
+
+ This signal is emitted by \l accept().
+*/
+
+/*!
+ \qmlsignal QtQuick::Dialogs::Dialog::rejected
+
+ This signal is emitted by \l reject().
+*/
+
+/*!
+ \class QQuickDialog
+ \inmodule QtQuick.Dialogs
+ \internal
+
+ The QQuickDialog class represents a container for arbitrary
+ dialog contents.
+
+ \since 5.3
+*/
+
+/*!
+ Constructs a dialog wrapper with parent window \a parent.
+*/
+QQuickDialog::QQuickDialog(QObject *parent)
+ : QQuickAbstractDialog(parent)
+{
+ connect(this, SIGNAL(buttonClicked()), this, SLOT(clicked()));
+}
+
+
+/*!
+ Destroys the dialog wrapper.
+*/
+QQuickDialog::~QQuickDialog()
+{
+}
+
+QJSValue QQuickDialog::standardButtonsLeftModel()
+{
+ updateStandardButtons();
+ return m_standardButtonsLeftModel;
+}
+
+QJSValue QQuickDialog::standardButtonsRightModel()
+{
+ updateStandardButtons();
+ return m_standardButtonsRightModel;
+}
+
+void QQuickDialog::updateStandardButtons()
+{
+ if (m_standardButtonsRightModel.isUndefined()) {
+ QJSEngine *engine = qmlEngine(this);
+ // Managed objects so no need to destroy any existing ones
+ m_standardButtonsLeftModel = engine->newArray();
+ m_standardButtonsRightModel = engine->newArray();
+ int i = 0;
+
+ QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme();
+ QPlatformDialogHelper::ButtonLayout layoutPolicy =
+ static_cast<QPlatformDialogHelper::ButtonLayout>(theme->themeHint(QPlatformTheme::DialogButtonBoxLayout).toInt());
+ const quint32 *buttonLayout = QPlatformDialogHelper::buttonLayout(Qt::Horizontal, layoutPolicy);
+ QJSValue *model = &m_standardButtonsLeftModel;
+ for (int r = 0; buttonLayout[r] != QPlatformDialogHelper::EOL; ++r) {
+ quint32 role = (buttonLayout[r] & ~QPlatformDialogHelper::Reverse);
+ // Keep implementation in sync with that in QDialogButtonBoxPrivate::layoutButtons()
+ // to the extent that QtQuick supports the same features
+ switch (role) {
+ case QPlatformDialogHelper::Stretch:
+ model = &m_standardButtonsRightModel;
+ i = 0;
+ break;
+ // TODO maybe: case QPlatformDialogHelper::AlternateRole:
+ default: {
+ for (int e = QPlatformDialogHelper::LowestBit; e <= QPlatformDialogHelper::HighestBit; ++e) {
+ quint32 standardButton = 1 << e;
+ quint32 standardButtonRole = QPlatformDialogHelper::buttonRole(
+ static_cast<QPlatformDialogHelper::StandardButton>(standardButton));
+ if ((m_enabledButtons & standardButton) && standardButtonRole == role) {
+ QJSValue o = engine->newObject();
+ o.setProperty("text", theme->standardButtonText(standardButton));
+ o.setProperty("standardButton", standardButton);
+ o.setProperty("role", role);
+ model->setProperty(i++, o);
+ }
+ }
+ } break;
+ }
+ }
+ }
+}
+
+void QQuickDialog::setTitle(const QString &arg)
+{
+ if (m_title != arg) {
+ m_title = arg;
+ emit titleChanged();
+ }
+}
+
+void QQuickDialog::setStandardButtons(StandardButtons buttons)
+{
+ m_enabledButtons = buttons;
+ m_standardButtonsLeftModel = QJSValue();
+ m_standardButtonsRightModel = QJSValue();
+ emit standardButtonsChanged();
+}
+
+/*!
+ \qmlproperty bool Dialog::visible
+
+ This property holds whether the dialog is visible. By default this is false.
+*/
+
+/*!
+ \qmlproperty QObject Dialog::implementation
+
+ The QML object which implements the dialog contents. Should be an \l Item.
+*/
+
+void QQuickDialog::click(QPlatformDialogHelper::StandardButton button, QPlatformDialogHelper::ButtonRole role)
+{
+ setVisible(false);
+ m_clickedButton = static_cast<StandardButton>(button);
+ emit buttonClicked();
+ switch (role) {
+ case QPlatformDialogHelper::AcceptRole:
+ emit accept();
+ break;
+ case QPlatformDialogHelper::RejectRole:
+ emit reject();
+ break;
+ case QPlatformDialogHelper::DestructiveRole:
+ emit discard();
+ break;
+ case QPlatformDialogHelper::HelpRole:
+ emit help();
+ break;
+ case QPlatformDialogHelper::YesRole:
+ emit yes();
+ break;
+ case QPlatformDialogHelper::NoRole:
+ emit no();
+ break;
+ case QPlatformDialogHelper::ApplyRole:
+ emit apply();
+ break;
+ case QPlatformDialogHelper::ResetRole:
+ emit reset();
+ break;
+ default:
+ qWarning("unhandled MessageDialog button %d with role %ld", button, role);
+ }
+}
+
+void QQuickDialog::click(QQuickAbstractDialog::StandardButton button)
+{
+ click(static_cast<QPlatformDialogHelper::StandardButton>(button),
+ static_cast<QPlatformDialogHelper::ButtonRole>(
+ QPlatformDialogHelper::buttonRole(static_cast<QPlatformDialogHelper::StandardButton>(button))));
+}
+
+void QQuickDialog::clicked() {
+ switch (QPlatformDialogHelper::buttonRole(static_cast<QPlatformDialogHelper::StandardButton>(m_clickedButton))) {
+ case QPlatformDialogHelper::AcceptRole:
+ accept();
+ break;
+ case QPlatformDialogHelper::RejectRole:
+ reject();
+ break;
+ case QPlatformDialogHelper::DestructiveRole:
+ emit discard();
+ break;
+ case QPlatformDialogHelper::HelpRole:
+ emit help();
+ break;
+ case QPlatformDialogHelper::YesRole:
+ emit yes();
+ break;
+ case QPlatformDialogHelper::NoRole:
+ emit no();
+ break;
+ case QPlatformDialogHelper::ApplyRole:
+ emit apply();
+ break;
+ case QPlatformDialogHelper::ResetRole:
+ emit reset();
+ break;
+ default:
+ qWarning("StandardButton %d has no role", m_clickedButton);
+ }
+}
+
+void QQuickDialog::accept() {
+ // enter key is treated like OK
+ if (m_clickedButton == NoButton)
+ m_clickedButton = Ok;
+ QQuickAbstractDialog::accept();
+}
+
+void QQuickDialog::reject() {
+ // escape key is treated like cancel
+ if (m_clickedButton == NoButton)
+ m_clickedButton = Cancel;
+ QQuickAbstractDialog::reject();
+}
+
+QT_END_NAMESPACE
diff --git a/src/dialogs/qquickdialog_p.h b/src/dialogs/qquickdialog_p.h
new file mode 100644
index 000000000..e9a96612d
--- /dev/null
+++ b/src/dialogs/qquickdialog_p.h
@@ -0,0 +1,127 @@
+/****************************************************************************
+**
+** 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 QQUICKDIALOG_P_H
+#define QQUICKDIALOG_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 QQuickDialog : public QQuickAbstractDialog
+{
+ Q_OBJECT
+
+ Q_ENUMS(StandardButton)
+ Q_FLAGS(StandardButtons)
+
+ Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
+ Q_PROPERTY(QQuickAbstractDialog::StandardButtons standardButtons READ standardButtons WRITE setStandardButtons NOTIFY standardButtonsChanged)
+ Q_PROPERTY(QQuickAbstractDialog::StandardButton clickedButton READ clickedButton NOTIFY buttonClicked)
+ Q_PROPERTY(QObject* implementation READ qmlImplementation WRITE setQmlImplementation DESIGNABLE false)
+ Q_PROPERTY(QJSValue standardButtonsLeftModel READ standardButtonsLeftModel NOTIFY standardButtonsChanged)
+ Q_PROPERTY(QJSValue standardButtonsRightModel READ standardButtonsRightModel NOTIFY standardButtonsChanged)
+ Q_CLASSINFO("DefaultProperty", "implementation") // Dialog in QML can have only one child
+
+public:
+ explicit QQuickDialog(QObject *parent = 0);
+ ~QQuickDialog();
+
+ StandardButtons standardButtons() const { return m_enabledButtons; }
+ StandardButton clickedButton() const { return m_clickedButton; }
+ QJSValue standardButtonsLeftModel();
+ QJSValue standardButtonsRightModel();
+
+ QString title() const { return m_title; }
+
+public Q_SLOTS:
+ virtual void setTitle(const QString &arg);
+ void setStandardButtons(StandardButtons buttons);
+ void click(QQuickAbstractDialog::StandardButton button);
+
+Q_SIGNALS:
+ void titleChanged();
+ void standardButtonsChanged();
+ void buttonClicked();
+ void discard();
+ void help();
+ void yes();
+ void no();
+ void apply();
+ void reset();
+
+protected:
+ virtual QPlatformDialogHelper *helper() { return 0; }
+ void click(QPlatformDialogHelper::StandardButton button, QPlatformDialogHelper::ButtonRole);
+
+protected Q_SLOTS:
+ virtual void accept();
+ virtual void reject();
+ void clicked();
+
+private:
+ void updateStandardButtons();
+
+private:
+ QString m_title;
+ StandardButton m_clickedButton;
+ StandardButtons m_enabledButtons;
+ QJSValue m_standardButtonsLeftModel;
+ QJSValue m_standardButtonsRightModel;
+ Q_DISABLE_COPY(QQuickDialog)
+};
+
+QT_END_NAMESPACE
+
+QML_DECLARE_TYPE(QQuickDialog *)
+
+#endif // QQUICKDIALOG_P_H
diff --git a/src/dialogs/qquickdialogassets_p.h b/src/dialogs/qquickdialogassets_p.h
index 406b68a66..f06fc4121 100644
--- a/src/dialogs/qquickdialogassets_p.h
+++ b/src/dialogs/qquickdialogassets_p.h
@@ -51,7 +51,7 @@ QT_BEGIN_NAMESPACE
class QQuickStandardButton
{
Q_GADGET
- Q_ENUMS(QQuickAbstractMessageDialog::StandardButton)
+ Q_ENUMS(QQuickAbstractDialog::StandardButton)
};
class QQuickStandardIcon