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
|
/*
quickdecorationsdrawer.h
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.
*/
#ifndef GAMMARAY_QUICKINSPECTOR_QUICKDECORATIONSDRAWER_H
#define GAMMARAY_QUICKINSPECTOR_QUICKDECORATIONSDRAWER_H
#include <QPen>
#include "quickitemgeometry.h"
namespace GammaRay {
struct QuickDecorationsSettings
{
QuickDecorationsSettings()
: boundingRectColor(QColor(232, 87, 82, 170))
, boundingRectBrush(QBrush(QColor(232, 87, 82, 95)))
, geometryRectColor(QColor(Qt::gray))
, geometryRectBrush(QBrush(QColor(Qt::gray), Qt::BDiagPattern))
, childrenRectColor(QColor(0, 99, 193, 170))
, childrenRectBrush(QBrush(QColor(0, 99, 193, 95)))
, transformOriginColor(QColor(156, 15, 86, 170))
, coordinatesColor(QColor(136, 136, 136))
, marginsColor(QColor(139, 179, 0))
, paddingColor(QColor(Qt::darkBlue))
, gridOffset(QPointF(0, 0))
, gridCellSize(QSizeF(0, 0))
, gridColor(QColor(Qt::red))
, componentsTraces(false)
, gridEnabled(false)
{
}
bool operator==(const QuickDecorationsSettings &other) const
{
return boundingRectColor == other.boundingRectColor && boundingRectBrush == other.boundingRectBrush && geometryRectColor == other.geometryRectColor && geometryRectBrush == other.geometryRectBrush && childrenRectColor == other.childrenRectColor && childrenRectBrush == other.childrenRectBrush && transformOriginColor == other.transformOriginColor && coordinatesColor == other.coordinatesColor && marginsColor == other.marginsColor && paddingColor == other.paddingColor && gridOffset == other.gridOffset && gridCellSize == other.gridCellSize && gridColor == other.gridColor && componentsTraces == other.componentsTraces && gridEnabled == other.gridEnabled;
}
bool operator!=(const QuickDecorationsSettings &other) const
{
return !operator==(other);
}
QColor boundingRectColor;
QBrush boundingRectBrush;
QColor geometryRectColor;
QBrush geometryRectBrush;
QColor childrenRectColor;
QBrush childrenRectBrush;
QColor transformOriginColor;
QColor coordinatesColor;
QColor marginsColor;
QColor paddingColor;
QPointF gridOffset;
QSizeF gridCellSize;
QColor gridColor;
bool componentsTraces;
bool gridEnabled;
};
QDataStream &operator<<(QDataStream &stream, const GammaRay::QuickDecorationsSettings &settings);
QDataStream &operator>>(QDataStream &stream, GammaRay::QuickDecorationsSettings &settings);
struct QuickDecorationsBaseRenderInfo
{
QuickDecorationsBaseRenderInfo(const QuickDecorationsSettings &settings = QuickDecorationsSettings(),
const QRectF &viewRect = QRectF(),
qreal zoom = 1.0)
: settings(settings)
, viewRect(viewRect)
, zoom(zoom)
{
}
const QuickDecorationsSettings settings;
const QRectF viewRect;
const qreal zoom;
};
struct QuickDecorationsRenderInfo : QuickDecorationsBaseRenderInfo
{
QuickDecorationsRenderInfo(const QuickDecorationsSettings &settings = QuickDecorationsSettings(),
const QuickItemGeometry &itemGeometry = QuickItemGeometry(),
const QRectF &viewRect = QRectF(),
qreal zoom = 1.0)
: QuickDecorationsBaseRenderInfo(settings, viewRect, zoom)
, itemGeometry(itemGeometry)
{
}
const QuickItemGeometry itemGeometry;
};
struct QuickDecorationsTracesInfo : QuickDecorationsBaseRenderInfo
{
QuickDecorationsTracesInfo(const QuickDecorationsSettings &settings = QuickDecorationsSettings(),
const QVector<QuickItemGeometry> &itemsGeometry = QVector<QuickItemGeometry>(),
const QRectF &viewRect = QRectF(),
qreal zoom = 1.0)
: QuickDecorationsBaseRenderInfo(settings, viewRect, zoom)
, itemsGeometry(itemsGeometry)
{
}
const QVector<QuickItemGeometry> itemsGeometry;
};
class QuickDecorationsDrawer
{
public:
enum Type
{
Decorations,
Traces
};
QuickDecorationsDrawer(QuickDecorationsDrawer::Type type, QPainter &painter,
const QuickDecorationsBaseRenderInfo &renderInfo);
void render();
private:
struct DrawTextInfo
{
DrawTextInfo(const QPen &pen = QPen(), const QRectF &rect = QRectF(),
const QString &label = QString(),
int align = Qt::AlignCenter | Qt::TextDontClip)
: pen(pen)
, rect(rect)
, label(label)
, align(align)
{
}
QPen pen;
QRectF rect;
QString label;
int align;
};
typedef QVector<DrawTextInfo> DrawTextInfoList;
QuickItemGeometry itemGeometry() const;
QVector<QuickItemGeometry> itemsGeometry() const;
void drawDecorations();
void drawTraces();
void drawGrid();
void drawArrow(const QPointF &first, const QPointF &second);
void drawAnchor(const QuickItemGeometry &itemGeometry, Qt::Orientation orientation,
qreal ownAnchorLine, qreal offset);
void drawVerticalAnchor(const QuickItemGeometry &itemGeometry, qreal ownAnchorLine,
qreal offset);
void drawHorizontalAnchor(const QuickItemGeometry &itemGeometry, qreal ownAnchorLine,
qreal offset);
DrawTextInfo drawAnchorLabel(const QuickItemGeometry &itemGeometry, Qt::Orientation orientation,
qreal ownAnchorLine, qreal offset, const QString &label,
Qt::Alignment align);
DrawTextInfo drawHorizontalAnchorLabel(const QuickItemGeometry &itemGeometry, qreal ownAnchorLine,
qreal offset, const QString &label, Qt::Alignment align);
DrawTextInfo drawVerticalAnchorLabel(const QuickItemGeometry &itemGeometry, qreal ownAnchorLine,
qreal offset, const QString &label, Qt::Alignment align);
const QuickDecorationsDrawer::Type m_type;
const QuickDecorationsBaseRenderInfo *const m_renderInfo;
QPainter *const m_painter;
};
}
Q_DECLARE_METATYPE(GammaRay::QuickDecorationsSettings)
#endif
|