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 the glyph palette actually insert glyphs.

Wolthera van Hövell tot Westerflier84c0607a936b
diff --git a/plugins/tools/svgtexttool/SvgTextTool.cpp b/plugins/tools/svgtexttool/SvgTextTool.cpp
index 5cd394dca2..81306c52c7 100644
--- a/plugins/tools/svgtexttool/SvgTextTool.cpp
+++ b/plugins/tools/svgtexttool/SvgTextTool.cpp
@@ -344,6 +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*)));
m_glyphPalette->activateWindow();
}
@@ -368,6 +369,11 @@ void SvgTextTool::updateGlyphPalette()
}
}
+void SvgTextTool::insertRichText(KoSvgTextShape *richText)
+{
+ m_textCursor.insertRichText(richText);
+}
+
void SvgTextTool::slotTextEditorClosed()
{
// change tools to the shape selection tool when we close the text editor to allow moving and further editing of the object.
diff --git a/plugins/tools/svgtexttool/SvgTextTool.h b/plugins/tools/svgtexttool/SvgTextTool.h
index 05a59b0dc9..e5cbcbb5d6 100644
--- a/plugins/tools/svgtexttool/SvgTextTool.h
+++ b/plugins/tools/svgtexttool/SvgTextTool.h
@@ -114,6 +114,7 @@ private Q_SLOTS:
void showGlyphPalette();
void updateGlyphPalette();
+ void insertRichText(KoSvgTextShape *richText);
/**
* @brief generateDefs
diff --git a/plugins/tools/svgtexttool/glyphpalette/GlyphPalette.qml b/plugins/tools/svgtexttool/glyphpalette/GlyphPalette.qml
index d41c045ad5..c807a71e34 100644
--- a/plugins/tools/svgtexttool/glyphpalette/GlyphPalette.qml
+++ b/plugins/tools/svgtexttool/glyphpalette/GlyphPalette.qml
@@ -51,7 +51,9 @@ Rectangle {
Component {
id: glyphDelegate;
+
SvgTextLabel {
+ id: glyphLabel;
textColor: palette.text;
fillColor: palette.base;
fontFamilies: root.fontFamilies;
@@ -67,6 +69,7 @@ Rectangle {
height: charMap.cellHeight;
property bool currentItem: GridView.isCurrentItem;
+
Rectangle {
anchors.fill: parent;
color: "transparent";
@@ -107,6 +110,7 @@ Rectangle {
parent.GridView.view.currentIndex = index;
console.log(model.toolTip)
}
+ onDoubleClicked: {model.childCount === 0? mainWindow.slotInsertRichText(root.currentIndex, index): mainWindow.slotInsertRichText(index)}
hoverEnabled: true;
ToolTip.text: model.toolTip;
ToolTip.visible: containsMouse;
@@ -137,6 +141,7 @@ Rectangle {
}
delegate: glyphDelegate;
+
}
focus: true;
clip: true;
diff --git a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.cpp b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.cpp
index 96c627d742..684d988d31 100644
--- a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.cpp
+++ b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.cpp
@@ -50,7 +50,10 @@ GlyphPaletteDialog::GlyphPaletteDialog(QWidget *parent)
void GlyphPaletteDialog::setGlyphModelFromProperties(KoSvgTextProperties properties, QString text)
{
- if (m_lastUsedProperties == properties) {
+ if (m_lastUsedProperties.property(KoSvgTextProperties::FontFamiliesId) == properties.property(KoSvgTextProperties::FontFamiliesId)
+ && m_lastUsedProperties.property(KoSvgTextProperties::FontWeightId) == properties.property(KoSvgTextProperties::FontWeightId)
+ && m_lastUsedProperties.property(KoSvgTextProperties::FontStyleId) == properties.property(KoSvgTextProperties::FontStyleId)
+ && m_lastUsedProperties.property(KoSvgTextProperties::FontStretchId) == properties.property(KoSvgTextProperties::FontStretchId)) {
if (m_model && m_model->rowCount() > 0) {
QModelIndex idx = m_model->indexForString(text);
if (idx.isValid() && m_quickWidget->rootObject()) {
@@ -96,3 +99,23 @@ void GlyphPaletteDialog::setGlyphModelFromProperties(KoSvgTextProperties propert
}
m_lastUsedProperties = properties;
}
+
+void GlyphPaletteDialog::slotInsertRichText(int charRow, int glyphRow)
+{
+ if (m_quickWidget->rootObject()) {
+ QModelIndex idx = m_model->index(charRow, 0);
+ if (glyphRow > -1) {
+ idx = m_model->index(glyphRow, 0, idx);
+ }
+ KoSvgTextShape *richText = new KoSvgTextShape();
+ KoSvgTextProperties props = m_lastUsedProperties;
+ QStringList otf = props.property(KoSvgTextProperties::FontFeatureSettingsId).value<QStringList>();
+ otf.append(m_model->data(idx, KoFontGlyphModel::OpenTypeFeatures).value<QStringList>());
+ props.setProperty(KoSvgTextProperties::FontFeatureSettingsId, otf);
+
+ richText->setPropertiesAtPos(-1, props);
+ richText->insertText(0, m_model->data(idx, Qt::DisplayRole).toString());
+ emit signalInsertRichText(richText);
+ }
+
+}
diff --git a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.h b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.h
index 699a6cfadd..3558f348d8 100644
--- a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.h
+++ b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.h
@@ -10,6 +10,7 @@
#include <QtQuickWidgets/QQuickWidget>
#include <KoSvgTextProperties.h>
#include <KoFontGlyphModel.h>
+#include <KoSvgTextShape.h>
class GlyphPaletteDialog: public KoDialog
{
@@ -18,6 +19,12 @@ public:
GlyphPaletteDialog(QWidget *parent = nullptr);
void setGlyphModelFromProperties(KoSvgTextProperties properties, QString text = QString());
+
+Q_SIGNALS:
+ void signalInsertRichText(KoSvgTextShape *text);
+public Q_SLOTS:
+
+ void slotInsertRichText(int charRow, int glyphRow = -1);
private:
QQuickWidget *m_quickWidget {0};
KoSvgTextProperties m_lastUsedProperties;