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

Improve glyph palette functionality by moving the delegate to its own file.

Wolthera van Hövell tot Westerflier8b6152fe41cc
diff --git a/plugins/tools/svgtexttool/SvgTextTool.cpp b/plugins/tools/svgtexttool/SvgTextTool.cpp
index 81306c52c7..2febd740e3 100644
--- a/plugins/tools/svgtexttool/SvgTextTool.cpp
+++ b/plugins/tools/svgtexttool/SvgTextTool.cpp
@@ -344,7 +344,7 @@ void SvgTextTool::showGlyphPalette()
m_glyphPalette->setAttribute( Qt::WA_QuitOnClose, false );
connect(&m_textCursor, SIGNAL(selectionChanged()), this, SLOT(updateGlyphPalette()));
- connect(m_glyphPalette, SIGNAL(signalInsertRichText(KoSvgTextShape*)), this, SLOT(insertRichText(KoSvgTextShape*)));
+ connect(m_glyphPalette, SIGNAL(signalInsertRichText(KoSvgTextShape*, bool)), this, SLOT(insertRichText(KoSvgTextShape*, bool)));
m_glyphPalette->activateWindow();
}
@@ -369,8 +369,12 @@ void SvgTextTool::updateGlyphPalette()
}
}
-void SvgTextTool::insertRichText(KoSvgTextShape *richText)
+void SvgTextTool::insertRichText(KoSvgTextShape *richText, bool replaceLastGlyph)
{
+ if (replaceLastGlyph) {
+ m_textCursor.setPos(m_textCursor.getPos(), m_textCursor.getPos());
+ m_textCursor.moveCursor(m_textCursor.getPos() == 0? SvgTextCursor::MoveNextChar : SvgTextCursor::MovePreviousChar, false);
+ }
m_textCursor.insertRichText(richText);
}
diff --git a/plugins/tools/svgtexttool/SvgTextTool.h b/plugins/tools/svgtexttool/SvgTextTool.h
index e5cbcbb5d6..697ebb4b78 100644
--- a/plugins/tools/svgtexttool/SvgTextTool.h
+++ b/plugins/tools/svgtexttool/SvgTextTool.h
@@ -114,7 +114,7 @@ private Q_SLOTS:
void showGlyphPalette();
void updateGlyphPalette();
- void insertRichText(KoSvgTextShape *richText);
+ void insertRichText(KoSvgTextShape *richText, bool replaceLastGlyph = false);
/**
* @brief generateDefs
diff --git a/plugins/tools/svgtexttool/glyphpalette/GlyphDelegate.qml b/plugins/tools/svgtexttool/glyphpalette/GlyphDelegate.qml
new file mode 100644
index 0000000000..111e22ab76
--- /dev/null
+++ b/plugins/tools/svgtexttool/glyphpalette/GlyphDelegate.qml
@@ -0,0 +1,74 @@
+/*
+ * SPDX-FileCopyrightText: 2024 Wolthera van Hövell tot Westerflier <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+import QtQuick 2.15
+import QtQuick.Controls 2.5
+import org.krita.sketch 1.0
+
+SvgTextLabel {
+ id: glyphLabel;
+ openTypeFeatures: model.openType;
+ text: model.display;
+ padding: height/8;
+ clip: true;
+
+ width: GridView.view.cellWidth;
+ height: GridView.view.cellHeight;
+
+ property bool currentItem: GridView.isCurrentItem;
+
+ signal glyphClicked(int index);
+ signal glyphDoubleClicked(int index);
+
+ Rectangle {
+ anchors.fill: parent;
+ color: "transparent";
+ border.color: parent.currentItem? palette.highlight: palette.alternateBase;
+ border.width: parent.currentItem? 2: 1;
+ }
+ Rectangle {
+ anchors.top: parent.top;
+ anchors.left: parent.left;
+ color: palette.text;
+ opacity: 0.3;
+ layer.enabled: true
+ width: childrenRect.width;
+ height: childrenRect.height;
+ Text {
+ padding: 2;
+ text: model.glyphLabel;
+ color: palette.base;
+ font.pointSize: 9;
+ }
+ visible: glyphMouseArea.containsMouse;
+ }
+ Rectangle {
+ anchors.top: parent.top;
+ anchors.right: parent.right;
+ width: 8;
+ height: 8;
+ radius: 4;
+ color: palette.text;
+ opacity: 0.3;
+ visible: model.childCount > 1;
+ }
+
+ MouseArea {
+ anchors.fill: parent;
+ id: glyphMouseArea
+ onClicked: {
+ parent.GridView.view.currentIndex = index;
+ glyphClicked(index);
+ }
+ onDoubleClicked: {
+ parent.GridView.view.currentIndex = index;
+ glyphDoubleClicked(index);
+ }
+ hoverEnabled: true;
+ ToolTip.text: model.toolTip;
+ ToolTip.visible: containsMouse;
+ ToolTip.delay: 1000;
+ }
+}
diff --git a/plugins/tools/svgtexttool/glyphpalette/GlyphPalette.qml b/plugins/tools/svgtexttool/glyphpalette/GlyphPalette.qml
index ba13281dd0..3b4b42901c 100644
--- a/plugins/tools/svgtexttool/glyphpalette/GlyphPalette.qml
+++ b/plugins/tools/svgtexttool/glyphpalette/GlyphPalette.qml
@@ -12,7 +12,6 @@ import org.krita.tools.text 1.0
Rectangle {
id: root;
anchors.fill: parent;
- property string titleText;
property QtObject model;
property QtObject charMapModel;
property QtObject charMapFilterModel;
@@ -28,22 +27,13 @@ Rectangle {
}
color: palette.window
- Text {
- id: title;
- text: titleText;
- color: palette.text;
-
- anchors.left: parent.left;
- anchors.right: parent.right;
- anchors.top: parent.top;
- }
-
TabBar {
id: tabs;
+ anchors.top: parent.top;
anchors.left: parent.left;
anchors.right: parent.right;
- anchors.top: title.bottom;
+ /// How are we going to translate this?
TabButton {
text: "Glyph Alternates"
}
@@ -52,75 +42,6 @@ Rectangle {
}
}
- Component {
- id: glyphDelegate;
-
- SvgTextLabel {
- id: glyphLabel;
- textColor: palette.text;
- fillColor: palette.base;
- fontFamilies: root.fontFamilies;
- fontSize: root.fontSize;
- fontStyle: root.fontStyle;
- fontWeight: root.fontWeight;
- openTypeFeatures: model.openType;
- text: model.display;
- padding: height/8;
- clip: true;
-
- width: GridView.view.cellWidth;
- height: GridView.view.cellHeight;
-
- property bool currentItem: GridView.isCurrentItem;
-
- Rectangle {
- anchors.fill: parent;
- color: "transparent";
- border.color: parent.currentItem? palette.highlight: palette.alternateBase;
- border.width: parent.currentItem? 2: 1;
- }
- Rectangle {
- anchors.top: parent.top;
- anchors.left: parent.left;
- color: palette.text;
- opacity: 0.3;
- layer.enabled: true
- width: childrenRect.width;
- height: childrenRect.height;
- Text {
- padding: 2;
- text: model.glyphLabel;
- color: palette.base;
- font.pointSize: 9;
- }
- visible: glyphMouseArea.containsMouse;
- }
- Rectangle {
- anchors.top: parent.top;
- anchors.right: parent.right;
- width: 8;
- height: 8;
- radius: 4;
- color: palette.text;
- opacity: 0.3;
- visible: model.childCount > 1;
- }
-
- MouseArea {
- anchors.fill: parent;
- id: glyphMouseArea
- onClicked: {
- parent.GridView.view.currentIndex = index;
- }
- onDoubleClicked: {model.childCount === 0? mainWindow.slotInsertRichText(root.currentIndex, index): mainWindow.slotInsertRichText(index)}
- hoverEnabled: true;
- ToolTip.text: model.toolTip;
- ToolTip.visible: containsMouse;
- ToolTip.delay: 1000;
- }
- }
- }
-
StackLayout {
id: stack;
@@ -142,7 +63,15 @@ Rectangle {
rootIndex = modelIndex(root.currentIndex);
}
- delegate: glyphDelegate;
+ delegate: GlyphDelegate {
+ textColor: palette.text;
+ fillColor: palette.base;
+ fontFamilies: root.fontFamilies;
+ fontSize: root.fontSize;
+ fontStyle: root.fontStyle;
+ fontWeight: root.fontWeight;
+ onGlyphDoubleClicked: (index)=> {mainWindow.slotInsertRichText(root.currentIndex, index, true)};
+ }
}
focus: true;
@@ -169,7 +98,6 @@ Rectangle {
onCurrentIndexChanged: {
mainWindow.slotChangeFilter(currentIndex);
- console.log(currentIndex)
}
clip: true;
@@ -197,12 +125,74 @@ Rectangle {
cellWidth: (width - charMapScroll.implicitBackgroundWidth)/8;
cellHeight: cellWidth;
- delegate: glyphDelegate;
+ delegate: GlyphDelegate {
+ textColor: palette.text;
+ fillColor: palette.base;
+ fontFamilies: root.fontFamilies;
+ fontSize: root.fontSize;
+ fontStyle: root.fontStyle;
+ fontWeight: root.fontWeight;
+ onGlyphDoubleClicked: (index)=> {mainWindow.slotInsertRichText(index)};
+ onGlyphClicked: (index)=> {
+ if (model.childCount > 1){
+ charMapAltGlyphs.open()
+ }
+ }
+ }
ScrollBar.vertical: ScrollBar {
id: charMapScroll;
}
+ Popup {
+ id: charMapAltGlyphs
+ x: 0
+ y: 0
+ width: charMap.width
+ height: charMap.cellHeight*3;
+ modal: true
+ focus: true
+ closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
+ GridView {
+ anchors.fill: parent;
+
+ cellWidth: (width - charMapAltGlyphsScroll.implicitBackgroundWidth)/8;
+ cellHeight: cellWidth;
+
+ ScrollBar.vertical: ScrollBar {
+ id: charMapAltGlyphsScroll;
+ }
+
+ model: DelegateModel {
+ model: charMap.model
+ property alias rIndex: charMap.currentIndex;
+ property var defaultIndex: modelIndex(-1);
+ onRIndexChanged: {
+ rootIndex = defaultIndex;
+ rootIndex = modelIndex(rIndex);
+ }
+
+ delegate: GlyphDelegate {
+ textColor: palette.text;
+ fillColor: palette.base;
+ fontFamilies: root.fontFamilies;
+ fontSize: root.fontSize;
+ fontStyle: root.fontStyle;
+ fontWeight: root.fontWeight;
+ onGlyphDoubleClicked: (index)=> {
+ mainWindow.slotInsertRichText(charMap.currentIndex, index);
+ charMapAltGlyphs.close()
+ };
+ onGlyphClicked: (index)=> {
+ mainWindow.slotInsertRichText(charMap.currentIndex, index);
+ charMapAltGlyphs.close()
+ };
+ }
+
+ }
+ }
+ }
+
}
}
}
diff --git a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.cpp b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.cpp
index 9d5531b20d..fab058dd38 100644
--- a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.cpp
+++ b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.cpp
@@ -10,6 +10,8 @@
#include <QQuickItem>
#include <QHBoxLayout>
+#include <KLocalizedString>
+
#include <KoResourcePaths.h>
#include <KoFontGlyphModel.h>
#include <KoFontRegistry.h>
@@ -43,6 +45,8 @@ GlyphPaletteDialog::GlyphPaletteDialog(QWidget *parent)
m_quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);
m_quickWidget->setSource(QUrl("qrc:/GlyphPalette.qml"));
+ this->setWindowTitle(i18nc("@windowTitle", "Glyph Palette"));
+
m_charMapModel->setSourceModel(m_model);
for (int i = 0; i< m_charMapModel->filterLabels().size(); i++) {
int key = m_charMapModel->filterLabels().keys().at(i);
@@ -53,7 +57,6 @@ GlyphPaletteDialog::GlyphPaletteDialog(QWidget *parent)
}
if (m_quickWidget->rootObject()) {
- m_quickWidget->rootObject()->setProperty("titleText", "Glyph palette");
m_quickWidget->rootObject()->setProperty("model", QVariant::fromValue(m_model));
m_quickWidget->rootObject()->setProperty("charMapModel", QVariant::fromValue(m_charMapModel));
m_quickWidget->rootObject()->setProperty("charMapFilterModel", QVariant::fromValue(m_filters));
@@ -103,7 +106,6 @@ void GlyphPaletteDialog::setGlyphModelFromProperties(KoSvgTextProperties propert
QModelIndex idx = m_model->indexForString(text);
if (m_quickWidget->rootObject()) {
QString name = faces.front().data()->family_name;
- m_quickWidget->rootObject()->setProperty("titleText", QString("Glyph palette: "+name));
m_quickWidget->rootObject()->setProperty("fontFamilies", QVariant::fromValue(families));
m_quickWidget->rootObject()->setProperty("fontSize", QVariant::fromValue(size));
m_quickWidget->rootObject()->setProperty("fontWeight", QVariant::fromValue(weight));
@@ -115,7 +117,7 @@ void GlyphPaletteDialog::setGlyphModelFromProperties(KoSvgTextProperties propert
m_lastUsedProperties = properties;
}
-void GlyphPaletteDialog::slotInsertRichText(int charRow, int glyphRow)
+void GlyphPaletteDialog::slotInsertRichText(int charRow, int glyphRow, bool replace)
{
if (m_quickWidget->rootObject()) {
QModelIndex idx = glyphRow > -1? m_model->index(charRow, 0): m_charMapModel->index(charRow, 0);
@@ -134,7 +136,7 @@ void GlyphPaletteDialog::slotInsertRichText(int charRow, int glyphRow)
richText->setPropertiesAtPos(-1, props);
richText->insertText(0, text);
- emit signalInsertRichText(richText);
+ emit signalInsertRichText(richText, replace);
}
}
diff --git a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.h b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.h
index 810967c623..d7a7faff1a 100644
--- a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.h
+++ b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.h
@@ -25,10 +25,10 @@ public:
void setGlyphModelFromProperties(KoSvgTextProperties properties, QString text = QString());
Q_SIGNALS:
- void signalInsertRichText(KoSvgTextShape *text);
+ void signalInsertRichText(KoSvgTextShape *text, bool replace);
public Q_SLOTS:
- void slotInsertRichText(int charRow, int glyphRow = -1);
+ void slotInsertRichText(int charRow, int glyphRow = -1, bool replace = false);
void slotChangeFilter(int filterRow);
private:
diff --git a/plugins/tools/svgtexttool/svgtexttool.qrc b/plugins/tools/svgtexttool/svgtexttool.qrc
index 1ba8d1419f..a843191e39 100644
--- a/plugins/tools/svgtexttool/svgtexttool.qrc
+++ b/plugins/tools/svgtexttool/svgtexttool.qrc
@@ -12,5 +12,6 @@
<file>tool_text_i_beam_vertical.xpm</file>
<file>tool_text_i_beam_horizontal_done.xpm</file>
<file alias="GlyphPalette.qml">glyphpalette/GlyphPalette.qml</file>
+ <file alias="GlyphDelegate.qml">glyphpalette/GlyphDelegate.qml</file>
</qresource>
</RCC>