Krita Source Code Documentation
Loading...
Searching...
No Matches
SvgTextShortCuts Class Reference

The SvgTextShortCuts class. More...

#include <SvgTextShortCuts.h>

Static Public Member Functions

static bool actionEnabled (QAction *action, const QList< KoSvgTextProperties > currentProperties)
 
static bool configureAction (QAction *action, const QString &name)
 
static KoSvgTextProperties getModifiedProperties (const QAction *action, QList< KoSvgTextProperties > currentProperties)
 
static QStringList possibleActions ()
 

Detailed Description

The SvgTextShortCuts class.

Class to handle text property shortcuts generically.

Many text property shortcuts 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.

Definition at line 24 of file SvgTextShortCuts.h.

Member Function Documentation

◆ actionEnabled()

bool SvgTextShortCuts::actionEnabled ( QAction * action,
const QList< KoSvgTextProperties > currentProperties )
static

Definition at line 188 of file SvgTextShortCuts.cpp.

188 {
189 if (!action || !action->isCheckable() || !action->data().canConvert<SvgTextShortcutInfo>()) return false;
190 SvgTextShortcutInfo info = action->data().value<SvgTextShortcutInfo>();
191
193 return false;
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 == oldValue);
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
The SvgTextShortcutInfo class This.
KoSvgTextProperties::PropertyId propertyId
@ Set
Will set value1, cannot be toggled.
@ 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, SvgTextShortcutInfo::Set, KoSvgText::CssFontStyleData::style, SvgTextShortcutInfo::testValue, KoSvgTextProperties::TextDecorationLineId, SvgTextShortcutInfo::Toggle, SvgTextShortcutInfo::type, KoSvgText::CssLengthPercentage::value, and SvgTextShortcutInfo::value1.

◆ configureAction()

bool SvgTextShortCuts::configureAction ( QAction * action,
const QString & name )
static

Definition at line 179 of file SvgTextShortCuts.cpp.

180{
181 if (!textShortCuts.contains(name)) return false;
182 if (!action) return false;
183 SvgTextShortcutInfo info = textShortCuts.value(name);
184 action->setData(QVariant::fromValue(info));
185 return true;
186}
const QMap< QString, SvgTextShortcutInfo > textShortCuts

References textShortCuts.

◆ getModifiedProperties()

KoSvgTextProperties SvgTextShortCuts::getModifiedProperties ( const QAction * action,
QList< KoSvgTextProperties > currentProperties )
static

Definition at line 366 of file SvgTextShortCuts.cpp.

367{
368 if (!action || !action->data().canConvert<SvgTextShortcutInfo>() || currentProperties.isEmpty()) return KoSvgTextProperties();
369 SvgTextShortcutInfo info = action->data().value<SvgTextShortcutInfo>();
370
371 QVariant newVal;
372 if (info.type == SvgTextShortcutInfo::Toggle) {
373 newVal = toggleProperty(info, currentProperties);
374 } else if (info.type == SvgTextShortcutInfo::Set) {
375 KoSvgTextProperties properties = currentProperties.first();
376 QVariant oldValue = properties.propertyOrDefault(info.propertyId);
377
378 if (oldValue.canConvert<int>()) {
379 newVal = info.value1;
380 }
381 } else {
382 KoSvgTextProperties properties = currentProperties.first();
383 QVariant oldValue = properties.propertyOrDefault(info.propertyId);
384
385 newVal = adjustValue(info, oldValue);
386 }
387 KoSvgTextProperties newProperties;
388 newProperties.setProperty(info.propertyId, newVal);
389 return newProperties;
390}
QVariant toggleProperty(SvgTextShortcutInfo info, QList< KoSvgTextProperties > currentProperties)
toggleProperty Handles toggling properties for getModifiedProperties split out to make code easier to...
QVariant adjustValue(SvgTextShortcutInfo info, QVariant oldValue)
adjustValue Handles increase/decrease value for getModifiedProperties, split out to make code easier ...
void setProperty(PropertyId id, const QVariant &value)
QVariant propertyOrDefault(PropertyId id) const

References adjustValue(), SvgTextShortcutInfo::propertyId, KoSvgTextProperties::propertyOrDefault(), SvgTextShortcutInfo::Set, KoSvgTextProperties::setProperty(), SvgTextShortcutInfo::Toggle, toggleProperty(), SvgTextShortcutInfo::type, and SvgTextShortcutInfo::value1.

◆ possibleActions()

QStringList SvgTextShortCuts::possibleActions ( )
static

Definition at line 174 of file SvgTextShortCuts.cpp.

175{
176 return textShortCuts.keys();
177}

References textShortCuts.


The documentation for this class was generated from the following files: