7#include "FrameGraphicsItem.h"
8#include "FrameGraphicsItem_p.h"
11#include "MarbleDebug.h"
16#include <QPainterPath>
17#include <QPixmapCache>
23FrameGraphicsItem::FrameGraphicsItem(MarbleGraphicsItem *parent)
24 : ScreenGraphicsItem(new FrameGraphicsItemPrivate(this, parent))
26 Q_D(FrameGraphicsItem);
30FrameGraphicsItem::FrameGraphicsItem(FrameGraphicsItemPrivate *dd)
31 : ScreenGraphicsItem(dd)
33 Q_D(FrameGraphicsItem);
37FrameGraphicsItem::~FrameGraphicsItem() =
default;
39FrameGraphicsItem::FrameType FrameGraphicsItem::frame()
const
41 Q_D(
const FrameGraphicsItem);
45void FrameGraphicsItem::setFrame(FrameType type)
47 Q_D(FrameGraphicsItem);
49 setPadding(padding());
52qreal FrameGraphicsItem::margin()
const
54 Q_D(
const FrameGraphicsItem);
58void FrameGraphicsItem::setMargin(qreal margin)
60 Q_D(FrameGraphicsItem);
66qreal FrameGraphicsItem::marginTop()
const
68 Q_D(
const FrameGraphicsItem);
69 return d->m_marginTop;
72void FrameGraphicsItem::setMarginTop(qreal marginTop)
74 Q_D(FrameGraphicsItem);
75 d->m_marginTop = marginTop;
80qreal FrameGraphicsItem::marginBottom()
const
82 Q_D(
const FrameGraphicsItem);
83 return d->m_marginBottom;
86void FrameGraphicsItem::setMarginBottom(qreal marginBottom)
88 Q_D(FrameGraphicsItem);
89 d->m_marginBottom = marginBottom;
94qreal FrameGraphicsItem::marginLeft()
const
96 Q_D(
const FrameGraphicsItem);
97 return d->m_marginLeft;
100void FrameGraphicsItem::setMarginLeft(qreal marginLeft)
102 Q_D(FrameGraphicsItem);
103 d->m_marginLeft = marginLeft;
108qreal FrameGraphicsItem::marginRight()
const
110 Q_D(
const FrameGraphicsItem);
111 return d->m_marginRight;
114void FrameGraphicsItem::setMarginRight(qreal marginRight)
116 Q_D(FrameGraphicsItem);
117 d->m_marginRight = marginRight;
122qreal FrameGraphicsItem::borderWidth()
const
124 Q_D(
const FrameGraphicsItem);
125 return d->m_borderWidth;
128void FrameGraphicsItem::setBorderWidth(qreal width)
130 Q_D(FrameGraphicsItem);
131 d->m_borderWidth = width;
136qreal FrameGraphicsItem::padding()
const
138 Q_D(
const FrameGraphicsItem);
142void FrameGraphicsItem::setPadding(qreal width)
144 Q_D(FrameGraphicsItem);
146 d->m_padding = width;
151QBrush FrameGraphicsItem::borderBrush()
const
153 Q_D(
const FrameGraphicsItem);
154 return d->m_borderBrush;
157void FrameGraphicsItem::setBorderBrush(
const QBrush &brush)
159 Q_D(FrameGraphicsItem);
160 d->m_borderBrush = brush;
166 Q_D(
const FrameGraphicsItem);
167 return d->m_borderStyle;
170void FrameGraphicsItem::setBorderStyle(
Qt::PenStyle style)
172 Q_D(FrameGraphicsItem);
173 d->m_borderStyle = style;
177QBrush FrameGraphicsItem::background()
const
179 Q_D(
const FrameGraphicsItem);
180 return d->m_backgroundBrush;
183void FrameGraphicsItem::setBackground(
const QBrush &background)
185 Q_D(FrameGraphicsItem);
186 d->m_backgroundBrush = background;
190QRectF FrameGraphicsItem::contentRect()
const
192 Q_D(
const FrameGraphicsItem);
193 qreal marginTop = (d->m_marginTop == 0.0) ? d->m_margin : d->m_marginTop;
194 qreal marginLeft = (d->m_marginLeft == 0.0) ? d->m_margin : d->m_marginLeft;
196 QRectF contentRect =
QRectF(marginLeft + d->m_padding, marginTop + d->m_padding, d->m_contentSize.width(), d->m_contentSize.height());
201QSizeF FrameGraphicsItem::contentSize()
const
203 Q_D(
const FrameGraphicsItem);
204 return d->m_contentSize;
207QRectF FrameGraphicsItem::paintedRect()
const
209 Q_D(
const FrameGraphicsItem);
210 qreal marginTop = (d->m_marginTop == 0.0) ? d->m_margin : d->m_marginTop;
211 qreal marginBottom = (d->m_marginBottom == 0.0) ? d->m_margin : d->m_marginBottom;
212 qreal marginLeft = (d->m_marginLeft == 0.0) ? d->m_margin : d->m_marginLeft;
213 qreal marginRight = (d->m_marginRight == 0.0) ? d->m_margin : d->m_marginRight;
215 QSizeF size = this->size();
217 QRectF paintedRect =
QRectF(marginLeft, marginTop, size.
width() - (marginLeft + marginRight), size.
height() - (marginTop + marginBottom));
221void FrameGraphicsItem::setContentSize(
const QSizeF &size)
223 Q_D(FrameGraphicsItem);
224 d->m_contentSize = size;
230 Q_D(
const FrameGraphicsItem);
232 if (d->m_frame == RectFrame || d->m_frame == ShadowFrame) {
233 QRectF renderedRect = paintedRect();
235 }
else if (d->m_frame == RoundedRectFrame) {
242void FrameGraphicsItem::paintBackground(
QPainter *painter)
244 Q_D(FrameGraphicsItem);
246 painter->
setPen(
QPen(d->m_borderBrush, d->m_borderWidth, d->m_borderStyle));
247 painter->
setBrush(d->m_backgroundBrush);
248 painter->
drawPath(backgroundShape());
253void FrameGraphicsItem::paint(
QPainter *painter)
255 Q_D(FrameGraphicsItem);
259 if (frame() == ShadowFrame) {
262 shadow =
QPixmap(QStringLiteral(
":/marble/frames/shadowframe.png"));
265 qDrawBorderPixmap(painter,
QRect(
QPoint(0, 0), size().toSize()),
QMargins(10, 10, 10, 10), shadow);
268 painter->
translate(paintedRect().topLeft());
269 paintBackground(painter);
270 painter->
translate(d->m_padding, d->m_padding);
271 paintContent(painter);
275void FrameGraphicsItem::paintContent(
QPainter *painter)
QString path(const QString &relativePath)
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
Binds a QML item to a specific geodetic location in screen coordinates.
void drawPath(const QPainterPath &path)
void setBrush(Qt::BrushStyle style)
void setPen(Qt::PenStyle style)
void translate(const QPoint &offset)
bool find(const Key &key, QPixmap *pixmap)
Key insert(const QPixmap &pixmap)
QSizeF size() const const
qreal height() const const
qreal width() const const