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

Make some adjustments to allow paragraph property editing in the text tool.

Wolthera van Hövell tot Westerflierd14ecc2689de
diff --git a/libs/flake/text/KoSvgTextPropertiesInterface.h b/libs/flake/text/KoSvgTextPropertiesInterface.h
index f80c6f0212..c804f82993 100644
--- a/libs/flake/text/KoSvgTextPropertiesInterface.h
+++ b/libs/flake/text/KoSvgTextPropertiesInterface.h
@@ -43,6 +43,9 @@ public:
* @param properties -- the properties to set.
*/
virtual void setPropertiesOnSelected(KoSvgTextProperties properties, QSet<KoSvgTextProperties::PropertyId> removeProperties = QSet<KoSvgTextProperties::PropertyId>()) = 0;
+
+ /// Whether the tool is currently selecting a set of characters instead of whole paragraphs.
+ virtual bool spanSelection() = 0;
Q_SIGNALS:
void textSelectionChanged();
};
diff --git a/libs/flake/text/KoSvgTextPropertyData.h b/libs/flake/text/KoSvgTextPropertyData.h
index 1b20954b3a..a9abd33fea 100644
--- a/libs/flake/text/KoSvgTextPropertyData.h
+++ b/libs/flake/text/KoSvgTextPropertyData.h
@@ -28,13 +28,16 @@ struct KRITAFLAKE_EXPORT KoSvgTextPropertyData : public boost::equality_comparab
KoSvgTextProperties commonProperties;
/// The properties that are inherited, so that widgets may be set correctly.
- KoSvgTextProperties inheritedProperties = KoSvgTextProperties::defaultProperties();
+ KoSvgTextProperties inheritedProperties {KoSvgTextProperties::defaultProperties()};
/// The properties that are not common (tri-state) between the selected text.
QSet<KoSvgTextProperties::PropertyId> tristate;
+ /// Whether we're currently selecting a span of text as opposed to editing the whole paragraph.
+ bool spanSelection {false};
+
bool operator==(const KoSvgTextPropertyData &rhs) const {
- return commonProperties == rhs.commonProperties && inheritedProperties == rhs.inheritedProperties && tristate == rhs.tristate;
+ return commonProperties == rhs.commonProperties && inheritedProperties == rhs.inheritedProperties && tristate == rhs.tristate && spanSelection == rhs.spanSelection;
}
};
diff --git a/libs/flake/text/lager/KoSvgTextPropertiesModel.cpp b/libs/flake/text/lager/KoSvgTextPropertiesModel.cpp
index 738b8f52f1..f721b2fa08 100644
--- a/libs/flake/text/lager/KoSvgTextPropertiesModel.cpp
+++ b/libs/flake/text/lager/KoSvgTextPropertiesModel.cpp
@@ -234,6 +234,7 @@ KoSvgTextPropertiesModel::KoSvgTextPropertiesModel(lager::cursor<KoSvgTextProper
, LAGER_QT(wordBreakState) {textData.zoom(propertyModifyState(KoSvgTextProperties::WordBreakId))}
, LAGER_QT(lineBreak){textData.zoom(createTextProperty(KoSvgTextProperties::LineBreakId)).zoom(integerProperty)}
, LAGER_QT(lineBreakState) {textData.zoom(propertyModifyState(KoSvgTextProperties::LineBreakId))}
+ , LAGER_QT(spanSelection) {textData[&KoSvgTextPropertyData::spanSelection]}
{
lager::watch(textData, std::bind(&KoSvgTextPropertiesModel::textPropertyChanged, this));
lager::watch(fontSizeData, std::bind(&KoSvgTextPropertiesModel::fontSizeChanged, this));
diff --git a/libs/flake/text/lager/KoSvgTextPropertiesModel.h b/libs/flake/text/lager/KoSvgTextPropertiesModel.h
index 53c1fb3f36..15ceeff951 100644
--- a/libs/flake/text/lager/KoSvgTextPropertiesModel.h
+++ b/libs/flake/text/lager/KoSvgTextPropertiesModel.h
@@ -148,6 +148,8 @@ public:
LAGER_QT_CURSOR(int, lineBreak);
LAGER_QT_CURSOR(PropertyState, lineBreakState);
+ /// We're selecting a span of text instead of the whole paragraph.
+ LAGER_QT_CURSOR(bool, spanSelection);
Q_SIGNALS:
void textPropertyChanged();
diff --git a/libs/ui/KisTextPropertiesManager.cpp b/libs/ui/KisTextPropertiesManager.cpp
index 54547818d3..b926616759 100644
--- a/libs/ui/KisTextPropertiesManager.cpp
+++ b/libs/ui/KisTextPropertiesManager.cpp
@@ -140,6 +140,7 @@ void KisTextPropertiesManager::slotInterfaceSelectionChanged() {
KoSvgTextPropertyData textData = textDataProperties(props, propIds);
textData.inheritedProperties = d->interface->getInheritedProperties();
+ textData.spanSelection = d->interface->spanSelection();
d->lastSetTextData = textData;
d->provider->setTextPropertyData(textData);
diff --git a/plugins/dockers/textproperties/qml/TextProperties.qml b/plugins/dockers/textproperties/qml/TextProperties.qml
index 77b63b6a3e..5fd00f15c8 100644
--- a/plugins/dockers/textproperties/qml/TextProperties.qml
+++ b/plugins/dockers/textproperties/qml/TextProperties.qml
@@ -164,6 +164,7 @@ Rectangle {
WritingMode {
}
Direction{
+ enabled: !properties.spanSelection;
}
TextIndent{
}
diff --git a/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp b/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp
index 87e950bc23..29283f6317 100644
--- a/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp
+++ b/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp
@@ -1980,8 +1980,15 @@ void DefaultToolTextPropertiesInterface::setPropertiesOnSelected(KoSvgTextProper
}
}
+bool DefaultToolTextPropertiesInterface::spanSelection()
+{
+ return true;
+}
+
void DefaultToolTextPropertiesInterface::notifyCursorPosChanged(int pos, int anchor)
{
+ Q_UNUSED(pos)
+ Q_UNUSED(anchor)
emit textSelectionChanged();
}
@@ -1992,24 +1999,22 @@ void DefaultToolTextPropertiesInterface::notifyMarkupChanged()
void DefaultToolTextPropertiesInterface::notifyShapeChanged(KoShape::ChangeType type, KoShape *shape)
{
+ Q_UNUSED(type)
+ Q_UNUSED(shape)
emit textSelectionChanged();
}
void DefaultToolTextPropertiesInterface::slotSelectionChanged()
{
- if (!d->shapes.isEmpty()) {
- for (int i = 0; i< d->shapes.size(); i++) {
- KoShape *shape = d->shapes.takeFirst();
- shape->removeShapeChangeListener(this);
- }
- }
QList<KoShape*> shapes = d->parent->canvas()->selectedShapesProxy()->selection()->selectedShapes();
- if (!shapes.isEmpty()) {
- for (int i = 0; i< shapes.size(); i++) {
- KoShape *shape = shapes.takeFirst();
- shape->addShapeChangeListener(this);
- d->shapes.append(shape);
- }
+ Q_FOREACH(KoShape *shape, d->shapes) {
+ shape->removeShapeChangeListener(this);
+ }
+
+ d->shapes = shapes;
+
+ Q_FOREACH(KoShape *shape, d->shapes) {
+ shape->addShapeChangeListener(this);
}
emit textSelectionChanged();
}
diff --git a/plugins/tools/defaulttool/defaulttool/DefaultTool.h b/plugins/tools/defaulttool/defaulttool/DefaultTool.h
index 88e03fa78b..a89c11b42a 100644
--- a/plugins/tools/defaulttool/defaulttool/DefaultTool.h
+++ b/plugins/tools/defaulttool/defaulttool/DefaultTool.h
@@ -215,6 +215,7 @@ public:
virtual QList<KoSvgTextProperties> getSelectedProperties() override;
virtual KoSvgTextProperties getInheritedProperties() override;
virtual void setPropertiesOnSelected(KoSvgTextProperties properties, QSet<KoSvgTextProperties::PropertyId> removeProperties = QSet<KoSvgTextProperties::PropertyId>()) override;
+ virtual bool spanSelection() override;
virtual void notifyCursorPosChanged(int pos, int anchor) override;
virtual void notifyMarkupChanged() override;
diff --git a/plugins/tools/svgtexttool/SvgTextCursor.cpp b/plugins/tools/svgtexttool/SvgTextCursor.cpp
index fba53450f4..69124164a4 100644
--- a/plugins/tools/svgtexttool/SvgTextCursor.cpp
+++ b/plugins/tools/svgtexttool/SvgTextCursor.cpp
@@ -333,13 +333,25 @@ KoSvgTextProperties SvgTextCursor::currentTextProperties() const
QList<KoSvgTextProperties> SvgTextCursor::propertiesForRange() const
{
if (!d->shape) return QList<KoSvgTextProperties>();
- return d->shape->propertiesForRange(qMin(d->pos, d->anchor), qMax(d->pos, d->anchor));
+ int start = -1;
+ int end = -1;
+ if (d->pos != d->anchor) {
+ start = qMin(d->pos, d->anchor);
+ end = qMax(d->pos, d->anchor);
+ }
+ return d->shape->propertiesForRange(start, end);
}
void SvgTextCursor::mergePropertiesIntoSelection(const KoSvgTextProperties props, const QSet<KoSvgTextProperties::PropertyId> removeProperties)
{
- if (d->shape && hasSelection()) {
- KUndo2Command *cmd = new SvgTextMergePropertiesRangeCommand(d->shape, props, d->pos, d->anchor, removeProperties);
+ if (d->shape) {
+ int start = -1;
+ int end = -1;
+ if (hasSelection()) {
+ start = d->pos;
+ end = d->anchor;
+ }
+ KUndo2Command *cmd = new SvgTextMergePropertiesRangeCommand(d->shape, props, start, end, removeProperties);
addCommandToUndoAdapter(cmd);
}
}
@@ -1446,6 +1458,11 @@ void SvgTextPropertyCursor::setPropertiesOnSelected(KoSvgTextProperties properti
d->parent->mergePropertiesIntoSelection(properties, removeProperties);
}
+bool SvgTextPropertyCursor::spanSelection()
+{
+ return d->parent->hasSelection();
+}
+
void SvgTextPropertyCursor::emitSelectionChange()
{
emit textSelectionChanged();
diff --git a/plugins/tools/svgtexttool/SvgTextCursor.h b/plugins/tools/svgtexttool/SvgTextCursor.h
index f63f7bb7b7..cfb0f4c85b 100644
--- a/plugins/tools/svgtexttool/SvgTextCursor.h
+++ b/plugins/tools/svgtexttool/SvgTextCursor.h
@@ -235,7 +235,7 @@ public:
virtual QList<KoSvgTextProperties> getSelectedProperties() override;
virtual KoSvgTextProperties getInheritedProperties() override;
virtual void setPropertiesOnSelected(KoSvgTextProperties properties, QSet<KoSvgTextProperties::PropertyId> removeProperties = QSet<KoSvgTextProperties::PropertyId>()) override;
-
+ virtual bool spanSelection() override;
void emitSelectionChange();
private:
struct Private;