diff options
author | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2013-06-28 19:18:39 +0200 |
---|---|---|
committer | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2013-06-28 19:18:54 +0200 |
commit | c1832b78d484ab76afc7baf494c556c7dba32677 (patch) | |
tree | 62e2ad5e05301c76b7bbda1dd31042f1a338e63e /src | |
parent | ffe861a0785056a90c787172400fa6061acfcc32 (diff) | |
parent | 811337a73c160447e5218ae55e93df99ac3d9edd (diff) |
Merge remote-tracking branch 'origin/release' into stable
Change-Id: I140852ef7fbbfe303dac620af5e6eba5ee3a4b02
Diffstat (limited to 'src')
26 files changed, 265 insertions, 114 deletions
diff --git a/src/imports/dialogs/DefaultColorDialog.qml b/src/imports/dialogs/DefaultColorDialog.qml index 7322aa18e7..8636259957 100644 --- a/src/imports/dialogs/DefaultColorDialog.qml +++ b/src/imports/dialogs/DefaultColorDialog.qml @@ -39,6 +39,7 @@ *****************************************************************************/ import QtQuick 2.1 +import QtQuick.Window 2.1 import QtQuick.Dialogs 1.0 import "qml" @@ -47,14 +48,17 @@ AbstractColorDialog { Rectangle { id: content - width: 320 - height: (usePaletteMap ? width : 0) + bottomMinHeight + property int maxSize: 0.9 * Math.min(Screen.desktopAvailableWidth, Screen.desktopAvailableHeight) + implicitHeight: Math.max(maxSize, Screen.logicalPixelDensity * (usePaletteMap ? 10 : 5)) + implicitWidth: usePaletteMap ? implicitHeight - bottomMinHeight : implicitHeight * 1.5 color: palette.window property real bottomMinHeight: sliders.height + buttonRow.height + outerSpacing * 3 property real spacing: 8 property real outerSpacing: 12 property bool usePaletteMap: true - property bool inited: false + + // set the preferred width based on height, to avoid "letterboxing" the paletteMap + onHeightChanged: implicitHeight = Math.max((usePaletteMap ? 480 : bottomMinHeight), height) SystemPalette { id: palette } diff --git a/src/imports/dialogs/DefaultFileDialog.qml b/src/imports/dialogs/DefaultFileDialog.qml index 5542e59cb5..2cdb34cc03 100644 --- a/src/imports/dialogs/DefaultFileDialog.qml +++ b/src/imports/dialogs/DefaultFileDialog.qml @@ -40,6 +40,7 @@ import QtQuick 2.1 import QtQuick.Dialogs 1.0 +import QtQuick.Window 2.1 import Qt.labs.folderlistmodel 2.0 import "qml" @@ -52,13 +53,13 @@ AbstractFileDialog { currentPathField.visible = false } } + onFolderChanged: view.model.folder = folder property bool showFocusHighlight: false - property real textX: 28 + property real textX: titleBar.height property SystemPalette palette property var selectedIndices: [] property int lastClickedIdx: -1 - folder: urlToPath(view.model.folder) function dirDown(path) { view.model.folder = path @@ -106,10 +107,11 @@ AbstractFileDialog { selectedIndices.map(function(idx) { if (view.model.isFolder(idx)) { if (selectFolder) - addSelection(view.model.get(idx, "filePath")) + // TODO after QTBUG-32039: should not need to convert pathToUrl here + addSelection(pathToUrl(view.model.get(idx, "filePath"))) } else { if (!selectFolder) - addSelection(view.model.get(idx, "filePath")) + addSelection(pathToUrl(view.model.get(idx, "filePath"))) } }) } @@ -117,11 +119,12 @@ AbstractFileDialog { } Rectangle { - width: 480 // TODO: QTBUG-29817 geometry from AbstractFileDialog - height: 320 + property int maxSize: Math.min(Screen.desktopAvailableWidth, Screen.desktopAvailableHeight) + // TODO: QTBUG-29817 geometry from AbstractFileDialog + implicitWidth: Math.min(maxSize, Screen.logicalPixelDensity * 100) + implicitHeight: Math.min(maxSize, Screen.logicalPixelDensity * 80) id: window color: palette.window - anchors.centerIn: Qt.application.supportsMultipleWindows ? null : parent SystemPalette { id: palette } @@ -209,7 +212,12 @@ AbstractFileDialog { clip: true x: 0 width: parent.width - model: FolderListModel { } + model: FolderListModel { + onFolderChanged: { + root.folder = folder + currentPathField.text = root.urlToPath(view.model.folder) + } + } delegate: folderDelegate highlight: Rectangle { color: "transparent" @@ -303,10 +311,9 @@ AbstractFileDialog { anchors.leftMargin: textX; anchors.rightMargin: 4 visible: false focus: visible - text: root.urlToPath(view.model.folder) onAccepted: { root.clearSelection() - if (root.addSelection(text)) + if (root.addSelection(root.pathToUrl(text))) root.accept() else view.model.folder = root.pathFolder(text) diff --git a/src/imports/dialogs/dialogs.pro b/src/imports/dialogs/dialogs.pro index 53cad30cee..e745d52e2b 100644 --- a/src/imports/dialogs/dialogs.pro +++ b/src/imports/dialogs/dialogs.pro @@ -31,6 +31,7 @@ QML_FILES += \ WidgetColorDialog.qml \ qml/Button.qml \ qml/ColorSlider.qml \ + qml/DefaultWindowDecoration.qml \ qml/TextField.qml \ qml/qmldir \ images/checkers.png \ @@ -38,6 +39,7 @@ QML_FILES += \ images/crosshairs.png \ images/slider_handle.png \ images/sunken_frame.png \ + images/window_border.png \ images/folder.png \ images/up.png diff --git a/src/imports/dialogs/images/window_border.png b/src/imports/dialogs/images/window_border.png Binary files differnew file mode 100644 index 0000000000..431af8545d --- /dev/null +++ b/src/imports/dialogs/images/window_border.png diff --git a/src/imports/dialogs/plugin.cpp b/src/imports/dialogs/plugin.cpp index 5502a65310..8d1501cd03 100644 --- a/src/imports/dialogs/plugin.cpp +++ b/src/imports/dialogs/plugin.cpp @@ -48,6 +48,7 @@ #include "qquickabstractcolordialog_p.h" #include "qquickplatformcolordialog_p.h" #include <private/qguiapplication_p.h> +#include <qpa/qplatformintegration.h> //#define PURE_QML_ONLY @@ -78,9 +79,18 @@ class QtQuick2DialogsPlugin : public QQmlExtensionPlugin public: QtQuick2DialogsPlugin() : QQmlExtensionPlugin() { } + virtual void initializeEngine(QQmlEngine *engine, const char *uri) { + //qDebug() << Q_FUNC_INFO << uri << m_decorationComponentUrl; + QQuickAbstractDialog::m_decorationComponent = + new QQmlComponent(engine, m_decorationComponentUrl, QQmlComponent::Asynchronous); + } + virtual void registerTypes(const char *uri) { Q_ASSERT(QLatin1String(uri) == QLatin1String("QtQuick.Dialogs")); + bool hasTopLevelWindows = QGuiApplicationPrivate::platformIntegration()-> + hasCapability(QPlatformIntegration::MultipleWindows); QDir qmlDir(baseUrl().toLocalFile()); + m_decorationComponentUrl = QUrl::fromLocalFile(qmlDir.filePath(QString("qml/DefaultWindowDecoration.qml"))); QDir widgetsDir(baseUrl().toLocalFile()); // TODO: find the directory by searching rather than assuming a relative path widgetsDir.cd("../PrivateWidgets"); @@ -96,8 +106,7 @@ public: qmlRegisterType<QQuickPlatformFileDialog>(uri, DIALOGS_MAJOR_MINOR, "FileDialog"); else #endif - registerWidgetOrQmlImplementation<QQuickFileDialog>(widgetsDir, "WidgetFileDialog.qml", - qmlDir, "DefaultFileDialog.qml", "FileDialog", uri); + registerWidgetOrQmlImplementation<QQuickFileDialog>(widgetsDir, qmlDir, "FileDialog", uri, hasTopLevelWindows); // ColorDialog #ifndef PURE_QML_ONLY @@ -105,35 +114,37 @@ public: qmlRegisterType<QQuickPlatformColorDialog>(uri, DIALOGS_MAJOR_MINOR, "ColorDialog"); else #endif - registerWidgetOrQmlImplementation<QQuickColorDialog>(widgetsDir, "WidgetColorDialog.qml", - qmlDir, "DefaultColorDialog.qml", "ColorDialog", uri); + registerWidgetOrQmlImplementation<QQuickColorDialog>(widgetsDir, qmlDir, "ColorDialog", uri, hasTopLevelWindows); } protected: template <class WrapperType> - void registerWidgetOrQmlImplementation(QDir widgetsDir, QString widgetQmlFile, - QDir qmlDir, QString qmlFile, const char *qmlName, const char *uri) { + void registerWidgetOrQmlImplementation(QDir widgetsDir, QDir qmlDir, + const char *qmlName, const char *uri, bool hasTopLevelWindows) { + //qDebug() << Q_FUNC_INFO << qmlDir << qmlName << uri; bool needQml = true; + #ifndef PURE_QML_ONLY // If there is a qmldir and we have a QApplication instance (as opposed to a // widget-free QGuiApplication), assume that the widget-based dialog will work. - if (widgetsDir.exists("qmldir") && !widgetQmlFile.isEmpty() && + if (hasTopLevelWindows && widgetsDir.exists("qmldir") && !qstrcmp(QCoreApplication::instance()->metaObject()->className(), "QApplication")) { - QString dialogQmlPath = qmlDir.filePath(widgetQmlFile); + QString dialogQmlPath = qmlDir.filePath(QString("Widget%1.qml").arg(qmlName)); if (qmlRegisterType(QUrl::fromLocalFile(dialogQmlPath), uri, DIALOGS_MAJOR_MINOR, qmlName) >= 0) needQml = false; - // qDebug() << "registering" << qmlName << " as " << dialogQmlPath << "success?" << needQml; + // qDebug() << "registering" << qmlName << " as " << dialogQmlPath << "success?" << !needQml; } #endif if (needQml) { - QString dialogQmlPath = qmlDir.filePath(qmlFile); QByteArray abstractTypeName = QByteArray("Abstract") + qmlName; qmlRegisterType<WrapperType>(uri, DIALOGS_MAJOR_MINOR, abstractTypeName); // implementation wrapper + QString dialogQmlPath = qmlDir.filePath(QString("Default%1.qml").arg(qmlName)); // qDebug() << "registering" << qmlName << " as " << dialogQmlPath << "success?" << qmlRegisterType(QUrl::fromLocalFile(dialogQmlPath), uri, DIALOGS_MAJOR_MINOR, qmlName); } } + QUrl m_decorationComponentUrl; }; QT_END_NAMESPACE diff --git a/src/imports/dialogs/plugins.qmltypes b/src/imports/dialogs/plugins.qmltypes index 80eb8bd291..4e7090b960 100644 --- a/src/imports/dialogs/plugins.qmltypes +++ b/src/imports/dialogs/plugins.qmltypes @@ -39,6 +39,7 @@ Module { Property { name: "visible"; type: "bool" } Property { name: "modality"; type: "Qt::WindowModality" } Property { name: "title"; type: "string" } + Property { name: "isWindow"; type: "bool"; isReadonly: true } Property { name: "x"; type: "int" } Property { name: "y"; type: "int" } Property { name: "width"; type: "int" } @@ -56,7 +57,7 @@ Module { Property { name: "selectExisting"; type: "bool" } Property { name: "selectMultiple"; type: "bool" } Property { name: "selectFolder"; type: "bool" } - Property { name: "folder"; type: "string" } + Property { name: "folder"; type: "QUrl" } Property { name: "nameFilters"; type: "QStringList" } Property { name: "selectedNameFilter"; type: "string" } Property { name: "fileUrl"; type: "QUrl"; isReadonly: true } @@ -86,7 +87,7 @@ Module { } Method { name: "setFolder" - Parameter { name: "f"; type: "string" } + Parameter { name: "f"; type: "QUrl" } } Method { name: "setNameFilters" @@ -116,7 +117,7 @@ Module { Method { name: "addSelection" type: "bool" - Parameter { name: "path"; type: "string" } + Parameter { name: "path"; type: "QUrl" } } } } diff --git a/src/imports/dialogs/qml/Button.qml b/src/imports/dialogs/qml/Button.qml index 491dc2e251..4a0ec12cd3 100644 --- a/src/imports/dialogs/qml/Button.qml +++ b/src/imports/dialogs/qml/Button.qml @@ -39,6 +39,7 @@ *****************************************************************************/ import QtQuick 2.1 +import QtQuick.Window 2.1 Item { id: container @@ -48,10 +49,10 @@ Item { signal clicked property alias containsMouse: mouseArea.containsMouse property alias pressed: mouseArea.pressed - implicitHeight: buttonLabel.implicitHeight - implicitWidth: buttonLabel.implicitWidth - height: buttonLabel.implicitHeight + 12 - width: Math.max(80, implicitWidth + 8) + implicitHeight: buttonLabel.implicitHeight * 1.2 + implicitWidth: Math.max(Screen.logicalPixelDensity * 10, buttonLabel.implicitWidth * 1.2) + height: implicitHeight + width: implicitWidth SystemPalette { id: palette } @@ -64,7 +65,7 @@ Item { GradientStop { position: 1.0; color: Qt.darker(palette.button, 1.3) } } antialiasing: true - radius: 5 + radius: height / 4 border.color: Qt.darker(palette.button, 1.5) border.width: 1 } @@ -78,10 +79,8 @@ Item { Text { id: buttonLabel - width: parent.width - horizontalAlignment: Text.Center text: container.text color: palette.buttonText - anchors.verticalCenter: parent.verticalCenter + anchors.centerIn: parent } } diff --git a/src/imports/dialogs/qml/DefaultWindowDecoration.qml b/src/imports/dialogs/qml/DefaultWindowDecoration.qml new file mode 100644 index 0000000000..69a8658aba --- /dev/null +++ b/src/imports/dialogs/qml/DefaultWindowDecoration.qml @@ -0,0 +1,68 @@ +/***************************************************************************** +** +** 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 + +Rectangle { + color: "#80000000" + anchors.fill: parent + z: 1000000 + property alias content: borderImage.content + property bool dismissOnOuterClick: true + signal dismissed + MouseArea { + anchors.fill: parent + enabled: dismissOnOuterClick + onClicked: dismissed() + BorderImage { + id: borderImage + property Item content + + width: content ? content.width + 15 : 0 + height: content ? content.height + 15 : 0 + onWidthChanged: content.x = 5 + onHeightChanged: content.y = 5 + border { left: 10; top: 10; right: 10; bottom: 10 } + source: "../images/window_border.png" + anchors.centerIn: parent + onContentChanged: if (content) content.parent = borderImage + } + } +} diff --git a/src/imports/dialogs/qml/TextField.qml b/src/imports/dialogs/qml/TextField.qml index baa469caa9..9a6427a105 100644 --- a/src/imports/dialogs/qml/TextField.qml +++ b/src/imports/dialogs/qml/TextField.qml @@ -45,10 +45,10 @@ Item { property alias textInput: textInput property alias text: textInput.text - property real implicitWidth: textInput.implicitWidth + rect.radius * 2 - property real implicitHeight: textInput.implicitHeight + rect.radius * 2 signal accepted signal downPressed + implicitWidth: textInput.implicitWidth + rect.radius * 2 + implicitHeight: textInput.implicitHeight function copyAll() { textInput.selectAll() diff --git a/src/imports/dialogs/qquickabstractcolordialog.cpp b/src/imports/dialogs/qquickabstractcolordialog.cpp index 9a9f3bc11b..7cfd7ea692 100644 --- a/src/imports/dialogs/qquickabstractcolordialog.cpp +++ b/src/imports/dialogs/qquickabstractcolordialog.cpp @@ -91,7 +91,7 @@ bool QQuickAbstractColorDialog::showAlphaChannel() const return m_options->testOption(QColorDialogOptions::ShowAlphaChannel); } -void QQuickAbstractColorDialog::setTitle(QString t) +void QQuickAbstractColorDialog::setTitle(const QString &t) { if (m_options->windowTitle() == t) return; m_options->setWindowTitle(t); diff --git a/src/imports/dialogs/qquickabstractcolordialog_p.h b/src/imports/dialogs/qquickabstractcolordialog_p.h index 3301605c86..46f0f84acb 100644 --- a/src/imports/dialogs/qquickabstractcolordialog_p.h +++ b/src/imports/dialogs/qquickabstractcolordialog_p.h @@ -78,7 +78,7 @@ public: public Q_SLOTS: void setVisible(bool v); void setModality(Qt::WindowModality m); - void setTitle(QString t); + void setTitle(const QString &t); void setColor(QColor arg); void setShowAlphaChannel(bool arg); diff --git a/src/imports/dialogs/qquickabstractdialog.cpp b/src/imports/dialogs/qquickabstractdialog.cpp index abdc9e067c..560cbaf3e0 100644 --- a/src/imports/dialogs/qquickabstractdialog.cpp +++ b/src/imports/dialogs/qquickabstractdialog.cpp @@ -44,11 +44,14 @@ #include <private/qguiapplication_p.h> #include <QWindow> +#include <QQmlComponent> #include <QQuickWindow> #include <qpa/qplatformintegration.h> QT_BEGIN_NAMESPACE +QQmlComponent *QQuickAbstractDialog::m_decorationComponent(0); + QQuickAbstractDialog::QQuickAbstractDialog(QObject *parent) : QObject(parent) , m_parentWindow(0) @@ -56,6 +59,10 @@ QQuickAbstractDialog::QQuickAbstractDialog(QObject *parent) , m_modality(Qt::WindowModal) , m_qmlImplementation(0) , m_dialogWindow(0) + , m_contentItem(0) + , m_windowDecoration(0) + , m_hasNativeWindows(QGuiApplicationPrivate::platformIntegration()-> + hasCapability(QPlatformIntegration::MultipleWindows)) { } @@ -82,36 +89,47 @@ void QQuickAbstractDialog::setVisible(bool v) if (!m_dialogWindow) { m_dialogWindow = qobject_cast<QWindow *>(m_qmlImplementation); if (!m_dialogWindow) { - QQuickItem *dlgItem = qobject_cast<QQuickItem *>(m_qmlImplementation); - if (dlgItem) { - m_dialogWindow = dlgItem->window(); + m_contentItem = qobject_cast<QQuickItem *>(m_qmlImplementation); + if (m_contentItem) { + 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 && QGuiApplicationPrivate::platformIntegration()-> - hasCapability(QPlatformIntegration::MultipleWindows)) { + if (!m_dialogWindow && m_hasNativeWindows) { QQuickWindow *win = new QQuickWindow; ((QObject *)win)->setParent(this); // memory management only m_dialogWindow = win; - dlgItem->setParentItem(win->contentItem()); - m_dialogWindow->setMinimumSize(QSize(dlgItem->width(), dlgItem->height())); + m_contentItem->setParentItem(win->contentItem()); + m_dialogWindow->setMinimumSize(QSize(m_contentItem->implicitWidth(), m_contentItem->implicitHeight())); connect(win, SIGNAL(widthChanged(int)), this, SLOT(windowGeometryChanged())); connect(win, SIGNAL(heightChanged(int)), this, SLOT(windowGeometryChanged())); } QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent()); - // qDebug() << "item implementation" << dlgItem << "has window" << m_dialogWindow << "and parent" << parentItem; // If the platform does not support multiple windows, but the dialog is - // implemented as an Item, then just reparent it and make it visible. - // TODO QTBUG-29818: put it into a fake Item-based window, when we have a reusable self-decorated one. - if (parentItem && !m_dialogWindow) - dlgItem->setParentItem(parentItem); + // 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) connect(m_dialogWindow, SIGNAL(visibleChanged(bool)), this, SLOT(visibleChanged(bool))); } - if (m_dialogWindow) { + if (m_windowDecoration) { + m_windowDecoration->setVisible(v); + } else if (m_dialogWindow) { if (v) { m_dialogWindow->setTransientParent(parentWindow()); m_dialogWindow->setTitle(title()); @@ -124,6 +142,38 @@ void QQuickAbstractDialog::setVisible(bool v) emit visibilityChanged(); } +void QQuickAbstractDialog::decorationLoaded() +{ + bool ok = false; + QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent()); + if (m_decorationComponent->isError()) { + qWarning() << m_decorationComponent->errors(); + } else { + QObject *decoration = m_decorationComponent->create(); + m_windowDecoration = qobject_cast<QQuickItem *>(decoration); + if (m_windowDecoration) { + m_windowDecoration->setParentItem(parentItem); + // Give the window decoration its content to manage + QVariant contentVariant; + contentVariant.setValue<QQuickItem*>(m_contentItem); + m_windowDecoration->setProperty("content", contentVariant); + connect(m_windowDecoration, SIGNAL(dismissed()), this, SLOT(reject())); + ok = true; + } else { + qWarning() << m_decorationComponent->url() << + "cannot be used as a window decoration because it's not an Item"; + delete m_windowDecoration; + delete m_decorationComponent; + m_decorationComponent = 0; + } + } + // Window decoration wasn't possible, so just reparent it into the scene + if (!ok) { + m_contentItem->setParentItem(parentItem); + m_contentItem->setZ(10000); + } +} + void QQuickAbstractDialog::setModality(Qt::WindowModality m) { if (m_modality == m) return; @@ -152,7 +202,6 @@ void QQuickAbstractDialog::visibleChanged(bool v) void QQuickAbstractDialog::windowGeometryChanged() { QQuickItem *content = qobject_cast<QQuickItem*>(m_qmlImplementation); -qDebug() << Q_FUNC_INFO << m_dialogWindow << content; if (m_dialogWindow && content) { content->setWidth(m_dialogWindow->width()); content->setHeight(m_dialogWindow->height()); diff --git a/src/imports/dialogs/qquickabstractdialog_p.h b/src/imports/dialogs/qquickabstractdialog_p.h index 2ad24f98e0..5e3d9b43f7 100644 --- a/src/imports/dialogs/qquickabstractdialog_p.h +++ b/src/imports/dialogs/qquickabstractdialog_p.h @@ -66,6 +66,7 @@ class QQuickAbstractDialog : public QObject 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) + Q_PROPERTY(bool isWindow READ isWindow CONSTANT) Q_PROPERTY(int x READ x WRITE setX NOTIFY geometryChanged) Q_PROPERTY(int y READ y WRITE setY NOTIFY geometryChanged) Q_PROPERTY(int width READ width WRITE setWidth NOTIFY geometryChanged) @@ -87,8 +88,9 @@ public: virtual void setVisible(bool v); virtual void setModality(Qt::WindowModality m); - virtual void setTitle(QString t) = 0; + virtual void setTitle(const QString &t) = 0; void setQmlImplementation(QObject* obj); + bool isWindow() const { return m_hasNativeWindows; } void setX(int arg); void setY(int arg); void setWidth(int arg); @@ -107,6 +109,7 @@ Q_SIGNALS: void rejected(); protected Q_SLOTS: + void decorationLoaded(); void accept(); void reject(); void visibleChanged(bool v); @@ -124,6 +127,13 @@ protected: protected: // variables for pure-QML implementations only QObject *m_qmlImplementation; QWindow *m_dialogWindow; + QQuickItem *m_contentItem; + QQuickItem *m_windowDecoration; + bool m_hasNativeWindows; + + static QQmlComponent *m_decorationComponent; + + friend class QtQuick2DialogsPlugin; Q_DISABLE_COPY(QQuickAbstractDialog) }; diff --git a/src/imports/dialogs/qquickabstractfiledialog.cpp b/src/imports/dialogs/qquickabstractfiledialog.cpp index 32442de41f..d8a75feb53 100644 --- a/src/imports/dialogs/qquickabstractfiledialog.cpp +++ b/src/imports/dialogs/qquickabstractfiledialog.cpp @@ -78,7 +78,7 @@ QString QQuickAbstractFileDialog::title() const return m_options->windowTitle(); } -void QQuickAbstractFileDialog::setTitle(QString t) +void QQuickAbstractFileDialog::setTitle(const QString &t) { if (m_options->windowTitle() == t) return; m_options->setWindowTitle(t); @@ -106,18 +106,19 @@ void QQuickAbstractFileDialog::setSelectFolder(bool selectFolder) updateModes(); } -QString QQuickAbstractFileDialog::folder() +QUrl QQuickAbstractFileDialog::folder() { if (m_dlgHelper && !m_dlgHelper->directory().isEmpty()) - return m_dlgHelper->directory(); - return m_options->initialDirectory(); + return QUrl::fromLocalFile(m_dlgHelper->directory()); + return QUrl::fromLocalFile(m_options->initialDirectory()); } -void QQuickAbstractFileDialog::setFolder(QString f) +void QQuickAbstractFileDialog::setFolder(const QUrl &f) { + QString dir = f.path(); if (m_dlgHelper) - m_dlgHelper->setDirectory(f); - m_options->setInitialDirectory(f); + m_dlgHelper->setDirectory(dir); + m_options->setInitialDirectory(dir); emit folderChanged(); } @@ -141,7 +142,7 @@ QString QQuickAbstractFileDialog::selectedNameFilter() return ret; } -void QQuickAbstractFileDialog::selectNameFilter(QString f) +void QQuickAbstractFileDialog::selectNameFilter(const QString &f) { // This should work whether the dialog is currently being shown already, or ahead of time. m_options->setInitiallySelectedNameFilter(f); diff --git a/src/imports/dialogs/qquickabstractfiledialog_p.h b/src/imports/dialogs/qquickabstractfiledialog_p.h index 965f1a7029..5ce48e8055 100644 --- a/src/imports/dialogs/qquickabstractfiledialog_p.h +++ b/src/imports/dialogs/qquickabstractfiledialog_p.h @@ -67,7 +67,7 @@ class QQuickAbstractFileDialog : public QQuickAbstractDialog Q_PROPERTY(bool selectExisting READ selectExisting WRITE setSelectExisting NOTIFY fileModeChanged) Q_PROPERTY(bool selectMultiple READ selectMultiple WRITE setSelectMultiple NOTIFY fileModeChanged) Q_PROPERTY(bool selectFolder READ selectFolder WRITE setSelectFolder NOTIFY fileModeChanged) - Q_PROPERTY(QString folder READ folder WRITE setFolder NOTIFY folderChanged) + Q_PROPERTY(QUrl folder READ folder WRITE setFolder NOTIFY folderChanged) Q_PROPERTY(QStringList nameFilters READ nameFilters WRITE setNameFilters NOTIFY nameFiltersChanged) Q_PROPERTY(QString selectedNameFilter READ selectedNameFilter WRITE selectNameFilter NOTIFY filterSelected) Q_PROPERTY(QUrl fileUrl READ fileUrl NOTIFY selectionAccepted) @@ -81,7 +81,7 @@ public: bool selectExisting() const { return m_selectExisting; } bool selectMultiple() const { return m_selectMultiple; } bool selectFolder() const { return m_selectFolder; } - QString folder(); + QUrl folder(); QStringList nameFilters() const { return m_options->nameFilters(); } QString selectedNameFilter(); QUrl fileUrl(); @@ -89,13 +89,13 @@ public: public Q_SLOTS: void setVisible(bool v); - void setTitle(QString t); + void setTitle(const QString &t); void setSelectExisting(bool s); void setSelectMultiple(bool s); void setSelectFolder(bool s); - void setFolder(QString f); + void setFolder(const QUrl &f); void setNameFilters(const QStringList &f); - void selectNameFilter(QString f); + void selectNameFilter(const QString &f); Q_SIGNALS: void folderChanged(); diff --git a/src/imports/dialogs/qquickcolordialog.cpp b/src/imports/dialogs/qquickcolordialog.cpp index 39af99770e..d0e0e11b07 100644 --- a/src/imports/dialogs/qquickcolordialog.cpp +++ b/src/imports/dialogs/qquickcolordialog.cpp @@ -64,13 +64,13 @@ QT_BEGIN_NAMESPACE /*! \qmlsignal QtQuick::Dialogs::AbstractColorDialog::accepted - The \a accepted signal is emitted by \l accept(). + This signal is emitted by \l accept(). */ /*! \qmlsignal QtQuick::Dialogs::AbstractColorDialog::rejected - The \a accepted signal is emitted by \l reject(). + This signal is emitted by \l reject(). */ /*! @@ -110,12 +110,6 @@ QQuickColorDialog::~QQuickColorDialog() */ /*! - \qmlproperty bool AbstractColorDialog::filePaths - - A list of files to be populated as the user chooses. -*/ - -/*! \qmlproperty QObject AbstractColorDialog::implementation The QML object which implements the actual file dialog. Should be either a diff --git a/src/imports/dialogs/qquickfiledialog.cpp b/src/imports/dialogs/qquickfiledialog.cpp index f78e8a6f8d..2ee4afc5d2 100644 --- a/src/imports/dialogs/qquickfiledialog.cpp +++ b/src/imports/dialogs/qquickfiledialog.cpp @@ -64,13 +64,13 @@ QT_BEGIN_NAMESPACE /*! \qmlsignal QtQuick::Dialogs::AbstractFileDialog::accepted - The \a accepted signal is emitted by \l accept(). + This signal is emitted by \l accept(). */ /*! \qmlsignal QtQuick::Dialogs::AbstractFileDialog::rejected - The \a accepted signal is emitted by \l reject(). + This signal is emitted by \l reject(). */ /*! @@ -105,10 +105,7 @@ QQuickFileDialog::~QQuickFileDialog() QList<QUrl> QQuickFileDialog::fileUrls() { - QList<QUrl> ret; - foreach (QString path, m_selections) - ret << QUrl::fromLocalFile(path); - return ret; + return m_selections; } /*! @@ -118,13 +115,13 @@ QList<QUrl> QQuickFileDialog::fileUrls() */ /*! - \qmlproperty bool AbstractFileDialog::filePaths + \qmlproperty bool AbstractFileDialog::fileUrls A list of files to be populated as the user chooses. */ /*! - \brief Clears \l filePaths + \brief Clears \l fileUrls */ void QQuickFileDialog::clearSelection() { @@ -132,20 +129,18 @@ void QQuickFileDialog::clearSelection() } /*! - \brief Adds one file to \l filePaths + \brief Adds one file to \l fileUrls - \l path should be given as an absolute file system path. If it is given as a - file:// URL, it will be converted to a path. Returns true on success, - false if the given path is not valid given the current setting properties. + \l path should be given as an absolute file:// path URL. + Returns true on success, false if the given path is + not valid given the current property settings. */ -bool QQuickFileDialog::addSelection(QString path) +bool QQuickFileDialog::addSelection(const QUrl &path) { - if (path.startsWith("file:")) - path = QUrl(path).toLocalFile(); - QFileInfo info(path); + QFileInfo info(path.toLocalFile()); if (info.exists() && ((info.isDir() && m_selectFolder) || !info.isDir())) { if (m_selectFolder) - m_selections.append(pathFolder(path).toLocalFile()); + m_selections.append(pathFolder(path.toLocalFile())); else m_selections.append(path); return true; diff --git a/src/imports/dialogs/qquickfiledialog_p.h b/src/imports/dialogs/qquickfiledialog_p.h index 93e11f9e3e..0176bc3fe4 100644 --- a/src/imports/dialogs/qquickfiledialog_p.h +++ b/src/imports/dialogs/qquickfiledialog_p.h @@ -72,7 +72,7 @@ signals: public Q_SLOTS: void clearSelection(); - bool addSelection(QString path); + bool addSelection(const QUrl &path); protected: virtual QPlatformFileDialogHelper *helper() { return 0; } @@ -81,7 +81,7 @@ protected: Q_INVOKABLE QUrl pathFolder(const QString &path); private: - QStringList m_selections; + QList<QUrl> m_selections; Q_DISABLE_COPY(QQuickFileDialog) }; diff --git a/src/imports/dialogs/qquickplatformcolordialog.cpp b/src/imports/dialogs/qquickplatformcolordialog.cpp index ea3114c86e..8dc6d09f2c 100644 --- a/src/imports/dialogs/qquickplatformcolordialog.cpp +++ b/src/imports/dialogs/qquickplatformcolordialog.cpp @@ -102,8 +102,8 @@ QT_BEGIN_NAMESPACE /*! \qmlsignal QtQuick::Dialogs::ColorDialog::accepted - The \a accepted signal is emitted when the user has finished using the - dialog. You can then inspect the \a color property to get the selection. + This handler is called when the user has finished using the + dialog. You can then inspect the \l color property to get the selection. Example: @@ -117,7 +117,7 @@ QT_BEGIN_NAMESPACE /*! \qmlsignal QtQuick::Dialogs::ColorDialog::rejected - The \a rejected signal is emitted when the user has dismissed the dialog, + This handler is called when the user has dismissed the dialog, either by closing the dialog window or by pressing the Cancel button. */ diff --git a/src/imports/dialogs/qquickplatformfiledialog.cpp b/src/imports/dialogs/qquickplatformfiledialog.cpp index 5ae7fd0067..3da9f6c3b2 100644 --- a/src/imports/dialogs/qquickplatformfiledialog.cpp +++ b/src/imports/dialogs/qquickplatformfiledialog.cpp @@ -73,7 +73,7 @@ QT_BEGIN_NAMESPACE id: fileDialog title: "Please choose a file" onAccepted: { - console.log("You chose: " + fileDialog.filePaths) + console.log("You chose: " + fileDialog.fileUrls) Qt.quit() } onRejected: { @@ -103,15 +103,15 @@ QT_BEGIN_NAMESPACE /*! \qmlsignal QtQuick::Dialogs::FileDialog::accepted - The \a accepted signal is emitted when the user has finished using the - dialog. You can then inspect the \a filePath or \a filePaths properties to + This handler is called when the user has finished using the + dialog. You can then inspect the \l fileUrl or \l fileUrls properties to get the selection. Example: \qml FileDialog { - onAccepted: { console.log("Selected file: " + filePath) } + onAccepted: { console.log("Selected file: " + fileUrl) } } \endqml */ @@ -119,7 +119,7 @@ QT_BEGIN_NAMESPACE /*! \qmlsignal QtQuick::Dialogs::FileDialog::rejected - The \a rejected signal is emitted when the user has dismissed the dialog, + This handler is called when the user has dismissed the dialog, either by closing the dialog window or by pressing the Cancel button. */ @@ -191,7 +191,7 @@ QPlatformFileDialogHelper *QQuickPlatformFileDialog::helper() containing the dialog's parent Item, modal with respect to the whole application, or non-modal. - By default it is \l WindowModal. + 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 @@ -252,7 +252,7 @@ QPlatformFileDialogHelper *QQuickPlatformFileDialog::helper() */ /*! - \qmlproperty string FileDialog::folder + \qmlproperty url FileDialog::folder The path to the currently selected folder. Setting this property before invoking open() will cause the file browser to be initially positioned on @@ -295,18 +295,18 @@ QPlatformFileDialogHelper *QQuickPlatformFileDialog::helper() */ /*! - \qmlproperty string FileDialog::filePath + \qmlproperty url FileDialog::fileUrl The path of the file which was selected by the user. \note This property is set only if exactly one file was selected. In all - other cases, it will return an empty string. + other cases, it will be empty. - \sa filePaths + \sa fileUrls */ /*! - \qmlproperty list<string> FileDialog::filePaths + \qmlproperty list<url> FileDialog::fileUrls The list of file paths which were selected by the user. */ diff --git a/src/imports/widgets/plugins.qmltypes b/src/imports/widgets/plugins.qmltypes index 583a36a357..9e73330c12 100644 --- a/src/imports/widgets/plugins.qmltypes +++ b/src/imports/widgets/plugins.qmltypes @@ -39,6 +39,7 @@ Module { Property { name: "visible"; type: "bool" } Property { name: "modality"; type: "Qt::WindowModality" } Property { name: "title"; type: "string" } + Property { name: "isWindow"; type: "bool"; isReadonly: true } Property { name: "x"; type: "int" } Property { name: "y"; type: "int" } Property { name: "width"; type: "int" } @@ -56,7 +57,7 @@ Module { Property { name: "selectExisting"; type: "bool" } Property { name: "selectMultiple"; type: "bool" } Property { name: "selectFolder"; type: "bool" } - Property { name: "folder"; type: "string" } + Property { name: "folder"; type: "QUrl" } Property { name: "nameFilters"; type: "QStringList" } Property { name: "selectedNameFilter"; type: "string" } Property { name: "fileUrl"; type: "QUrl"; isReadonly: true } @@ -86,7 +87,7 @@ Module { } Method { name: "setFolder" - Parameter { name: "f"; type: "string" } + Parameter { name: "f"; type: "QUrl" } } Method { name: "setNameFilters" diff --git a/src/imports/widgets/qquickqfiledialog.cpp b/src/imports/widgets/qquickqfiledialog.cpp index afb150b509..498e34a24c 100644 --- a/src/imports/widgets/qquickqfiledialog.cpp +++ b/src/imports/widgets/qquickqfiledialog.cpp @@ -135,14 +135,14 @@ private: \qmlsignal QtQuick::Dialogs::FileDialog::accepted The \a accepted signal is emitted when the user has finished using the - dialog. You can then inspect the \a filePath or \a filePaths properties to + dialog. You can then inspect the \a fileUrl or \a fileUrls properties to get the selection. Example: \qml FileDialog { - onAccepted: { console.log("Selected file: " + filePath) } + onAccepted: { console.log("Selected file: " + fileUrl) } } \endqml */ diff --git a/src/qml/doc/src/whatsnew.qdoc b/src/qml/doc/src/whatsnew.qdoc index f1c69160b6..9ad8c23a42 100644 --- a/src/qml/doc/src/whatsnew.qdoc +++ b/src/qml/doc/src/whatsnew.qdoc @@ -115,6 +115,8 @@ has now been replaced by the new \l {Qt QML} and \l {Qt Quick} modules. See the \list \li Arbitrary functionality may be provided in a namespace through a singleton type. See qmlRegisterSingletonType() for more information. \li JavaScript (.js) files may now import QML modules and other JavaScript files using the ".import" syntax. +\li Plugins may now use QQmlExtensionPlugin::baseUrl to get the directory from which the plugin is loaded. + This will be useful if the plugin needs to load QML or other assets from the same directory. \endlist \section2 Other diff --git a/src/qml/qml/qqml.h b/src/qml/qml/qqml.h index fb0133f305..b48a776b4f 100644 --- a/src/qml/qml/qqml.h +++ b/src/qml/qml/qqml.h @@ -49,7 +49,6 @@ #include <QtCore/qbytearray.h> #include <QtCore/qmetaobject.h> -#include <QtCore/qdebug.h> #define QML_VERSION 0x020000 #define QML_VERSION_STR "2.0" @@ -477,7 +476,7 @@ inline int qmlRegisterType(const QUrl &url, const char *uri, int versionMajor, i { if (url.isRelative()) { // User input check must go here, because QQmlPrivate::qmlregister is also used internally for composite types - qWarning() << "qmlRegisterType requires absolute URLs."; + qWarning("qmlRegisterType requires absolute URLs."); return 0; } diff --git a/src/qml/qml/qqmlextensionplugin.cpp b/src/qml/qml/qqmlextensionplugin.cpp index f77b176404..30eca7b112 100644 --- a/src/qml/qml/qqmlextensionplugin.cpp +++ b/src/qml/qml/qqmlextensionplugin.cpp @@ -45,7 +45,7 @@ QT_BEGIN_NAMESPACE /*! - \since 5.0 + \since Qt 5.0 \inmodule QtQml \class QQmlExtensionPlugin \brief The QQmlExtensionPlugin class provides an abstract base for custom QML extension plugins. @@ -156,6 +156,13 @@ QQmlExtensionPlugin::~QQmlExtensionPlugin() { } +/*! + \since Qt 5.1 + \brief Returns the URL of the directory from which the extension is loaded. + + This is useful when the plugin also needs to load QML files or other + assets from the same directory. +*/ QUrl QQmlExtensionPlugin::baseUrl() const { Q_D(const QQmlExtensionPlugin); diff --git a/src/qml/qml/qqmlextensionplugin.h b/src/qml/qml/qqmlextensionplugin.h index 170c7915a5..245651979b 100644 --- a/src/qml/qml/qqmlextensionplugin.h +++ b/src/qml/qml/qqmlextensionplugin.h @@ -68,6 +68,7 @@ public: virtual void registerTypes(const char *uri) = 0; virtual void initializeEngine(QQmlEngine *engine, const char *uri); +private: Q_DISABLE_COPY(QQmlExtensionPlugin) }; |