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

Introduce KoSvgTextShapeOutlineHelper for going into contour mode.

Wolthera van Hövell tot Westerflier948717851915
diff --git a/libs/flake/CMakeLists.txt b/libs/flake/CMakeLists.txt
index f05b1dc680..b2a49240f6 100644
--- a/libs/flake/CMakeLists.txt
+++ b/libs/flake/CMakeLists.txt
@@ -247,6 +247,7 @@ set(kritaflake_SRCS
text/KoFontGlyphModel.cpp
text/KoOpenTypeFeatureInfoFactory.cpp
text/data/KoUnicodeBlockData.cpp
+ text/KoSvgTextShapeOutlineHelper.cpp
resources/KoSvgSymbolCollectionResource.cpp
resources/KoGamutMask.cpp
diff --git a/libs/flake/KoCanvasBase.h b/libs/flake/KoCanvasBase.h
index 79f82840e7..cab031c623 100644
--- a/libs/flake/KoCanvasBase.h
+++ b/libs/flake/KoCanvasBase.h
@@ -27,6 +27,7 @@ class KoCanvasController;
class KoShape;
class KoSnapGuide;
class KoSelectedShapesProxy;
+class KoSvgTextShape;
class QWidget;
class QCursor;
@@ -115,6 +116,17 @@ public:
*/
virtual KoSelectedShapesProxy *selectedShapesProxy() const = 0;
+ /**
+ * @brief textShapeManagerEnabled
+ * textShape for which we're currently editing the child shapes.
+ * @return KoSvgTextShape that is currently set.
+ */
+ virtual KoSvgTextShape *textShapeManagerEnabled() const {
+ return nullptr;
+ }
+ virtual void setTextShapeManagerEnabled(KoSvgTextShape *source) {
+ Q_UNUSED(source)
+ }
/**
* Tell the canvas to repaint the specified rectangle. The coordinates
* are document coordinates, not view coordinates.
diff --git a/libs/flake/text/KoSvgTextShape.cpp b/libs/flake/text/KoSvgTextShape.cpp
index c92d5871e3..8a61bb2403 100644
--- a/libs/flake/text/KoSvgTextShape.cpp
+++ b/libs/flake/text/KoSvgTextShape.cpp
@@ -2098,6 +2098,11 @@ void KoSvgTextShape::setShapesSubtract(QList<KoShape *> shapesSubtract)
update();
}
+QList<QPainterPath> KoSvgTextShape::textWrappingAreas() const
+{
+ return d->currentTextWrappingAreas;
+}
+
QList<KoShape *> KoSvgTextShape::shapesSubtract() const
{
return d->shapesSubtract;
diff --git a/libs/flake/text/KoSvgTextShape.h b/libs/flake/text/KoSvgTextShape.h
index 90d2be2159..2510ec258b 100644
--- a/libs/flake/text/KoSvgTextShape.h
+++ b/libs/flake/text/KoSvgTextShape.h
@@ -109,6 +109,18 @@ public:
*/
void setShapesSubtract(QList<KoShape*> shapesSubtract);
+ /**
+ * @brief textWrappingAreas
+ * The text wrapping areas are computed from shapesInside()
+ * and shapesSubtract(), as well as the text properties
+ * ShapeMargin and ShapePadding. This returns the computed
+ * wrapping areas, in the local coordinates of the shape.
+ *
+ * @seealso outline()
+ * @return a list of computed text wrapping areas.
+ */
+ QList<QPainterPath> textWrappingAreas() const;
+
/**
* @brief shapesSubtract
* @return list of subtract shapes.
diff --git a/libs/flake/text/KoSvgTextShapeOutlineHelper.cpp b/libs/flake/text/KoSvgTextShapeOutlineHelper.cpp
new file mode 100644
index 0000000000..fc1267df47
--- /dev/null
+++ b/libs/flake/text/KoSvgTextShapeOutlineHelper.cpp
@@ -0,0 +1,209 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#include "KoSvgTextShapeOutlineHelper.h"
+
+#include <KoCanvasBase.h>
+#include <kis_icon.h>
+#include <KoCanvasResourceProvider.h>
+
+#include <KoSvgTextShape.h>
+#include <KisHandlePainterHelper.h>
+#include <KoShapeManager.h>
+#include <KoSelection.h>
+#include <QApplication>
+#include <QPalette>
+
+const int BUTTON_ICON_SIZE = 16;
+const int BUTTON_PADDING = 4;
+const int BUTTON_CORNER_ROUND = 1;
+const QString ICON_EXIT = "object-ungroup-calligra";
+const QString ICON_ENTER = "object-group-calligra";
+
+struct KoSvgTextShapeOutlineHelper::Private {
+ Private(KoCanvasBase *canvasBase): canvas(canvasBase) {
+ }
+ KoCanvasBase *canvas;
+ int handleRadius = 7;
+ int decorationThickness = 1;
+
+ bool drawBoundingRect = true;
+ bool drawTextWrappingArea = false;
+ bool drawOutline = false;
+
+ KoSvgTextShape *getTextModeShape() {
+ return canvas->textShapeManagerEnabled();
+ }
+
+ KoSvgTextShape *getPotentialTextShape(const QPointF &point) {
+ Q_FOREACH(KoShape*shape, canvas->shapeManager()->selection()->selectedEditableShapes()) {
+ KoSvgTextShape *text = dynamic_cast<KoSvgTextShape*>(shape);
+ if (text) {
+ if (getButtonRectCorrected(text->boundingRect()).contains(point)) {
+ return text;
+ }
+ }
+ }
+ return nullptr;
+ }
+
+ KoViewConverter *converter() const {
+ return canvas->viewConverter();
+ }
+
+ QRectF getButtonRect(QRectF base) {
+ const int buttonSize = BUTTON_ICON_SIZE + (2* BUTTON_PADDING);
+ return QRectF(base.topRight(), QSizeF(buttonSize, buttonSize));
+ }
+ QRectF getButtonRectCorrected(QRectF base) {
+ return converter()->viewToDocument().mapRect(getButtonRect(converter()->documentToView().mapRect(base)));
+ }
+};
+
+KoSvgTextShapeOutlineHelper::KoSvgTextShapeOutlineHelper(KoCanvasBase *canvas)
+ : d(new Private(canvas))
+{
+}
+
+KoSvgTextShapeOutlineHelper::~KoSvgTextShapeOutlineHelper()
+{
+
+}
+
+void KoSvgTextShapeOutlineHelper::paintTextShape(QPainter *painter, const KoViewConverter &converter,
+ const QPalette &pal, KoSvgTextShape *text,
+ bool contourModeActive) {
+ painter->save();
+ KisHandlePainterHelper helper =
+ KoShape::createHandlePainterHelperView(painter, text, converter, d->handleRadius, d->decorationThickness);
+ helper.setHandleStyle(KisHandleStyle::secondarySelection());
+ if (contourModeActive) {
+ if (d->drawOutline) {
+ Q_FOREACH(KoShape *shape, text->internalShapeManager()->shapes()) {
+ helper.drawPath(shape->transformation().map(shape->outline()));
+ }
+ }
+ if (d->drawBoundingRect) {
+ QPainterPath rect;
+ rect.addRect(text->outlineRect());
+ helper.drawPath(rect);
+ }
+ }
+ if (d->drawTextWrappingArea) {
+ Q_FOREACH(const QPainterPath path, text->textWrappingAreas()) {
+ helper.drawPath(path);
+ }
+ }
+ painter->restore();
+
+ painter->save();
+ //painter->setTransform(converter.viewToDocument() *
+ // painter->transform());
+ QIcon icon = contourModeActive? KisIconUtils::loadIcon(ICON_EXIT): KisIconUtils::loadIcon(ICON_ENTER);
+ QPixmap pm = icon.pixmap(BUTTON_ICON_SIZE, BUTTON_ICON_SIZE);
+ painter->setBrush(contourModeActive? pal.highlight(): pal.button());
+ QPen pen;
+ pen.setColor(contourModeActive? pal.highlightedText().color(): pal.buttonText().color());
+ pen.setCosmetic(true);
+ pen.setWidthF(d->decorationThickness);
+ painter->setPen(pen);
+ const QRectF buttonRect = d->getButtonRect(converter.documentToView().mapRect(text->boundingRect()));
+ painter->drawRoundedRect(buttonRect, BUTTON_CORNER_ROUND, BUTTON_CORNER_ROUND);
+ painter->drawPixmap(buttonRect.topLeft()+QPointF(BUTTON_PADDING, BUTTON_PADDING), pm);
+ painter->restore();
+}
+
+void KoSvgTextShapeOutlineHelper::paint(QPainter *painter, const KoViewConverter &converter)
+{
+ const QPalette pal = qApp->palette();
+ KoSvgTextShape *text = d->getTextModeShape();
+ if (text) {
+ paintTextShape(painter, converter, pal, text, true);
+ } else {
+ Q_FOREACH(KoShape* shape, d->canvas->shapeManager()->selection()->selectedEditableShapes()) {
+ text = dynamic_cast<KoSvgTextShape*>(shape);
+ if (text && !text->internalShapeManager()->shapes().isEmpty()) {
+ paintTextShape(painter, converter, pal, text, false);
+ }
+ }
+ }
+}
+
+QRectF KoSvgTextShapeOutlineHelper::decorationRect()
+{
+ QRectF decorationRect;
+ KoSvgTextShape *text = d->getTextModeShape();
+ if (text) {
+ QRectF base = text->boundingRect();
+ 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()) {
+ QRectF base = text->boundingRect();
+ base |= d->getButtonRectCorrected(base);
+ decorationRect |= base;
+ }
+ }
+ }
+ return decorationRect;
+}
+
+void KoSvgTextShapeOutlineHelper::setDrawBoundingRect(bool enable)
+{
+ d->drawBoundingRect = enable;
+}
+
+bool KoSvgTextShapeOutlineHelper::drawBoundingRect() const
+{
+ return d->drawBoundingRect;
+}
+
+void KoSvgTextShapeOutlineHelper::setDrawTextWrappingArea(bool enable)
+{
+ d->drawTextWrappingArea = enable;
+}
+
+void KoSvgTextShapeOutlineHelper::setDrawShapeOutlines(bool enable)
+{
+ d->drawOutline = enable;
+}
+
+bool KoSvgTextShapeOutlineHelper::drawShapeOutlines() const
+{
+ return d->drawOutline;
+}
+
+void KoSvgTextShapeOutlineHelper::setHandleRadius(int radius)
+{
+ d->handleRadius = radius;
+}
+
+void KoSvgTextShapeOutlineHelper::setDecorationThickness(int thickness)
+{
+ d->decorationThickness = thickness;
+}
+
+KoSvgTextShape *KoSvgTextShapeOutlineHelper::contourModeButtonHovered(const QPointF &point)
+{
+ if (d->getTextModeShape()) {
+ if (d->getButtonRect(d->getTextModeShape()->boundingRect()).contains(point)) {
+ return d->getTextModeShape();
+ }
+ }
+ return d->getPotentialTextShape(point);
+}
+
+void KoSvgTextShapeOutlineHelper::toggleTextContourMode(KoSvgTextShape *shape)
+{
+ if (d->canvas) {
+ if (shape == d->canvas->textShapeManagerEnabled()) {
+ d->canvas->setTextShapeManagerEnabled(nullptr);
+ } else {
+ d->canvas->setTextShapeManagerEnabled(shape);
+ }
+ }
+}
diff --git a/libs/flake/text/KoSvgTextShapeOutlineHelper.h b/libs/flake/text/KoSvgTextShapeOutlineHelper.h
new file mode 100644
index 0000000000..76f0bba71b
--- /dev/null
+++ b/libs/flake/text/KoSvgTextShapeOutlineHelper.h
@@ -0,0 +1,75 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#ifndef KOSVGTEXTSHAPEOUTLINEHELPER_H
+#define KOSVGTEXTSHAPEOUTLINEHELPER_H
+
+#include <KoCanvasBase.h>
+#include <KoViewConverter.h>
+
+#include <QPainter>
+#include <QPointF>
+#include <QScopedPointer>
+
+#include <kritaflake_export.h>
+
+class KoSvgTextShape;
+/**
+ * @brief The KoSvgTextShapeOutlineHelper class
+ * helper class that draws the text outlines and
+ * contour mode button of the KoSvgTextTool.
+ */
+class KRITAFLAKE_EXPORT KoSvgTextShapeOutlineHelper
+{
+public:
+ KoSvgTextShapeOutlineHelper(KoCanvasBase *canvas);
+ ~KoSvgTextShapeOutlineHelper();
+
+ void paint(QPainter *painter, const KoViewConverter &converter);
+
+ /**
+ * @brief decorationRect
+ * @return the current rect necessary.
+ */
+ QRectF decorationRect();
+
+ /**
+ * @brief setDrawBoundingRect
+ * Whether to draw the bounding rect of the shapes.
+ * @param enable
+ */
+ void setDrawBoundingRect(bool enable);
+ bool drawBoundingRect() const;
+
+ /**
+ * @brief setDrawTextWrappingArea
+ * draw the wrapping area. The wrapping area is computer from
+ * the shapes as well as padding and margin.
+ */
+ void setDrawTextWrappingArea(bool enable);
+ bool drawTextWrappingArea() const;
+
+ /**
+ * @brief setDrawShapeOutlines
+ * Draw the shape outlines instead of only the rect.
+ */
+ void setDrawShapeOutlines(bool enable);
+ bool drawShapeOutlines() const;
+
+ void setHandleRadius(int radius);
+ void setDecorationThickness(int thickness);
+
+ KoSvgTextShape *contourModeButtonHovered(const QPointF &point);
+
+ void toggleTextContourMode(KoSvgTextShape *shape);
+private:
+ void paintTextShape(QPainter *painter, const KoViewConverter &converter,
+ const QPalette &pal, KoSvgTextShape *text,
+ bool contourModeActive = false);
+ struct Private;
+ QScopedPointer<Private> d;
+};
+
+#endif // KOSVGTEXTSHAPEOUTLINEHELPER_H
diff --git a/libs/flake/tools/KoPathTool.cpp b/libs/flake/tools/KoPathTool.cpp
index 1e906cceb0..f4ac88a664 100644
--- a/libs/flake/tools/KoPathTool.cpp
+++ b/libs/flake/tools/KoPathTool.cpp
@@ -86,6 +86,7 @@ struct KoPathTool::PathSegment {
KoPathTool::KoPathTool(KoCanvasBase *canvas)
: KoToolBase(canvas)
, m_pointSelection(this)
+ , m_textOutlineHelper(new KoSvgTextShapeOutlineHelper(canvas))
{
m_actionPathPointCorner = action("pathpoint-corner");
m_actionPathPointSmooth = action("pathpoint-smooth");
@@ -104,6 +105,8 @@ KoPathTool::KoPathTool(KoCanvasBase *canvas)
m_actionConvertToPath = action("convert-to-path");
m_contextMenu.reset(new QMenu());
+ m_textOutlineHelper->setDrawBoundingRect(true);
+ m_textOutlineHelper->setDrawShapeOutlines(false);
m_selectCursor = QCursor(QIcon(":/cursor-needle.svg").pixmap(32), 0, 0);
m_moveCursor = QCursor(QIcon(":/cursor-needle-move.svg").pixmap(32), 0, 0);
@@ -437,6 +440,9 @@ void KoPathTool::breakAtSegment()
void KoPathTool::paint(QPainter &painter, const KoViewConverter &converter)
{
Q_D(KoToolBase);
+ m_textOutlineHelper->setDecorationThickness(decorationThickness());
+ m_textOutlineHelper->setHandleRadius(handleRadius());
+ m_textOutlineHelper->paint(&painter, converter);
Q_FOREACH (KoPathShape *shape, m_pointSelection.selectedShapes()) {
KisHandlePainterHelper helper =
@@ -533,6 +539,8 @@ QRectF KoPathTool::decorationsRect() const
newDecorationsRect |= kisGrowRect(rect, handleDocRadius());
}
+ newDecorationsRect |= m_textOutlineHelper->decorationRect();
+
return newDecorationsRect;
}
@@ -551,10 +559,15 @@ void KoPathTool::mousePressEvent(KoPointerEvent *event)
mouseMoveEvent(event);
}
+ if (KoSvgTextShape *shape = m_textOutlineHelper->contourModeButtonHovered(event->point)) {
+ m_textOutlineHelper->toggleTextContourMode(shape);
+ event->accept();
+ }
// we are moving if we hit a point and use the left mouse button
if (m_activeHandle) {
m_currentStrategy.reset(m_activeHandle->handleMousePress(event));
} else {
+
if (event->button() & Qt::LeftButton) {
// check if we hit a path segment
diff --git a/libs/flake/tools/KoPathTool.h b/libs/flake/tools/KoPathTool.h
index 50c4c5b0f3..46cffd8700 100644
--- a/libs/flake/tools/KoPathTool.h
+++ b/libs/flake/tools/KoPathTool.h
@@ -18,6 +18,7 @@
#include <QCursor>
#include <KoShapeFillResourceConnector.h>
#include "KoPathPointTypeCommand.h"
+#include <KoSvgTextShapeOutlineHelper.h>
class QActionGroup;
class QButtonGroup;
@@ -140,6 +141,7 @@ private:
QAction *m_actionConvertToPath;
QCursor m_moveCursor;
QScopedPointer<QMenu> m_contextMenu;
+ QScopedPointer<KoSvgTextShapeOutlineHelper> m_textOutlineHelper;
KisSignalAutoConnectionsStore m_canvasConnections;
KoShapeFillResourceConnector m_shapeFillResourceConnector;
diff --git a/libs/ui/canvas/kis_canvas2.cpp b/libs/ui/canvas/kis_canvas2.cpp
index ba47148827..533c36e7ad 100644
--- a/libs/ui/canvas/kis_canvas2.cpp
+++ b/libs/ui/canvas/kis_canvas2.cpp
@@ -190,7 +190,7 @@ public:
KoShapeManager shapeManager;
KisSelectedShapesProxy selectedShapesProxy;
bool currentCanvasIsOpenGL = true;
- bool textShapeManagerEnabled = false;
+ KoSvgTextShape *textShape = nullptr;
int openGLFilterMode = 0;
KisToolProxy toolProxy;
KisPrescaledProjectionSP prescaledProjection;
@@ -576,15 +576,15 @@ KoShapeManager* KisCanvas2::globalShapeManager() const
return &m_d->shapeManager;
}
-bool KisCanvas2::textShapeManagerEnabled() const
+KoSvgTextShape *KisCanvas2::textShapeManagerEnabled() const
{
- return m_d->textShapeManagerEnabled;
+ return m_d->textShape;
}
-void KisCanvas2::setTextShapeManagerEnabled(const bool enable)
+void KisCanvas2::setTextShapeManagerEnabled(KoSvgTextShape *source)
{
- if (m_d->textShapeManagerEnabled == enable) return;
- m_d->textShapeManagerEnabled = enable;
+ if (m_d->textShape == source) return;
+ m_d->textShape = source;
slotTrySwitchShapeManager();
}
@@ -593,13 +593,11 @@ KoShapeManager *KisCanvas2::localShapeManager() const
KisNodeSP node = m_d->view->currentNode();
KoShapeManager *localShapeManager = fetchShapeManagerFromNode(node);
- if (m_d->textShapeManagerEnabled) {
- Q_FOREACH(KoShape*shape, localShapeManager->selection()->selectedEditableShapes()) {
- KoSvgTextShape *text = dynamic_cast<KoSvgTextShape*>(shape);
- if (text) {
- localShapeManager = text->internalShapeManager();
- break;
- }
+ if (m_d->textShape) {
+ if (localShapeManager && localShapeManager->shapes().contains(m_d->textShape)) {
+ localShapeManager = m_d->textShape->internalShapeManager();
+ } else {
+ m_d->textShape = nullptr;
}
}
diff --git a/libs/ui/canvas/kis_canvas2.h b/libs/ui/canvas/kis_canvas2.h
index d7035454ea..5ca5377eb5 100644
--- a/libs/ui/canvas/kis_canvas2.h
+++ b/libs/ui/canvas/kis_canvas2.h
@@ -47,6 +47,7 @@ class KisCoordinatesConverter;
class KoViewConverter;
class KisAbstractCanvasWidget;
class KisPopupPalette;
+class KoSvgTextShape;
/**
@@ -109,8 +110,8 @@ public: // KoCanvasBase implementation
*/
KoShapeManager *globalShapeManager() const;
- bool textShapeManagerEnabled() const;
- void setTextShapeManagerEnabled(const bool enable);
+ KoSvgTextShape *textShapeManagerEnabled() const override;
+ void setTextShapeManagerEnabled(KoSvgTextShape *source) override;
/**
* Return shape manager associated with the currently active node.
diff --git a/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp b/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp
index 1560e4e347..b995e8903d 100644
--- a/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp
+++ b/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp
@@ -53,6 +53,7 @@
#include "KisTextPropertiesManager.h"
#include <kis_signal_compressor.h>
#include <KoInteractionStrategyFactory.h>
+#include <KisHandlePainterHelper.h>
#include "kis_document_aware_spin_box_unit_manager.h"
@@ -417,6 +418,7 @@ DefaultTool::DefaultTool(KoCanvasBase *canvas, bool connectToSelectedShapesProxy
, m_lastHandle(KoFlake::NoHandle)
, m_hotPosition(KoFlake::TopLeft)
, m_mouseWasInsideHandles(false)
+ , m_textOutlineHelper(new KoSvgTextShapeOutlineHelper(canvas))
, m_selectionHandler(new SelectionHandler(this))
, m_tabbedOptionWidget(0)
, m_textPropertyInterface(new DefaultToolTextPropertiesInterface(this))
@@ -471,6 +473,9 @@ DefaultTool::DefaultTool(KoCanvasBase *canvas, bool connectToSelectedShapesProxy
connect(canvas->selectedShapesProxy(), SIGNAL(selectionChanged()), m_textPropertyInterface, SLOT(slotSelectionChanged()));
connect(canvas->selectedShapesProxy(), SIGNAL(selectionContentChanged()), this, SLOT(repaintDecorations()));
}
+
+ m_textOutlineHelper->setDrawBoundingRect(false);
+ m_textOutlineHelper->setDrawShapeOutlines(true);
}
DefaultTool::~DefaultTool()
@@ -859,6 +864,8 @@ void DefaultTool::paint(QPainter &painter, const KoViewConverter &converter)
KisNodeSP node = kisCanvas->viewManager()->nodeManager()->activeNode();
const bool isSelectionMask = node && node->inherits("KisSelectionMask");
m_decorator->setForceShapeOutlines(isSelectionMask);
+
+
}
m_decorator->setSelection(selection);
@@ -871,6 +878,10 @@ void DefaultTool::paint(QPainter &painter, const KoViewConverter &converter)
m_decorator->paint(painter, converter);
}
+ m_textOutlineHelper->setHandleRadius(handleRadius());
+ m_textOutlineHelper->setDecorationThickness(decorationThickness());
+ m_textOutlineHelper->paint(&painter, converter);
+
KoInteractionTool::paint(painter, converter);
painter.save();
@@ -903,6 +914,12 @@ void DefaultTool::mousePressEvent(KoPointerEvent *event)
return;
}
+ if (KoSvgTextShape *shape = m_textOutlineHelper->contourModeButtonHovered(event->point)) {
+ m_textOutlineHelper->toggleTextContourMode(shape);
+ event->accept();
+ updateCursor();
+ return;
+ }
KoInteractionTool::mousePressEvent(event);
updateCursor();
}
@@ -1046,6 +1063,7 @@ QRectF DefaultTool::decorationsRect() const
if (canvas()->snapGuide()->isSnapping()) {
dirtyRect |= canvas()->snapGuide()->boundingRect();
}
+ dirtyRect |= m_textOutlineHelper->decorationRect();
return dirtyRect;
}
diff --git a/plugins/tools/defaulttool/defaulttool/DefaultTool.h b/plugins/tools/defaulttool/defaulttool/DefaultTool.h
index 9c5e87101e..8f9eb4ff22 100644
--- a/plugins/tools/defaulttool/defaulttool/DefaultTool.h
+++ b/plugins/tools/defaulttool/defaulttool/DefaultTool.h
@@ -14,6 +14,7 @@
#include <commands/KoShapeAlignCommand.h>
#include <commands/KoShapeReorderCommand.h>
#include "SelectionDecorator.h"
+#include <KoSvgTextShapeOutlineHelper.h>
#include "KoShapeMeshGradientHandles.h"
#include <KoSvgTextPropertiesInterface.h>
@@ -185,6 +186,7 @@ private:
QPointF m_lastPoint;
QScopedPointer<SelectionDecorator> m_decorator;
+ QScopedPointer<KoSvgTextShapeOutlineHelper> m_textOutlineHelper;
KoShapeMeshGradientHandles::Handle m_selectedMeshHandle;
KoShapeMeshGradientHandles::Handle m_hoveredMeshHandle;
diff --git a/plugins/tools/defaulttool/defaulttool/DefaultToolGeometryWidget.cpp b/plugins/tools/defaulttool/defaulttool/DefaultToolGeometryWidget.cpp
index e19bd6e818..51213ff8d1 100644
--- a/plugins/tools/defaulttool/defaulttool/DefaultToolGeometryWidget.cpp
+++ b/plugins/tools/defaulttool/defaulttool/DefaultToolGeometryWidget.cpp
@@ -113,9 +113,6 @@ DefaultToolGeometryWidget::DefaultToolGeometryWidget(KoInteractionTool *tool, QW
cmbPaintOrder->addItem(KisIconUtils::loadIcon("paint-order-marker-stroke-fill"), i18n("Markers, Stroke, Fill"));
connect(cmbPaintOrder, SIGNAL(currentIndexChanged(int)), SLOT(slotPaintOrderChanged()));
- connect(btnInternalShapes, SIGNAL(toggled(bool)), this, SLOT(slotUpdateInternalShapes()));
-
-
dblOpacity->setRange(0.0, 1.0, 2);
dblOpacity->setSingleStep(0.01);
dblOpacity->setFastSliderStep(0.1);
@@ -369,15 +366,6 @@ void DefaultToolGeometryWidget::slotUpdatePaintOrder() {
}
}
-
-void DefaultToolGeometryWidget::slotUpdateInternalShapes()
-{
- KisCanvas2 *canvas = dynamic_cast<KisCanvas2*>(m_tool->canvas());
- if (canvas) {
- canvas->setTextShapeManagerEnabled(btnInternalShapes->isChecked());
- }
-}
-
void DefaultToolGeometryWidget::slotUpdateSizeBoxes(bool updateAspect)
{
if (!isVisible()) return;
diff --git a/plugins/tools/defaulttool/defaulttool/DefaultToolGeometryWidget.h b/plugins/tools/defaulttool/defaulttool/DefaultToolGeometryWidget.h
index 068a29616b..ef78b3c5ee 100644
--- a/plugins/tools/defaulttool/defaulttool/DefaultToolGeometryWidget.h
+++ b/plugins/tools/defaulttool/defaulttool/DefaultToolGeometryWidget.h
@@ -54,8 +54,6 @@ private Q_SLOTS:
void slotPaintOrderChanged();
void slotUpdatePaintOrder();
- void slotUpdateInternalShapes();
-
private:
KoInteractionTool *m_tool;
QScopedPointer<KisAspectRatioLocker> m_sizeAspectLocker;
diff --git a/plugins/tools/defaulttool/defaulttool/DefaultToolGeometryWidget.ui b/plugins/tools/defaulttool/defaulttool/DefaultToolGeometryWidget.ui
index 602a444ced..8ccc0c2e9e 100644
--- a/plugins/tools/defaulttool/defaulttool/DefaultToolGeometryWidget.ui
+++ b/plugins/tools/defaulttool/defaulttool/DefaultToolGeometryWidget.ui
@@ -236,16 +236,6 @@
<item>
<widget class="QComboBox" name="cmbPaintOrder"/>
</item>
- <item>
- <widget class="QPushButton" name="btnInternalShapes">
- <property name="text">
- <string>Internal Shapes</string>
- </property>
- <property name="checkable">
- <bool>true</bool>
- </property>
- </widget>
- </item>
<item>
<widget class="KisShapePropertySlider" name="dblOpacity" native="true"/>
</item>
diff --git a/plugins/tools/svgtexttool/SvgTextTool.cpp b/plugins/tools/svgtexttool/SvgTextTool.cpp
index b97e2fefaa..f86a9812dc 100644
--- a/plugins/tools/svgtexttool/SvgTextTool.cpp
+++ b/plugins/tools/svgtexttool/SvgTextTool.cpp
@@ -97,6 +97,7 @@ SvgTextTool::SvgTextTool(KoCanvasBase *canvas)
: KoToolBase(canvas)
, m_textCursor(canvas)
, m_optionManager(new SvgTextToolOptionsManager(this))
+ , m_textOutlineHelper(new KoSvgTextShapeOutlineHelper(canvas))
{
// TODO: figure out whether we should use system config for this, Windows and GTK have values for it, but Qt and MacOS don't(?).
const int cursorFlashLimit = 5000;
@@ -142,6 +143,8 @@ SvgTextTool::SvgTextTool(KoCanvasBase *canvas)
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);
+ m_textOutlineHelper->setDrawBoundingRect(false);
+ m_textOutlineHelper->setDrawTextWrappingArea(true);
m_base_cursor = QCursor(QPixmap(":/tool_text_basic.xpm"), 7, 7);
m_text_inline_horizontal = QCursor(QPixmap(":/tool_text_inline_horizontal.xpm"), 7, 7);
@@ -168,8 +171,9 @@ void SvgTextTool::activate(const QSet<KoShape *> &shapes)
KoToolBase::activate(shapes);
m_canvasConnections.addConnection(canvas()->selectedShapesProxy(), SIGNAL(selectionChanged()), this, SLOT(slotShapeSelectionChanged()));
- const KisCanvas2 *canvas2 = qobject_cast<const KisCanvas2 *>(this->canvas());
+ KisCanvas2 *canvas2 = qobject_cast<KisCanvas2 *>(this->canvas());
if (canvas2) {
+ canvas2->setTextShapeManagerEnabled(nullptr);
canvas2->viewManager()->textPropertyManager()->setTextPropertiesInterface(m_textCursor.textPropertyInterface());
QDockWidget *docker = canvas2->viewManager()->mainWindow()->dockWidget("TextProperties");
if (docker && m_optionManager) {
@@ -644,6 +648,8 @@ QRectF SvgTextTool::decorationsRect() const
rect |= m_hoveredShapeHighlightRect.boundingRect();
+ rect |= m_textOutlineHelper->decorationRect();
+
return rect;
}
@@ -699,6 +705,9 @@ void SvgTextTool::paint(QPainter &gc, const KoViewConverter &converter)
handlePainter.drawHandleCircle(QPointF(), KoToolBase::handleRadius() * 0.75);
}
+ m_textOutlineHelper->setDecorationThickness(decorationThickness());
+ m_textOutlineHelper->setHandleRadius(handleRadius());
+ m_textOutlineHelper->paint(&gc, converter);
gc.setTransform(converter.documentToView(), true);
{
KisHandlePainterHelper handlePainter(&gc, handleRadius(), decorationThickness());
@@ -710,7 +719,7 @@ void SvgTextTool::paint(QPainter &gc, const KoViewConverter &converter)
}
}
if (shape) {
- m_textCursor.paintDecorations(gc, qApp->palette().color(QPalette::Highlight), decorationThickness(), handleRadius());
+ m_textCursor.paintDecorations(gc, qApp->palette().color(QPalette::Highlight), decorationThickness(), handleRadius());
}
if (m_interactionStrategy) {
gc.save();
@@ -741,6 +750,12 @@ void SvgTextTool::mousePressEvent(KoPointerEvent *event)
KoSvgTextShape *selectedShape = this->selectedShape();
if (selectedShape) {
+ if (m_textOutlineHelper->contourModeButtonHovered(event->point)) {
+ m_textOutlineHelper->toggleTextContourMode(selectedShape);
+ event->accept();
+ KoToolManager::instance()->switchToolRequested("InteractionTool");
+ return;
+ }
if (m_highlightItem == HighlightItem::TypeSettingHandle) {
SvgTextCursor::TypeSettingModeHandle handle = m_textCursor.typeSettingHandleAtPos(handleGrabRect(event->point));
if (handle != SvgTextCursor::NoHandle) {
diff --git a/plugins/tools/svgtexttool/SvgTextTool.h b/plugins/tools/svgtexttool/SvgTextTool.h
index 02fdea4ed1..61877aad97 100644
--- a/plugins/tools/svgtexttool/SvgTextTool.h
+++ b/plugins/tools/svgtexttool/SvgTextTool.h
@@ -13,6 +13,8 @@
#include <KoToolBase.h>
#include <QPointer>
+#include <KoSvgTextShapeOutlineHelper.h>
+
#include <kis_signal_auto_connection.h>
#include <KisSignalMapper.h>
@@ -218,6 +220,7 @@ private:
SvgTextCursor m_textCursor;
+ QScopedPointer<KoSvgTextShapeOutlineHelper> m_textOutlineHelper;
KisSignalAutoConnectionsStore m_canvasConnections;
QPainterPath m_hoveredShapeHighlightRect;