Krita Source Code Documentation
Loading...
Searching...
No Matches
SvgTextShortCuts.cpp File Reference
#include "SvgTextShortCuts.h"
#include <QAction>
#include <KoSvgTextProperties.h>
#include <KisStaticInitializer.h>

Go to the source code of this file.

Classes

struct  SvgTextShortcutInfo
 The SvgTextShortcutInfo class This. More...
 

Functions

QVariant adjustValue (SvgTextShortcutInfo info, QVariant oldValue)
 adjustValue Handles increase/decrease value for getModifiedProperties, split out to make code easier to navigate.
 
QVariant toggleProperty (SvgTextShortcutInfo info, QList< KoSvgTextProperties > currentProperties)
 toggleProperty Handles toggling properties for getModifiedProperties split out to make code easier to navigate.
 

Variables

 KIS_DECLARE_STATIC_INITIALIZER
 
const QMap< QString, SvgTextShortcutInfotextShortCuts
 

Function Documentation

◆ adjustValue()

QVariant adjustValue ( SvgTextShortcutInfo info,
QVariant oldValue )

adjustValue Handles increase/decrease value for getModifiedProperties, split out to make code easier to navigate.

TODO: handle max/min.

Definition at line 316 of file SvgTextShortCuts.cpp.

316 {
317 QVariant newVal;
318
319 if (oldValue.canConvert<KoSvgText::CssLengthPercentage>()) {
322 length.value += info.value1.toDouble();
323 } else {
324 length.value -= info.value1.toDouble();
325 }
326 newVal = QVariant::fromValue(length);
327 } else if (oldValue.canConvert<KoSvgText::AutoLengthPercentage>()) {
329 length.isAuto = false;
331 length.length.value += info.value1.toDouble();
332 } else {
333 length.length.value -= info.value1.toDouble();
334 }
335 newVal = QVariant::fromValue(length);
336 } else if (oldValue.canConvert<KoSvgText::AutoValue>()) {
338 value.isAuto = false;
340 value.customValue += info.value1.toDouble();
341 } else {
342 value.customValue -= info.value1.toDouble();
343 }
344 newVal = QVariant::fromValue(value);
345 } else if (oldValue.canConvert<double>()) {
346 double value = oldValue.toDouble();
348 value += info.value1.toDouble();
349 } else {
350 value -= info.value1.toDouble();
351 }
352 newVal = QVariant::fromValue(value);
353 } else if (oldValue.canConvert<int>()) {
354 int value = oldValue.toInt();
356 value += info.value1.toInt();
357 } else {
358 value -= info.value1.toInt();
359 }
360 newVal = QVariant::fromValue(value);
361 }
362
363 return newVal;
364}
qreal length(const QPointF &vec)
Definition Ellipse.cc:82
float value(const T *src, size_t ch)

References SvgTextShortcutInfo::Increase, KoSvgText::AutoValue::isAuto, KoSvgText::AutoLengthPercentage::isAuto, length(), SvgTextShortcutInfo::type, KoSvgText::CssLengthPercentage::value, value(), and SvgTextShortcutInfo::value1.

◆ toggleProperty()

QVariant toggleProperty ( SvgTextShortcutInfo info,
QList< KoSvgTextProperties > currentProperties )

toggleProperty Handles toggling properties for getModifiedProperties split out to make code easier to navigate.

Definition at line 255 of file SvgTextShortCuts.cpp.

255 {
256 QVariant newVal;
257 for(auto properties = currentProperties.begin(); properties != currentProperties.end(); properties++) {
258 QVariant oldValue = properties->propertyOrDefault(info.propertyId);
259
260 if (oldValue.canConvert<KoSvgText::TextDecorations>() && info.propertyId == KoSvgTextProperties::TextDecorationLineId) {
262 KoSvgText::TextDecorations oldDecor = oldValue.value<KoSvgText::TextDecorations>();
263 KoSvgText::TextDecorations newDecor;
264 newDecor.setFlag(decor, !oldDecor.testFlag(decor));
265 newVal = QVariant::fromValue(newDecor);
266 if (oldDecor.testFlag(decor)) {
267 break;
268 }
269 } else if (oldValue.canConvert<KoSvgText::CssFontStyleData>() && info.propertyId == KoSvgTextProperties::FontStyleId) {
271 KoSvgText::CssFontStyleData currentVal = oldValue.value<KoSvgText::CssFontStyleData>();
272 if (currentVal.style == testVal.style) {
273 newVal = info.value2;
274 break;
275 } else {
276 newVal = info.value1;
277 }
278 } else if (oldValue.canConvert<KoSvgText::AutoValue>() && info.propertyId == KoSvgTextProperties::KerningId) {
279 bool testVal = info.testValue.toBool();
280 KoSvgText::AutoValue currentVal = oldValue.value<KoSvgText::AutoValue>();
281 if (currentVal.isAuto == testVal) {
282 currentVal.customValue = 0.0;
283 currentVal.isAuto = info.value2.toBool();
284 newVal = QVariant::fromValue(currentVal);
285 break;
286 } else {
287 currentVal.isAuto = info.value1.toBool();
288 newVal = QVariant::fromValue(currentVal);
289 }
290 } else if (oldValue.canConvert<double>()) {
291 if (oldValue.toDouble() > info.testValue.toDouble()) {
292 newVal = info.value1;
293 break;
294 } else {
295 newVal = info.value2;
296 }
297 } else if (oldValue.canConvert<int>()) {
298 if (oldValue.toInt() > info.testValue.toInt()) {
299 newVal = info.value1;
300 break;
301 } else {
302 newVal = info.value2;
303 }
304 }
305 }
306 return newVal;
307}
@ FontStyleId
KoSvgText::CssSlantData.
@ TextDecorationLineId
Flags, KoSvgText::TextDecorations.
@ KerningId
KoSvgText::AutoValue.
TextDecoration
Flags for text-decoration, for underline, overline and strikethrough.
Definition KoSvgText.h:257
When style is oblique, a custom slant value can be specified for variable fonts.
Definition KoSvgText.h:475
KoSvgTextProperties::PropertyId propertyId

References KoSvgText::AutoValue::customValue, KoSvgTextProperties::FontStyleId, KoSvgText::AutoValue::isAuto, KoSvgTextProperties::KerningId, SvgTextShortcutInfo::propertyId, KoSvgText::CssFontStyleData::style, SvgTextShortcutInfo::testValue, KoSvgTextProperties::TextDecorationLineId, SvgTextShortcutInfo::value1, and SvgTextShortcutInfo::value2.

Variable Documentation

◆ KIS_DECLARE_STATIC_INITIALIZER

KIS_DECLARE_STATIC_INITIALIZER
Initial value:
{
qRegisterMetaType<SvgTextShortcutInfo>("SvgTextShortcutInfo")

Definition at line 72 of file SvgTextShortCuts.cpp.

◆ textShortCuts

const QMap<QString, SvgTextShortcutInfo> textShortCuts

Definition at line 79 of file SvgTextShortCuts.cpp.

79 {
80 {
81 "svg_weight_bold",
83 QVariant(400), QVariant(700), QVariant(500))
84 },
85
86 {
87 "svg_weight_normal",
89 QVariant(400))
90 },
91 {
92 "svg_weight_demi",
94 QVariant(600))
95 },
96 {
97 "svg_weight_black",
99 QVariant(900))
100 },
101 {
102 "svg_weight_light",
104 QVariant(300))
105 },
106
107 {
108 "svg_format_italic",
110 QVariant::fromValue(KoSvgText::CssFontStyleData(QFont::StyleNormal)),
111 QVariant::fromValue(KoSvgText::CssFontStyleData(QFont::StyleItalic)),
112 QVariant::fromValue(KoSvgText::CssFontStyleData(QFont::StyleNormal)))
113 },
114
115 {
116 "svg_increase_font_size",
118 QVariant::fromValue(1), true)
119 },
120
121 {
122 "svg_decrease_font_size",
124 QVariant::fromValue(1), false)
125 },
126
127 {
128 "svg_format_underline",
130 QVariant(true), QVariant(false), QVariant(KoSvgText::DecorationUnderline))
131 },
132 {
133 "svg_format_strike_through",
135 QVariant(true), QVariant(false), QVariant(KoSvgText::DecorationLineThrough))
136 },
137 {
138 "svg_font_kerning",
140 QVariant(true), QVariant(false), QVariant(true))
141 },
142 {
143 "svg_align_right",
145 QVariant(KoSvgText::AlignStart))
146 },
147 {
148 "svg_align_left",
150 QVariant(KoSvgText::AlignEnd))
151 },
152 {
153 "svg_align_center",
155 QVariant(KoSvgText::AlignCenter))
156 },
157 {
158 "svg_align_justified",
160 QVariant(KoSvgText::AlignJustify))
161 },
162 {
163 "svg_format_subscript",
165 QVariant(KoSvgText::ShiftSub))
166 },
167 {
168 "svg_format_superscript",
170 QVariant(KoSvgText::ShiftSuper))
171 }
172};
@ TextAlignAllId
KoSvgText::TextAlign.
@ BaselineShiftModeId
KoSvgText::BaselineShiftMode.
@ AlignCenter
Center text in line.
Definition KoSvgText.h:173
@ ShiftSuper
Use parent font metric for 'superscript'.
Definition KoSvgText.h:243
@ ShiftSub
Use parent font metric for 'subscript'.
Definition KoSvgText.h:242
@ DecorationLineThrough
Definition KoSvgText.h:261
@ DecorationUnderline
Definition KoSvgText.h:259
static SvgTextShortcutInfo propertySet(KoSvgTextProperties::PropertyId _propertyId, QVariant _value1)
static SvgTextShortcutInfo propertyChange(KoSvgTextProperties::PropertyId _propertyId, QVariant _value1, bool _increase)
static SvgTextShortcutInfo propertyToggle(KoSvgTextProperties::PropertyId _propertyId, QVariant _value1, QVariant _value2, QVariant _testValue)