diff options
author | Shawn Rutledge <shawn.rutledge@digia.com> | 2014-04-09 14:07:15 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-04-15 17:47:28 +0200 |
commit | 6d438f3b5ca9fd94889461ca481bba387904af94 (patch) | |
tree | 48f2982c0a896257e2d422ee577f32b2b594821f | |
parent | f42ef1db6a111fd420776da2c620be9cefba7f14 (diff) | |
download | qtquickcontrols-6d438f3b5ca9fd94889461ca481bba387904af94.tar.gz |
Dialogs: implementation prop renamed to contentItem; API cleanup
- contentItem is a common name for an item inside something such as a
window or a flickable. We now consider it adequate API that you can
directly set this to some item which you want to fill the whole dialog
instead of adding an item as a child of the default property and being
subject to the dialog's margins and space reservation for buttons.
- contentItem MUST be an Item. Allowing the old "implementation"
property to alternatively be a ready-made Window was just a
hypothetical use case, but if anyone made use of that, then it would
be a problem to have that kind of dialog on a GUI that cannot have
windows (such as Android or EGLFS). So there's no point in having
the possibility as long as we cannot emulate windows as items.
- standardButtonsRightModel and standardButtonsLeftModel are
implementation details so they should not be exposed as properties
which Creator can discover; users shouldn't depend on them.
Task-number: QTBUG-38056
Change-Id: Iefa3def314353495cfe8d1ef9f775a8e46d5bcf4
Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
-rw-r--r-- | src/dialogs/DefaultDialogWrapper.qml | 32 | ||||
-rw-r--r-- | src/dialogs/qquickabstractdialog.cpp | 130 | ||||
-rw-r--r-- | src/dialogs/qquickabstractdialog_p.h | 7 | ||||
-rw-r--r-- | src/dialogs/qquickcolordialog_p.h | 4 | ||||
-rw-r--r-- | src/dialogs/qquickdialog.cpp | 4 | ||||
-rw-r--r-- | src/dialogs/qquickdialog_p.h | 10 | ||||
-rw-r--r-- | src/dialogs/qquickfiledialog_p.h | 4 | ||||
-rw-r--r-- | src/dialogs/qquickfontdialog_p.h | 4 | ||||
-rw-r--r-- | src/dialogs/qquickmessagedialog_p.h | 4 |
9 files changed, 94 insertions, 105 deletions
diff --git a/src/dialogs/DefaultDialogWrapper.qml b/src/dialogs/DefaultDialogWrapper.qml index 0771bdb9..9f295914 100644 --- a/src/dialogs/DefaultDialogWrapper.qml +++ b/src/dialogs/DefaultDialogWrapper.qml @@ -47,19 +47,19 @@ import "qml" AbstractDialog { id: root - default property alias data: contentItem.data + default property alias data: defaultContentItem.data Rectangle { id: content property real spacing: 6 property real outerSpacing: 12 property real buttonsRowImplicitWidth: minimumWidth - property bool buttonsInSingleRow: contentItem.width >= buttonsRowImplicitWidth + property bool buttonsInSingleRow: defaultContentItem.width >= buttonsRowImplicitWidth property real minimumHeight: implicitHeight property real minimumWidth: Screen.pixelDensity * 50 - implicitHeight: contentItem.implicitHeight + spacing + outerSpacing * 2 + buttonsRight.implicitHeight + implicitHeight: defaultContentItem.implicitHeight + spacing + outerSpacing * 2 + buttonsRight.implicitHeight implicitWidth: Math.min(Screen.desktopAvailableWidth * 0.9, Math.max( - contentItem.implicitWidth, buttonsRowImplicitWidth, Screen.pixelDensity * 50) + outerSpacing * 2); + defaultContentItem.implicitWidth, buttonsRowImplicitWidth, Screen.pixelDensity * 50) + outerSpacing * 2); color: palette.window focus: root.visible Keys.onPressed: { @@ -81,7 +81,7 @@ AbstractDialog { SystemPalette { id: palette } Item { - id: contentItem + id: defaultContentItem anchors { left: parent.left right: parent.right @@ -101,10 +101,10 @@ AbstractDialog { } Repeater { - model: standardButtonsLeftModel + id: buttonsLeftRepeater Button { - text: standardButtonsLeftModel[index].text - onClicked: root.click(standardButtonsLeftModel[index].standardButton) + text: (buttonsLeftRepeater.model && buttonsLeftRepeater.model[index] ? buttonsLeftRepeater.model[index].text : index) + onClicked: root.click(buttonsLeftRepeater.model[index].standardButton) } } @@ -127,17 +127,19 @@ AbstractDialog { } Repeater { - model: standardButtonsRightModel + id: buttonsRightRepeater // TODO maybe: insert gaps if the button requires it (destructive buttons only) Button { - text: standardButtonsRightModel[index].text - onClicked: root.click(standardButtonsRightModel[index].standardButton) + text: (buttonsRightRepeater.model && buttonsRightRepeater.model[index] ? buttonsRightRepeater.model[index].text : index) + onClicked: root.click(buttonsRightRepeater.model[index].standardButton) } } } } - function calculateImplicitWidth() { - if (standardButtonsRightModel.length < 2) + function setupButtons() { + buttonsLeftRepeater.model = root.__standardButtonsLeftModel() + buttonsRightRepeater.model = root.__standardButtonsRightModel() + if (!buttonsRightRepeater.model || buttonsRightRepeater.model.length < 2) return; var calcWidth = 0; @@ -157,6 +159,6 @@ AbstractDialog { calculateForButton(i, buttonsLeft.visibleChildren[i]) content.buttonsRowImplicitWidth = calcWidth + content.spacing } - onStandardButtonsChanged: calculateImplicitWidth() - Component.onCompleted: calculateImplicitWidth() + onStandardButtonsChanged: setupButtons() + Component.onCompleted: setupButtons() } diff --git a/src/dialogs/qquickabstractdialog.cpp b/src/dialogs/qquickabstractdialog.cpp index 62d59c19..005d1015 100644 --- a/src/dialogs/qquickabstractdialog.cpp +++ b/src/dialogs/qquickabstractdialog.cpp @@ -57,9 +57,8 @@ QQuickAbstractDialog::QQuickAbstractDialog(QObject *parent) , m_parentWindow(0) , m_visible(false) , m_modality(Qt::WindowModal) - , m_qmlImplementation(0) - , m_dialogWindow(0) , m_contentItem(0) + , m_dialogWindow(0) , m_windowDecoration(0) , m_hasNativeWindows(QGuiApplicationPrivate::platformIntegration()-> hasCapability(QPlatformIntegration::MultipleWindows) && @@ -87,71 +86,64 @@ void QQuickAbstractDialog::setVisible(bool v) helper()->hide(); } } else { - // For a pure QML implementation, there is no helper. - // But m_implementation is probably either an Item or a Window at this point. - if (!m_dialogWindow) { - m_dialogWindow = qobject_cast<QWindow *>(m_qmlImplementation); - if (!m_dialogWindow) { - m_contentItem = qobject_cast<QQuickItem *>(m_qmlImplementation); - if (m_contentItem) { - if (m_hasNativeWindows) - m_dialogWindow = m_contentItem->window(); - // An Item-based dialog implementation doesn't come with a window, so - // we have to instantiate one iff the platform allows it. - if (!m_dialogWindow && m_hasNativeWindows) { - QQuickWindow *win = new QQuickWindow; - ((QObject *)win)->setParent(this); // memory management only - m_dialogWindow = win; - m_contentItem->setParentItem(win->contentItem()); - 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())); - } + // Pure QML implementation: wrap the contentItem in a window, or fake it + if (!m_dialogWindow && m_contentItem) { + if (m_hasNativeWindows) + m_dialogWindow = m_contentItem->window(); + // An Item-based dialog implementation doesn't come with a window, so + // we have to instantiate one iff the platform allows it. + if (!m_dialogWindow && m_hasNativeWindows) { + QQuickWindow *win = new QQuickWindow; + ((QObject *)win)->setParent(this); // memory management only + m_dialogWindow = win; + m_contentItem->setParentItem(win->contentItem()); + 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())); + } - QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent()); + QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent()); - // If the platform does not support multiple windows, but the dialog is - // implemented as an Item, then try to decorate it as a fake window and make it visible. - if (parentItem && !m_dialogWindow && !m_windowDecoration) { - if (m_decorationComponent) { - if (m_decorationComponent->isLoading()) - connect(m_decorationComponent, SIGNAL(statusChanged(QQmlComponent::Status)), - this, SLOT(decorationLoaded())); - else - decorationLoaded(); - } - // Window decoration wasn't possible, so just reparent it into the scene - else { - m_contentItem->setParentItem(parentItem); - m_contentItem->setZ(10000); - } - } + // If the platform does not support multiple windows, but the dialog is + // implemented as an Item, then try to decorate it as a fake window and make it visible. + if (parentItem && !m_dialogWindow && !m_windowDecoration) { + if (m_decorationComponent) { + if (m_decorationComponent->isLoading()) + connect(m_decorationComponent, SIGNAL(statusChanged(QQmlComponent::Status)), + this, SLOT(decorationLoaded())); + else + decorationLoaded(); + } + // Window decoration wasn't possible, so just reparent it into the scene + else { + m_contentItem->setParentItem(parentItem); + m_contentItem->setZ(10000); } } - if (m_dialogWindow) { - // "grow up" to the size and position expected to achieve - if (!m_sizeAspiration.isNull()) { - if (m_hasAspiredPosition) - m_dialogWindow->setGeometry(m_sizeAspiration); - else { - if (m_sizeAspiration.width() > 0) - m_dialogWindow->setWidth(m_sizeAspiration.width()); - if (m_sizeAspiration.height() > 0) - m_dialogWindow->setHeight(m_sizeAspiration.height()); - } + } + if (m_dialogWindow) { + // "grow up" to the size and position expected to achieve + if (!m_sizeAspiration.isNull()) { + if (m_hasAspiredPosition) + m_dialogWindow->setGeometry(m_sizeAspiration); + else { + if (m_sizeAspiration.width() > 0) + m_dialogWindow->setWidth(m_sizeAspiration.width()); + if (m_sizeAspiration.height() > 0) + m_dialogWindow->setHeight(m_sizeAspiration.height()); } connect(m_dialogWindow, SIGNAL(visibleChanged(bool)), this, SLOT(visibleChanged(bool))); connect(m_dialogWindow, SIGNAL(xChanged(int)), this, SLOT(setX(int))); @@ -172,7 +164,6 @@ void QQuickAbstractDialog::setVisible(bool v) m_dialogWindow->setVisible(v); } } - emit visibilityChanged(); } @@ -237,10 +228,9 @@ void QQuickAbstractDialog::visibleChanged(bool v) void QQuickAbstractDialog::windowGeometryChanged() { - QQuickItem *content = qobject_cast<QQuickItem*>(m_qmlImplementation); - if (m_dialogWindow && content) { - content->setWidth(m_dialogWindow->width()); - content->setHeight(m_dialogWindow->height()); + if (m_dialogWindow && m_contentItem) { + m_contentItem->setWidth(m_dialogWindow->width()); + m_contentItem->setHeight(m_dialogWindow->height()); } } @@ -264,9 +254,9 @@ QQuickWindow *QQuickAbstractDialog::parentWindow() return m_parentWindow; } -void QQuickAbstractDialog::setQmlImplementation(QObject *obj) +void QQuickAbstractDialog::setContentItem(QQuickItem *obj) { - m_qmlImplementation = obj; + m_contentItem = obj; if (m_dialogWindow) { disconnect(this, SLOT(visibleChanged(bool))); // Can't necessarily delete because m_dialogWindow might have been provided by the QML. diff --git a/src/dialogs/qquickabstractdialog_p.h b/src/dialogs/qquickabstractdialog_p.h index 79283c19..a905b097 100644 --- a/src/dialogs/qquickabstractdialog_p.h +++ b/src/dialogs/qquickabstractdialog_p.h @@ -82,7 +82,7 @@ public: bool isVisible() const { return m_visible; } Qt::WindowModality modality() const { return m_modality; } virtual QString title() const = 0; - QObject* qmlImplementation() { return m_qmlImplementation; } + QQuickItem* contentItem() { return m_contentItem; } int x() const; int y() const; @@ -92,7 +92,7 @@ public: virtual void setVisible(bool v); virtual void setModality(Qt::WindowModality m); virtual void setTitle(const QString &t) = 0; - void setQmlImplementation(QObject* obj); + void setContentItem(QQuickItem* obj); bool isWindow() const { return m_hasNativeWindows; } enum StandardButton { @@ -154,9 +154,8 @@ protected: Qt::WindowModality m_modality; protected: // variables for pure-QML implementations only - QObject *m_qmlImplementation; - QWindow *m_dialogWindow; QQuickItem *m_contentItem; + QWindow *m_dialogWindow; QQuickItem *m_windowDecoration; bool m_hasNativeWindows; QRect m_sizeAspiration; diff --git a/src/dialogs/qquickcolordialog_p.h b/src/dialogs/qquickcolordialog_p.h index c6ae69f8..20549459 100644 --- a/src/dialogs/qquickcolordialog_p.h +++ b/src/dialogs/qquickcolordialog_p.h @@ -60,8 +60,8 @@ QT_BEGIN_NAMESPACE class QQuickColorDialog : public QQuickAbstractColorDialog { Q_OBJECT - Q_PROPERTY(QObject* implementation READ qmlImplementation WRITE setQmlImplementation DESIGNABLE false) - Q_CLASSINFO("DefaultProperty", "implementation") // AbstractColorDialog in QML can have only one child + Q_PROPERTY(QQuickItem* contentItem READ contentItem WRITE setContentItem DESIGNABLE false) + Q_CLASSINFO("DefaultProperty", "contentItem") // AbstractColorDialog in QML can have only one child public: explicit QQuickColorDialog(QObject *parent = 0); diff --git a/src/dialogs/qquickdialog.cpp b/src/dialogs/qquickdialog.cpp index 9e726ccd..bed69e7b 100644 --- a/src/dialogs/qquickdialog.cpp +++ b/src/dialogs/qquickdialog.cpp @@ -104,13 +104,13 @@ QQuickDialog::~QQuickDialog() { } -QJSValue QQuickDialog::standardButtonsLeftModel() +QJSValue QQuickDialog::__standardButtonsLeftModel() { updateStandardButtons(); return m_standardButtonsLeftModel; } -QJSValue QQuickDialog::standardButtonsRightModel() +QJSValue QQuickDialog::__standardButtonsRightModel() { updateStandardButtons(); return m_standardButtonsRightModel; diff --git a/src/dialogs/qquickdialog_p.h b/src/dialogs/qquickdialog_p.h index 54718221..d8b95234 100644 --- a/src/dialogs/qquickdialog_p.h +++ b/src/dialogs/qquickdialog_p.h @@ -68,10 +68,8 @@ class QQuickDialog : public QQuickAbstractDialog 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 + Q_PROPERTY(QQuickItem* contentItem READ contentItem WRITE setContentItem DESIGNABLE false) + Q_CLASSINFO("DefaultProperty", "contentItem") // Dialog in QML can have only one child public: explicit QQuickDialog(QObject *parent = 0); @@ -79,8 +77,8 @@ public: StandardButtons standardButtons() const { return m_enabledButtons; } StandardButton clickedButton() const { return m_clickedButton; } - QJSValue standardButtonsLeftModel(); - QJSValue standardButtonsRightModel(); + Q_INVOKABLE QJSValue __standardButtonsLeftModel(); + Q_INVOKABLE QJSValue __standardButtonsRightModel(); QString title() const { return m_title; } diff --git a/src/dialogs/qquickfiledialog_p.h b/src/dialogs/qquickfiledialog_p.h index 0cfef472..1d2f37ab 100644 --- a/src/dialogs/qquickfiledialog_p.h +++ b/src/dialogs/qquickfiledialog_p.h @@ -62,9 +62,9 @@ QT_BEGIN_NAMESPACE class QQuickFileDialog : public QQuickAbstractFileDialog { Q_OBJECT - Q_PROPERTY(QObject* implementation READ qmlImplementation WRITE setQmlImplementation DESIGNABLE false) + Q_PROPERTY(QQuickItem* contentItem READ contentItem WRITE setContentItem DESIGNABLE false) Q_PROPERTY(QJSValue shortcuts READ shortcuts CONSTANT) - Q_CLASSINFO("DefaultProperty", "implementation") // AbstractFileDialog in QML can have only one child + Q_CLASSINFO("DefaultProperty", "contentItem") // AbstractFileDialog in QML can have only one child public: explicit QQuickFileDialog(QObject *parent = 0); diff --git a/src/dialogs/qquickfontdialog_p.h b/src/dialogs/qquickfontdialog_p.h index c51e1fd9..a6f2ee4e 100644 --- a/src/dialogs/qquickfontdialog_p.h +++ b/src/dialogs/qquickfontdialog_p.h @@ -60,8 +60,8 @@ QT_BEGIN_NAMESPACE class QQuickFontDialog : public QQuickAbstractFontDialog { Q_OBJECT - Q_PROPERTY(QObject* implementation READ qmlImplementation WRITE setQmlImplementation DESIGNABLE false) - Q_CLASSINFO("DefaultProperty", "implementation") + Q_PROPERTY(QQuickItem* contentItem READ contentItem WRITE setContentItem DESIGNABLE false) + Q_CLASSINFO("DefaultProperty", "contentItem") public: explicit QQuickFontDialog(QObject *parent = 0); diff --git a/src/dialogs/qquickmessagedialog_p.h b/src/dialogs/qquickmessagedialog_p.h index b21d8cba..80a0b04d 100644 --- a/src/dialogs/qquickmessagedialog_p.h +++ b/src/dialogs/qquickmessagedialog_p.h @@ -60,8 +60,8 @@ 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 + Q_PROPERTY(QQuickItem* contentItem READ contentItem WRITE setContentItem DESIGNABLE false) + Q_CLASSINFO("DefaultProperty", "contentItem") // AbstractMessageDialog in QML can have only one child public: explicit QQuickMessageDialog(QObject *parent = 0); |