Krita Source Code Documentation
Loading...
Searching...
No Matches
KoSvgTextShapeOutlineHelper Class Reference

The KoSvgTextShapeOutlineHelper class helper class that draws the text outlines and contour mode button of the KoSvgTextTool. More...

#include <KoSvgTextShapeOutlineHelper.h>

Classes

struct  Private
 

Public Member Functions

KoSvgTextShapecontourModeButtonHovered (const QPointF &point)
 
QRectF decorationRect ()
 decorationRect
 
bool drawBoundingRect () const
 
bool drawShapeOutlines () const
 
bool drawTextWrappingArea () const
 
 KoSvgTextShapeOutlineHelper (KoCanvasBase *canvas)
 
void paint (QPainter *painter, const KoViewConverter &converter)
 
void setDecorationThickness (int thickness)
 
void setDrawBoundingRect (bool enable)
 setDrawBoundingRect Whether to draw the bounding rect of the shapes.
 
void setDrawShapeOutlines (bool enable)
 setDrawShapeOutlines Draw the shape outlines instead of only the rect.
 
void setDrawTextWrappingArea (bool enable)
 setDrawTextWrappingArea draw the wrapping area. The wrapping area is computed from the shapes as well as padding and margin. This also draws connection lines.
 
void setHandleRadius (int radius)
 
void setTextAreasHovered (bool enabled)
 
void toggleTextContourMode (KoSvgTextShape *shape)
 
bool updateTextContourMode ()
 updateTextContourMode This checks if the text contour mode still has shapes, and otherwise switches out of this mode.
 
 ~KoSvgTextShapeOutlineHelper ()
 

Private Member Functions

void paintTextShape (QPainter *painter, const KoViewConverter &converter, KoSvgTextShape *text, bool contourModeActive=false)
 

Private Attributes

QScopedPointer< Privated
 

Detailed Description

The KoSvgTextShapeOutlineHelper class helper class that draws the text outlines and contour mode button of the KoSvgTextTool.

Definition at line 25 of file KoSvgTextShapeOutlineHelper.h.

Constructor & Destructor Documentation

◆ KoSvgTextShapeOutlineHelper()

KoSvgTextShapeOutlineHelper::KoSvgTextShapeOutlineHelper ( KoCanvasBase * canvas)

Definition at line 75 of file KoSvgTextShapeOutlineHelper.cpp.

76 : d(new Private(canvas))
77{
78}

◆ ~KoSvgTextShapeOutlineHelper()

KoSvgTextShapeOutlineHelper::~KoSvgTextShapeOutlineHelper ( )

Definition at line 80 of file KoSvgTextShapeOutlineHelper.cpp.

81{
82
83}

Member Function Documentation

◆ contourModeButtonHovered()

KoSvgTextShape * KoSvgTextShapeOutlineHelper::contourModeButtonHovered ( const QPointF & point)

Definition at line 253 of file KoSvgTextShapeOutlineHelper.cpp.

254{
255 KoSvgTextShape *text = d->getTextModeShape();
256 if (text) {
257 if (d->getButtonRect(text->boundingRect()).contains(point)) {
258 return text;
259 }
260 }
261 return d->getPotentialTextShape(point);
262}
QRectF boundingRect() const override
Get the bounding box of the shape.

References KoSvgTextShape::boundingRect(), and d.

◆ decorationRect()

QRectF KoSvgTextShapeOutlineHelper::decorationRect ( )

decorationRect

Returns
the current rect necessary.

Definition at line 197 of file KoSvgTextShapeOutlineHelper.cpp.

198{
199 QRectF decorationRect;
200 KoSvgTextShape *text = d->getTextModeShape();
201 if (text) {
202 QRectF base = text->boundingRect();
203 base |= d->getButtonRectCorrected(base);
204 decorationRect = base;
205 } else {
206 Q_FOREACH(KoShape* shape, d->canvas->shapeManager()->selection()->selectedEditableShapes()) {
207 text = dynamic_cast<KoSvgTextShape*>(shape);
208 if (d->drawButton(text)) {
209 QRectF base = text->boundingRect();
210 base |= d->getButtonRectCorrected(base);
211 decorationRect |= base;
212 }
213 }
214 }
215 return decorationRect;
216}

References KoSvgTextShape::boundingRect(), d, and decorationRect().

◆ drawBoundingRect()

bool KoSvgTextShapeOutlineHelper::drawBoundingRect ( ) const

Definition at line 223 of file KoSvgTextShapeOutlineHelper.cpp.

224{
225 return d->drawBoundingRect;
226}

References d.

◆ drawShapeOutlines()

bool KoSvgTextShapeOutlineHelper::drawShapeOutlines ( ) const

Definition at line 238 of file KoSvgTextShapeOutlineHelper.cpp.

239{
240 return d->drawOutline;
241}

References d.

◆ drawTextWrappingArea()

bool KoSvgTextShapeOutlineHelper::drawTextWrappingArea ( ) const

◆ paint()

void KoSvgTextShapeOutlineHelper::paint ( QPainter * painter,
const KoViewConverter & converter )

Definition at line 182 of file KoSvgTextShapeOutlineHelper.cpp.

183{
184 KoSvgTextShape *text = d->getTextModeShape();
185 if (text) {
186 paintTextShape(painter, converter, text, true);
187 } else {
188 Q_FOREACH(KoShape* shape, d->canvas->shapeManager()->selection()->selectedEditableShapes()) {
189 text = dynamic_cast<KoSvgTextShape*>(shape);
190 if (d->drawButton(text)) {
191 paintTextShape(painter, converter, text, false);
192 }
193 }
194 }
195}
void paintTextShape(QPainter *painter, const KoViewConverter &converter, KoSvgTextShape *text, bool contourModeActive=false)

References d, and paintTextShape().

◆ paintTextShape()

void KoSvgTextShapeOutlineHelper::paintTextShape ( QPainter * painter,
const KoViewConverter & converter,
KoSvgTextShape * text,
bool contourModeActive = false )
private

Definition at line 124 of file KoSvgTextShapeOutlineHelper.cpp.

125 {
126 painter->save();
127 KisHandlePalette handlePalette = d->renderInterface()->handlePaletteForDisplayColorSpace();
129 KoShape::createHandlePainterHelperView(painter, text, converter, d->handleRadius, d->decorationThickness);
131 if (contourModeActive) {
132 if (d->drawOutline) {
133
134 Q_FOREACH(KoShape *shape, text->internalShapeManager()->shapes()) {
135 QPainterPath p = shape->transformation().map(shape->outline());
136 helper.drawPath(p);
137 }
139 Q_FOREACH(const KoShape *shape, text->shapesInside()) {
140 areas.append(shape->transformation().map(shape->outline()));
141 }
142 Q_FOREACH(QLineF arrow, getTextAreaOrderArrows(areas)) {
143 helper.drawGradientArrow(arrow.p1(), arrow.p2(), 1.5 * d->handleRadius);
144 }
145 }
146 if (d->drawBoundingRect) {
147 QPainterPath rect;
148 rect.addRect(text->outlineRect());
149 helper.drawPath(rect);
150 }
151 }
152 if (d->drawTextWrappingArea) {
153 if (d->textWrappingAreasHovered) {
155 }
157 Q_FOREACH(QLineF arrow, getTextAreaOrderArrows(areas)) {
158 helper.drawGradientArrow(arrow.p1(), arrow.p2(), 1.5 * d->handleRadius);
159 }
160 Q_FOREACH(const QPainterPath path, areas) {
161 helper.drawPath(path);
162 }
163 }
164 painter->restore();
165
166 painter->save();
167 QPalette systemPalette = d->renderInterface()->systemPaletteForDisplayColorSpace();
168 QIcon icon = contourModeActive? KisIconUtils::loadIcon(ICON_EXIT): KisIconUtils::loadIcon(ICON_ENTER);
169 QImage pm = d->renderInterface()->convertImageToDisplayColorSpace(icon.pixmap(BUTTON_ICON_SIZE, BUTTON_ICON_SIZE).toImage());
170 painter->setBrush(contourModeActive? systemPalette.highlight(): systemPalette.button());
171 QPen pen;
172 pen.setColor(contourModeActive? systemPalette.highlightedText().color(): systemPalette.buttonText().color());
173 pen.setCosmetic(true);
174 pen.setWidthF(d->decorationThickness);
175 painter->setPen(pen);
176 const QRectF buttonRect = d->getButtonRect(converter.documentToView().mapRect(text->boundingRect()));
177 painter->drawRoundedRect(buttonRect, BUTTON_CORNER_ROUND, BUTTON_CORNER_ROUND);
178 painter->drawImage(buttonRect.topLeft()+QPointF(BUTTON_PADDING, BUTTON_PADDING), pm);
179 painter->restore();
180}
const Params2D p
const int BUTTON_CORNER_ROUND
const QString ICON_ENTER
QList< QLineF > getTextAreaOrderArrows(QList< QPainterPath > areas)
const int BUTTON_ICON_SIZE
const QString ICON_EXIT
const int BUTTON_PADDING
The KisHandlePainterHelper class is a special helper for painting handles around objects....
void drawPath(const QPainterPath &path)
void setHandleStyle(const KisHandleStyle &style)
void drawGradientArrow(const QPointF &start, const QPointF &end, qreal radius)
static KisHandleStyle & partiallyHighlightedPrimaryHandles(KisHandlePalette palette=KisHandlePalette())
static KisHandleStyle & secondarySelection(KisHandlePalette palette=KisHandlePalette())
QList< KoShape * > shapes
virtual QPainterPath outline() const
Definition KoShape.cpp:554
static KisHandlePainterHelper createHandlePainterHelperView(QPainter *painter, KoShape *shape, const KoViewConverter &converter, qreal handleRadius=0.0, int decorationThickness=1)
Definition KoShape.cpp:977
QTransform transformation() const
Returns the shapes local transformation matrix.
Definition KoShape.cpp:378
QList< QPainterPath > textWrappingAreas() const
textWrappingAreas The text wrapping areas are computed from shapesInside() and shapesSubtract(),...
QList< KoShape * > shapesInside
KoShapeManager * internalShapeManager() const
internalShapeManager
QRectF outlineRect() const override
virtual QPointF documentToView(const QPointF &documentPoint) const
QString button(const QWheelEvent &ev)
QIcon loadIcon(const QString &name)

References KoSvgTextShape::boundingRect(), BUTTON_CORNER_ROUND, BUTTON_ICON_SIZE, BUTTON_PADDING, KoShape::createHandlePainterHelperView(), d, KoViewConverter::documentToView(), KisHandlePainterHelper::drawGradientArrow(), KisHandlePainterHelper::drawPath(), getTextAreaOrderArrows(), ICON_ENTER, ICON_EXIT, KoSvgTextShape::internalShapeManager(), KisIconUtils::loadIcon(), KoShape::outline(), KoSvgTextShape::outlineRect(), p, KisHandleStyle::partiallyHighlightedPrimaryHandles(), KisHandleStyle::secondarySelection(), KisHandlePainterHelper::setHandleStyle(), KoShapeManager::shapes, KoSvgTextShape::shapesInside, KoSvgTextShape::textWrappingAreas(), and KoShape::transformation().

◆ setDecorationThickness()

void KoSvgTextShapeOutlineHelper::setDecorationThickness ( int thickness)

Definition at line 248 of file KoSvgTextShapeOutlineHelper.cpp.

249{
250 d->decorationThickness = thickness;
251}

References d.

◆ setDrawBoundingRect()

void KoSvgTextShapeOutlineHelper::setDrawBoundingRect ( bool enable)

setDrawBoundingRect Whether to draw the bounding rect of the shapes.

Parameters
enable

Definition at line 218 of file KoSvgTextShapeOutlineHelper.cpp.

219{
220 d->drawBoundingRect = enable;
221}

References d.

◆ setDrawShapeOutlines()

void KoSvgTextShapeOutlineHelper::setDrawShapeOutlines ( bool enable)

setDrawShapeOutlines Draw the shape outlines instead of only the rect.

Definition at line 233 of file KoSvgTextShapeOutlineHelper.cpp.

234{
235 d->drawOutline = enable;
236}

References d.

◆ setDrawTextWrappingArea()

void KoSvgTextShapeOutlineHelper::setDrawTextWrappingArea ( bool enable)

setDrawTextWrappingArea draw the wrapping area. The wrapping area is computed from the shapes as well as padding and margin. This also draws connection lines.

Definition at line 228 of file KoSvgTextShapeOutlineHelper.cpp.

229{
230 d->drawTextWrappingArea = enable;
231}

References d.

◆ setHandleRadius()

void KoSvgTextShapeOutlineHelper::setHandleRadius ( int radius)

Definition at line 243 of file KoSvgTextShapeOutlineHelper.cpp.

244{
245 d->handleRadius = radius;
246}

References d.

◆ setTextAreasHovered()

void KoSvgTextShapeOutlineHelper::setTextAreasHovered ( bool enabled)

Definition at line 285 of file KoSvgTextShapeOutlineHelper.cpp.

286{
287 d->textWrappingAreasHovered = enabled;
288}

References d.

◆ toggleTextContourMode()

void KoSvgTextShapeOutlineHelper::toggleTextContourMode ( KoSvgTextShape * shape)

Definition at line 274 of file KoSvgTextShapeOutlineHelper.cpp.

275{
276 if (d->canvas) {
277 if (shape == d->canvas->currentShapeManagerOwnerShape()) {
278 d->canvas->setCurrentShapeManagerOwnerShape(nullptr);
279 } else {
280 d->canvas->setCurrentShapeManagerOwnerShape(shape);
281 }
282 }
283}

References d.

◆ updateTextContourMode()

bool KoSvgTextShapeOutlineHelper::updateTextContourMode ( )

updateTextContourMode This checks if the text contour mode still has shapes, and otherwise switches out of this mode.

Returns
whether the mode was updated.

Definition at line 264 of file KoSvgTextShapeOutlineHelper.cpp.

265{
266 KoSvgTextShape *text = d->getTextModeShape();
267 if (text && !d->drawButton(text)) {
268 toggleTextContourMode(nullptr);
269 return true;
270 }
271 return false;
272}
void toggleTextContourMode(KoSvgTextShape *shape)

References d, and toggleTextContourMode().

Member Data Documentation

◆ d

QScopedPointer<Private> KoSvgTextShapeOutlineHelper::d
private

Definition at line 84 of file KoSvgTextShapeOutlineHelper.h.


The documentation for this class was generated from the following files: