7#include "LabelGraphicsItem.h"
8#include "LabelGraphicsItem_p.h"
11#include <QApplication>
18LabelGraphicsItemPrivate::LabelGraphicsItemPrivate(
LabelGraphicsItem *labelGraphicsItem, MarbleGraphicsItem *parent)
19 : FrameGraphicsItemPrivate(labelGraphicsItem, parent)
23QFont LabelGraphicsItemPrivate::font()
28void LabelGraphicsItem::setContentSize(
const QSizeF &contentSize)
30 Q_D(LabelGraphicsItem);
31 QSizeF updatedSize = contentSize;
36 if (d->m_minimumSize.width() > updatedSize.
width()) {
37 updatedSize.
setWidth(d->m_minimumSize.width());
39 if (d->m_minimumSize.height() > updatedSize.
height()) {
40 updatedSize.
setHeight(d->m_minimumSize.height());
44 FrameGraphicsItem::setContentSize(updatedSize);
49LabelGraphicsItem::LabelGraphicsItem(MarbleGraphicsItem *parent)
50 : FrameGraphicsItem(new LabelGraphicsItemPrivate(this, parent))
54LabelGraphicsItem::~LabelGraphicsItem() =
default;
56QString LabelGraphicsItem::text()
const
58 Q_D(
const LabelGraphicsItem);
62void LabelGraphicsItem::setText(
const QString &text)
64 Q_D(LabelGraphicsItem);
67 QFontMetrics metrics(d->font());
68 QSizeF size = metrics.boundingRect(text).size() + QSizeF(14, 2);
72QImage LabelGraphicsItem::image()
const
74 Q_D(
const LabelGraphicsItem);
78void LabelGraphicsItem::setImage(
const QImage &image,
const QSize &size)
80 Q_D(LabelGraphicsItem);
84 setContentSize(image.size());
90QIcon LabelGraphicsItem::icon()
const
92 Q_D(
const LabelGraphicsItem);
96void LabelGraphicsItem::setIcon(
const QIcon &icon,
const QSize &size)
98 Q_D(LabelGraphicsItem);
101 setContentSize(size);
104QSizeF LabelGraphicsItem::minimumSize()
const
106 Q_D(
const LabelGraphicsItem);
107 return d->m_minimumSize;
110void LabelGraphicsItem::setMinimumSize(
const QSizeF &size)
112 Q_D(LabelGraphicsItem);
113 const QSizeF oldContentSize = contentSize();
114 d->m_minimumSize = size;
115 setContentSize(oldContentSize);
118void LabelGraphicsItem::clear()
120 Q_D(LabelGraphicsItem);
122 d->m_image = QImage();
124 setContentSize(QSizeF(0.0, 0.0));
127void LabelGraphicsItem::paintContent(QPainter *painter)
129 Q_D(LabelGraphicsItem);
132 if (!d->m_text.isNull()) {
136 }
else if (!d->m_image.isNull()) {
137 painter->
drawImage(QRectF(QPointF(0, 0), contentSize()), d->m_image);
138 }
else if (!d->m_icon.isNull()) {
139 d->m_icon.paint(painter, QRect(QPoint(0, 0), contentSize().toSize()),
Qt::AlignCenter);
A label item provides an Item that displays text or images/pixmaps.
Binds a QML item to a specific geodetic location in screen coordinates.
void drawImage(const QPoint &point, const QImage &image)
void drawText(const QPoint &position, const QString &text)
void setFont(const QFont &font)
void setPen(Qt::PenStyle style)
qreal height() const const
bool isEmpty() const const
void setHeight(qreal height)
void setWidth(qreal width)
qreal width() const const