| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the Qt Quick Dialogs module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | #ifndef QQUICKABSTRACTDIALOG_P_H |
| 41 | #define QQUICKABSTRACTDIALOG_P_H |
| 42 | |
| 43 | // |
| 44 | // W A R N I N G |
| 45 | // ------------- |
| 46 | // |
| 47 | // This file is not part of the Qt API. It exists purely as an |
| 48 | // implementation detail. This header file may change from version to |
| 49 | // version without notice, or even be removed. |
| 50 | // |
| 51 | // We mean it. |
| 52 | // |
| 53 | |
| 54 | #include <QtQml/qqml.h> |
| 55 | #include <QQuickView> |
| 56 | #include <QtGui/qpa/qplatformdialoghelper.h> |
| 57 | #include <qpa/qplatformtheme.h> |
| 58 | |
| 59 | QT_BEGIN_NAMESPACE |
| 60 | |
| 61 | class QQuickAbstractDialog : public QObject |
| 62 | { |
| 63 | Q_OBJECT |
| 64 | // TODO move the enum to QQuickDialog1 at the same time that QQuickMessageDialog inherits from it |
| 65 | Q_ENUMS(StandardButton) |
| 66 | Q_FLAGS(StandardButtons) |
| 67 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibilityChanged) |
| 68 | Q_PROPERTY(Qt::WindowModality modality READ modality WRITE setModality NOTIFY modalityChanged) |
| 69 | Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) |
| 70 | Q_PROPERTY(bool isWindow READ isWindow CONSTANT) |
| 71 | Q_PROPERTY(int x READ x WRITE setX NOTIFY geometryChanged) |
| 72 | Q_PROPERTY(int y READ y WRITE setY NOTIFY geometryChanged) |
| 73 | Q_PROPERTY(int width READ width WRITE setWidth NOTIFY geometryChanged) |
| 74 | Q_PROPERTY(int height READ height WRITE setHeight NOTIFY geometryChanged) |
| 75 | Q_PROPERTY(int __maximumDimension READ __maximumDimension NOTIFY __maximumDimensionChanged) |
| 76 | |
| 77 | public: |
| 78 | QQuickAbstractDialog(QObject *parent = 0); |
| 79 | virtual ~QQuickAbstractDialog(); |
| 80 | |
| 81 | bool isVisible() const { return m_visible; } |
| 82 | Qt::WindowModality modality() const { return m_modality; } |
| 83 | virtual QString title() const = 0; |
| 84 | QQuickItem* contentItem() { return m_contentItem; } |
| 85 | |
| 86 | int x() const; |
| 87 | int y() const; |
| 88 | int width() const; |
| 89 | int height() const; |
| 90 | int __maximumDimension() const; |
| 91 | |
| 92 | virtual void setVisible(bool v); |
| 93 | virtual void setModality(Qt::WindowModality m); |
| 94 | virtual void setTitle(const QString &t) = 0; |
| 95 | void setContentItem(QQuickItem* obj); |
| 96 | bool isWindow() const { return m_hasNativeWindows; } |
| 97 | |
| 98 | enum StandardButton { |
| 99 | NoButton = QPlatformDialogHelper::NoButton, |
| 100 | Ok = QPlatformDialogHelper::Ok, |
| 101 | Save = QPlatformDialogHelper::Save, |
| 102 | SaveAll = QPlatformDialogHelper::SaveAll, |
| 103 | Open = QPlatformDialogHelper::Open, |
| 104 | Yes = QPlatformDialogHelper::Yes, |
| 105 | YesToAll = QPlatformDialogHelper::YesToAll, |
| 106 | No = QPlatformDialogHelper::No, |
| 107 | NoToAll = QPlatformDialogHelper::NoToAll, |
| 108 | Abort = QPlatformDialogHelper::Abort, |
| 109 | Retry = QPlatformDialogHelper::Retry, |
| 110 | Ignore = QPlatformDialogHelper::Ignore, |
| 111 | Close = QPlatformDialogHelper::Close, |
| 112 | Cancel = QPlatformDialogHelper::Cancel, |
| 113 | Discard = QPlatformDialogHelper::Discard, |
| 114 | Help = QPlatformDialogHelper::Help, |
| 115 | Apply = QPlatformDialogHelper::Apply, |
| 116 | Reset = QPlatformDialogHelper::Reset, |
| 117 | RestoreDefaults = QPlatformDialogHelper::RestoreDefaults, |
| 118 | NButtons |
| 119 | }; |
| 120 | Q_DECLARE_FLAGS(StandardButtons, StandardButton) |
| 121 | |
| 122 | public Q_SLOTS: |
| 123 | void open() { setVisible(true); } |
| 124 | void close() { setVisible(false); } |
| 125 | void setX(int arg); |
| 126 | void setY(int arg); |
| 127 | void setWidth(int arg); |
| 128 | void setHeight(int arg); |
| 129 | |
| 130 | Q_SIGNALS: |
| 131 | void visibilityChanged(); |
| 132 | void geometryChanged(); |
| 133 | void modalityChanged(); |
| 134 | void titleChanged(); |
| 135 | void accepted(); |
| 136 | void rejected(); |
| 137 | void __maximumDimensionChanged(); |
| 138 | |
| 139 | protected Q_SLOTS: |
| 140 | void decorationLoaded(); |
| 141 | virtual void accept(); |
| 142 | virtual void reject(); |
| 143 | void visibleChanged(bool v); |
| 144 | void windowGeometryChanged(); |
| 145 | void minimumWidthChanged(); |
| 146 | void minimumHeightChanged(); |
| 147 | void implicitHeightChanged(); |
| 148 | |
| 149 | protected: |
| 150 | virtual QPlatformDialogHelper *helper() = 0; |
| 151 | QQuickWindow *parentWindow(); |
| 152 | |
| 153 | protected: |
| 154 | QQuickWindow *m_parentWindow; |
| 155 | bool m_visible; |
| 156 | Qt::WindowModality m_modality; |
| 157 | |
| 158 | protected: // variables and methods for pure-QML implementations only |
| 159 | void setDecorationDismissBehavior(); |
| 160 | |
| 161 | QQuickItem *m_contentItem; |
| 162 | QWindow *m_dialogWindow; |
| 163 | QQuickItem *m_windowDecoration; |
| 164 | bool m_hasNativeWindows; |
| 165 | QRect m_sizeAspiration; |
| 166 | bool m_hasAspiredPosition; |
| 167 | bool m_visibleChangedConnected; |
| 168 | bool m_dialogHelperInUse; |
| 169 | |
| 170 | QQmlComponent *m_decorationComponent = nullptr; |
| 171 | static QUrl m_decorationComponentUrl; |
| 172 | |
| 173 | friend class QtQuick2DialogsPlugin; |
| 174 | |
| 175 | Q_DISABLE_COPY(QQuickAbstractDialog) |
| 176 | }; |
| 177 | |
| 178 | Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickAbstractDialog::StandardButtons) |
| 179 | |
| 180 | QT_END_NAMESPACE |
| 181 | |
| 182 | #endif // QQUICKABSTRACTDIALOG_P_H |
| 183 | |