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 is a struct that describes a text property shortcut. More...
 

Functions

QVariant adjustValue (SvgTextShortcutInfo info, QVariant oldValue)
 adjustValue Handles increase/decrease value for getModifiedProperties, split out to make code easier to navigate.
 
bool testPropertyEnabled (const SvgTextShortcutInfo &info, const QList< KoSvgTextProperties > currentProperties)
 testPropertyEnabled
 
QVariant toggleProperty (SvgTextShortcutInfo info, bool checked, 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 296 of file SvgTextShortCuts.cpp.

296 {
297 QVariant newVal;
298
299 if (oldValue.canConvert<KoSvgText::CssLengthPercentage>()) {
302 length.value += info.value1.toDouble();
303 } else {
304 length.value -= info.value1.toDouble();
305 }
306 newVal = QVariant::fromValue(length);
307 } else if (oldValue.canConvert<KoSvgText::AutoLengthPercentage>()) {
309 length.isAuto = false;
311 length.length.value += info.value1.toDouble();
312 } else {
313 length.length.value -= info.value1.toDouble();
314 }
315 newVal = QVariant::fromValue(length);
316 } else if (oldValue.canConvert<KoSvgText::AutoValue>()) {
318 value.isAuto = false;
320 value.customValue += info.value1.toDouble();
321 } else {
322 value.customValue -= info.value1.toDouble();
323 }
324 newVal = QVariant::fromValue(value);
325 } else if (oldValue.canConvert<double>()) {
326 double value = oldValue.toDouble();
328 value += info.value1.toDouble();
329 } else {
330 value -= info.value1.toDouble();
331 }
332 newVal = QVariant::fromValue(value);
333 } else if (oldValue.canConvert<int>()) {
334 int value = oldValue.toInt();
336 value += info.value1.toInt();
337 } else {
338 value -= info.value1.toInt();
339 }
340 newVal = QVariant::fromValue(value);
341 }
342
343 return newVal;
344}
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.

◆ testPropertyEnabled()

bool testPropertyEnabled ( const SvgTextShortcutInfo & info,
const QList< KoSvgTextProperties > currentProperties )

testPropertyEnabled

Parameters
info
currentProperties
Returns
whether any properties in the current properties pass the info.testValue.

Definition at line 193 of file SvgTextShortCuts.cpp.

194{
195 const QVariant testValue = info.type == SvgTextShortcutInfo::Toggle? info.testValue: info.value1;
196
197 for (auto properties = currentProperties.begin(); properties != currentProperties.end(); properties++) {
198 const QVariant oldValue = properties->propertyOrDefault(info.propertyId);
199
200
201 if (oldValue.canConvert<KoSvgText::TextDecorations>() && info.propertyId == KoSvgTextProperties::TextDecorationLineId) {
202
203 const KoSvgText::TextDecorations oldDecor = oldValue.value<KoSvgText::TextDecorations>();
204 return oldDecor.testFlag(KoSvgText::TextDecoration(testValue.toInt()));
205
206 } else if (oldValue.canConvert<KoSvgText::CssFontStyleData>()) {
207 const KoSvgText::CssFontStyleData testVal = testValue.value<KoSvgText::CssFontStyleData>();
208 const KoSvgText::CssFontStyleData currentVal = oldValue.value<KoSvgText::CssFontStyleData>();
209 return (testVal.style == currentVal.style);
210 } else if (oldValue.canConvert<KoSvgText::AutoValue>()) {
211 const KoSvgText::AutoValue currentVal = oldValue.value<KoSvgText::AutoValue>();
212 if (testValue.canConvert<KoSvgText::AutoValue>()) {
213 return (testValue == oldValue);
214 } else if (testValue.canConvert<double>()) {
215 return currentVal.customValue == testValue.toDouble();
216 } else {
217 return currentVal.isAuto == testValue.toBool();
218 }
219 } else if (oldValue.canConvert<KoSvgText::CssLengthPercentage>()) {
220 const KoSvgText::CssLengthPercentage currentVal = oldValue.value<KoSvgText::CssLengthPercentage>();
221 if (testValue.canConvert<KoSvgText::CssLengthPercentage>()) {
222 return (testValue == oldValue);
223 } else {
224 return currentVal.value >= testValue.toDouble();
225 }
226 } else if (oldValue.canConvert<KoSvgText::AutoLengthPercentage>()) {
227 const KoSvgText::AutoLengthPercentage currentVal = oldValue.value<KoSvgText::CssLengthPercentage>();
228 if (testValue.canConvert<KoSvgText::AutoLengthPercentage>()) {
229 return (testValue == oldValue);
230 } else if (testValue.canConvert<KoSvgText::CssLengthPercentage>()) {
231 return (testValue == QVariant::fromValue(currentVal.length));
232 } else {
233 return currentVal.length.value == testValue.toDouble();
234 }
235 } else if (oldValue.canConvert<KoSvgText::LineHeightInfo>()) {
236 const KoSvgText::LineHeightInfo currentVal = oldValue.value<KoSvgText::LineHeightInfo>();
237 if (testValue.canConvert<KoSvgText::LineHeightInfo>()) {
238 return (testValue == oldValue);
239 } else if (testValue.canConvert<KoSvgText::CssLengthPercentage>()) {
240 return (testValue == QVariant::fromValue(currentVal.length));
241 } else {
242 return currentVal.length.value == testValue.toDouble();
243 }
244 }
245 return (testValue.toDouble() <= oldValue.toDouble());
246 }
247 return false;
248}
@ TextDecorationLineId
Flags, KoSvgText::TextDecorations.
TextDecoration
Flags for text-decoration, for underline, overline and strikethrough.
Definition KoSvgText.h:257
CssLengthPercentage length
Definition KoSvgText.h:466
When style is oblique, a custom slant value can be specified for variable fonts.
Definition KoSvgText.h:475
CssLengthPercentage length
Definition KoSvgText.h:693
KoSvgTextProperties::PropertyId propertyId
@ Toggle
Toggle will test "testValue", and toggle between value1 and value 2;.

References KoSvgText::AutoValue::customValue, KoSvgText::AutoValue::isAuto, KoSvgText::AutoLengthPercentage::length, KoSvgText::LineHeightInfo::length, SvgTextShortcutInfo::propertyId, KoSvgText::CssFontStyleData::style, SvgTextShortcutInfo::testValue, KoSvgTextProperties::TextDecorationLineId, SvgTextShortcutInfo::Toggle, SvgTextShortcutInfo::type, KoSvgText::CssLengthPercentage::value, and SvgTextShortcutInfo::value1.

◆ toggleProperty()

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

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

Definition at line 266 of file SvgTextShortCuts.cpp.

266 {
267 QVariant newVal;
268
269 if (currentProperties.isEmpty()) return newVal;
270
271 QVariant oldValue = currentProperties.first().propertyOrDefault(info.propertyId);
272 if (oldValue.canConvert<KoSvgText::TextDecorations>() && info.propertyId == KoSvgTextProperties::TextDecorationLineId) {
274 KoSvgText::TextDecorations newDecor;
275 newDecor.setFlag(decor, checked);
276 newVal = QVariant::fromValue(newDecor);
277
278 } else {
279 if (checked) {
280 newVal = info.value2;
281 } else {
282 newVal = info.value1;
283 }
284 }
285
286 return newVal;
287}

References SvgTextShortcutInfo::propertyId, 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.
@ FontStyleId
KoSvgText::CssSlantData.
@ BaselineShiftModeId
KoSvgText::BaselineShiftMode.
@ KerningId
KoSvgText::AutoValue.
@ 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)