summaryrefslogtreecommitdiffstats
path: root/src/dialogs/qquickabstractdialog.cpp
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@digia.com>2014-04-09 14:07:15 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-04-15 17:47:28 +0200
commit6d438f3b5ca9fd94889461ca481bba387904af94 (patch)
tree48f2982c0a896257e2d422ee577f32b2b594821f /src/dialogs/qquickabstractdialog.cpp
parentf42ef1db6a111fd420776da2c620be9cefba7f14 (diff)
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>
Diffstat (limited to 'src/dialogs/qquickabstractdialog.cpp')
-rw-r--r--src/dialogs/qquickabstractdialog.cpp130
1 files changed, 60 insertions, 70 deletions
diff --git a/src/dialogs/qquickabstractdialog.cpp b/src/dialogs/qquickabstractdialog.cpp
index 62d59c19b..005d10157 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.