Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Implement import/remove resources to qml resource picker.

Wolthera van Hövell tot Westerflier7c987f8a0462
diff --git a/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.cpp b/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.cpp
index fec68deca1..ab99956c51 100644
--- a/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.cpp
+++ b/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.cpp
@@ -13,6 +13,12 @@
#include <KisTagResourceModel.h>
#include <kis_signal_compressor.h>
#include <KisResourceSearchBoxFilter.h>
+#include <KisResourceUserOperations.h>
+#include <KisResourceLoaderRegistry.h>
+
+#include <KoFileDialog.h>
+#include <QStandardPaths>
+#include <QApplication>
#include <resources/KoFontFamily.h>
@@ -317,6 +323,43 @@ KoResourceSP TagFilterProxyModelQmlWrapper::currentResource() const
return d->currentResource;
}
+void TagFilterProxyModelQmlWrapper::importResource()
+{
+ // Below copied from KisResourceItemChooser::slotButtonClicked
+ QStringList mimeTypes = KisResourceLoaderRegistry::instance()->mimeTypes(d->resourceType);
+ KoFileDialog dialog(QApplication::activeWindow(), KoFileDialog::OpenFiles, "OpenDocument");
+ dialog.setMimeTypeFilters(mimeTypes);
+ dialog.setDefaultDir(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation));
+ dialog.setCaption(i18nc("@title:window", "Choose File to Add"));
+ Q_FOREACH(const QString &filename, dialog.filenames()) {
+ if (QFileInfo(filename).exists() && QFileInfo(filename).isReadable()) {
+
+ KoResourceSP previousResource = this->currentResource();
+ KoResourceSP newResource = KisResourceUserOperations::importResourceFileWithUserInput(QApplication::activeWindow(), "", d->resourceType, filename);
+
+ if (previousResource && newResource && !currentResource()) {
+ /// We have overridden the currently selected resource and
+ /// nothing is selected now
+ QModelIndex index = d->tagFilterProxyModel->indexForResource(newResource);
+ setCurrentIndex(index.row());
+ }
+ }
+ }
+}
+
+void TagFilterProxyModelQmlWrapper::removeResource()
+{
+ // Below copied from KisResourceItemChooser::slotButtonClicked
+ QModelIndex index = d->tagFilterProxyModel->indexForResource(d->currentResource);
+ if (index.isValid()) {
+ d->tagFilterProxyModel->setResourceInactive(index);
+ }
+ int row = index.row();
+ int rowMin = --row;
+ row = qBound(0, rowMin, row);
+ setCurrentIndex(row);
+}
+
void TagFilterProxyModelQmlWrapper::setSearchTextOnModel()
{
if (!d->tagFilterProxyModel) return;
diff --git a/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.h b/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.h
index 1393ae1e20..62c960766c 100644
--- a/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.h
+++ b/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.h
@@ -88,12 +88,21 @@ public:
/// Set the resource index in tagfilterproxy.
void setCurrentIndex(const int &index);
+ /// Set resource to resource file name.
Q_INVOKABLE void setResourceToFileName(const QString &filename);
+ /// File name of the current resource.
QString resourceFilename();
+ /// current resource.
KoResourceSP currentResource() const;
+ /// Import a resource with file picker.
+ Q_INVOKABLE void importResource();
+
+ /// Disable the currently selected resource.
+ Q_INVOKABLE void removeResource();
+
Q_SIGNALS:
void modelChanged();
void searchTextChanged();
diff --git a/plugins/dockers/textproperties/qml/FontResourceDropdown.qml b/plugins/dockers/textproperties/qml/FontResourceDropdown.qml
index 2079b886ec..00b0396a7f 100644
--- a/plugins/dockers/textproperties/qml/FontResourceDropdown.qml
+++ b/plugins/dockers/textproperties/qml/FontResourceDropdown.qml
@@ -207,6 +207,7 @@ Button {
modelWrapper: familyCmb.modelWrapper;
resourceDelegate: fontDelegate;
palette: familyCmbPopup.palette;
+ addResourceRow.visible: false;
}
}
}
diff --git a/plugins/dockers/textproperties/qml/ResourceView.qml b/plugins/dockers/textproperties/qml/ResourceView.qml
index ee22acfa2e..bd14af15f0 100644
--- a/plugins/dockers/textproperties/qml/ResourceView.qml
+++ b/plugins/dockers/textproperties/qml/ResourceView.qml
@@ -19,6 +19,8 @@ Control {
property alias resourceDelegate : view.delegate;
+ property alias addResourceRow: addResourceRow;
+
function openContextMenu(x, y, resourceName, resourceIndex) {
tagActionsContextMenu.resourceName = resourceName;
tagActionsContextMenu.resourceIndex = resourceIndex;
@@ -206,5 +208,40 @@ Control {
palette: control.palette;
}
}
+ RowLayout {
+ id: addResourceRow;
+
+ height: visible? implicitContentHeight: 0;
+
+ ToolButton {
+ id: importResource;
+ palette: control.palette;
+ icon.source: "qrc:///light_document-import-16.svg";
+ icon.width: 16;
+ icon.height: 16;
+ icon.color: palette.text;
+ hoverEnabled: true;
+ ToolTip.text: i18nc("@info:tooltip", "Import Resource");
+ ToolTip.visible: hovered;
+ ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval;
+
+ onClicked: modelWrapper.importResource();
+
+ }
+ ToolButton {
+ id: removeResource;
+ palette: control.palette;
+ icon.source: "qrc:///light_edit-delete.svg";
+ icon.width: 16;
+ icon.height: 16;
+ icon.color: palette.text;
+ hoverEnabled: true;
+ ToolTip.text: i18nc("@info:tooltip", "Remove Resource");
+ ToolTip.visible: hovered;
+ ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval;
+
+ onClicked: modelWrapper.removeResource();
+ }
+ }
}
}
diff --git a/plugins/dockers/textproperties/qml/TextProperties.qml b/plugins/dockers/textproperties/qml/TextProperties.qml
index d6b057db1f..408b3dfac1 100644
--- a/plugins/dockers/textproperties/qml/TextProperties.qml
+++ b/plugins/dockers/textproperties/qml/TextProperties.qml
@@ -80,9 +80,8 @@ Rectangle {
Layout.fillWidth: true;
palette: paletteControl.palette;
- onCurrentResourceChanged: {
- mainWindow.applyPreset(currentResource);
- }
+ signal applyPreset;
+ onApplyPreset: mainWindow.applyPreset(currentResource);
resourceDelegate: ItemDelegate {
id: presetDelegate;
@@ -90,6 +89,7 @@ Rectangle {
property var meta: presetView.modelWrapper.metadataForIndex(model.index);
width: ListView.view.width;
highlighted: delegateMouseArea.containsMouse;
+ property bool selected: presetView.currentIndex === model.index;
contentItem: KoShapeQtQuickLabel {
width: parent.width;
height: nameLabel.height * 5;
@@ -112,6 +112,8 @@ Rectangle {
}
background: Rectangle {
color: presetDelegate.highlighted? presetDelegate.palette.highlight: "transparent";
+ border.color: presetDelegate.selected? presetDelegate.palette.highlight: presetDelegate.palette.base;
+ border.width: presetDelegate.selected? 2: 1;
}
MouseArea {
@@ -126,6 +128,11 @@ Rectangle {
presetView.modelWrapper.currentIndex = parent.model.index;
}
}
+ onDoubleClicked: {
+ presetView.modelWrapper.currentIndex = parent.model.index;
+ presetView.applyPreset;
+ }
+
ToolTip.text: presetDelegate.model.name + "\n" + presetDelegate.meta.description;
ToolTip.visible: containsMouse;
ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval;