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

Make font tagging more usable.

Wolthera van Hövell tot Westerflierfd47fd8e8c91
diff --git a/libs/flake/resources/KoFontFamily.cpp b/libs/flake/resources/KoFontFamily.cpp
index 4486d62a57..d8a40f2538 100644
--- a/libs/flake/resources/KoFontFamily.cpp
+++ b/libs/flake/resources/KoFontFamily.cpp
@@ -187,26 +187,13 @@ QString KoFontFamily::typographicFamily() const
return metadata().value(TYPOGRAPHIC_NAME).toString();
}
-QString KoFontFamily::translatedFontName(QList<QLocale> locales) const
+QString KoFontFamily::translatedFontName(QStringList locales) const
{
- QHash<QString, QVariant> names = metadata().value(LOCALIZED_FONT_FAMILY).toHash();
+ QMap<QString, QVariant> names = metadata().value(LOCALIZED_FONT_FAMILY).toMap();
QString name = filename();
- Q_FOREACH(const QLocale locale, locales) {
- if (names.keys().contains(locale.bcp47Name())) {
- name = names.value(locale.bcp47Name()).toString();
- break;
- }
- }
- return name;
-}
-
-QString KoFontFamily::translatedTypographicName(QList<QLocale> locales) const
-{
- QHash<QString, QVariant> names = metadata().value(LOCALIZED_TYPOGRAPHIC_NAME).toHash();
- QString name = QString();
- Q_FOREACH(const QLocale locale, locales) {
- if (names.keys().contains(locale.bcp47Name())) {
- name = names.value(locale.bcp47Name()).toString();
+ Q_FOREACH(const QString locale, locales) {
+ if (names.keys().contains(locale)) {
+ name = names.value(locale).toString();
break;
}
}
diff --git a/libs/flake/resources/KoFontFamily.h b/libs/flake/resources/KoFontFamily.h
index 64454ed532..36eba24f70 100644
--- a/libs/flake/resources/KoFontFamily.h
+++ b/libs/flake/resources/KoFontFamily.h
@@ -38,8 +38,8 @@ public:
/// Returns the typographic family name, if any.
QString typographicFamily() const;
- QString translatedFontName(QList<QLocale> locales) const;
- QString translatedTypographicName(QList<QLocale> locales) const;
+ /// Return the translated name for a given locale...
+ QString translatedFontName(QStringList locales) const;
/// Font is variable
bool isVariable() const;
diff --git a/plugins/dockers/textproperties/TextPropertiesDock.cpp b/plugins/dockers/textproperties/TextPropertiesDock.cpp
index 127a368f2c..2362107b05 100644
--- a/plugins/dockers/textproperties/TextPropertiesDock.cpp
+++ b/plugins/dockers/textproperties/TextPropertiesDock.cpp
@@ -68,7 +68,7 @@ public:
connect(&m_compressor, SIGNAL(timeout()), this, SLOT(setSearchTextOnModel()));
}
- void tagActivated(int row) {
+ void tagActivated(const int &row) {
if (row == currentTag()) {
return;
}
@@ -111,7 +111,7 @@ public:
return m_tagModel->indexForTag(m_tagFilterProxyModel->currentTagFilter()).row();
}
- void setSearchInTag(bool newSearchInTag) {
+ void setSearchInTag(const bool &newSearchInTag) {
if (m_tagFilterProxyModel->filterInCurrentTag() != newSearchInTag) {
m_tagFilterProxyModel->setFilterInCurrentTag(newSearchInTag);
emit searchInTagChanged();
@@ -123,7 +123,7 @@ public:
return m_tagFilterProxyModel->filterInCurrentTag();
}
- Q_INVOKABLE void addNewTag(QString newTagName, int resourceIndex = -1) {
+ Q_INVOKABLE void addNewTag(const QString &newTagName, const int &resourceIndex = -1) {
KisTagSP tagsp = m_tagModel->tagForUrl(newTagName);
QModelIndex resourceIdx = m_tagFilterProxyModel->index(resourceIndex, 0);
if (tagsp.isNull()) {
@@ -133,13 +133,13 @@ public:
}
// 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();
+ int resourceId = m_tagFilterProxyModel->data(resourceIdx, Qt::UserRole + KisResourceModel::Id).toInt();
m_tagFilterProxyModel->tagResources(tagsp, {resourceId});
}
}
- Q_INVOKABLE void tagResource(int tagIndex, int resourceIndex) {
+ Q_INVOKABLE void tagResource(const int &tagIndex, const int &resourceIndex) {
QModelIndex idx = m_tagModel->index(tagIndex, 0);
QModelIndex resourceIdx = m_tagFilterProxyModel->index(resourceIndex, 0);
KisTagSP tagsp;
@@ -147,12 +147,12 @@ public:
tagsp = m_tagModel->tagForIndex(idx);
}
if (tagsp && resourceIdx.isValid()) {
- int resourceId = m_tagFilterProxyModel->data(resourceIdx, KisResourceModel::Id).toInt();
+ int resourceId = m_tagFilterProxyModel->data(resourceIdx, Qt::UserRole + KisResourceModel::Id).toInt();
m_tagFilterProxyModel->tagResources(tagsp, {resourceId});
}
}
- Q_INVOKABLE void untagResource(int tagIndex, int resourceIndex) {
+ Q_INVOKABLE void untagResource(const int &tagIndex, const int &resourceIndex) {
QModelIndex idx = m_tagModel->index(tagIndex, 0);
QModelIndex resourceIdx = m_tagFilterProxyModel->index(resourceIndex, 0);
KisTagSP tagsp;
@@ -160,11 +160,65 @@ public:
tagsp = m_tagModel->tagForIndex(idx);
}
if (tagsp && resourceIdx.isValid()) {
- int resourceId = m_tagFilterProxyModel->data(resourceIdx, KisResourceModel::Id).toInt();
+ int resourceId = m_tagFilterProxyModel->data(resourceIdx, Qt::UserRole + KisResourceModel::Id).toInt();
m_tagFilterProxyModel->untagResources(tagsp, {resourceId});
}
}
+ Q_INVOKABLE QString localizedNameForIndex(const int &resourceIndex, const QStringList &locales, const QString &fallBack = "") {
+ QModelIndex resourceIdx = m_tagFilterProxyModel->index(resourceIndex, 0);
+ QString name = fallBack;
+ if (resourceIdx.isValid()) {
+ name = m_tagFilterProxyModel->data(resourceIdx, Qt::UserRole + KisResourceModel::Name).toString();
+ QMap<QString, QVariant> metadata = m_tagFilterProxyModel->data(resourceIdx, Qt::UserRole + KisResourceModel::MetaData).toMap();
+ QVariantMap localizedNames = metadata.value("localized_font_family").toMap();
+ Q_FOREACH(const QString locale, locales) {
+ if (localizedNames.keys().contains(locale)) {
+ name = localizedNames.value(locale).toString();
+ break;
+ }
+ }
+ }
+ return name;
+ }
+
+ Q_INVOKABLE QVariantList taggedResourceModel (const int &resourceIndex) const {
+ QVariantList taggedResourceModel;
+ QModelIndex resourceIdx = m_tagFilterProxyModel->index(resourceIndex, 0);
+ KisTagSP tagsp;
+ for (int i = 0; i< m_tagModel->rowCount(); i++) {
+ QModelIndex idx = m_tagModel->index(i, 0);
+ tagsp = m_tagModel->tagForIndex(idx);
+ bool visible = tagsp->id() >= 0;
+ bool enabled = false;
+ if (resourceIdx.isValid()) {
+ int resourceId = m_tagFilterProxyModel->data(resourceIdx, Qt::UserRole + KisResourceModel::Id).toInt();
+ enabled = m_tagFilterProxyModel->isResourceTagged(tagsp, resourceId) > 0 && visible;
+ }
+ QVariantMap tag {{"name", tagsp->name()}, {"value", i}, {"visible", visible}, {"enabled", enabled} };
+ taggedResourceModel.append(tag);
+ }
+ return taggedResourceModel;
+ }
+
+ Q_INVOKABLE bool showResourceTagged(const int &tagIndex, const int &resourceIndex) const {
+ 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) {
+ if (tagsp->id() < 0) return false;
+ return true;
+ if (resourceIdx.isValid()) {
+ int resourceId = m_tagFilterProxyModel->data(resourceIdx, Qt::UserRole + KisResourceModel::Id).toInt();
+ return m_tagFilterProxyModel->isResourceTagged(tagsp, resourceId);
+ }
+ }
+ return false;
+ }
+
Q_SIGNALS:
void sourceModelChanged();
void modelChanged();
diff --git a/plugins/dockers/textproperties/qml/FontResourceDropdown.qml b/plugins/dockers/textproperties/qml/FontResourceDropdown.qml
index b053027def..75a53c0797 100644
--- a/plugins/dockers/textproperties/qml/FontResourceDropdown.qml
+++ b/plugins/dockers/textproperties/qml/FontResourceDropdown.qml
@@ -26,21 +26,10 @@ ComboBox {
ItemDelegate {
id: fontDelegateItem;
required property var model;
- property string fontName: model.name;
+ property string fontName: modelWrapper.localizedNameForIndex(model.index, locales, model.name);
width: fontResourceView.listWidth;
highlighted: familyCmb.highlightedIndex === model.index;
- 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;
@@ -115,28 +104,13 @@ ComboBox {
background: Rectangle {
color: highlighted? familyCmb.palette.highlight:"transparent";
}
-
- 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 {
+ id: familyCmbPopup;
y: familyCmb.height - 1;
x: familyCmb.width - width;
width: contentWidth;
@@ -167,6 +141,117 @@ ComboBox {
onActivated: modelWrapper.currentTag = currentIndex;
}
+ Button {
+ id: tagMenuButton;
+ icon.source: "qrc:///light_bookmarks.svg";
+ text: i18nc("@label:button", "Tag");
+ onClicked: hideShowMenu();
+ function hideShowMenu() {
+ if (!tagActionsContextMenu.visible) {
+ tagActionsContextMenu.resourceIndex = familyCmb.highlightedIndex;
+ tagActionsContextMenu.popup(tagMenuButton,
+ tagActionsContextMenu.width - tagMenuButton.width,
+ tagMenuButton.height - 1);
+ } else {
+ tagActionsContextMenu.dismiss();
+ }
+ }
+
+ //--- Tag Setup ---//
+ Menu {
+ id: tagActionsContextMenu;
+ property int resourceIndex: -1;
+ property alias resourceName: resourceLabel.text;
+ property var resourceTaggedModel : [];
+ enabled: resourceIndex >= 0;
+ onResourceIndexChanged: {
+ resourceName = modelWrapper.localizedNameForIndex(resourceIndex, locales);
+ updateResourceTaggedModel();
+ }
+ function updateResourceTaggedModel() {
+ resourceTaggedModel = modelWrapper.taggedResourceModel(tagActionsContextMenu.resourceIndex);
+ }
+
+ modal: true;
+ closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
+ Label {
+ id: resourceLabel;
+ }
+
+ Menu {
+ id: assignToTag;
+ title: i18nc("@title:menu", "Assign to Tag");
+ height: contentChildren.height;
+ ListView {
+ id: tagAddView;
+ model: tagActionsContextMenu.resourceTaggedModel;
+ height: contentHeight;
+ width: parent.width;
+ delegate: ItemDelegate {
+ width: tagAddView.width;
+ text: modelData.name;
+ visible: modelData.visible && !modelData.enabled;
+ height: visible? implicitContentHeight: 0;
+ onClicked: {
+ modelWrapper.tagResource(modelData.value, tagActionsContextMenu.resourceIndex);
+ tagActionsContextMenu.updateResourceTaggedModel();
+ 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);
+ newTagName.text = "";
+ tagActionsContextMenu.updateResourceTaggedModel();
+ tagActionsContextMenu.dismiss();
+ }
+ }
+ }
+
+ }
+ MenuSeparator {}
+ Action {
+ enabled: modelWrapper.showResourceTagged(modelWrapper.currentTag, tagActionsContextMenu.resourceIndex);
+ id: removeFromThisTag;
+ text: i18nc("@action:inmenu", "Remove from this tag");
+ icon.source: "qrc:///16_light_list-remove.svg";
+ onTriggered: modelWrapper.untagResource(modelWrapper.currentTag, tagActionsContextMenu.resourceIndex);
+ }
+
+ Menu {
+ id: removeFromTag;
+ title: i18nc("@title:menu", "Remove from other tag");
+ ListView {
+ id: tagRemoveView;
+ model: tagActionsContextMenu.resourceTaggedModel;
+ height: contentHeight;
+ width: parent.width;
+ delegate: ItemDelegate {
+ width: tagRemoveView.width;
+ text: modelData.name;
+ visible: modelData.visible && modelData.enabled;
+ height: visible? implicitContentHeight: 0;
+ onClicked: {
+ modelWrapper.untagResource(modelData.value, tagActionsContextMenu.resourceIndex);
+ tagActionsContextMenu.updateResourceTaggedModel();
+ tagActionsContextMenu.dismiss()
+ }
+ }
+ }
+ }
+ }
+ }
+
}
Frame {
Layout.minimumHeight: font.pixelSize*3;
@@ -199,81 +284,7 @@ ComboBox {
}
}
- //--- 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;