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, const QPalette &pal, 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 24 of file KoSvgTextShapeOutlineHelper.h.

Constructor & Destructor Documentation

◆ KoSvgTextShapeOutlineHelper()

KoSvgTextShapeOutlineHelper::KoSvgTextShapeOutlineHelper ( KoCanvasBase * canvas)

Definition at line 70 of file KoSvgTextShapeOutlineHelper.cpp.

71 : d(new Private(canvas))
72{
73}

◆ ~KoSvgTextShapeOutlineHelper()

KoSvgTextShapeOutlineHelper::~KoSvgTextShapeOutlineHelper ( )

Definition at line 75 of file KoSvgTextShapeOutlineHelper.cpp.

76{
77
78}

Member Function Documentation

◆ contourModeButtonHovered()

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

Definition at line 248 of file KoSvgTextShapeOutlineHelper.cpp.

249{
250 KoSvgTextShape *text = d->getTextModeShape();
251 if (text) {
252 if (d->getButtonRect(text->boundingRect()).contains(point)) {
253 return text;
254 }
255 }
256 return d->getPotentialTextShape(point);
257}
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 192 of file KoSvgTextShapeOutlineHelper.cpp.

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

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

◆ drawBoundingRect()

bool KoSvgTextShapeOutlineHelper::drawBoundingRect ( ) const

Definition at line 218 of file KoSvgTextShapeOutlineHelper.cpp.

219{
220 return d->drawBoundingRect;
221}

References d.

◆ drawShapeOutlines()

bool KoSvgTextShapeOutlineHelper::drawShapeOutlines ( ) const

Definition at line 233 of file KoSvgTextShapeOutlineHelper.cpp.

234{
235 return d->drawOutline;
236}

References d.

◆ drawTextWrappingArea()

bool KoSvgTextShapeOutlineHelper::drawTextWrappingArea ( ) const

◆ paint()

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

Definition at line 176 of file KoSvgTextShapeOutlineHelper.cpp.

177{
178 const QPalette pal = qApp->palette();
179 KoSvgTextShape *text = d->getTextModeShape();
180 if (text) {
181 paintTextShape(painter, converter, pal, text, true);
182 } else {
183 Q_FOREACH(KoShape* shape, d->canvas->shapeManager()->selection()->selectedEditableShapes()) {
184 text = dynamic_cast<KoSvgTextShape*>(shape);
185 if (d->drawButton(text)) {
186 paintTextShape(painter, converter, pal, text, false);
187 }
188 }
189 }
190}
void paintTextShape(QPainter *painter, const KoViewConverter &converter, const QPalette &pal, KoSvgTextShape *text, bool contourModeActive=false)

References d, and paintTextShape().

◆ paintTextShape()

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

Definition at line 119 of file KoSvgTextShapeOutlineHelper.cpp.

121 {
122 painter->save();
124 KoShape::createHandlePainterHelperView(painter, text, converter, d->handleRadius, d->decorationThickness);
126 if (contourModeActive) {
127 if (d->drawOutline) {
128
129 Q_FOREACH(KoShape *shape, text->internalShapeManager()->shapes()) {
130 QPainterPath p = shape->transformation().map(shape->outline());
131 helper.drawPath(p);
132 }
134 Q_FOREACH(const KoShape *shape, text->shapesInside()) {
135 areas.append(shape->transformation().map(shape->outline()));
136 }
137 Q_FOREACH(QLineF arrow, getTextAreaOrderArrows(areas)) {
138 helper.drawGradientArrow(arrow.p1(), arrow.p2(), 1.5 * d->handleRadius);
139 }
140 }
141 if (d->drawBoundingRect) {
142 QPainterPath rect;
143 rect.addRect(text->outlineRect());
144 helper.drawPath(rect);
145 }
146 }
147 if (d->drawTextWrappingArea) {
148 if (d->textWrappingAreasHovered) {
150 }
152 Q_FOREACH(QLineF arrow, getTextAreaOrderArrows(areas)) {
153 helper.drawGradientArrow(arrow.p1(), arrow.p2(), 1.5 * d->handleRadius);
154 }
155 Q_FOREACH(const QPainterPath path, areas) {
156 helper.drawPath(path);
157 }
158 }
159 painter->restore();
160
161 painter->save();
162 QIcon icon = contourModeActive? KisIconUtils::loadIcon(ICON_EXIT): KisIconUtils::loadIcon(ICON_ENTER);
163 QPixmap pm = icon.pixmap(BUTTON_ICON_SIZE, BUTTON_ICON_SIZE);
164 painter->setBrush(contourModeActive? pal.highlight(): pal.button());
165 QPen pen;
166 pen.setColor(contourModeActive? pal.highlightedText().color(): pal.buttonText().color());
167 pen.setCosmetic(true);
168 pen.setWidthF(d->decorationThickness);
169 painter->setPen(pen);
170 const QRectF buttonRect = d->getButtonRect(converter.documentToView().mapRect(text->boundingRect()));
171 painter->drawRoundedRect(buttonRect, BUTTON_CORNER_ROUND, BUTTON_CORNER_ROUND);
172 painter->drawPixmap(buttonRect.topLeft()+QPointF(BUTTON_PADDING, BUTTON_PADDING), pm);
173 painter->restore();
174}
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()
static KisHandleStyle & secondarySelection()
QList< KoShape * > shapes
virtual QPainterPath outline() const
Definition KoShape.cpp:559
static KisHandlePainterHelper createHandlePainterHelperView(QPainter *painter, KoShape *shape, const KoViewConverter &converter, qreal handleRadius=0.0, int decorationThickness=1)
Definition KoShape.cpp:982
QTransform transformation() const
Returns the shapes local transformation matrix.
Definition KoShape.cpp:383
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 243 of file KoSvgTextShapeOutlineHelper.cpp.

244{
245 d->decorationThickness = thickness;
246}

References d.

◆ setDrawBoundingRect()

void KoSvgTextShapeOutlineHelper::setDrawBoundingRect ( bool enable)

setDrawBoundingRect Whether to draw the bounding rect of the shapes.

Parameters
enable

Definition at line 213 of file KoSvgTextShapeOutlineHelper.cpp.

214{
215 d->drawBoundingRect = enable;
216}

References d.

◆ setDrawShapeOutlines()

void KoSvgTextShapeOutlineHelper::setDrawShapeOutlines ( bool enable)

setDrawShapeOutlines Draw the shape outlines instead of only the rect.

Definition at line 228 of file KoSvgTextShapeOutlineHelper.cpp.

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

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 223 of file KoSvgTextShapeOutlineHelper.cpp.

224{
225 d->drawTextWrappingArea = enable;
226}

References d.

◆ setHandleRadius()

void KoSvgTextShapeOutlineHelper::setHandleRadius ( int radius)

Definition at line 238 of file KoSvgTextShapeOutlineHelper.cpp.

239{
240 d->handleRadius = radius;
241}

References d.

◆ setTextAreasHovered()

void KoSvgTextShapeOutlineHelper::setTextAreasHovered ( bool enabled)

Definition at line 280 of file KoSvgTextShapeOutlineHelper.cpp.

281{
282 d->textWrappingAreasHovered = enabled;
283}

References d.

◆ toggleTextContourMode()

void KoSvgTextShapeOutlineHelper::toggleTextContourMode ( KoSvgTextShape * shape)

Definition at line 269 of file KoSvgTextShapeOutlineHelper.cpp.

270{
271 if (d->canvas) {
272 if (shape == d->canvas->currentShapeManagerOwnerShape()) {
273 d->canvas->setCurrentShapeManagerOwnerShape(nullptr);
274 } else {
275 d->canvas->setCurrentShapeManagerOwnerShape(shape);
276 }
277 }
278}

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 259 of file KoSvgTextShapeOutlineHelper.cpp.

260{
261 KoSvgTextShape *text = d->getTextModeShape();
262 if (text && !d->drawButton(text)) {
263 toggleTextContourMode(nullptr);
264 return true;
265 }
266 return false;
267}
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: