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

Ensure we leave contour mode when there's no contours left in the textshape.

Wolthera van Hövell tot Westerflier48288135b924
diff --git a/libs/flake/text/KoSvgTextShapeOutlineHelper.cpp b/libs/flake/text/KoSvgTextShapeOutlineHelper.cpp
index 256eec2c2f..117abfeef2 100644
--- a/libs/flake/text/KoSvgTextShapeOutlineHelper.cpp
+++ b/libs/flake/text/KoSvgTextShapeOutlineHelper.cpp
@@ -40,7 +40,7 @@ struct KoSvgTextShapeOutlineHelper::Private {
KoSvgTextShape *getPotentialTextShape(const QPointF &point) {
Q_FOREACH(KoShape*shape, canvas->shapeManager()->selection()->selectedEditableShapes()) {
KoSvgTextShape *text = dynamic_cast<KoSvgTextShape*>(shape);
- if (text && !text->internalShapeManager()->shapes().isEmpty()) {
+ if (drawButton(text)) {
if (getButtonRectCorrected(text->boundingRect()).contains(point)) {
return text;
}
@@ -60,6 +60,10 @@ struct KoSvgTextShapeOutlineHelper::Private {
QRectF getButtonRectCorrected(QRectF base) {
return converter()->viewToDocument().mapRect(getButtonRect(converter()->documentToView().mapRect(base)));
}
+
+ bool drawButton(KoSvgTextShape *text) {
+ return text && !text->internalShapeManager()->shapes().isEmpty();
+ }
};
KoSvgTextShapeOutlineHelper::KoSvgTextShapeOutlineHelper(KoCanvasBase *canvas)
@@ -160,7 +164,7 @@ void KoSvgTextShapeOutlineHelper::paint(QPainter *painter, const KoViewConverter
} else {
Q_FOREACH(KoShape* shape, d->canvas->shapeManager()->selection()->selectedEditableShapes()) {
text = dynamic_cast<KoSvgTextShape*>(shape);
- if (text && !text->internalShapeManager()->shapes().isEmpty()) {
+ if (d->drawButton(text)) {
paintTextShape(painter, converter, pal, text, false);
}
}
@@ -173,14 +177,12 @@ QRectF KoSvgTextShapeOutlineHelper::decorationRect()
KoSvgTextShape *text = d->getTextModeShape();
if (text) {
QRectF base = text->boundingRect();
- if (!text->internalShapeManager()->shapes().isEmpty()) {
- base |= d->getButtonRectCorrected(base);
- }
+ base |= d->getButtonRectCorrected(base);
decorationRect = base;
} else {
Q_FOREACH(KoShape* shape, d->canvas->shapeManager()->selection()->selectedEditableShapes()) {
text = dynamic_cast<KoSvgTextShape*>(shape);
- if (text && !text->internalShapeManager()->shapes().isEmpty()) {
+ if (d->drawButton(text)) {
QRectF base = text->boundingRect();
base |= d->getButtonRectCorrected(base);
decorationRect |= base;
@@ -228,7 +230,7 @@ void KoSvgTextShapeOutlineHelper::setDecorationThickness(int thickness)
KoSvgTextShape *KoSvgTextShapeOutlineHelper::contourModeButtonHovered(const QPointF &point)
{
KoSvgTextShape *text = d->getTextModeShape();
- if (text && !text->internalShapeManager()->shapes().isEmpty()) {
+ if (text) {
if (d->getButtonRect(text->boundingRect()).contains(point)) {
return text;
}
@@ -236,6 +238,16 @@ KoSvgTextShape *KoSvgTextShapeOutlineHelper::contourModeButtonHovered(const QPoi
return d->getPotentialTextShape(point);
}
+bool KoSvgTextShapeOutlineHelper::updateTextContourMode()
+{
+ KoSvgTextShape *text = d->getTextModeShape();
+ if (text && !d->drawButton(text)) {
+ toggleTextContourMode(nullptr);
+ return true;
+ }
+ return false;
+}
+
void KoSvgTextShapeOutlineHelper::toggleTextContourMode(KoSvgTextShape *shape)
{
if (d->canvas) {
diff --git a/libs/flake/text/KoSvgTextShapeOutlineHelper.h b/libs/flake/text/KoSvgTextShapeOutlineHelper.h
index 5b72ecff51..76fc26610b 100644
--- a/libs/flake/text/KoSvgTextShapeOutlineHelper.h
+++ b/libs/flake/text/KoSvgTextShapeOutlineHelper.h
@@ -64,6 +64,14 @@ public:
KoSvgTextShape *contourModeButtonHovered(const QPointF &point);
+ /**
+ * @brief updateTextContourMode
+ * This checks if the text contour mode still has shapes,
+ * and otherwise switches out of this mode.
+ * @return whether the mode was updated.
+ */
+ bool updateTextContourMode();
+
void toggleTextContourMode(KoSvgTextShape *shape);
private:
void paintTextShape(QPainter *painter, const KoViewConverter &converter,
diff --git a/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp b/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp
index a3dd37a018..d5c8d47a14 100644
--- a/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp
+++ b/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp
@@ -705,6 +705,11 @@ void DefaultTool::slotReorderFlowShapes(int type)
}
}
+bool DefaultTool::updateTextContourMode()
+{
+ return m_textOutlineHelper->updateTextContourMode();
+}
+
bool DefaultTool::wantsAutoScroll() const
{
return true;
@@ -2319,6 +2324,7 @@ void DefaultToolTextPropertiesInterface::clearSelection()
void DefaultToolTextPropertiesInterface::slotSelectionChanged()
{
+ if (d->parent->updateTextContourMode()) return;
Q_FOREACH(KoShape *shape, d->shapes) {
if (!shape) continue;
shape->removeShapeChangeListener(this);
diff --git a/plugins/tools/defaulttool/defaulttool/DefaultTool.h b/plugins/tools/defaulttool/defaulttool/DefaultTool.h
index c4d8d9a942..a66cf9e3e7 100644
--- a/plugins/tools/defaulttool/defaulttool/DefaultTool.h
+++ b/plugins/tools/defaulttool/defaulttool/DefaultTool.h
@@ -91,6 +91,7 @@ public:
*/
KoFlake::SelectionHandle handleAt(const QPointF &point, bool *innerHandleMeaning = 0);
+ bool updateTextContourMode();
public Q_SLOTS:
void activate(const QSet<KoShape *> &shapes) override;