From 092d969f10944415b3a0a38869de488b983fd11f Mon Sep 17 00:00:00 2001 From: Aleksei German Date: Mon, 18 Mar 2019 14:59:24 +0100 Subject: [PATCH] QtDesignStudio Gradient Picker Dialog Dialog allows you to save your gradients and to use stored presets, including system gradients. Change-Id: I6888446afd63c00f3cb8d9277d9e37517243491f Reviewed-by: Tim Jenssen --- .../imports/HelperWidgets/ButtonRowButton.qml | 5 +- .../imports/HelperWidgets/ColorEditor.qml | 40 ++++ .../imports/HelperWidgets/GradientLine.qml | 16 ++ .../HelperWidgets/GradientPresetList.qml | 129 +++++++++++ .../GradientPresetTabContent.qml | 217 ++++++++++++++++++ .../imports/HelperWidgets/qmldir | 2 + .../propertyeditor/gradientmodel.cpp | 111 ++++++++- .../components/propertyeditor/gradientmodel.h | 8 + .../gradientpresetcustomlistmodel.cpp | 161 +++++++++++++ .../gradientpresetcustomlistmodel.h | 62 +++++ .../gradientpresetdefaultlistmodel.cpp | 60 +++++ .../gradientpresetdefaultlistmodel.h | 49 ++++ .../propertyeditor/gradientpresetitem.cpp | 201 ++++++++++++++++ .../propertyeditor/gradientpresetitem.h | 85 +++++++ .../gradientpresetlistmodel.cpp | 115 ++++++++++ .../propertyeditor/gradientpresetlistmodel.h | 61 +++++ .../propertyeditor/propertyeditor.pri | 12 +- .../quick2propertyeditorview.cpp | 4 + 18 files changed, 1325 insertions(+), 13 deletions(-) create mode 100644 share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/GradientPresetList.qml create mode 100644 share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/GradientPresetTabContent.qml create mode 100644 src/plugins/qmldesigner/components/propertyeditor/gradientpresetcustomlistmodel.cpp create mode 100644 src/plugins/qmldesigner/components/propertyeditor/gradientpresetcustomlistmodel.h create mode 100644 src/plugins/qmldesigner/components/propertyeditor/gradientpresetdefaultlistmodel.cpp create mode 100644 src/plugins/qmldesigner/components/propertyeditor/gradientpresetdefaultlistmodel.h create mode 100644 src/plugins/qmldesigner/components/propertyeditor/gradientpresetitem.cpp create mode 100644 src/plugins/qmldesigner/components/propertyeditor/gradientpresetitem.h create mode 100644 src/plugins/qmldesigner/components/propertyeditor/gradientpresetlistmodel.cpp create mode 100644 src/plugins/qmldesigner/components/propertyeditor/gradientpresetlistmodel.h diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/ButtonRowButton.qml b/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/ButtonRowButton.qml index 8557552b535..6ba9957cd57 100644 --- a/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/ButtonRowButton.qml +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/ButtonRowButton.qml @@ -39,6 +39,8 @@ Item { signal clicked() + signal doubleClicked() + property alias tooltip: toolTipArea.tooltip width: 24 + leftPadding @@ -100,7 +102,8 @@ Item { buttonRowButton.parent.__checkButton(index()) } buttonRowButton.clicked() - } + } + onDoubleClicked: buttonRowButton.doubleClicked() } } diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/ColorEditor.qml b/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/ColorEditor.qml index d10f302f6ab..7a573d94c53 100644 --- a/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/ColorEditor.qml +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/ColorEditor.qml @@ -234,6 +234,46 @@ Column { gradientLine.addGradient() } + GradientPresetList { + id: presetList + visible: false + + function applyPreset() { + if (presetList.gradientData.presetType == 0) { + gradientLine.setPresetByID(presetList.gradientData.presetID); + } + else if (presetList.gradientData.presetType == 1) { + gradientLine.setPresetByStops( + presetList.gradientData.stops, + presetList.gradientData.colors, + presetList.gradientData.stopsCount); + } + else { console.log("INVALID GRADIENT TYPE: " + presetList.gradientData.presetType); } + } + + onApply: { + if (presetList.gradientData.stopsCount > 0) { + applyPreset(); + } + } + + onSaved: { + gradientLine.savePreset(); + presetList.updatePresets(); + } + + onAccepted: { //return key + if (presetList.gradientData.stopsCount > 0) { + applyPreset(); + } + } + + } + + onDoubleClicked: { + presetList.open() + } + tooltip: qsTr("Linear Gradient") GradientPopupIndicator { diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/GradientLine.qml b/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/GradientLine.qml index 0f0c8b85864..8db236176f7 100644 --- a/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/GradientLine.qml +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/GradientLine.qml @@ -59,6 +59,22 @@ Item { gradientModel.deleteGradient() } + function setPresetByID(presetID) { + gradientModel.setPresetByID(presetID) + colorLine.invalidate() + colorLine.select(0) + } + + function setPresetByStops(stopsPositions, stopsColors, stopsCount) { + gradientModel.setPresetByStops(stopsPositions, stopsColors, stopsCount) + colorLine.invalidate() + colorLine.select(0) + } + + function savePreset() { + gradientModel.savePreset() + } + Connections { target: modelNodeBackend onSelectionChanged: { diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/GradientPresetList.qml b/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/GradientPresetList.qml new file mode 100644 index 00000000000..b96d858ba4b --- /dev/null +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/GradientPresetList.qml @@ -0,0 +1,129 @@ +/**************************************************************************** +** +** 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.11 +import QtQuick.Layouts 1.12 +import QtQuick.Controls 2.5 +import QtQuick.Dialogs 1.3 + +import HelperWidgets 2.0 +import QtQuickDesignerTheme 1.0 + +Dialog { + id: dialogWindow + width: 1200 + height: 650 + title: "Gradient Picker" + + signal saved; + property alias gradientData: gradientPickerData; + + + QtObject { + id: gradientPickerData + property var stops; + property var colors; + property int stopsCount; + property int presetID; + property int presetType; //default(0) or custom(1) + } + + function addGradient(stopsPositions, stopsColors, stopsCount) { + customPresetListModel.addGradient(stopsPositions, stopsColors, stopsCount); + } + + function updatePresets() { + customPresetListModel.readPresets(); + } + + GradientPresetDefaultListModel { id: defaultPresetListModel; } + GradientPresetCustomListModel { id: customPresetListModel; } + + standardButtons: Dialog.NoButton + + Rectangle { + anchors.fill: parent + anchors.margins: -12 + anchors.bottomMargin: -70 + color: "#363636" + ColumnLayout { + anchors.fill: parent + anchors.margins: 13 + anchors.bottomMargin: 71 + TabView { + id: presetTabView + Layout.alignment: Qt.AlignTop | Qt.AlignHCenter + Layout.fillHeight: true + Layout.fillWidth: true + Tab { + title: qsTr("System Presets") + anchors.fill:parent + + GradientPresetTabContent { + id: defaultTabContent + viewModel: defaultPresetListModel + editableName: false + } + + } //tab default + Tab { + title: qsTr("User Presets") + anchors.fill: parent + + GradientPresetTabContent { + id: customTabContent + viewModel: customPresetListModel + editableName: true + onPresetNameChanged: customPresetListModel.changePresetName(id, name); + property int deleteId; + + onDeleteButtonClicked: { + deleteId = id; + deleteDialog.open() + } + + MessageDialog { + id: deleteDialog + visible: false + modality: Qt.WindowModal + standardButtons: Dialog.No | Dialog.Yes + title: qsTr("Delete preset?") + text: qsTr("Are you sure you want to delete this preset?") + onAccepted: customPresetListModel.deletePreset(customTabContent.deleteId); + } + } + } //tab custom + } //tabview + RowLayout { + Layout.alignment: Qt.AlignBottom | Qt.AlignRight + Layout.topMargin: 5 + + Button { id: buttonClose; text: qsTr("Close"); onClicked: { dialogWindow.reject(); } } + Button { id: buttonSave; text: qsTr("Save"); onClicked: { dialogWindow.saved(); } } + Button { id: buttonApply; text: qsTr("Apply"); onClicked: { dialogWindow.apply(); } } + } //RowLayout + } //ColumnLayout + } //rectangle +} //dialog diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/GradientPresetTabContent.qml b/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/GradientPresetTabContent.qml new file mode 100644 index 00000000000..fa59794b149 --- /dev/null +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/GradientPresetTabContent.qml @@ -0,0 +1,217 @@ +/**************************************************************************** +** +** 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.11 +import QtQuick.Layouts 1.12 +import QtQuick.Controls 2.5 +import QtQuick.Controls.Styles 1.4 +import QtQuick.Dialogs 1.3 + +import HelperWidgets 2.0 +import QtQuickDesignerTheme 1.0 + + +Rectangle { + id: tabBackground + width: parent.width + height: parent.height + color: "#242424" + anchors.fill: parent + + property alias viewModel : gradientTable.model; + property bool editableName : false; + signal presetNameChanged(int id, string name) + signal deleteButtonClicked(int id) + + property int delegateWidth: 153; + property int delegateHeight: 173; + property int gridCellWidth: 160; + + + ScrollView { + Layout.fillWidth: true + Layout.fillHeight: true + anchors.fill: parent + + GridView { + id: gradientTable + Layout.fillWidth: true + Layout.fillHeight: true + anchors.fill: parent + anchors.leftMargin: 10 + clip: true + delegate: gradientDelegate + + + property int gridColumns: width / tabBackground.gridCellWidth; + cellWidth: width / gridColumns + cellHeight: 180 + + Component { + id: gradientDelegate + + Rectangle { + id: backgroundCard + color: "#404040" + clip: false + + property real flexibleWidth: (gradientTable.width - gradientTable.cellWidth * gradientTable.gridColumns) / gradientTable.gridColumns + width: gradientTable.cellWidth + flexibleWidth - 8; height: tabBackground.delegateHeight + radius: 16 + + MouseArea { + id: rectMouseArea + anchors.fill: parent + hoverEnabled: true + onClicked: { + gradientTable.currentIndex = index; + gradientData.stops = stopsPosList; + gradientData.colors = stopsColorList; + gradientData.stopsCount = stopListSize; + gradientData.presetID = presetID; + gradientData.presetType = presetTabView.currentIndex + +// console.log( "#" + preset + " " + presetName + " Stops: " + stopsPosList + " Colors: " + stopsColorList); + } + onEntered: { + if (backgroundCard.state != "CLICKED") { + backgroundCard.state = "HOVER"; + } + } + onExited: { + if (backgroundCard.state != "CLICKED") { + backgroundCard.state = "USUAL"; + } + } + } //mouseArea + + states: [ + State { + name: "HOVER" + PropertyChanges { + target: backgroundCard + color: "#606060" + z: 5 + clip: true + border.width: 1 + border.color: "#029de0" + } + }, + State { + name: "USUAL" + PropertyChanges + { + target: backgroundCard + color: "#404040" + scale: 1.0 + border.width: 0 + } + } + ] //states + + ColumnLayout { + anchors.fill: parent + + Rectangle { + width: 150; height: 150 + id: gradientRect + radius: 16 + Layout.alignment: Qt.AlignHCenter | Qt.AlignTop + Layout.topMargin: 2 + gradient: Gradient { + id: showGr + } + + Component { + id: stopComponent + GradientStop {} + } + + Component.onCompleted: { + var stopsAmount = stopListSize; + var newStops = []; + for (var i = 0; i < stopsAmount; i++ ) { + newStops.push( stopComponent.createObject(showGr, { "position": stopsPosList[i], "color": stopsColorList[i] }) ); + } + showGr.stops = newStops; + } + + Rectangle { + id: removeItemRect + anchors.right: parent.right + anchors.rightMargin: 2 + anchors.top: parent.top + anchors.topMargin: 2 + height: 16 + width: 16 + visible: editableName && rectMouseArea.containsMouse + color: "#804682b4" + + + MouseArea { + anchors.fill: parent; + onClicked: tabBackground.deleteButtonClicked(index); + } + + Image { + id: remoreItemImg + source: "image://icons/close" + fillMode: Image.PreserveAspectFit + anchors.fill: parent; + Layout.alignment: Qt.AlignCenter + } + } + } //rectangle gradient + + TextInput { + id: presetNameBox + readOnly: !editableName + text: (presetName) + Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom + Layout.preferredWidth: backgroundCard.width + Layout.topMargin: -5 + padding: 5.0 + topPadding: -2.0 + horizontalAlignment: Text.AlignHCenter + wrapMode: Text.Wrap + color: "#ffffff" + activeFocusOnPress: true + + onEditingFinished: tabBackground.presetNameChanged(index, text); + + Keys.onPressed: { + if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) { + event.accepted = true; + editingFinished(); + focus = false; + } + } //Keys.onPressed + } //textInput + } //columnLayout + } //rectangle background + } //component delegate + } //gridview + } //scrollView +} //rectangle diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/qmldir b/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/qmldir index 2bb87380c31..43e4da76368 100644 --- a/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/qmldir +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/qmldir @@ -21,6 +21,8 @@ FontComboBox 2.0 FontComboBox.qml FontSection 2.0 FontSection.qml FontStyleButtons 2.0 FontStyleButtons.qml GradientLine 2.0 GradientLine.qml +GradientPresetList 2.0 GradientPresetList.qml +GradientPresetTabContent 2.0 GradientPresetTabContent.qml GroupBox 2.0 GroupBox.qml HueSlider 2.0 HueSlider.qml IconLabel 2.0 IconLabel.qml diff --git a/src/plugins/qmldesigner/components/propertyeditor/gradientmodel.cpp b/src/plugins/qmldesigner/components/propertyeditor/gradientmodel.cpp index fec1f3bdfd6..d462bfdacc9 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/gradientmodel.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/gradientmodel.cpp @@ -27,6 +27,8 @@ #include "qmlanchorbindingproxy.h" #include "propertyeditorview.h" +#include "gradientpresetitem.h" +#include "gradientpresetcustomlistmodel.h" #include #include @@ -262,16 +264,7 @@ void GradientModel::deleteGradient() if (!m_itemNode.modelNode().metaInfo().hasProperty(gradientPropertyName().toUtf8())) return; - QmlDesigner::ModelNode modelNode = m_itemNode.modelNode(); - - if (m_itemNode.isInBaseState()) { - if (modelNode.hasProperty(gradientPropertyName().toUtf8())) { - QmlDesigner::RewriterTransaction transaction = view()->beginRewriterTransaction(QByteArrayLiteral("GradientModel::deleteGradient")); - QmlDesigner::ModelNode gradientNode = modelNode.nodeProperty(gradientPropertyName().toUtf8()).modelNode(); - if (QmlDesigner::QmlObjectNode(gradientNode).isValid()) - QmlDesigner::QmlObjectNode(gradientNode).destroy(); - } - } + deleteGradientNode(true); emit hasGradientChanged(); emit gradientTypeChanged(); @@ -477,6 +470,23 @@ QmlDesigner::ModelNode GradientModel::createGradientStopNode() return view()->createModelNode(fullTypeName, majorVersion, minorVersion); } +void GradientModel::deleteGradientNode(bool saveTransaction) +{ + QmlDesigner::ModelNode modelNode = m_itemNode.modelNode(); + + if (m_itemNode.isInBaseState()) { + if (modelNode.hasProperty(gradientPropertyName().toUtf8())) { + if (saveTransaction) + QmlDesigner::RewriterTransaction transaction = view()->beginRewriterTransaction( + QByteArrayLiteral("GradientModel::deleteGradient")); + QmlDesigner::ModelNode gradientNode + = modelNode.nodeProperty(gradientPropertyName().toUtf8()).modelNode(); + if (QmlDesigner::QmlObjectNode(gradientNode).isValid()) + QmlDesigner::QmlObjectNode(gradientNode).destroy(); + } + } +} + void GradientModel::setGradientProperty(const QString &propertyName, qreal value) { QTC_ASSERT(m_itemNode.isValid(), return); @@ -494,3 +504,84 @@ void GradientModel::setGradientProperty(const QString &propertyName, qreal value e.showException(); } } + +void GradientModel::setPresetByID(int presetID) +{ + const QGradient gradient(static_cast(presetID)); + const QList gradientStops = gradient.stops().toList(); + + QList stopsPositions; + QList stopsColors; + for (const QGradientStop &stop : gradientStops) { + stopsPositions.append(stop.first); + stopsColors.append(stop.second.name()); + } + + setPresetByStops(stopsPositions, stopsColors, gradientStops.size()); +} + +void GradientModel::setPresetByStops(const QList &stopsPositions, + const QList &stopsColors, + int stopsCount) +{ + if (m_locked) + return; + + if (!m_itemNode.isValid() || gradientPropertyName().isEmpty()) + return; + + QmlDesigner::RewriterTransaction transaction = view()->beginRewriterTransaction( + QByteArrayLiteral("GradientModel::setCustomPreset")); + + //delete an old gradient without rewriter transaction + deleteGradientNode(false); + + //create a new gradient: + if (!m_itemNode.modelNode().hasNodeProperty(gradientPropertyName().toUtf8())) { + try { + QmlDesigner::ModelNode gradientNode = createGradientNode(); + + m_itemNode.modelNode() + .nodeProperty(gradientPropertyName().toUtf8()) + .reparentHere(gradientNode); + + //create stops and give them positions and colors based on value + for (int i = 0; i < stopsCount; i++) { + QmlDesigner::ModelNode gradientStopNode = createGradientStopNode(); + gradientStopNode.variantProperty("position").setValue(stopsPositions.at(i)); + gradientStopNode.variantProperty("color").setValue(stopsColors.at(i)); + gradientNode.nodeListProperty("stops").reparentHere(gradientStopNode); + } + + } catch (const QmlDesigner::Exception &e) { + e.showException(); + } + } + setupModel(); + + emit hasGradientChanged(); + emit gradientTypeChanged(); +} + +void GradientModel::savePreset() +{ + //preparing qgradient: + QGradient currentGradient; + QGradientStops currentStops; + QGradientStop stop; //double, color + + for (int i = 0; i < rowCount(); i++) { + stop.first = getPosition(i); + stop.second = getColor(i); + currentStops.append(stop); + } + currentGradient.setStops(currentStops); + const GradientPresetItem item(currentGradient, "Custom Gradient"); + + //reading the custom gradient file + //filling the file with old data + new data + const QString filename(GradientPresetCustomListModel::getFilename()); + QList items = GradientPresetCustomListModel::storedPresets(filename); + items.append(item); + GradientPresetCustomListModel::storePresets(filename, items); +} diff --git a/src/plugins/qmldesigner/components/propertyeditor/gradientmodel.h b/src/plugins/qmldesigner/components/propertyeditor/gradientmodel.h index 804731c1e24..d5fb3aea2a9 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/gradientmodel.h +++ b/src/plugins/qmldesigner/components/propertyeditor/gradientmodel.h @@ -70,6 +70,13 @@ public: Q_INVOKABLE void setGradientProperty(const QString &propertyName, qreal value); + Q_INVOKABLE void setPresetByID(int presetID); + Q_INVOKABLE void setPresetByStops(const QList &stopsPositions, + const QList &stopsColors, + int stopsCount); + + Q_INVOKABLE void savePreset(); + signals: void anchorBackendChanged(); void hasGradientChanged(); @@ -87,6 +94,7 @@ private: bool locked() const; QmlDesigner::ModelNode createGradientNode(); QmlDesigner::ModelNode createGradientStopNode(); + void deleteGradientNode(bool saveTransaction); private: QmlDesigner::QmlItemNode m_itemNode; diff --git a/src/plugins/qmldesigner/components/propertyeditor/gradientpresetcustomlistmodel.cpp b/src/plugins/qmldesigner/components/propertyeditor/gradientpresetcustomlistmodel.cpp new file mode 100644 index 00000000000..3888706cfeb --- /dev/null +++ b/src/plugins/qmldesigner/components/propertyeditor/gradientpresetcustomlistmodel.cpp @@ -0,0 +1,161 @@ +/**************************************************************************** +** +** 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. +** +****************************************************************************/ + +#include "gradientpresetcustomlistmodel.h" + +#include "gradientpresetitem.h" +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace Internal { + +static const char settingsKey[] = "GradientPresetCustomList"; +static const char settingsFileName[] = "/GradientPresets.ini"; + +QString settingsFullFilePath(const QSettings::Scope &scope) +{ + if (scope == QSettings::SystemScope) + return Core::ICore::installerResourcePath() + settingsFileName; + + return Core::ICore::userResourcePath() + settingsFileName; +} + +} // namespace Internal + +GradientPresetCustomListModel::GradientPresetCustomListModel(QObject *parent) + : GradientPresetListModel(parent) + , m_filename(getFilename()) +{ + qRegisterMetaTypeStreamOperators("GradientPresetItem"); + readPresets(); +} + +GradientPresetCustomListModel::~GradientPresetCustomListModel() {} + +void GradientPresetCustomListModel::registerDeclarativeType() +{ + qmlRegisterType("HelperWidgets", + 2, + 0, + "GradientPresetCustomListModel"); +} + +QString GradientPresetCustomListModel::getFilename() +{ + return Internal::settingsFullFilePath(QSettings::UserScope); +} + +void GradientPresetCustomListModel::storePresets(const QString &filename, + const QList &items) +{ + const QList presets + = Utils::transform>(items, [](const GradientPresetItem &item) { + return QVariant::fromValue(item); + }); + + QSettings settings(filename, QSettings::IniFormat); + settings.clear(); + settings.setValue(Internal::settingsKey, QVariant::fromValue(presets)); +} + +QList GradientPresetCustomListModel::storedPresets(const QString &filename) +{ + const QSettings settings(filename, QSettings::IniFormat); + const QVariant presetSettings = settings.value(Internal::settingsKey); + + if (!presetSettings.isValid()) + return {}; + + const QList presets = presetSettings.toList(); + + QList out; + for (const QVariant &preset : presets) { + if (preset.isValid()) { + out.append(preset.value()); + } + } + + return out; +} + +void GradientPresetCustomListModel::addGradient(const QList &stopsPositions, + const QList &stopsColors, + int stopsCount) +{ + QGradient tempGradient; + QGradientStops gradientStops; + QGradientStop gradientStop; + for (int i = 0; i < stopsCount; i++) { + gradientStop.first = stopsPositions.at(i); + gradientStop.second = stopsColors.at(i); + gradientStops.push_back(gradientStop); + } + + tempGradient.setStops(gradientStops); + + addItem(GradientPresetItem(tempGradient)); +} + +void GradientPresetCustomListModel::changePresetName(int id, const QString &newName) +{ + QTC_ASSERT(id >= 0, return); + QTC_ASSERT(id < m_items.size(), return); + m_items[id].setPresetName(newName); + writePresets(); +} + +void GradientPresetCustomListModel::deletePreset(int id) +{ + QTC_ASSERT(id >= 0, return); + QTC_ASSERT(id < m_items.size(), return); + beginResetModel(); + m_items.removeAt(id); + writePresets(); + endResetModel(); +} + +void GradientPresetCustomListModel::writePresets() +{ + storePresets(m_filename, m_items); +} + +void GradientPresetCustomListModel::readPresets() +{ + const QList presets = storedPresets(m_filename); + beginResetModel(); + m_items.clear(); + + for (const GradientPresetItem &preset : presets) { + addItem(preset); + } + endResetModel(); +} diff --git a/src/plugins/qmldesigner/components/propertyeditor/gradientpresetcustomlistmodel.h b/src/plugins/qmldesigner/components/propertyeditor/gradientpresetcustomlistmodel.h new file mode 100644 index 00000000000..382b651e3b9 --- /dev/null +++ b/src/plugins/qmldesigner/components/propertyeditor/gradientpresetcustomlistmodel.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** 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. +** +****************************************************************************/ + +#pragma once + +#include "gradientpresetlistmodel.h" + +#include +#include +#include + +class GradientPresetCustomListModel : public GradientPresetListModel +{ + Q_OBJECT + +public: + explicit GradientPresetCustomListModel(QObject *parent = nullptr); + ~GradientPresetCustomListModel() override; + + static void registerDeclarativeType(); + + static QString getFilename(); + static void storePresets(const QString &filename, const QList &items); + static QList storedPresets(const QString &filename); + + Q_INVOKABLE void addGradient(const QList &stopsPositions, + const QList &stopsColors, + int stopsCount); + + Q_INVOKABLE void changePresetName(int id, const QString &newName); + Q_INVOKABLE void deletePreset(int id); + + Q_INVOKABLE void writePresets(); + Q_INVOKABLE void readPresets(); + +private: + QString m_filename; +}; + +QML_DECLARE_TYPE(GradientPresetCustomListModel) diff --git a/src/plugins/qmldesigner/components/propertyeditor/gradientpresetdefaultlistmodel.cpp b/src/plugins/qmldesigner/components/propertyeditor/gradientpresetdefaultlistmodel.cpp new file mode 100644 index 00000000000..e7d8a28e7b6 --- /dev/null +++ b/src/plugins/qmldesigner/components/propertyeditor/gradientpresetdefaultlistmodel.cpp @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** 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. +** +****************************************************************************/ + +#include "gradientpresetdefaultlistmodel.h" + +#include +#include +#include + +#include + +#include "gradientpresetitem.h" + +GradientPresetDefaultListModel::GradientPresetDefaultListModel(QObject *parent) + : GradientPresetListModel(parent) +{ + addAllPresets(); +} + +GradientPresetDefaultListModel::~GradientPresetDefaultListModel() {} + +void GradientPresetDefaultListModel::registerDeclarativeType() +{ + qmlRegisterType("HelperWidgets", + 2, + 0, + "GradientPresetDefaultListModel"); +} + +void GradientPresetDefaultListModel::addAllPresets() +{ + const QMetaObject &metaObj = QGradient::staticMetaObject; + const QMetaEnum metaEnum = metaObj.enumerator(metaObj.indexOfEnumerator("Preset")); + + for (int i = 0; i < metaEnum.keyCount(); i++) { + addItem(GradientPresetItem(QGradient::Preset(metaEnum.value(i)))); + } +} diff --git a/src/plugins/qmldesigner/components/propertyeditor/gradientpresetdefaultlistmodel.h b/src/plugins/qmldesigner/components/propertyeditor/gradientpresetdefaultlistmodel.h new file mode 100644 index 00000000000..9d2dbdac536 --- /dev/null +++ b/src/plugins/qmldesigner/components/propertyeditor/gradientpresetdefaultlistmodel.h @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** 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. +** +****************************************************************************/ + +#pragma once + +#include +#include +#include +#include + +#include "gradientpresetlistmodel.h" + +class GradientPresetDefaultListModel : public GradientPresetListModel +{ + Q_OBJECT + +public: + explicit GradientPresetDefaultListModel(QObject *parent = nullptr); + ~GradientPresetDefaultListModel() override; + + static void registerDeclarativeType(); + +private: + void addAllPresets(); +}; + +QML_DECLARE_TYPE(GradientPresetDefaultListModel) diff --git a/src/plugins/qmldesigner/components/propertyeditor/gradientpresetitem.cpp b/src/plugins/qmldesigner/components/propertyeditor/gradientpresetitem.cpp new file mode 100644 index 00000000000..d557b6c3d44 --- /dev/null +++ b/src/plugins/qmldesigner/components/propertyeditor/gradientpresetitem.cpp @@ -0,0 +1,201 @@ +/**************************************************************************** +** +** 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. +** +****************************************************************************/ + +#include "gradientpresetitem.h" + +#include +#include + +#include +#include +#include +#include +#include + + +GradientPresetItem::GradientPresetItem() + : m_gradientVal(QGradient::Preset(0)) + , m_gradientID(QGradient::Preset(0)) + , m_presetName(QString()) +{} + +GradientPresetItem::GradientPresetItem(const QGradient &value, const QString &name) + : m_gradientVal(value) + , m_gradientID(QGradient::Preset(0)) + , m_presetName(name) +{} + +GradientPresetItem::GradientPresetItem(const QGradient::Preset value) + : m_gradientVal(QGradient::Preset(value)) + , m_gradientID(value) + , m_presetName(getNameByPreset(value)) +{} + +GradientPresetItem::~GradientPresetItem() = default; + +QVariant GradientPresetItem::getProperty(GradientPresetItem::Property id) const +{ + QVariant out; + + switch (id) { + case objectNameRole: + out.setValue(QString()); + break; + case presetRole: + out.setValue(preset()); + break; + case stopsPosListRole: + out.setValue(stopsPosList()); + break; + case stopsColorListRole: + out.setValue(stopsColorList()); + break; + case stopListSizeRole: + out.setValue(stopListSize()); + break; + case presetNameRole: + out.setValue(presetName()); + break; + case presetIDRole: + out.setValue(presetID()); + break; + default: + qWarning() << "GradientPresetItem Property switch default case"; + break; //replace with assert before switch? + } + + return out; +} + +QGradient GradientPresetItem::gradientVal() const +{ + return m_gradientVal; +} + +QGradient::Preset GradientPresetItem::preset() const +{ + return m_gradientID; +} + +void GradientPresetItem::setGradient(const QGradient &value) +{ + m_gradientVal = value; + m_gradientID = QGradient::Preset(0); + m_presetName = QString(); +} + +void GradientPresetItem::setGradient(const QGradient::Preset value) +{ + m_gradientID = value; + m_gradientVal = QGradient(value); + m_presetName = getNameByPreset(value); +} + +QList GradientPresetItem::stopsPosList() const +{ + const QList> subres = m_gradientVal.stops().toList(); + const QList result = Utils::transform>(subres, + [](const QPair &item) { + return item.first; + }); + return result; +} + +QList GradientPresetItem::stopsColorList() const +{ + const QList> subres = m_gradientVal.stops().toList(); + const QList result + = Utils::transform>(subres, [](const QPair &item) { + return item.second.name(); + }); + return result; +} + +int GradientPresetItem::stopListSize() const +{ + return m_gradientVal.stops().size(); +} + +void GradientPresetItem::setPresetName(const QString &value) +{ + m_presetName = value; +} + +QString GradientPresetItem::presetName() const +{ + return m_presetName; +} + +int GradientPresetItem::presetID() const +{ + return static_cast(m_gradientID); +} + +QString GradientPresetItem::getNameByPreset(QGradient::Preset value) +{ + const QMetaObject &metaObj = QGradient::staticMetaObject; + const QMetaEnum metaEnum = metaObj.enumerator(metaObj.indexOfEnumerator("Preset")); + + QString enumName = QString::fromUtf8(metaEnum.valueToKey(static_cast(value))); + + const QStringList sl = enumName.split(QRegExp("(?=[A-Z])"), QString::SkipEmptyParts); + + enumName.clear(); + std::for_each(sl.begin(), sl.end(), [&enumName](const QString &s) { enumName += (s + " "); }); + enumName.chop(1); //let's remove the last empty space + + return (enumName.isEmpty() ? "Custom" : enumName); +} + +QDebug &operator<<(QDebug &stream, const GradientPresetItem &gradient) +{ + stream << "\"stops:" << gradient.m_gradientVal.stops() << "\""; + stream << "\"preset:" << gradient.m_gradientID << "\""; + stream << "\"name:" << gradient.m_presetName << "\""; + return stream; +} + +QDataStream &operator<<(QDataStream &stream, const GradientPresetItem &gradient) +{ + stream << gradient.m_gradientVal.stops(); + + stream << static_cast(gradient.m_gradientID); + stream << gradient.m_presetName; + return stream; +} + +QDataStream &operator>>(QDataStream &stream, GradientPresetItem &gradient) +{ + QGradientStops stops; + stream >> stops; + gradient.m_gradientVal.setStops(stops); + + int gradientID; + stream >> gradientID; + gradient.m_gradientID = static_cast(gradientID); + + stream >> gradient.m_presetName; + return stream; +} diff --git a/src/plugins/qmldesigner/components/propertyeditor/gradientpresetitem.h b/src/plugins/qmldesigner/components/propertyeditor/gradientpresetitem.h new file mode 100644 index 00000000000..b3d3ad14a00 --- /dev/null +++ b/src/plugins/qmldesigner/components/propertyeditor/gradientpresetitem.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** 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. +** +****************************************************************************/ + +#include +#include + +class GradientPresetItem +{ + Q_GADGET + + Q_PROPERTY(QGradient::Preset preset READ preset FINAL) + Q_PROPERTY(QList stopsPosList READ stopsPosList FINAL) + Q_PROPERTY(QList stopsColorList READ stopsColorList FINAL) + Q_PROPERTY(int stopListSize READ stopListSize FINAL) + Q_PROPERTY(QString presetName READ presetName FINAL) + Q_PROPERTY(int presetID READ presetID FINAL) + +public: + explicit GradientPresetItem(); + explicit GradientPresetItem(const QGradient &value, const QString &name = QString()); + explicit GradientPresetItem(const QGradient::Preset number); + ~GradientPresetItem(); + + enum Property { + objectNameRole = 0, + presetRole = 1, + stopsPosListRole = 2, + stopsColorListRole = 3, + stopListSizeRole = 4, + presetNameRole = 5, + presetIDRole = 6 + }; + + QVariant getProperty(Property id) const; + + QGradient gradientVal() const; + QGradient::Preset preset() const; + + void setGradient(const QGradient &value); + void setGradient(const QGradient::Preset value); + + QList stopsPosList() const; + QList stopsColorList() const; + int stopListSize() const; + + void setPresetName(const QString &value); + QString presetName() const; + int presetID() const; + + static QString getNameByPreset(QGradient::Preset value); + + friend QDebug &operator<<(QDebug &stream, const GradientPresetItem &gradient); + + friend QDataStream &operator<<(QDataStream &stream, const GradientPresetItem &gradient); + friend QDataStream &operator>>(QDataStream &stream, GradientPresetItem &gradient); + +private: + QGradient m_gradientVal; + QGradient::Preset m_gradientID; + QString m_presetName; +}; + +Q_DECLARE_METATYPE(GradientPresetItem) diff --git a/src/plugins/qmldesigner/components/propertyeditor/gradientpresetlistmodel.cpp b/src/plugins/qmldesigner/components/propertyeditor/gradientpresetlistmodel.cpp new file mode 100644 index 00000000000..c0e8393550d --- /dev/null +++ b/src/plugins/qmldesigner/components/propertyeditor/gradientpresetlistmodel.cpp @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** 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. +** +****************************************************************************/ + +#include "gradientpresetlistmodel.h" + +#include "gradientpresetitem.h" + +#include +#include +#include +#include + +GradientPresetListModel::GradientPresetListModel(QObject *parent) + : QAbstractListModel(parent) +{ + m_roleNames + = {{static_cast(GradientPresetItem::Property::objectNameRole), "objectName"}, + {static_cast(GradientPresetItem::Property::presetRole), "preset"}, + {static_cast(GradientPresetItem::Property::stopsPosListRole), "stopsPosList"}, + {static_cast(GradientPresetItem::Property::stopsColorListRole), "stopsColorList"}, + {static_cast(GradientPresetItem::Property::stopListSizeRole), "stopListSize"}, + {static_cast(GradientPresetItem::Property::presetNameRole), "presetName"}, + {static_cast(GradientPresetItem::Property::presetIDRole), "presetID"}}; +} + +GradientPresetListModel::~GradientPresetListModel() +{ + clearItems(); +} + +int GradientPresetListModel::rowCount(const QModelIndex & /*parent*/) const +{ + return m_items.count(); +} + +QVariant GradientPresetListModel::data(const QModelIndex &index, int role) const +{ + if (index.isValid() && (index.row() >= 0) && (index.row() < m_items.count())) { + if (m_roleNames.contains(role)) { + QVariant value = m_items.at(index.row()) + .getProperty(static_cast(role)); + + if (auto model = qobject_cast(value.value())) + return QVariant::fromValue(model); + + return value; + } + + qWarning() << Q_FUNC_INFO << "invalid role requested"; + return QVariant(); + } + + qWarning() << Q_FUNC_INFO << "invalid index requested"; + return QVariant(); +} + +QHash GradientPresetListModel::roleNames() const +{ + return m_roleNames; +} + +void GradientPresetListModel::clearItems() +{ + beginResetModel(); + m_items.clear(); + endResetModel(); +} + +void GradientPresetListModel::addItem(const GradientPresetItem &element) +{ + beginResetModel(); + m_items.append(element); + endResetModel(); +} + +const QList &GradientPresetListModel::items() const +{ + return m_items; +} + +void GradientPresetListModel::sortItems() +{ + auto itemSort = [](const GradientPresetItem &first, const GradientPresetItem &second) { + return (static_cast(first.preset()) < static_cast(second.preset())); + }; + + std::sort(m_items.begin(), m_items.end(), itemSort); +} + +void GradientPresetListModel::registerDeclarativeType() +{ + qmlRegisterType("HelperWidgets", 2, 0, "GradientPresetListModel"); +} diff --git a/src/plugins/qmldesigner/components/propertyeditor/gradientpresetlistmodel.h b/src/plugins/qmldesigner/components/propertyeditor/gradientpresetlistmodel.h new file mode 100644 index 00000000000..fdf7080c7b7 --- /dev/null +++ b/src/plugins/qmldesigner/components/propertyeditor/gradientpresetlistmodel.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** 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. +** +****************************************************************************/ + +#pragma once + +#include +#include +#include +#include + +class GradientPresetItem; + +class GradientPresetListModel : public QAbstractListModel +{ + Q_OBJECT + +public: + explicit GradientPresetListModel(QObject *parent = nullptr); + ~GradientPresetListModel() override; + + int rowCount(const QModelIndex &parent = QModelIndex()) const override; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + QHash roleNames() const override; + + void clearItems(); + void addItem(const GradientPresetItem &element); + + const QList &items() const; + + void sortItems(); + + static void registerDeclarativeType(); + +protected: + QList m_items; + QHash m_roleNames; +}; + +//QML_DECLARE_TYPE(GradientPresetListModel) diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditor.pri b/src/plugins/qmldesigner/components/propertyeditor/propertyeditor.pri index d822fbb70d2..9d53bda311d 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditor.pri +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditor.pri @@ -11,7 +11,11 @@ SOURCES += propertyeditorview.cpp \ propertyeditorwidget.cpp \ fileresourcesmodel.cpp \ gradientmodel.cpp \ - qmlmodelnodeproxy.cpp + qmlmodelnodeproxy.cpp \ + gradientpresetitem.cpp \ + gradientpresetlistmodel.cpp \ + gradientpresetdefaultlistmodel.cpp \ + gradientpresetcustomlistmodel.cpp HEADERS += propertyeditorview.h \ qmlanchorbindingproxy.h \ @@ -24,6 +28,10 @@ HEADERS += propertyeditorview.h \ propertyeditorwidget.h \ fileresourcesmodel.h \ gradientmodel.h \ - qmlmodelnodeproxy.h + qmlmodelnodeproxy.h \ + gradientpresetitem.h \ + gradientpresetlistmodel.h \ + gradientpresetdefaultlistmodel.h \ + gradientpresetcustomlistmodel.h QT += qml quick diff --git a/src/plugins/qmldesigner/components/propertyeditor/quick2propertyeditorview.cpp b/src/plugins/qmldesigner/components/propertyeditor/quick2propertyeditorview.cpp index 4e58374759e..f9b42cf8eb8 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/quick2propertyeditorview.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/quick2propertyeditorview.cpp @@ -28,6 +28,8 @@ #include "propertyeditorvalue.h" #include "fileresourcesmodel.h" #include "gradientmodel.h" +#include "gradientpresetdefaultlistmodel.h" +#include "gradientpresetcustomlistmodel.h" #include "qmlanchorbindingproxy.h" #include "theme.h" @@ -48,6 +50,8 @@ void Quick2PropertyEditorView::registerQmlTypes() PropertyEditorValue::registerDeclarativeTypes(); FileResourcesModel::registerDeclarativeType(); GradientModel::registerDeclarativeType(); + GradientPresetDefaultListModel::registerDeclarativeType(); + GradientPresetCustomListModel::registerDeclarativeType(); Internal::QmlAnchorBindingProxy::registerDeclarativeType(); } }