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

Add text conversion actions to Shape Select rightclick menu.

Wolthera van Hövell tot Westerflier43137e4d17b0
diff --git a/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp b/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp
index d5c8d47a14..af5c3d7d26 100644
--- a/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp
+++ b/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp
@@ -765,6 +765,14 @@ void DefaultTool::setupActions()
addMappedAction(m_textTypeSignalsMapper, "text_type_inline_wrap", KoSvgTextShape::InlineWrap);
addMappedAction(m_textTypeSignalsMapper, "text_type_pre_positioned", KoSvgTextShape::PrePositionedText);
+ if (!action("text_type_preformatted")->actionGroup()) {
+ QActionGroup *textTypeActions = new QActionGroup(this);
+ textTypeActions->addAction(action("text_type_preformatted"));
+ textTypeActions->addAction(action("text_type_inline_wrap"));
+ textTypeActions->addAction(action("text_type_pre_positioned"));
+ textTypeActions->setExclusive(true);
+ }
+
m_textFlowSignalsMapper = new KisSignalMapper(this);
addMappedAction(m_textFlowSignalsMapper, "flow_shape_order_back", KoSvgTextReorderShapeInsideCommand::SendToBack);
@@ -2122,20 +2130,29 @@ void DefaultTool::updateDistinctiveActions(const QList<KoShape*> &editableShapes
bool enablePreformatted = false;
bool enablePrePositioned = false;
bool enableInlineWrapped = false;
+ bool text = false;
Q_FOREACH (KoShape *shape, editableShapes) {
KoSvgTextShape *textShape = dynamic_cast<KoSvgTextShape *>(shape);
if (textShape) {
+ text = true;
if (textShape->textType() != KoSvgTextShape::PreformattedText && !enablePreformatted) {
enablePreformatted = true;
}
if (textShape && textShape->textType() != KoSvgTextShape::PrePositionedText && !enablePrePositioned) {
enablePrePositioned = true;
}
- if (textShape && textShape->textType() != KoSvgTextShape::PrePositionedText && !enableInlineWrapped) {
+ if (textShape && textShape->textType() != KoSvgTextShape::InlineWrap && !enableInlineWrapped) {
enableInlineWrapped = true;
}
}
}
+ QActionGroup *group = action("text_type_preformatted")->actionGroup();
+ group->setEnabled(true);
+ group->setExclusive(false);
+ Q_FOREACH (QAction *a, group->actions()) {
+ a->setCheckable(false);
+ }
+
action("text_type_preformatted")->setEnabled(enablePreformatted);
action("text_type_pre_positioned")->setEnabled(enablePrePositioned);
action("text_type_inline_wrap")->setEnabled(enableInlineWrapped);
@@ -2205,6 +2222,10 @@ QMenu* DefaultTool::popupActionsMenu()
text->addAction(action("add_shape_to_flow_area"));
text->addAction(action("subtract_shape_from_flow_area"));
text->addSeparator();
+ text->addAction(action("text_type_preformatted"));
+ text->addAction(action("text_type_inline_wrap"));
+ text->addAction(action("text_type_pre_positioned"));
+ text->addSeparator();
text->addAction(action("remove_shapes_from_text_flow"));
text->addAction(action("flow_shape_type_toggle"));
text->addSeparator();
diff --git a/plugins/tools/svgtexttool/SvgTextCursor.cpp b/plugins/tools/svgtexttool/SvgTextCursor.cpp
index 041b5ea919..696d55e56e 100644
--- a/plugins/tools/svgtexttool/SvgTextCursor.cpp
+++ b/plugins/tools/svgtexttool/SvgTextCursor.cpp
@@ -223,8 +223,7 @@ void SvgTextCursor::setShape(KoSvgTextShape *textShape)
d->shape->addShapeChangeListener(this);
updateInputMethodItemTransform();
d->pos = d->shape->posForIndex(d->shape->plainText().size());
- d->typeSettingDecor.handlesEnabled = (d->shape->textType() == KoSvgTextShape::PreformattedText
- || d->shape->textType() == KoSvgTextShape::PrePositionedText);
+ updateTypeSettingDecorFromShape();
} else {
d->pos = 0;
}
@@ -357,6 +356,14 @@ void SvgTextCursor::setDrawTypeSettingHandle(bool draw)
d->drawTypeSettingHandle = draw;
}
+void SvgTextCursor::updateTypeSettingDecorFromShape()
+{
+ if (d->shape) {
+ d->typeSettingDecor.handlesEnabled = (d->shape->textType() == KoSvgTextShape::PreformattedText
+ || d->shape->textType() == KoSvgTextShape::PrePositionedText);
+ }
+}
+
QCursor SvgTextCursor::cursorTypeForTypeSetting() const
{
if (d->hoveredTypeSettingHandle == StartPos ||
diff --git a/plugins/tools/svgtexttool/SvgTextCursor.h b/plugins/tools/svgtexttool/SvgTextCursor.h
index 9b2b7848c9..38775af266 100644
--- a/plugins/tools/svgtexttool/SvgTextCursor.h
+++ b/plugins/tools/svgtexttool/SvgTextCursor.h
@@ -145,6 +145,8 @@ public:
/// Turned off when the typesetting strategy is active to give artists more control.
void setDrawTypeSettingHandle(bool draw);
+ void updateTypeSettingDecorFromShape();
+
/// Return appropriate typeSetting cursor;
QCursor cursorTypeForTypeSetting() const;
diff --git a/plugins/tools/svgtexttool/SvgTextTool.cpp b/plugins/tools/svgtexttool/SvgTextTool.cpp
index 869ba11306..7e88d192a4 100644
--- a/plugins/tools/svgtexttool/SvgTextTool.cpp
+++ b/plugins/tools/svgtexttool/SvgTextTool.cpp
@@ -135,15 +135,17 @@ SvgTextTool::SvgTextTool(KoCanvasBase *canvas)
}
m_textTypeSignalsMapper.reset(new KisSignalMapper(this));
- addMappedAction(m_textTypeSignalsMapper.data(), "text_type_preformatted", KoSvgTextShape::PreformattedText);
- addMappedAction(m_textTypeSignalsMapper.data(), "text_type_inline_wrap", KoSvgTextShape::InlineWrap);
- addMappedAction(m_textTypeSignalsMapper.data(), "text_type_pre_positioned", KoSvgTextShape::PrePositionedText);
+ QActionGroup *textTypeActions = new QActionGroup(this);
+ addMappedAction(m_textTypeSignalsMapper.data(), "text_type_preformatted", KoSvgTextShape::PreformattedText, textTypeActions);
+ addMappedAction(m_textTypeSignalsMapper.data(), "text_type_inline_wrap", KoSvgTextShape::InlineWrap, textTypeActions);
+ addMappedAction(m_textTypeSignalsMapper.data(), "text_type_pre_positioned", KoSvgTextShape::PrePositionedText, textTypeActions);
m_typeSettingMovementMapper.reset(new KisSignalMapper(this));
- addMappedAction(m_typeSettingMovementMapper.data(), "svg_type_setting_move_selection_start_down_1_px", Qt::Key_Down);
- addMappedAction(m_typeSettingMovementMapper.data(), "svg_type_setting_move_selection_start_up_1_px", Qt::Key_Up);
- addMappedAction(m_typeSettingMovementMapper.data(), "svg_type_setting_move_selection_start_left_1_px", Qt::Key_Left);
- addMappedAction(m_typeSettingMovementMapper.data(), "svg_type_setting_move_selection_start_right_1_px", Qt::Key_Right);
+ QActionGroup *typeSettingActions = new QActionGroup(this);
+ addMappedAction(m_typeSettingMovementMapper.data(), "svg_type_setting_move_selection_start_down_1_px", Qt::Key_Down, typeSettingActions);
+ addMappedAction(m_typeSettingMovementMapper.data(), "svg_type_setting_move_selection_start_up_1_px", Qt::Key_Up, typeSettingActions);
+ addMappedAction(m_typeSettingMovementMapper.data(), "svg_type_setting_move_selection_start_left_1_px", Qt::Key_Left, typeSettingActions);
+ addMappedAction(m_typeSettingMovementMapper.data(), "svg_type_setting_move_selection_start_right_1_px", Qt::Key_Right, typeSettingActions);
m_textOutlineHelper->setDrawBoundingRect(false);
m_textOutlineHelper->setDrawTextWrappingArea(true);
@@ -569,28 +571,26 @@ void SvgTextTool::slotUpdateTextPasteBehaviour()
void SvgTextTool::slotTextTypeUpdated()
{
KoSvgTextShape *shape = selectedShape();
+ QActionGroup *typeConvertGroup = action("text_type_preformatted")->actionGroup();
+ typeConvertGroup->setExclusive(true);
+ Q_FOREACH (QAction *a, typeConvertGroup->actions()) {
+ a->setCheckable(true);
+ }
if (m_optionManager) {
if (shape) {
m_optionManager->convertToTextType(int(shape->textType()));
- action("text_type_preformatted")->setEnabled(true);
- action("text_type_pre_positioned")->setEnabled(true);
- action("text_type_inline_wrap")->setEnabled(true);
+ typeConvertGroup->setEnabled(true);
action("text_type_preformatted")->setChecked(shape->textType() == KoSvgTextShape::PreformattedText);
action("text_type_pre_positioned")->setChecked(shape->textType() == KoSvgTextShape::PrePositionedText);
action("text_type_inline_wrap")->setChecked(shape->textType() == KoSvgTextShape::InlineWrap);
} else {
m_optionManager->convertToTextType(-1);
- action("text_type_preformatted")->setEnabled(false);
- action("text_type_pre_positioned")->setEnabled(false);
- action("text_type_inline_wrap")->setEnabled(false);
- }
- Q_FOREACH(QObject *obj, m_typeSettingMovementMapper->children()) {
- QAction *a = qobject_cast<QAction*>(obj);
- if (a && shape) {
- a->setEnabled(m_optionManager->typeSettingMode());
- }
+ typeConvertGroup->setEnabled(false);
}
+ const bool enableTypeSetting = (m_optionManager->typeSettingMode() && shape && (shape->textType() == KoSvgTextShape::PreformattedText ||shape->textType() == KoSvgTextShape::PrePositionedText));
+ action("svg_type_setting_move_selection_start_down_1_px")->actionGroup()->setEnabled(enableTypeSetting);
+ m_textCursor.updateTypeSettingDecorFromShape();
}
}
@@ -626,13 +626,7 @@ void SvgTextTool::slotMoveTextSelection(int index)
void SvgTextTool::slotUpdateTypeSettingMode()
{
m_textCursor.setTypeSettingModeActive(m_optionManager->typeSettingMode());
- KoSvgTextShape *shape = selectedShape();
- Q_FOREACH(QObject *obj, m_typeSettingMovementMapper->children()) {
- QAction *a = qobject_cast<QAction*>(obj);
- if (a && shape) {
- a->setEnabled(m_optionManager->typeSettingMode());
- }
- }
+ slotTextTypeUpdated();
}
QRectF SvgTextTool::decorationsRect() const
@@ -1108,13 +1102,16 @@ KoSvgText::WritingMode SvgTextTool::writingMode() const
return KoSvgText::WritingMode(props.propertyOrDefault(KoSvgTextProperties::WritingModeId).toInt());
}
-void SvgTextTool::addMappedAction(KisSignalMapper *mapper, const QString &actionName, const int value)
+void SvgTextTool::addMappedAction(KisSignalMapper *mapper, const QString &actionName, const int value, QActionGroup *group)
{
QAction *a = action(actionName);
if (a) {
connect(a, SIGNAL(triggered()), mapper, SLOT(map()));
mapper->setMapping(a, value);
m_textCursor.registerPropertyAction(a, actionName);
+ if (group && !a->actionGroup()) {
+ group->addAction(a);
+ }
}
}
diff --git a/plugins/tools/svgtexttool/SvgTextTool.h b/plugins/tools/svgtexttool/SvgTextTool.h
index 5acc27f30b..67e6b1537b 100644
--- a/plugins/tools/svgtexttool/SvgTextTool.h
+++ b/plugins/tools/svgtexttool/SvgTextTool.h
@@ -30,6 +30,7 @@ class SvgTextEditor;
class KoSvgTextShape;
class KoInteractionStrategy;
class KUndo2Command;
+class QActionGroup;
class SvgTextTool : public KoToolBase
{
@@ -102,7 +103,7 @@ private:
KoSvgText::WritingMode writingMode() const;
- void addMappedAction(KisSignalMapper* mapper, const QString &actionName, const int value);
+ void addMappedAction(KisSignalMapper* mapper, const QString &actionName, const int value, QActionGroup *group = nullptr);
private Q_SLOTS: