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++
Cleanup SvgTextShortcuts code a little, ensure glyph palette is connected.
Wolthera van Hövell tot Westerflierf01c3189a348
diff --git a/plugins/tools/svgtexttool/SvgTextCursor.cpp b/plugins/tools/svgtexttool/SvgTextCursor.cppindex 5399fa437a..2533cc5e82 100644--- a/plugins/tools/svgtexttool/SvgTextCursor.cpp+++ b/plugins/tools/svgtexttool/SvgTextCursor.cpp@@ -1230,6 +1230,10 @@ bool SvgTextCursor::registerPropertyAction(QAction *action, const QString &name)d->actions.append(action);connect(action, SIGNAL(triggered(bool)), this, SLOT(propertyAction()));return true;+ } else if (name == "svg_insert_special_character") {+ d->actions.append(action);+ connect(action, SIGNAL(triggered(bool)), this, SIGNAL(sigOpenGlyphPalette()));+ return true;}return false;}diff --git a/plugins/tools/svgtexttool/SvgTextCursor.h b/plugins/tools/svgtexttool/SvgTextCursor.hindex 67261b8f01..57ae084143 100644--- a/plugins/tools/svgtexttool/SvgTextCursor.h+++ b/plugins/tools/svgtexttool/SvgTextCursor.h@@ -199,6 +199,8 @@ Q_SIGNALS:void updateCursorDecoration(QRectF updateRect);void selectionChanged();++ void sigOpenGlyphPalette();private Q_SLOTS:void blinkCursor();void stopBlinkCursor();diff --git a/plugins/tools/svgtexttool/SvgTextShortCuts.cpp b/plugins/tools/svgtexttool/SvgTextShortCuts.cppindex 95e8181ffa..24434b6b7b 100644--- a/plugins/tools/svgtexttool/SvgTextShortCuts.cpp+++ b/plugins/tools/svgtexttool/SvgTextShortCuts.cpp@@ -85,6 +85,27 @@ const QMap<QString, SvgTextShortcutInfo> textShortCuts = {QVariant(400), QVariant(700), QVariant(500))},+ {+ "svg_weight_normal",+ SvgTextShortcutInfo::propertySet(KoSvgTextProperties::FontWeightId,+ QVariant(400))+ },+ {+ "svg_weight_demi",+ SvgTextShortcutInfo::propertySet(KoSvgTextProperties::FontWeightId,+ QVariant(600))+ },+ {+ "svg_weight_black",+ SvgTextShortcutInfo::propertySet(KoSvgTextProperties::FontWeightId,+ QVariant(900))+ },+ {+ "svg_weight_light",+ SvgTextShortcutInfo::propertySet(KoSvgTextProperties::FontWeightId,+ QVariant(300))+ },+{"svg_format_italic",SvgTextShortcutInfo::propertyToggle(KoSvgTextProperties::FontStyleId,@@ -110,6 +131,11 @@ const QMap<QString, SvgTextShortcutInfo> textShortCuts = {SvgTextShortcutInfo::propertyToggle(KoSvgTextProperties::TextDecorationLineId,QVariant(true), QVariant(false), QVariant(KoSvgText::DecorationUnderline))},+ {+ "svg_format_strike_through",+ SvgTextShortcutInfo::propertyToggle(KoSvgTextProperties::TextDecorationLineId,+ QVariant(true), QVariant(false), QVariant(KoSvgText::DecorationLineThrough))+ },{"svg_font_kerning",SvgTextShortcutInfo::propertyToggle(KoSvgTextProperties::KerningId,@@ -223,6 +249,122 @@ bool SvgTextShortCuts::actionEnabled(QAction *action, const QList<KoSvgTextPropereturn false;}+/**+ * @brief toggleProperty+ * Handles toggling properties for getModifiedProperties+ * split out to make code easier to navigate.+ */+QVariant toggleProperty(SvgTextShortcutInfo info, QList<KoSvgTextProperties> currentProperties) {+ QVariant newVal;+ for(auto properties = currentProperties.begin(); properties != currentProperties.end(); properties++) {+ QVariant oldValue = properties->propertyOrDefault(info.propertyId);++ if (oldValue.canConvert<KoSvgText::TextDecorations>() && info.propertyId == KoSvgTextProperties::TextDecorationLineId) {+ KoSvgText::TextDecoration decor = KoSvgText::TextDecoration(info.testValue.toInt());+ KoSvgText::TextDecorations oldDecor = oldValue.value<KoSvgText::TextDecorations>();+ KoSvgText::TextDecorations newDecor;+ newDecor.setFlag(decor, !oldDecor.testFlag(decor));+ newVal = QVariant::fromValue(newDecor);+ if (oldDecor.testFlag(decor)) {+ break;+ }+ } else if (oldValue.canConvert<KoSvgText::CssFontStyleData>() && info.propertyId == KoSvgTextProperties::FontStyleId) {+ KoSvgText::CssFontStyleData testVal = info.testValue.value<KoSvgText::CssFontStyleData>();+ KoSvgText::CssFontStyleData currentVal = oldValue.value<KoSvgText::CssFontStyleData>();+ if (currentVal.style == testVal.style) {+ newVal = info.value2;+ break;+ } else {+ newVal = info.value1;+ }+ } else if (oldValue.canConvert<KoSvgText::AutoValue>() && info.propertyId == KoSvgTextProperties::KerningId) {+ bool testVal = info.testValue.toBool();+ KoSvgText::AutoValue currentVal = oldValue.value<KoSvgText::AutoValue>();+ if (currentVal.isAuto == testVal) {+ currentVal.customValue = 0.0;+ currentVal.isAuto = info.value2.toBool();+ newVal = QVariant::fromValue(currentVal);+ break;+ } else {+ currentVal.isAuto = info.value1.toBool();+ newVal = QVariant::fromValue(currentVal);+ }+ } else if (oldValue.canConvert<double>()) {+ if (oldValue.toDouble() > info.testValue.toDouble()) {+ newVal = info.value1;+ break;+ } else {+ newVal = info.value2;+ }+ } else if (oldValue.canConvert<int>()) {+ if (oldValue.toInt() > info.testValue.toInt()) {+ newVal = info.value1;+ break;+ } else {+ newVal = info.value2;+ }+ }+ }+ return newVal;+}++/**+ * @brief adjustValue+ * Handles increase/decrease value for getModifiedProperties,+ * split out to make code easier to navigate.+ *+ * TODO: handle max/min.+ */+QVariant adjustValue(SvgTextShortcutInfo info, QVariant oldValue) {+ QVariant newVal;++ if (oldValue.canConvert<KoSvgText::CssLengthPercentage>()) {+ KoSvgText::CssLengthPercentage length = oldValue.value<KoSvgText::CssLengthPercentage>();+ if (info.type == SvgTextShortcutInfo::Increase) {+ length.value += info.value1.toDouble();+ } else {+ length.value -= info.value1.toDouble();+ }+ newVal = QVariant::fromValue(length);+ } else if (oldValue.canConvert<KoSvgText::AutoLengthPercentage>()) {+ KoSvgText::AutoLengthPercentage length = oldValue.value<KoSvgText::AutoLengthPercentage>();+ length.isAuto = false;+ if (info.type == SvgTextShortcutInfo::Increase) {+ length.length.value += info.value1.toDouble();+ } else {+ length.length.value -= info.value1.toDouble();+ }+ newVal = QVariant::fromValue(length);+ } else if (oldValue.canConvert<KoSvgText::AutoValue>()) {+ KoSvgText::AutoValue value = oldValue.value<KoSvgText::AutoValue>();+ value.isAuto = false;+ if (info.type == SvgTextShortcutInfo::Increase) {+ value.customValue += info.value1.toDouble();+ } else {+ value.customValue -= info.value1.toDouble();+ }+ newVal = QVariant::fromValue(value);+ } else if (oldValue.canConvert<double>()) {+ double value = oldValue.toDouble();+ if (info.type == SvgTextShortcutInfo::Increase) {+ value += info.value1.toDouble();+ } else {+ value -= info.value1.toDouble();+ }+ newVal = QVariant::fromValue(value);+ } else if (oldValue.canConvert<int>()) {+ int value = oldValue.toInt();+ if (info.type == SvgTextShortcutInfo::Increase) {+ value += info.value1.toInt();+ } else {+ value -= info.value1.toInt();+ }+ newVal = QVariant::fromValue(value);+ }++ return newVal;+}+KoSvgTextProperties SvgTextShortCuts::getModifiedProperties(const QAction *action, QList<KoSvgTextProperties> currentProperties){if (!action || !action->data().canConvert<SvgTextShortcutInfo>() || currentProperties.isEmpty()) return KoSvgTextProperties();@@ -230,55 +372,7 @@ KoSvgTextProperties SvgTextShortCuts::getModifiedProperties(const QAction *actioQVariant newVal;if (info.type == SvgTextShortcutInfo::Toggle) {- for(auto properties = currentProperties.begin(); properties != currentProperties.end(); properties++) {- QVariant oldValue = properties->propertyOrDefault(info.propertyId);-- if (oldValue.canConvert<KoSvgText::TextDecorations>() && info.propertyId == KoSvgTextProperties::TextDecorationLineId) {- KoSvgText::TextDecoration decor = KoSvgText::TextDecoration(info.testValue.toInt());- KoSvgText::TextDecorations oldDecor = oldValue.value<KoSvgText::TextDecorations>();- KoSvgText::TextDecorations newDecor;- newDecor.setFlag(decor, !oldDecor.testFlag(decor));- newVal = QVariant::fromValue(newDecor);- if (oldDecor.testFlag(decor)) {- break;- }- } else if (oldValue.canConvert<KoSvgText::CssFontStyleData>() && info.propertyId == KoSvgTextProperties::FontStyleId) {- KoSvgText::CssFontStyleData testVal = info.testValue.value<KoSvgText::CssFontStyleData>();- KoSvgText::CssFontStyleData currentVal = oldValue.value<KoSvgText::CssFontStyleData>();- if (currentVal.style == testVal.style) {- newVal = info.value2;- break;- } else {- newVal = info.value1;- }- } else if (oldValue.canConvert<KoSvgText::AutoValue>() && info.propertyId == KoSvgTextProperties::KerningId) {- bool testVal = info.testValue.toBool();- KoSvgText::AutoValue currentVal = oldValue.value<KoSvgText::AutoValue>();- if (currentVal.isAuto == testVal) {- currentVal.customValue = 0.0;- currentVal.isAuto = info.value2.toBool();- newVal = QVariant::fromValue(currentVal);- break;- } else {- currentVal.isAuto = info.value1.toBool();- newVal = QVariant::fromValue(currentVal);- }- } else if (oldValue.canConvert<double>()) {- if (oldValue.toDouble() > info.testValue.toDouble()) {- newVal = info.value1;- break;- } else {- newVal = info.value2;- }- } else if (oldValue.canConvert<int>()) {- if (oldValue.toInt() > info.testValue.toInt()) {- newVal = info.value1;- break;- } else {- newVal = info.value2;- }- }- }+ newVal = toggleProperty(info, currentProperties);} else if (info.type == SvgTextShortcutInfo::Set) {KoSvgTextProperties properties = currentProperties.first();QVariant oldValue = properties.propertyOrDefault(info.propertyId);@@ -290,24 +384,7 @@ KoSvgTextProperties SvgTextShortCuts::getModifiedProperties(const QAction *actioKoSvgTextProperties properties = currentProperties.first();QVariant oldValue = properties.propertyOrDefault(info.propertyId);- if (oldValue.canConvert<KoSvgText::CssLengthPercentage>()) {- KoSvgText::CssLengthPercentage length = oldValue.value<KoSvgText::CssLengthPercentage>();- if (info.type == SvgTextShortcutInfo::Increase) {- length.value += info.value1.toDouble();- } else {- length.value -= info.value1.toDouble();- }- newVal = QVariant::fromValue(length);- } else if (oldValue.canConvert<KoSvgText::AutoLengthPercentage>()) {- KoSvgText::AutoLengthPercentage length = oldValue.value<KoSvgText::AutoLengthPercentage>();- length.isAuto = false;- if (info.type == SvgTextShortcutInfo::Increase) {- length.length.value += info.value1.toDouble();- } else {- length.length.value -= info.value1.toDouble();- }- newVal = QVariant::fromValue(length);- }+ newVal = adjustValue(info, oldValue);}KoSvgTextProperties newProperties;newProperties.setProperty(info.propertyId, newVal);diff --git a/plugins/tools/svgtexttool/SvgTextShortCuts.h b/plugins/tools/svgtexttool/SvgTextShortCuts.hindex 085f93b710..d482bb365c 100644--- a/plugins/tools/svgtexttool/SvgTextShortCuts.h+++ b/plugins/tools/svgtexttool/SvgTextShortCuts.h@@ -10,7 +10,17 @@class QString;class KoSvgTextProperties;-+/**+ * @brief The SvgTextShortCuts class+ *+ * Class to handle text property shortcuts generically.+ *+ * Many text property shorcuts are about toggling/enabling a single property.+ * Given there's a huge amount of them, it thus makes sense to generalize the+ * actions by adding a special QVariant to them and using that QVariant to+ * determine which property adjustment is at play.+ *+ */class SvgTextShortCuts{public:@@ -20,6 +30,7 @@ public:static bool actionEnabled(QAction *action, const QList<KoSvgTextProperties> currentProperties);static KoSvgTextProperties getModifiedProperties(const QAction *action, QList<KoSvgTextProperties> currentProperties);+private:};diff --git a/plugins/tools/svgtexttool/SvgTextTool.action b/plugins/tools/svgtexttool/SvgTextTool.actionindex ab273612aa..91a8773687 100644--- a/plugins/tools/svgtexttool/SvgTextTool.action+++ b/plugins/tools/svgtexttool/SvgTextTool.action@@ -13,14 +13,14 @@<statusTip/></Action><Action name="svg_insert_special_character">- <iconText>Special Character...</iconText>- <shortcut>Alt+Shift+C</shortcut>+ <iconText>Glyph Palette...</iconText>+ <shortcut>Alt+Shift+G</shortcut><toolTip>Insert one or more symbols or characters not found on the keyboard</toolTip><icon>character-set</icon><whatsThis>Insert one or more symbols or characters not found on the keyboard.</whatsThis><statusTip/><isCheckable>false</isCheckable>- <text>Special Character...</text>+ <text>Glyph Palette...</text></Action><Action name="svg_align_right"><iconText>Align Right</iconText>diff --git a/plugins/tools/svgtexttool/SvgTextTool.cpp b/plugins/tools/svgtexttool/SvgTextTool.cppindex 7473bf3dd2..052df2b089 100644--- a/plugins/tools/svgtexttool/SvgTextTool.cpp+++ b/plugins/tools/svgtexttool/SvgTextTool.cpp@@ -97,6 +97,13 @@ SvgTextTool::SvgTextTool(KoCanvasBase *canvas)}}+ const QString glyphName = "svg_insert_special_character";+ QAction *glyphAction = action(glyphName);+ if (glyphAction) {+ m_textCursor.registerPropertyAction(glyphAction, glyphName);+ connect(&m_textCursor, SIGNAL(sigOpenGlyphPalette()), this, SLOT(showGlyphPalette()));+ }+m_base_cursor = QCursor(QPixmap(":/tool_text_basic.xpm"), 7, 7);m_text_inline_horizontal = QCursor(QPixmap(":/tool_text_inline_horizontal.xpm"), 7, 7);m_text_inline_vertical = QCursor(QPixmap(":/tool_text_inline_vertical.xpm"), 7, 7);diff --git a/plugins/tools/svgtexttool/SvgTextToolFactory.cpp b/plugins/tools/svgtexttool/SvgTextToolFactory.cppindex 3dc19b135a..a5b06c252a 100644--- a/plugins/tools/svgtexttool/SvgTextToolFactory.cpp+++ b/plugins/tools/svgtexttool/SvgTextToolFactory.cpp@@ -40,6 +40,7 @@ QList<QAction *> SvgTextToolFactory::createActionsImpl()Q_FOREACH(const QString name, SvgTextShortCuts::possibleActions()) {actions << KisActionRegistry::instance()->makeQAction(name, this);}+ actions << KisActionRegistry::instance()->makeQAction("svg_insert_special_character", this);return actions;}