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

Add tagging inside the font resource selector.

Wolthera van Hövell tot Westerfliera317fd8303a9
diff --git a/plugins/dockers/textproperties/KoShapeQtQuickLabel.cpp b/plugins/dockers/textproperties/KoShapeQtQuickLabel.cpp
index 1b05d860b1..db0a719848 100644
--- a/plugins/dockers/textproperties/KoShapeQtQuickLabel.cpp
+++ b/plugins/dockers/textproperties/KoShapeQtQuickLabel.cpp
@@ -78,7 +78,7 @@ QString KoShapeQtQuickLabel::svgData() const
void KoShapeQtQuickLabel::setSvgData(const QString &newSvgData)
{
- qreal max = qMax(20.0*imageScale(), qMax(width()-(d->imagePadding*2), height()-(d->imagePadding*2)));
+ qreal max = qMax(20.0*imageScale(), qMin(width()-(d->imagePadding*2), height()-(d->imagePadding*2)));
setImplicitHeight(max);
if (d->svgData == newSvgData)
return;
diff --git a/plugins/dockers/textproperties/TextPropertiesDock.cpp b/plugins/dockers/textproperties/TextPropertiesDock.cpp
index 1b47c29938..127a368f2c 100644
--- a/plugins/dockers/textproperties/TextPropertiesDock.cpp
+++ b/plugins/dockers/textproperties/TextPropertiesDock.cpp
@@ -28,6 +28,7 @@
#include <KisResourceModelProvider.h>
#include <KisTagFilterResourceProxyModel.h>
#include <KisTagModel.h>
+#include <KisTagResourceModel.h>
#include <KoCanvasResourcesIds.h>
#include <KoSvgTextPropertyData.h>
@@ -122,6 +123,48 @@ public:
return m_tagFilterProxyModel->filterInCurrentTag();
}
+ Q_INVOKABLE void addNewTag(QString newTagName, int resourceIndex = -1) {
+ KisTagSP tagsp = m_tagModel->tagForUrl(newTagName);
+ QModelIndex resourceIdx = m_tagFilterProxyModel->index(resourceIndex, 0);
+ if (tagsp.isNull()) {
+ QVector<KoResourceSP> vec;
+ tagsp = m_tagModel->addTag(newTagName, false, vec);
+
+ }
+ // TODO: figure out how to get a tag reactivated again, without doing too much code duplication :|
+ if (resourceIdx.isValid()) {
+ int resourceId = m_tagFilterProxyModel->data(resourceIdx, KisResourceModel::Id).toInt();
+ m_tagFilterProxyModel->tagResources(tagsp, {resourceId});
+ }
+
+ }
+
+ Q_INVOKABLE void tagResource(int tagIndex, int resourceIndex) {
+ QModelIndex idx = m_tagModel->index(tagIndex, 0);
+ QModelIndex resourceIdx = m_tagFilterProxyModel->index(resourceIndex, 0);
+ KisTagSP tagsp;
+ if (idx.isValid()) {
+ tagsp = m_tagModel->tagForIndex(idx);
+ }
+ if (tagsp && resourceIdx.isValid()) {
+ int resourceId = m_tagFilterProxyModel->data(resourceIdx, KisResourceModel::Id).toInt();
+ m_tagFilterProxyModel->tagResources(tagsp, {resourceId});
+ }
+ }
+
+ Q_INVOKABLE void untagResource(int tagIndex, int resourceIndex) {
+ QModelIndex idx = m_tagModel->index(tagIndex, 0);
+ QModelIndex resourceIdx = m_tagFilterProxyModel->index(resourceIndex, 0);
+ KisTagSP tagsp;
+ if (idx.isValid()) {
+ tagsp = m_tagModel->tagForIndex(idx);
+ }
+ if (tagsp && resourceIdx.isValid()) {
+ int resourceId = m_tagFilterProxyModel->data(resourceIdx, KisResourceModel::Id).toInt();
+ m_tagFilterProxyModel->untagResources(tagsp, {resourceId});
+ }
+ }
+
Q_SIGNALS:
void sourceModelChanged();
void modelChanged();
diff --git a/plugins/dockers/textproperties/qml/FontResourceDropdown.qml b/plugins/dockers/textproperties/qml/FontResourceDropdown.qml
index 1acb6888d7..b053027def 100644
--- a/plugins/dockers/textproperties/qml/FontResourceDropdown.qml
+++ b/plugins/dockers/textproperties/qml/FontResourceDropdown.qml
@@ -10,19 +10,38 @@ import org.krita.flake.text 1.0
ComboBox {
id: familyCmb;
+ wheelEnabled: true;
+
+ //--- Model setup. ---//
property var sourceModel;
property TagFilterProxyModelQmlWrapper modelWrapper : TagFilterProxyModelQmlWrapper{
sourceModel: sourceModel;
};
model: modelWrapper.model;
+ textRole: "name";
+ //--- Delegate setup. ---//
Component {
id: fontDelegate
ItemDelegate {
+ id: fontDelegateItem;
required property var model;
-
+ property string fontName: model.name;
+ width: fontResourceView.listWidth;
highlighted: familyCmb.highlightedIndex === model.index;
- contentItem: KoShapeQtQuickLabel{
+
+ Component.onCompleted: {
+ var localizedDict = model.metadata.localized_font_family;
+ for (var i in locales) {
+ var key = locales[i];
+ if (key in localizedDict) {
+ fontName = localizedDict[key];
+ break;
+ }
+ }
+ }
+
+ contentItem: KoShapeQtQuickLabel {
id: fontFamilyDelegate;
property bool colorBitmap : model.metadata.color_bitmap;
property bool colorCLRV0 : model.metadata.color_clrv0;
@@ -30,26 +49,15 @@ ComboBox {
property bool colorSVG : model.metadata.color_svg;
property bool isVariable : model.metadata.is_variable;
property int type : model.metadata.font_type;
- property string fontName: model.name;
-
- Layout.fillWidth: true;
- svgData: model.metadata.sample_svg;
+ property string fontName: fontDelegateItem.fontName;
+ width: parent.width;
+ height: nameLabel.height * 5;
imageScale: 3;
imagePadding: nameLabel.height;
+ svgData: model.metadata.sample_svg;
foregroundColor: sysPalette.text;
fullColor: colorBitmap || colorCLRV0 || colorCLRV1 || colorSVG;
- Component.onCompleted: {
- var localizedDict = model.metadata.localized_font_family;
- for (var i in locales) {
- var key = locales[i];
- if (key in localizedDict) {
- fontName = localizedDict[key];
- break;
- }
- }
- }
-
Label {
id: nameLabel;
text: fontFamilyDelegate.fontName;
@@ -104,15 +112,30 @@ ComboBox {
}
}
}
- width: fontResourceView.listWidth;
- background: Rectangle { color: highlighted? parent.palette.highlight:"transparent"; }
- }
- }
-
+ background: Rectangle {
+ color: highlighted? familyCmb.palette.highlight:"transparent";
+ }
- textRole: "name";
+ MouseArea {
+ acceptedButtons: Qt.RightButton;
+ anchors.fill: parent;
+ //preventStealing: true;
+ onClicked: openContextMenu(mouse.x, mouse.y);
+ //onPressAndHold: openContextMenu(mouse.x, mouse.y);
+ function openContextMenu(x, y) {
+ tagActionsContextMenu.resourceName = fontDelegateItem.fontName;
+ tagActionsContextMenu.resourceIndex = model.index;
+ tagActionsContextMenu.x = x;
+ tagActionsContextMenu.y = y;
+ tagActionsContextMenu.visible = true;
+ }
+ }
+ }
+ }
delegate: fontDelegate;
+
+ //--- Pop up setup ---//
popup: Popup {
y: familyCmb.height - 1;
x: familyCmb.width - width;
@@ -125,7 +148,7 @@ ComboBox {
id: fontResourceView;
fontModel: familyCmb.delegateModel;
tagModel: fontTagModel;
- currentIndex: familyCmb.highlightedIndex;
+ currentIndex: familyCmb.currentIndex;
clip:true;
property var fontModel;
property var tagModel;
@@ -175,8 +198,87 @@ ComboBox {
checked: modelWrapper.searchInTag;
}
}
+
+ //--- Tag Setup ---//
+ Menu {
+ id: tagActionsContextMenu;
+ property int resourceIndex: -1;
+ property string resourceName: "";
+ Label {
+ id: resourceLabel;
+ text: tagActionsContextMenu.resourceName;
+ }
+
+ Menu {
+ id: assignToTag;
+ title: i18nc("@title:menu", "Assign to Tag");
+ // submenus can't have icons in qml...
+ //icon: "qrc:///light_list-add.svg";
+ height: contentChildren.height;
+ ListView {
+ id: tagAddView;
+ model: fontTagModel;
+ height: contentHeight;
+ width: parent.width;
+ delegate: ItemDelegate {
+ width: tagAddView.width;
+ text: model.display;
+ onClicked: {
+ modelWrapper.tagResource(model.index, tagActionsContextMenu.resourceIndex);
+ tagActionsContextMenu.close();
+ }
+ }
+ }
+ MenuSeparator {}
+ RowLayout {
+ TextField {
+ id: newTagName;
+ placeholderText: i18nc("@info:placeholder", "New Tag Name...");
+ Layout.fillWidth: true;
+ }
+ ToolButton {
+ icon.source: "qrc:///light_list-add.svg";
+ icon.color: palette.text;
+ onClicked: {
+ modelWrapper.addNewTag(newTagName.text, tagActionsContextMenu.resourceIndex);
+ tagActionsContextMenu.visible = false;
+ }
+ }
+ }
+
+ }
+ MenuSeparator {}
+ Action {
+ enabled: tagFilter.currentIndex != 0;
+ id: removeFromThisTag;
+ text: i18nc("@action:inmenu", "Remove from this tag");
+ icon.source: "qrc:///16_light_list-remove.svg";
+ }
+
+ Menu {
+ id: removeFromTag;
+ title: i18nc("@title:menu", "Remove from other tag");
+ ListView {
+ id: tagRemoveView;
+ model: fontTagModel;
+ height: contentHeight;
+ width: parent.width;
+ delegate: ItemDelegate {
+ width: tagRemoveView.width;
+ text: model.display;
+ onClicked: {
+ modelWrapper.untagResource(model.index, tagActionsContextMenu.resourceIndex);
+ tagActionsContextMenu.visible = false;
+ }
+ }
+ }
+ }
+ }
}
palette: familyCmb.palette;
+
+
}
- wheelEnabled: true;
+
+
}