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 <tim.jenssen@qt.io>
This commit is contained in:
Thomas Hartmann
2016-10-13 12:30:48 +02:00
committed by Tim Jenssen
parent 6884ab080e
commit da202bff82
10 changed files with 204 additions and 8 deletions

View File

@@ -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
}
}
}
}

View File

@@ -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

View File

@@ -68,4 +68,8 @@ Column {
TextInputSection {
}
PaddingSection {
visible: minorQtQuickVersion > 5
}
}

View File

@@ -68,4 +68,9 @@ Column {
TextInputSection {
isTextInput: true
}
PaddingSection {
visible: minorQtQuickVersion > 5
}
}

View File

@@ -67,4 +67,8 @@ Column {
FontSection {
showStyle: true
}
PaddingSection {
visible: minorQtQuickVersion > 5
}
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -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";
}

View File

@@ -236,6 +236,7 @@ public:
QmlModelState currentState() const;
int majorQtQuickVersion() const;
int minorQtQuickVersion() const;
void resetView();

View File

@@ -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