Skip to content

armgit / krita

Public Imported from GitHub
0

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++

Fix testing and applying text mode toggling shortcuts.

Wolthera van Hövell tot Westerflierd4b9b695e434
diff --git a/plugins/tools/svgtexttool/SvgTextCursor.cpp b/plugins/tools/svgtexttool/SvgTextCursor.cpp
index a917478b55..1150769528 100644
--- a/plugins/tools/svgtexttool/SvgTextCursor.cpp
+++ b/plugins/tools/svgtexttool/SvgTextCursor.cpp
@@ -1232,53 +1232,12 @@ void SvgTextCursor::canvasResourceChanged(int key, const QVariant &value)
}
}
-void SvgTextCursor::toggleProperty(KoSvgTextProperties::PropertyId property)
-{
- if (d->shape) {
- QVariant newVal;
- QList<KoSvgTextProperties> p = d->shape->propertiesForRange(qMin(d->pos, d->anchor), qMax(d->pos, d->anchor));
- for(auto it = p.begin(); it != p.end(); it++) {
- if (property == KoSvgTextProperties::FontWeightId) {
- int value = it->property(property, QVariant(400)).toInt();
- newVal = value == 400? QVariant(700): QVariant(400);
- if (value == 400) break;
- } else if (property == KoSvgTextProperties::FontStyleId) {
- KoSvgText::CssFontStyleData value = it->property(property, QVariant(QFont::StyleNormal)).value<KoSvgText::CssFontStyleData>();
- KoSvgText::CssFontStyleData newSlant = value;
- if (value.style == QFont::StyleNormal) {
- newSlant.style = QFont::StyleItalic;
- } else {
- newSlant.style = QFont::StyleNormal;
- newSlant.slantValue.customValue = 0;
- newSlant.slantValue.isAuto = true;
- }
- newVal = QVariant::fromValue(newSlant);
- if (value.style == QFont::StyleNormal) break;
- } else if (property == KoSvgTextProperties::TextDecorationLineId) {
- KoSvgText::TextDecorations decor = it->propertyOrDefault(KoSvgTextProperties::TextDecorationLineId).value<KoSvgText::TextDecorations>();
- KoSvgText::TextDecorations newDecor;
- if (decor.testFlag(KoSvgText::DecorationUnderline)) {
- newDecor.setFlag(KoSvgText::DecorationUnderline, false);
- newVal = QVariant::fromValue(newDecor);
- } else {
- newDecor.setFlag(KoSvgText::DecorationUnderline, true);
- newVal = QVariant::fromValue(newDecor);
- break;
- }
- }
- }
- KoSvgTextProperties properties;
- properties.setProperty(property, newVal);
- mergePropertiesIntoSelection(properties);
- }
-}
-
void SvgTextCursor::propertyAction()
{
QAction *action = dynamic_cast<QAction*>(QObject::sender());
if (!action || !d->shape) return;
- QList<KoSvgTextProperties> p = d->shape->propertiesForRange(qMin(d->pos, d->anchor), qMax(d->pos, d->anchor));
+ const QList<KoSvgTextProperties> p = d->shape->propertiesForRange(qMin(d->pos, d->anchor), qMax(d->pos, d->anchor));
KoSvgTextProperties properties = SvgTextShortCuts::getModifiedProperties(action, p);
if (properties.isEmpty()) return;
mergePropertiesIntoSelection(properties);
@@ -1939,10 +1898,18 @@ void SvgTextCursor::updateCanvasResources()
d->canvas->resourceManager()->setBackgroundColor(c);
}
}
+
Q_FOREACH (QAction *action, d->actions) {
- if (action->isCheckable()) {
- action->setChecked(SvgTextShortCuts::actionEnabled(action, {props}));
+ // Blocking signals so that we don't get a toggle action while evaluating the checked-ness.
+ action->blockSignals(true);
+ const QList<KoSvgTextProperties> r = d->shape->propertiesForRange(qMin(d->pos, d->anchor), qMax(d->pos, d->anchor), true);
+ if (action->isCheckable() && SvgTextShortCuts::possibleActions().contains(action->objectName())) {
+ const bool checked = SvgTextShortCuts::actionEnabled(action, r);
+ if (action->isChecked() != checked) {
+ action->setChecked(checked);
+ }
}
+ action->blockSignals(false);
}
}
}
diff --git a/plugins/tools/svgtexttool/SvgTextCursor.h b/plugins/tools/svgtexttool/SvgTextCursor.h
index bfa1f1bbf4..2b9af4d7de 100644
--- a/plugins/tools/svgtexttool/SvgTextCursor.h
+++ b/plugins/tools/svgtexttool/SvgTextCursor.h
@@ -264,22 +264,35 @@ public:
/// Register an action.
bool registerPropertyAction(QAction *action, const QString &name);
+ /// The text properties interface. This is how the text properties docker
+ /// communicates with the text tool.
KoSvgTextPropertiesInterface *textPropertyInterface();
Q_SIGNALS:
+ /// Sents an update to the parent tool to update it's decorations.
void updateCursorDecoration(QRectF updateRect);
+ /// Sents an update selection was changed.
void selectionChanged();
+ /// Called by actions, tells the parent tool to open the glyph palette.
void sigOpenGlyphPalette();
private Q_SLOTS:
+ /// Called by timer, toggles the text cursor visible or invisible.
void blinkCursor();
+ /// Called by timer, stops the text blinking animation.
void stopBlinkCursor();
+ /*
+ * Called when the canvas view navigation changes,
+ * so we can ensure the input method widgets get aligned.
+ */
void updateInputMethodItemTransform();
+ /// Called when the canvas resources (foreground/background) change.
void canvasResourceChanged(int key, const QVariant &value);
- void toggleProperty(KoSvgTextProperties::PropertyId property);
+ /// Called by the actions to execute a property change based on their data.
void propertyAction();
+ /// Called by the clear formatting action.
void clearFormattingAction();
/**
diff --git a/plugins/tools/svgtexttool/SvgTextShortCuts.cpp b/plugins/tools/svgtexttool/SvgTextShortCuts.cpp
index 4a068c4be2..2e3daf6561 100644
--- a/plugins/tools/svgtexttool/SvgTextShortCuts.cpp
+++ b/plugins/tools/svgtexttool/SvgTextShortCuts.cpp
@@ -11,7 +11,7 @@
/**
* @brief The SvgTextShortcutInfo class
- * This
+ * This is a struct that describes a text property shortcut.
*/
struct SvgTextShortcutInfo : public boost::equality_comparable<SvgTextShortcutInfo> {
@@ -184,14 +184,14 @@ bool SvgTextShortCuts::configureAction(QAction *action, const QString &name)
action->setData(QVariant::fromValue(info));
return true;
}
-
-bool SvgTextShortCuts::actionEnabled(QAction *action, const QList<KoSvgTextProperties> currentProperties) {
- if (!action || !action->isCheckable() || !action->data().canConvert<SvgTextShortcutInfo>()) return false;
- SvgTextShortcutInfo info = action->data().value<SvgTextShortcutInfo>();
-
- if (info.type != SvgTextShortcutInfo::Toggle && info.type != SvgTextShortcutInfo::Set) {
- return false;
- }
+/**
+ * @brief testPropertyEnabled
+ * @param info
+ * @param currentProperties
+ * @return whether any properties in the current properties pass the info.testValue.
+ */
+bool testPropertyEnabled(const SvgTextShortcutInfo &info, const QList<KoSvgTextProperties> currentProperties)
+{
const QVariant testValue = info.type == SvgTextShortcutInfo::Toggle? info.testValue: info.value1;
for (auto properties = currentProperties.begin(); properties != currentProperties.end(); properties++) {
@@ -221,7 +221,7 @@ bool SvgTextShortCuts::actionEnabled(QAction *action, const QList<KoSvgTextPrope
if (testValue.canConvert<KoSvgText::CssLengthPercentage>()) {
return (testValue == oldValue);
} else {
- return currentVal.value == testValue.toDouble();
+ return currentVal.value >= testValue.toDouble();
}
} else if (oldValue.canConvert<KoSvgText::AutoLengthPercentage>()) {
const KoSvgText::AutoLengthPercentage currentVal = oldValue.value<KoSvgText::CssLengthPercentage>();
@@ -242,67 +242,47 @@ bool SvgTextShortCuts::actionEnabled(QAction *action, const QList<KoSvgTextPrope
return currentVal.length.value == testValue.toDouble();
}
}
- return (testValue == oldValue);
+ return (testValue <= oldValue);
}
return false;
}
+bool SvgTextShortCuts::actionEnabled(QAction *action, const QList<KoSvgTextProperties> currentProperties) {
+ if (!action || !action->isCheckable() || !action->data().canConvert<SvgTextShortcutInfo>()) return action->isChecked();
+ SvgTextShortcutInfo info = action->data().value<SvgTextShortcutInfo>();
+
+ if (info.type != SvgTextShortcutInfo::Toggle && info.type != SvgTextShortcutInfo::Set) {
+ return false;
+ }
+
+ return testPropertyEnabled(info, currentProperties);
+}
+
/**
* @brief toggleProperty
* Handles toggling properties for getModifiedProperties
* split out to make code easier to navigate.
*/
-QVariant toggleProperty(SvgTextShortcutInfo info, QList<KoSvgTextProperties> currentProperties) {
+QVariant toggleProperty(SvgTextShortcutInfo info, bool checked, 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;
- }
+ if (currentProperties.isEmpty()) return newVal;
+
+ QVariant oldValue = currentProperties.first().propertyOrDefault(info.propertyId);
+ if (oldValue.canConvert<KoSvgText::TextDecorations>() && info.propertyId == KoSvgTextProperties::TextDecorationLineId) {
+ KoSvgText::TextDecoration decor = KoSvgText::TextDecoration(info.testValue.toInt());
+ KoSvgText::TextDecorations newDecor;
+ newDecor.setFlag(decor, checked);
+ newVal = QVariant::fromValue(newDecor);
+
+ } else {
+ if (checked) {
+ newVal = info.value2;
+ } else {
+ newVal = info.value1;
}
}
+
return newVal;
}
@@ -370,7 +350,7 @@ KoSvgTextProperties SvgTextShortCuts::getModifiedProperties(const QAction *actio
QVariant newVal;
if (info.type == SvgTextShortcutInfo::Toggle) {
- newVal = toggleProperty(info, currentProperties);
+ newVal = toggleProperty(info, action->isChecked(), currentProperties);
} else if (info.type == SvgTextShortcutInfo::Set) {
KoSvgTextProperties properties = currentProperties.first();
QVariant oldValue = properties.propertyOrDefault(info.propertyId);