File: quickdecorationsdrawer.cpp

package info (click to toggle)
gammaray 3.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 21,612 kB
  • sloc: cpp: 94,643; ansic: 2,227; sh: 336; python: 164; yacc: 90; lex: 82; xml: 61; makefile: 26
file content (597 lines) | stat: -rw-r--r-- 24,281 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
/*
  quickdecorationsdrawer.cpp

  This file is part of GammaRay, the Qt application inspection and manipulation tool.

  SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
  Author: Filipe Azevedo <filipe.azevedo@kdab.com>

  SPDX-License-Identifier: GPL-2.0-or-later

  Contact KDAB at <info@kdab.com> for commercial licensing options.
*/

#include "quickdecorationsdrawer.h"

#include <QDebug>
#include <QPainter>
#include <QVector2D>

#ifndef GL_BGRA
#define GL_BGRA GL_BGRA_EXT
#endif

using namespace GammaRay;

QuickDecorationsDrawer::QuickDecorationsDrawer(QuickDecorationsDrawer::Type type,
                                               QPainter &painter,
                                               const QuickDecorationsBaseRenderInfo &renderInfo)
    : m_type(type)
    , m_renderInfo(&renderInfo)
    , m_painter(&painter)
{
    Q_ASSERT(m_painter);
    Q_ASSERT(m_renderInfo);
}

void QuickDecorationsDrawer::render()
{
    // Draw the grid if needed
    drawGrid();

    switch (m_type) {
    case QuickDecorationsDrawer::Decorations: {
        drawDecorations();
        break;
    }

    case QuickDecorationsDrawer::Traces: {
        drawTraces();
        break;
    }
    }
}

void QuickDecorationsDrawer::drawDecorations()
{
    QuickItemGeometry itemGeometry(this->itemGeometry());

    if (!itemGeometry.isValid())
        return;

    const qreal &zoom(m_renderInfo->zoom);
    DrawTextInfoList texts;

    itemGeometry.scaleTo(zoom);

    m_painter->save();

    // bounding box
    if (itemGeometry.boundingRect.isValid()) {
        m_painter->setPen(m_renderInfo->settings.boundingRectColor);
        m_painter->setBrush(m_renderInfo->settings.boundingRectBrush);
        m_painter->drawRect(itemGeometry.boundingRect);
    }

    // original geometry
    if (itemGeometry.itemRect.isValid() && itemGeometry.itemRect != itemGeometry.boundingRect) {
        m_painter->setPen(m_renderInfo->settings.geometryRectColor);
        m_painter->setBrush(m_renderInfo->settings.geometryRectBrush);
        m_painter->drawRect(itemGeometry.itemRect);
    }

    // children rect
    if (itemGeometry.childrenRect.isValid() && itemGeometry.itemRect != itemGeometry.boundingRect && itemGeometry.transform.isIdentity()) {
        // If this item is transformed the children rect will be painted wrongly,
        // so for now skip painting it.
        m_painter->setPen(m_renderInfo->settings.childrenRectColor);
        m_painter->setBrush(m_renderInfo->settings.childrenRectBrush);
        m_painter->drawRect(itemGeometry.childrenRect);
    }

    // transform origin
    if (itemGeometry.itemRect != itemGeometry.boundingRect) {
        m_painter->setPen(m_renderInfo->settings.transformOriginColor);
        m_painter->drawEllipse(itemGeometry.transformOriginPoint, 2.5, 2.5);
        m_painter->drawLine(itemGeometry.transformOriginPoint - QPointF(0, 6),
                            itemGeometry.transformOriginPoint + QPointF(0, 6));
        m_painter->drawLine(itemGeometry.transformOriginPoint - QPointF(6, 0),
                            itemGeometry.transformOriginPoint + QPointF(6, 0));
    }

    // x and y values
    m_painter->setPen(m_renderInfo->settings.coordinatesColor);
    if (!itemGeometry.left && !itemGeometry.horizontalCenter && !itemGeometry.right && itemGeometry.x != 0) {
        QPointF parentEnd = (QPointF(itemGeometry.itemRect.x() - itemGeometry.x,
                                     itemGeometry.itemRect.y()));
        QPointF itemEnd = itemGeometry.itemRect.topLeft();
        drawArrow(parentEnd, itemEnd);
        texts << DrawTextInfo(m_painter->pen(),
                              QRectF(parentEnd.x(), parentEnd.y() + 10, itemEnd.x() - parentEnd.x(), 50),
                              QStringLiteral("x: %1px").arg(itemGeometry.x / zoom),
                              Qt::AlignHCenter | Qt::TextDontClip);
    }
    if (!itemGeometry.top && !itemGeometry.verticalCenter && !itemGeometry.bottom && !itemGeometry.baseline && itemGeometry.y != 0) {
        QPointF parentEnd = (QPointF(itemGeometry.itemRect.x(),
                                     itemGeometry.itemRect.y() - itemGeometry.y));
        QPointF itemEnd = itemGeometry.itemRect.topLeft();
        drawArrow(parentEnd, itemEnd);
        texts << DrawTextInfo(m_painter->pen(),
                              QRectF(parentEnd.x() + 10, parentEnd.y(), 100, itemEnd.y() - parentEnd.y()),
                              QStringLiteral("y: %1px").arg(itemGeometry.y / zoom),
                              Qt::AlignVCenter | Qt::TextDontClip);
    }

    // anchors
    m_painter->setPen(m_renderInfo->settings.marginsColor);

    if (itemGeometry.left) {
        drawHorizontalAnchor(itemGeometry, itemGeometry.itemRect.left(),
                             itemGeometry.leftMargin);
        texts << drawHorizontalAnchorLabel(itemGeometry,
                                           itemGeometry.itemRect.left(),
                                           itemGeometry.leftMargin,
                                           QStringLiteral("%1px").arg(itemGeometry.leftMargin / zoom),
                                           Qt::AlignBottom | Qt::AlignHCenter);
    }

    if (itemGeometry.horizontalCenter) {
        drawHorizontalAnchor(itemGeometry,
                             (itemGeometry.itemRect.left() + itemGeometry.itemRect.right()) / 2,
                             itemGeometry.horizontalCenterOffset);
        texts << drawHorizontalAnchorLabel(itemGeometry,
                                           (itemGeometry.itemRect.left() + itemGeometry.itemRect.right()) / 2,
                                           itemGeometry.horizontalCenterOffset,
                                           QStringLiteral("offset: %1px").arg(itemGeometry.horizontalCenterOffset / zoom),
                                           Qt::AlignBottom | Qt::AlignHCenter);
    }

    if (itemGeometry.right) {
        drawHorizontalAnchor(itemGeometry,
                             itemGeometry.itemRect.right(),
                             -itemGeometry.rightMargin);
        texts << drawHorizontalAnchorLabel(itemGeometry,
                                           itemGeometry.itemRect.right(),
                                           -itemGeometry.rightMargin,
                                           QStringLiteral("%1px").arg(itemGeometry.rightMargin / zoom),
                                           Qt::AlignTop | Qt::AlignHCenter);
    }

    if (itemGeometry.top) {
        drawVerticalAnchor(itemGeometry,
                           itemGeometry.itemRect.top(),
                           itemGeometry.topMargin);
        texts << drawVerticalAnchorLabel(itemGeometry,
                                         itemGeometry.itemRect.top(),
                                         itemGeometry.topMargin,
                                         QStringLiteral("%1px").arg(itemGeometry.topMargin / zoom),
                                         Qt::AlignVCenter | Qt::AlignRight);
    }

    if (itemGeometry.verticalCenter) {
        drawVerticalAnchor(itemGeometry,
                           (itemGeometry.itemRect.top() + itemGeometry.itemRect.bottom()) / 2,
                           itemGeometry.verticalCenterOffset);
        texts << drawVerticalAnchorLabel(itemGeometry,
                                         (itemGeometry.itemRect.top() + itemGeometry.itemRect.bottom()) / 2,
                                         itemGeometry.verticalCenterOffset,
                                         QStringLiteral("offset: %1px").arg(itemGeometry.verticalCenterOffset / zoom),
                                         Qt::AlignVCenter | Qt::AlignRight);
    }

    if (itemGeometry.bottom) {
        drawVerticalAnchor(itemGeometry,
                           itemGeometry.itemRect.bottom(),
                           -itemGeometry.bottomMargin);
        texts << drawVerticalAnchorLabel(itemGeometry,
                                         itemGeometry.itemRect.bottom(),
                                         -itemGeometry.bottomMargin,
                                         QStringLiteral("%1px").arg(itemGeometry.bottomMargin / zoom),
                                         Qt::AlignVCenter | Qt::AlignLeft);
    }

    if (itemGeometry.baseline) {
        drawVerticalAnchor(itemGeometry,
                           itemGeometry.itemRect.top(),
                           itemGeometry.baselineOffset);
        texts << drawVerticalAnchorLabel(itemGeometry,
                                         itemGeometry.itemRect.top(), itemGeometry.baselineOffset,
                                         QStringLiteral("offset: %1px").arg(itemGeometry.baselineOffset / zoom),
                                         Qt::AlignVCenter | Qt::AlignLeft);
    }

    // padding
    m_painter->setPen(m_renderInfo->settings.paddingColor);

    if (!qIsNaN(itemGeometry.leftPadding)) {
        drawHorizontalAnchor(itemGeometry,
                             itemGeometry.itemRect.left(),
                             -itemGeometry.leftPadding);
        texts << drawHorizontalAnchorLabel(itemGeometry,
                                           itemGeometry.itemRect.left(),
                                           -itemGeometry.leftPadding,
                                           QStringLiteral("%1px").arg(itemGeometry.leftPadding / zoom),
                                           Qt::AlignTop | Qt::AlignHCenter);
    }

    if (!qIsNaN(itemGeometry.rightPadding)) {
        drawHorizontalAnchor(itemGeometry,
                             itemGeometry.itemRect.right(),
                             itemGeometry.rightPadding);
        texts << drawHorizontalAnchorLabel(itemGeometry,
                                           itemGeometry.itemRect.right(),
                                           itemGeometry.rightPadding,
                                           QStringLiteral("%1px").arg(itemGeometry.rightPadding / zoom),
                                           Qt::AlignBottom | Qt::AlignHCenter);
    }

    if (!qIsNaN(itemGeometry.topPadding)) {
        drawVerticalAnchor(itemGeometry,
                           itemGeometry.itemRect.top(),
                           -itemGeometry.topPadding);
        texts << drawVerticalAnchorLabel(itemGeometry,
                                         itemGeometry.itemRect.top(),
                                         -itemGeometry.topPadding,
                                         QStringLiteral("%1px").arg(itemGeometry.topPadding / zoom),
                                         Qt::AlignVCenter | Qt::AlignLeft);
    }

    if (!qIsNaN(itemGeometry.bottomPadding)) {
        drawVerticalAnchor(itemGeometry,
                           itemGeometry.itemRect.bottom(),
                           itemGeometry.bottomPadding);
        texts << drawVerticalAnchorLabel(itemGeometry,
                                         itemGeometry.itemRect.bottom(),
                                         itemGeometry.bottomPadding,
                                         QStringLiteral("%1px").arg(itemGeometry.bottomPadding / zoom),
                                         Qt::AlignVCenter | Qt::AlignRight);
    }

    // Finally draw texts over the traced rectangles and lines
    // This make sure texts are always readable
    for (const auto &t : std::as_const(texts)) {
        if (t.label.isEmpty())
            continue;

        m_painter->setPen(t.pen);
        m_painter->drawText(t.rect, t.align, t.label);
    }

    m_painter->restore();
}

void QuickDecorationsDrawer::drawTraces()
{
    const QVector<QuickItemGeometry> itemsGeometry(this->itemsGeometry());

    if (itemsGeometry.isEmpty())
        return;

    m_painter->save();

    for (auto itemGeometry : itemsGeometry) {
        itemGeometry.scaleTo(m_renderInfo->zoom);

        // bounding box
        m_painter->setPen(itemGeometry.traceColor);
        m_painter->setBrush(itemGeometry.traceColor.lighter());
        m_painter->drawRect(itemGeometry.boundingRect);

        // bounding class box
        m_painter->setPen(QColor(60, 60, 60, 70));
        m_painter->setBrush(m_painter->pen().color());

        const int margin = m_painter->fontMetrics().horizontalAdvance(QLatin1Char('X')) / 2;
        const QRectF classRect =
            itemGeometry.boundingRect.adjusted(
                0, 0, 0,
                -(itemGeometry.boundingRect.height() - (m_painter->fontMetrics().height() * 1.6)));
        m_painter->drawRect(classRect);

        // type name label
        m_painter->setPen(QColor(250, 250, 250, 120));
        m_painter->drawText(classRect.adjusted(margin, margin, -margin, -margin),
                            Qt::AlignVCenter | Qt::AlignLeft | Qt::TextDontClip,
                            itemGeometry.traceTypeName);

        // draw bounding box corners
        m_painter->setPen(QPen(QColor(30, 30, 30), 3));
        m_painter->setBrush(m_painter->pen().color());
        const QVector<QPointF> points = QVector<QPointF>()
            << itemGeometry.boundingRect.topLeft()
            << itemGeometry.boundingRect.topRight()
            << itemGeometry.boundingRect.bottomRight()
            << itemGeometry.boundingRect.bottomLeft();
        m_painter->drawPoints(points);

        // name label
        m_painter->setPen(QColor(250, 250, 250, 120));
        m_painter->drawText(itemGeometry.boundingRect.adjusted(margin, margin, -margin, -margin),
                            Qt::AlignVCenter | Qt::AlignLeft | Qt::TextDontClip,
                            itemGeometry.traceName);
    }

    m_painter->restore();
}

QuickItemGeometry QuickDecorationsDrawer::itemGeometry() const
{
    switch (m_type) {
    case QuickDecorationsDrawer::Decorations:
        return static_cast<const QuickDecorationsRenderInfo *>(m_renderInfo)->itemGeometry;
    case QuickDecorationsDrawer::Traces:
        break;
    }

    return QuickItemGeometry();
}

QVector<QuickItemGeometry> QuickDecorationsDrawer::itemsGeometry() const
{
    switch (m_type) {
    case QuickDecorationsDrawer::Decorations:
        break;
    case QuickDecorationsDrawer::Traces:
        return static_cast<const QuickDecorationsTracesInfo *>(m_renderInfo)->itemsGeometry;
    }

    return QVector<QuickItemGeometry>();
}

void QuickDecorationsDrawer::drawGrid()
{
    const QRectF &viewRect(m_renderInfo->viewRect);
    const QPointF &gridOffset(m_renderInfo->settings.gridOffset);
    const QSizeF &gridCellSize(m_renderInfo->settings.gridCellSize);

    if (!m_renderInfo->settings.gridEnabled || gridCellSize.isEmpty())
        return;

    m_painter->save();
    m_painter->setPen(m_renderInfo->settings.gridColor);

    QVector<QLineF> lines;
    lines.reserve((viewRect.width() / gridCellSize.width()) + (viewRect.height() / gridCellSize.height()));

    // NOLINTNEXTLINE (clang-analyzer-security.FloatLoopCounter)
    for (qreal x = viewRect.left() + gridOffset.x(); x < viewRect.right(); x += gridCellSize.width()) {
        if (x < viewRect.left())
            continue;

        lines << QLineF(QPointF(x, viewRect.top()) * m_renderInfo->zoom,
                        QPointF(x, viewRect.bottom()) * m_renderInfo->zoom);
    }

    // NOLINTNEXTLINE (clang-analyzer-security.FloatLoopCounter)
    for (qreal y = viewRect.top() + gridOffset.y(); y < viewRect.bottom(); y += gridCellSize.height()) {
        if (y < viewRect.top())
            continue;

        lines << QLineF(QPointF(viewRect.left(), y) * m_renderInfo->zoom,
                        QPointF(viewRect.right(), y) * m_renderInfo->zoom);
    }

    m_painter->drawLines(lines);
    m_painter->restore();
}

void QuickDecorationsDrawer::drawArrow(const QPointF &first, const QPointF &second)
{
    m_painter->drawLine(first, second);
    QPointF vector(second - first);
    QTransform m;
    m.rotate(30);
    QVector2D v1 = QVector2D(m.map(vector)).normalized() * 10;
    m.rotate(-60);
    QVector2D v2 = QVector2D(m.map(vector)).normalized() * 10;
    m_painter->drawLine(first, first + v1.toPointF());
    m_painter->drawLine(first, first + v2.toPointF());
    m_painter->drawLine(second, second - v1.toPointF());
    m_painter->drawLine(second, second - v2.toPointF());
}

void QuickDecorationsDrawer::drawAnchor(const QuickItemGeometry &itemGeometry, Qt::Orientation orientation, qreal ownAnchorLine, qreal offset)
{
    const QRectF &viewRect(m_renderInfo->viewRect);
    const qreal &zoom(m_renderInfo->zoom);

    m_painter->save();

    const qreal foreignAnchorLine = ownAnchorLine - offset;

    // Arrow
    if (offset) {
        if (orientation == Qt::Horizontal) {
            drawArrow(QPointF(foreignAnchorLine,
                              (itemGeometry.itemRect.top() + itemGeometry.itemRect.bottom()) / 2),
                      QPointF(ownAnchorLine,
                              (itemGeometry.itemRect.top() + itemGeometry.itemRect.bottom()) / 2));
        } else {
            drawArrow(QPointF((itemGeometry.itemRect.left() + itemGeometry.itemRect.right()) / 2,
                              foreignAnchorLine),
                      QPointF((itemGeometry.itemRect.left() + itemGeometry.itemRect.right()) / 2,
                              ownAnchorLine));
        }
    }

    // Own Anchor line
    QPen pen(m_painter->pen());
    pen.setWidth(2);
    m_painter->setPen(pen);
    if (orientation == Qt::Horizontal) {
        m_painter->drawLine(ownAnchorLine,
                            itemGeometry.itemRect.top(), ownAnchorLine,
                            itemGeometry.itemRect.bottom());
    } else {
        m_painter->drawLine(
            itemGeometry.itemRect.left(), ownAnchorLine,
            itemGeometry.itemRect.right(), ownAnchorLine);
    }

    // Foreign Anchor line
    pen.setStyle(Qt::DotLine);
    m_painter->setPen(pen);
    if (orientation == Qt::Horizontal) {
        m_painter->drawLine(foreignAnchorLine, 0, foreignAnchorLine, viewRect.height() * zoom);
    } else {
        m_painter->drawLine(0, foreignAnchorLine, viewRect.width() * zoom, foreignAnchorLine);
    }

    m_painter->restore();
}

void QuickDecorationsDrawer::drawVerticalAnchor(const QuickItemGeometry &itemGeometry,
                                                qreal ownAnchorLine, qreal offset)
{
    drawAnchor(itemGeometry, Qt::Vertical, ownAnchorLine, offset);
}

void QuickDecorationsDrawer::drawHorizontalAnchor(const QuickItemGeometry &itemGeometry,
                                                  qreal ownAnchorLine, qreal offset)
{
    drawAnchor(itemGeometry, Qt::Horizontal, ownAnchorLine, offset);
}

QuickDecorationsDrawer::DrawTextInfo QuickDecorationsDrawer::drawAnchorLabel(const QuickItemGeometry &itemGeometry,
                                                                             Qt::Orientation orientation, qreal ownAnchorLine, qreal offset, const QString &label, Qt::Alignment align)
{
    if (align.testFlag(Qt::AlignCenter)) {
        qWarning("%s: You can not use Qt::AlignCenter!", Q_FUNC_INFO);
        return QuickDecorationsDrawer::DrawTextInfo();
    }

    if (align.testFlag(Qt::AlignJustify)) {
        qWarning("%s: You can not use Qt::AlignJustify!", Q_FUNC_INFO);
        return QuickDecorationsDrawer::DrawTextInfo();
    }

    if (align.testFlag(Qt::AlignBaseline)) {
        qWarning("%s: You can not use Qt::AlignBaseline!", Q_FUNC_INFO);
        return QuickDecorationsDrawer::DrawTextInfo();
    }

    if (offset) {
        const qreal foreignAnchorLine = ownAnchorLine - offset;
        const int margin = 10;

        if (orientation == Qt::Horizontal) {
            QRectF rect(m_painter->fontMetrics().boundingRect(label));

            QPointF center(foreignAnchorLine + ((ownAnchorLine - foreignAnchorLine) / 2),
                           itemGeometry.itemRect.center().y());

            if (align.testFlag(Qt::AlignLeft)) {
                rect.moveRight(center.x());

                if (align.testFlag(Qt::AlignVCenter)) {
                    rect.moveRight(foreignAnchorLine - margin);
                }
            } else if (align.testFlag(Qt::AlignRight)) {
                rect.moveLeft(center.x());

                if (align.testFlag(Qt::AlignVCenter)) {
                    rect.moveLeft(foreignAnchorLine + offset + margin);
                }
            } else if (align.testFlag(Qt::AlignHCenter)) {
                rect.moveCenter(QPointF(center.x(), rect.center().y()));
            }

            if (align.testFlag(Qt::AlignTop)) {
                rect.moveBottom(center.y() - margin);
            } else if (align.testFlag(Qt::AlignBottom)) {
                rect.moveTop(center.y() + margin);
            } else if (align.testFlag(Qt::AlignVCenter)) {
                rect.moveCenter(QPointF(rect.center().x(), center.y()));
            }

            return QuickDecorationsDrawer::DrawTextInfo(
                m_painter->pen(),
                rect,
                label);
        } else {
            QRectF rect(m_painter->fontMetrics().boundingRect(label));

            QPointF center(itemGeometry.itemRect.center().x(),
                           foreignAnchorLine + ((ownAnchorLine - foreignAnchorLine) / 2));

            if (align.testFlag(Qt::AlignLeft)) {
                rect.moveRight(center.x() - margin);
            } else if (align.testFlag(Qt::AlignRight)) {
                rect.moveLeft(center.x() + margin);
            } else if (align.testFlag(Qt::AlignHCenter)) {
                rect.moveCenter(QPointF(center.x(), rect.center().y()));
            }

            if (align.testFlag(Qt::AlignTop)) {
                rect.moveBottom(center.y());
            } else if (align.testFlag(Qt::AlignBottom)) {
                rect.moveTop(center.y());
            } else if (align.testFlag(Qt::AlignVCenter)) {
                rect.moveCenter(QPointF(rect.center().x(), center.y()));
            }

            return QuickDecorationsDrawer::DrawTextInfo(
                m_painter->pen(),
                rect,
                label);
        }
    }

    return QuickDecorationsDrawer::DrawTextInfo();
}

QuickDecorationsDrawer::DrawTextInfo QuickDecorationsDrawer::drawHorizontalAnchorLabel(const QuickItemGeometry &itemGeometry,
                                                                                       qreal ownAnchorLine, qreal offset, const QString &label, Qt::Alignment align)
{
    return drawAnchorLabel(itemGeometry, Qt::Horizontal, ownAnchorLine, offset, label, align);
}

QuickDecorationsDrawer::DrawTextInfo QuickDecorationsDrawer::drawVerticalAnchorLabel(const QuickItemGeometry &itemGeometry,
                                                                                     qreal ownAnchorLine, qreal offset, const QString &label, Qt::Alignment align)
{
    return drawAnchorLabel(itemGeometry, Qt::Vertical, ownAnchorLine, offset, label, align);
}

QDataStream &GammaRay::operator<<(QDataStream &stream, const GammaRay::QuickDecorationsSettings &settings)
{
    stream
        << settings.boundingRectColor
        << settings.boundingRectBrush
        << settings.geometryRectColor
        << settings.geometryRectBrush
        << settings.childrenRectColor
        << settings.childrenRectBrush
        << settings.transformOriginColor
        << settings.coordinatesColor
        << settings.marginsColor
        << settings.paddingColor
        << settings.gridOffset
        << settings.gridCellSize
        << settings.gridColor
        << settings.componentsTraces
        << settings.gridEnabled;

    return stream;
}

QDataStream &GammaRay::operator>>(QDataStream &stream, GammaRay::QuickDecorationsSettings &settings)
{
    stream
        >> settings.boundingRectColor
        >> settings.boundingRectBrush
        >> settings.geometryRectColor
        >> settings.geometryRectBrush
        >> settings.childrenRectColor
        >> settings.childrenRectBrush
        >> settings.transformOriginColor
        >> settings.coordinatesColor
        >> settings.marginsColor
        >> settings.paddingColor
        >> settings.gridOffset
        >> settings.gridCellSize
        >> settings.gridColor
        >> settings.componentsTraces
        >> settings.gridEnabled;

    return stream;
}