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 250 of file SvgTextShortCuts.cpp.

250 {
251 if (!action || !action->isCheckable() || !action->data().canConvert<SvgTextShortcutInfo>()) return action->isChecked();
252 SvgTextShortcutInfo info = action->data().value<SvgTextShortcutInfo>();
253
255 return false;
256 }
257
258 return testPropertyEnabled(info, currentProperties);
259}
bool testPropertyEnabled(const SvgTextShortcutInfo &info, const QList< KoSvgTextProperties > currentProperties)
testPropertyEnabled
The SvgTextShortcutInfo class This is a struct that describes a text property shortcut.
@ Set
Will set value1, cannot be toggled.
@ Toggle
Toggle will test "testValue", and toggle between value1 and value 2;.

References SvgTextShortcutInfo::Set, testPropertyEnabled(), SvgTextShortcutInfo::Toggle, and SvgTextShortcutInfo::type.

◆ 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 346 of file SvgTextShortCuts.cpp.

347{
348 if (!action || !action->data().canConvert<SvgTextShortcutInfo>() || currentProperties.isEmpty()) return KoSvgTextProperties();
349 SvgTextShortcutInfo info = action->data().value<SvgTextShortcutInfo>();
350
351 QVariant newVal;
352 if (info.type == SvgTextShortcutInfo::Toggle) {
353 newVal = toggleProperty(info, action->isChecked(), currentProperties);
354 } else if (info.type == SvgTextShortcutInfo::Set) {
355 KoSvgTextProperties properties = currentProperties.first();
356 QVariant oldValue = properties.propertyOrDefault(info.propertyId);
357
358 if (oldValue.canConvert<int>()) {
359 newVal = info.value1;
360 }
361 } else {
362 KoSvgTextProperties properties = currentProperties.first();
363 QVariant oldValue = properties.propertyOrDefault(info.propertyId);
364
365 newVal = adjustValue(info, oldValue);
366 }
367 KoSvgTextProperties newProperties;
368 newProperties.setProperty(info.propertyId, newVal);
369 return newProperties;
370}
QVariant toggleProperty(SvgTextShortcutInfo info, bool checked, 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
KoSvgTextProperties::PropertyId propertyId

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: