From da202bff82e5c470ee2662542c47aa6381ed591c Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Thu, 13 Oct 2016 12:30:48 +0200 Subject: [PATCH] QmlDesigner: Adding support for padding This property has been added to Qt Quick 2.6. We do not show the padding section for Qt Quick versions that do not support padding. Change-Id: I10123c65849e1708d452320ba3e3b4cb19f5b5bb Reviewed-by: Tim Jenssen --- .../HelperWidgets/PaddingSection.qml | 122 ++++++++++++++++++ .../HelperWidgets/qmldir | 1 + .../QtQuick/TextEditSpecifics.qml | 4 + .../QtQuick/TextInputSpecifics.qml | 5 + .../QtQuick/TextSpecifics.qml | 4 + .../propertyeditorcontextobject.cpp | 20 ++- .../propertyeditorcontextobject.h | 11 +- .../propertyeditorqmlbackend.cpp | 4 +- .../designercore/include/abstractview.h | 1 + .../designercore/model/abstractview.cpp | 40 ++++++ 10 files changed, 204 insertions(+), 8 deletions(-) create mode 100644 share/qtcreator/qmldesigner/propertyEditorQmlSources/HelperWidgets/PaddingSection.qml diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/HelperWidgets/PaddingSection.qml b/share/qtcreator/qmldesigner/propertyEditorQmlSources/HelperWidgets/PaddingSection.qml new file mode 100644 index 00000000000..aad10455c7d --- /dev/null +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/HelperWidgets/PaddingSection.qml @@ -0,0 +1,122 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +import QtQuick 2.1 +import HelperWidgets 2.0 +import QtQuick.Layouts 1.0 +import QtQuick.Controls 1.0 as Controls + +Section { + caption: qsTr("Padding") + + anchors.left: parent.left + anchors.right: parent.right + + SectionLayout { + Label { + text: qsTr("Vertical") + } + SecondColumnLayout { + Label { + text: qsTr("Top") + tooltip: qsTr("Padding between the content and the top edge of the item.") + width: 42 + } + SpinBox { + maximumValue: 9999999 + minimumValue: -9999999 + decimals: 0 + backendValue: backendValues.topPadding + Layout.fillWidth: true + } + Item { + width: 4 + height: 4 + } + + Label { + text: qsTr("Bottom") + tooltip: qsTr("Padding between the content and the bottom edge of the item.") + width: 42 + } + SpinBox { + maximumValue: 9999999 + minimumValue: -9999999 + decimals: 0 + backendValue: backendValues.bottomPadding + Layout.fillWidth: true + } + } + + Label { + text: qsTr("Horizontal") + } + SecondColumnLayout { + Label { + text: qsTr("Left") + tooltip: qsTr("Padding between the content and the left edge of the item.") + width: 42 + } + SpinBox { + maximumValue: 9999999 + minimumValue: -9999999 + decimals: 0 + backendValue: backendValues.leftPadding + Layout.fillWidth: true + } + Item { + width: 4 + height: 4 + } + + Label { + text: qsTr("Right") + tooltip: qsTr("Padding between the content and the right edge of the item.") + width: 42 + } + SpinBox { + maximumValue: 9999999 + minimumValue: -9999999 + decimals: 0 + backendValue: backendValues.rightPadding + Layout.fillWidth: true + } + } + + Label { + text: qsTr("Padding") + tooltip: qsTr("Padding between the content and the edges of the items.") + } + SecondColumnLayout { + SpinBox { + maximumValue: 9999999 + minimumValue: -9999999 + decimals: 0 + backendValue: backendValues.padding + Layout.fillWidth: true + } + } + } +} diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/HelperWidgets/qmldir b/share/qtcreator/qmldesigner/propertyEditorQmlSources/HelperWidgets/qmldir index b4ee6dda7fc..10f92a578ad 100644 --- a/share/qtcreator/qmldesigner/propertyEditorQmlSources/HelperWidgets/qmldir +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/HelperWidgets/qmldir @@ -38,3 +38,4 @@ Tab 2.0 Tab.qml TabView 2.0 TabView.qml ToolTipArea 2.0 ToolTipArea.qml UrlChooser 2.0 UrlChooser.qml +PaddingSection 2.0 PaddingSection.qml diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/QtQuick/TextEditSpecifics.qml b/share/qtcreator/qmldesigner/propertyEditorQmlSources/QtQuick/TextEditSpecifics.qml index 09d14657795..c1a7a1e8d6d 100644 --- a/share/qtcreator/qmldesigner/propertyEditorQmlSources/QtQuick/TextEditSpecifics.qml +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/QtQuick/TextEditSpecifics.qml @@ -68,4 +68,8 @@ Column { TextInputSection { } + + PaddingSection { + visible: minorQtQuickVersion > 5 + } } diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/QtQuick/TextInputSpecifics.qml b/share/qtcreator/qmldesigner/propertyEditorQmlSources/QtQuick/TextInputSpecifics.qml index 62f1ee9ba07..615ce16aefe 100644 --- a/share/qtcreator/qmldesigner/propertyEditorQmlSources/QtQuick/TextInputSpecifics.qml +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/QtQuick/TextInputSpecifics.qml @@ -68,4 +68,9 @@ Column { TextInputSection { isTextInput: true } + + PaddingSection { + visible: minorQtQuickVersion > 5 + } + } diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/QtQuick/TextSpecifics.qml b/share/qtcreator/qmldesigner/propertyEditorQmlSources/QtQuick/TextSpecifics.qml index 03f29c520e8..28910fc05a4 100644 --- a/share/qtcreator/qmldesigner/propertyEditorQmlSources/QtQuick/TextSpecifics.qml +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/QtQuick/TextSpecifics.qml @@ -67,4 +67,8 @@ Column { FontSection { showStyle: true } + + PaddingSection { + visible: minorQtQuickVersion > 5 + } } diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.cpp index c6ca7974c7b..12d716c4100 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.cpp @@ -80,9 +80,6 @@ PropertyEditorContextObject::PropertyEditorContextObject(QObject *parent) : m_isBaseState(false), m_selectionChanged(false), m_backendValues(0), - m_majorVersion(-1), - m_minorVersion(-1), - m_majorQtQuickVersion(-1), m_qmlComponent(0), m_qmlContext(0) { @@ -167,7 +164,12 @@ int PropertyEditorContextObject::majorVersion() const int PropertyEditorContextObject::majorQtQuickVersion() const { - return m_majorQtQuickVersion; + return m_majorQtQuickVersion; +} + +int PropertyEditorContextObject::minorQtQuickVersion() const +{ + return m_minorQtQuickVersion; } void PropertyEditorContextObject::setMajorVersion(int majorVersion) @@ -191,6 +193,16 @@ void PropertyEditorContextObject::setMajorQtQuickVersion(int majorVersion) } +void PropertyEditorContextObject::setMinorQtQuickVersion(int minorVersion) +{ + if (m_minorQtQuickVersion == minorVersion) + return; + + m_minorQtQuickVersion = minorVersion; + + emit minorQtQuickVersionChanged(); +} + int PropertyEditorContextObject::minorVersion() const { return m_minorVersion; diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.h b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.h index 6b6e572ef3d..ae79d9bd863 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.h +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.h @@ -51,6 +51,7 @@ class PropertyEditorContextObject : public QObject Q_PROPERTY(int majorVersion READ majorVersion WRITE setMajorVersion NOTIFY majorVersionChanged) Q_PROPERTY(int minorVersion READ minorVersion WRITE setMinorVersion NOTIFY minorVersionChanged) Q_PROPERTY(int majorQtQuickVersion READ majorQtQuickVersion WRITE setMajorQtQuickVersion NOTIFY majorQtQuickVersionChanged) + Q_PROPERTY(int minorQtQuickVersion READ minorQtQuickVersion WRITE setMinorQtQuickVersion NOTIFY minorQtQuickVersionChanged) Q_PROPERTY(bool hasAliasExport READ hasAliasExport NOTIFY hasAliasExportChanged) @@ -81,8 +82,10 @@ public: int majorVersion() const; int majorQtQuickVersion() const; + int minorQtQuickVersion() const; void setMajorVersion(int majorVersion); void setMajorQtQuickVersion(int majorVersion); + void setMinorQtQuickVersion(int minorVersion); int minorVersion() const; void setMinorVersion(int minorVersion); @@ -102,6 +105,7 @@ signals: void majorVersionChanged(); void minorVersionChanged(); void majorQtQuickVersionChanged(); + void minorQtQuickVersionChanged(); void specificQmlComponentChanged(); void hasAliasExportChanged(); @@ -137,9 +141,10 @@ private: QQmlPropertyMap* m_backendValues; - int m_majorVersion; - int m_minorVersion; - int m_majorQtQuickVersion; + int m_majorVersion = 1; + int m_minorVersion = 1; + int m_majorQtQuickVersion = 1; + int m_minorQtQuickVersion = -1; QQmlComponent *m_qmlComponent; QQmlContext *m_qmlContext; diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp index 4e7256ca9f4..3d4884d9bd5 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp @@ -328,10 +328,12 @@ void PropertyEditorQmlBackend::setup(const QmlObjectNode &qmlObjectNode, const Q } else { contextObject()->setMajorVersion(-1); contextObject()->setMinorVersion(-1); - contextObject()->setMajorQtQuickVersion(-1); + contextObject()->setMajorQtQuickVersion(-1); + contextObject()->setMinorQtQuickVersion(-1); } contextObject()->setMajorQtQuickVersion(qmlObjectNode.view()->majorQtQuickVersion()); + contextObject()->setMinorQtQuickVersion(qmlObjectNode.view()->minorQtQuickVersion()); } else { qWarning() << "PropertyEditor: invalid node for setup"; } diff --git a/src/plugins/qmldesigner/designercore/include/abstractview.h b/src/plugins/qmldesigner/designercore/include/abstractview.h index aae79fc9ef4..8d4ca2de834 100644 --- a/src/plugins/qmldesigner/designercore/include/abstractview.h +++ b/src/plugins/qmldesigner/designercore/include/abstractview.h @@ -236,6 +236,7 @@ public: QmlModelState currentState() const; int majorQtQuickVersion() const; + int minorQtQuickVersion() const; void resetView(); diff --git a/src/plugins/qmldesigner/designercore/model/abstractview.cpp b/src/plugins/qmldesigner/designercore/model/abstractview.cpp index 4673b33601a..0ebc577c90d 100644 --- a/src/plugins/qmldesigner/designercore/model/abstractview.cpp +++ b/src/plugins/qmldesigner/designercore/model/abstractview.cpp @@ -672,6 +672,21 @@ QmlModelState AbstractView::currentState() const return QmlModelState(currentStateNode()); } +static int getMinorVersionFromImport(const Model *model) +{ + foreach (const Import &import, model->imports()) { + if (import.isLibraryImport() && import.url() == "QtQuick") { + const QString versionString = import.version(); + if (versionString.contains(".")) { + const QString minorVersionString = versionString.split(".").last(); + return minorVersionString.toInt(); + } + } + } + + return -1; +} + static int getMajorVersionFromImport(const Model *model) { foreach (const Import &import, model->imports()) { @@ -702,6 +717,21 @@ static int getMajorVersionFromNode(const ModelNode &modelNode) return 1; //default } +static int getMinorVersionFromNode(const ModelNode &modelNode) +{ + if (modelNode.metaInfo().isValid()) { + if (modelNode.type() == "QtQuick.QtObject" || modelNode.type() == "QtQuick.Item") + return modelNode.minorVersion(); + + foreach (const NodeMetaInfo &superClass, modelNode.metaInfo().superClasses()) { + if (modelNode.type() == "QtQuick.QtObject" || modelNode.type() == "QtQuick.Item") + return superClass.minorVersion(); + } + } + + return 1; //default +} + int AbstractView::majorQtQuickVersion() const { int majorVersionFromImport = getMajorVersionFromImport(model()); @@ -711,4 +741,14 @@ int AbstractView::majorQtQuickVersion() const return getMajorVersionFromNode(rootModelNode()); } +int AbstractView::minorQtQuickVersion() const +{ + int minorVersionFromImport = getMinorVersionFromImport(model()); + if (minorVersionFromImport >= 0) + return minorVersionFromImport; + + return getMinorVersionFromNode(rootModelNode()); +} + + } // namespace QmlDesigner