summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets/qlabel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/widgets/qlabel.cpp')
-rw-r--r--src/widgets/widgets/qlabel.cpp158
1 files changed, 55 insertions, 103 deletions
diff --git a/src/widgets/widgets/qlabel.cpp b/src/widgets/widgets/qlabel.cpp
index bc40b0f442..a5681c0857 100644
--- a/src/widgets/widgets/qlabel.cpp
+++ b/src/widgets/widgets/qlabel.cpp
@@ -3,21 +3,15 @@
#include "qpainter.h"
#include "qevent.h"
-#include "qdrawutil.h"
-#include "qapplication.h"
-#if QT_CONFIG(abstractbutton)
-#include "qabstractbutton.h"
-#endif
#include "qstyle.h"
#include "qstyleoption.h"
-#include <limits.h>
-#include "qclipboard.h"
-#include <qdebug.h>
-#include <qurl.h>
#include "qlabel_p.h"
#include "private/qstylesheetstyle_p.h"
#include <qmath.h>
+#if QT_CONFIG(abstractbutton)
+#include "qabstractbutton.h"
+#endif
#if QT_CONFIG(accessibility)
#include <qaccessible.h>
#endif
@@ -28,46 +22,17 @@ using namespace Qt::StringLiterals;
QLabelPrivate::QLabelPrivate()
: QFramePrivate(),
- sh(),
- msh(),
- text(),
- pixmap(),
- scaledpixmap(),
- cachedimage(),
-#ifndef QT_NO_PICTURE
- picture(),
-#endif
-#if QT_CONFIG(movie)
- movie(),
-#endif
- control(nullptr),
- shortcutCursor(),
-#ifndef QT_NO_CURSOR
- cursor(),
-#endif
-#ifndef QT_NO_SHORTCUT
- buddy(),
- shortcutId(0),
-#endif
- textformat(Qt::AutoText),
- effectiveTextFormat(Qt::PlainText),
- textInteractionFlags(Qt::LinksAccessibleByMouse),
- sizePolicy(),
- margin(0),
- align(Qt::AlignLeft | Qt::AlignVCenter | Qt::TextExpandTabs),
- indent(-1),
valid_hints(false),
scaledcontents(false),
textLayoutDirty(false),
textDirty(false),
isTextLabel(false),
- hasShortcut(/*???*/),
+ hasShortcut(false),
#ifndef QT_NO_CURSOR
validCursor(false),
onAnchor(false),
#endif
- openExternalLinks(false),
- resourceProvider(nullptr)
+ openExternalLinks(false)
{
}
@@ -173,9 +138,7 @@ QLabelPrivate::~QLabelPrivate()
QPicture QLabel::picture() const
{
Q_D(const QLabel);
- if (d->picture)
- return *(d->picture);
- return QPicture();
+ return d->picture;
}
#endif // QT_NO_PICTURE
@@ -339,7 +302,7 @@ void QLabel::clear()
void QLabel::setPixmap(const QPixmap &pixmap)
{
Q_D(QLabel);
- if (!d->pixmap || d->pixmap->cacheKey() != pixmap.cacheKey()) {
+ if (d->pixmap.cacheKey() != pixmap.cacheKey()) {
d->clearContents();
d->pixmap = pixmap;
}
@@ -350,9 +313,7 @@ void QLabel::setPixmap(const QPixmap &pixmap)
QPixmap QLabel::pixmap() const
{
Q_D(const QLabel);
- if (d->pixmap)
- return *(d->pixmap);
- return QPixmap();
+ return d->pixmap;
}
/*!
@@ -405,9 +366,7 @@ void QLabel::setPicture(const QPicture &picture)
void QLabel::setNum(int num)
{
- QString str;
- str.setNum(num);
- setText(str);
+ setText(QString::number(num));
}
/*!
@@ -425,9 +384,7 @@ void QLabel::setNum(int num)
void QLabel::setNum(double num)
{
- QString str;
- str.setNum(num);
- setText(str);
+ setText(QString::number(num));
}
/*!
@@ -564,12 +521,12 @@ QSize QLabelPrivate::sizeForWidth(int w) const
int vextra = hextra;
QFontMetrics fm = q->fontMetrics();
- if (pixmap && !pixmap->isNull()) {
- br = pixmap->rect();
- br.setSize(pixmap->deviceIndependentSize().toSize());
+ if (!pixmap.isNull()) {
+ br = pixmap.rect();
+ br.setSize(pixmap.deviceIndependentSize().toSize());
#ifndef QT_NO_PICTURE
- } else if (picture && !picture->isNull()) {
- br = picture->boundingRect();
+ } else if (!picture.isNull()) {
+ br = picture.boundingRect();
#endif
#if QT_CONFIG(movie)
} else if (movie && !movie->currentPixmap().isNull()) {
@@ -1064,15 +1021,15 @@ void QLabel::paintEvent(QPaintEvent *)
}
} else
#ifndef QT_NO_PICTURE
- if (d->picture) {
- QRect br = d->picture->boundingRect();
+ if (!d->picture.isNull()) {
+ QRect br = d->picture.boundingRect();
int rw = br.width();
int rh = br.height();
if (d->scaledcontents) {
painter.save();
painter.translate(cr.x(), cr.y());
painter.scale((double)cr.width()/rw, (double)cr.height()/rh);
- painter.drawPicture(-br.x(), -br.y(), *d->picture);
+ painter.drawPicture(-br.x(), -br.y(), d->picture);
painter.restore();
} else {
int xo = 0;
@@ -1085,29 +1042,25 @@ void QLabel::paintEvent(QPaintEvent *)
xo = cr.width()-rw;
else if (align & Qt::AlignHCenter)
xo = (cr.width()-rw)/2;
- painter.drawPicture(cr.x()+xo-br.x(), cr.y()+yo-br.y(), *d->picture);
+ painter.drawPicture(cr.x()+xo-br.x(), cr.y()+yo-br.y(), d->picture);
}
} else
#endif
- if (d->pixmap && !d->pixmap->isNull()) {
+ if (!d->pixmap.isNull()) {
QPixmap pix;
const qreal dpr = devicePixelRatio();
- if (d->scaledcontents || dpr != d->pixmap->devicePixelRatio()) {
+ if (d->scaledcontents || dpr != d->pixmap.devicePixelRatio()) {
QSize scaledSize = d->scaledcontents ? (cr.size() * dpr)
- : (d->pixmap->size() * (dpr / d->pixmap->devicePixelRatio()));
- if (!d->scaledpixmap || d->scaledpixmap->size() != scaledSize) {
- if (!d->cachedimage)
- d->cachedimage = d->pixmap->toImage();
- d->scaledpixmap.reset();
- QImage scaledImage =
- d->cachedimage->scaled(scaledSize,
- Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
- d->scaledpixmap = QPixmap::fromImage(std::move(scaledImage));
- d->scaledpixmap->setDevicePixelRatio(dpr);
+ : (d->pixmap.size() * (dpr / d->pixmap.devicePixelRatio()));
+ if (d->scaledpixmap.size() != scaledSize) {
+ d->scaledpixmap =
+ d->pixmap.scaled(scaledSize,
+ Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
+ d->scaledpixmap.setDevicePixelRatio(dpr);
}
- pix = *d->scaledpixmap;
+ pix = d->scaledpixmap;
} else
- pix = *d->pixmap;
+ pix = d->pixmap;
QStyleOption opt;
opt.initFrom(this);
if (!isEnabled())
@@ -1171,12 +1124,14 @@ void QLabel::setBuddy(QWidget *buddy)
Q_D(QLabel);
if (d->buddy)
- disconnect(d->buddy, SIGNAL(destroyed()), this, SLOT(_q_buddyDeleted()));
+ QObjectPrivate::disconnect(d->buddy, &QObject::destroyed,
+ d, &QLabelPrivate::buddyDeleted);
d->buddy = buddy;
if (buddy)
- connect(buddy, SIGNAL(destroyed()), this, SLOT(_q_buddyDeleted()));
+ QObjectPrivate::connect(buddy, &QObject::destroyed,
+ d, &QLabelPrivate::buddyDeleted);
if (d->isTextLabel) {
if (d->shortcutId)
@@ -1219,7 +1174,7 @@ void QLabelPrivate::updateShortcut()
}
-void QLabelPrivate::_q_buddyDeleted()
+void QLabelPrivate::buddyDeleted()
{
Q_Q(QLabel);
q->setBuddy(nullptr);
@@ -1228,7 +1183,7 @@ void QLabelPrivate::_q_buddyDeleted()
#endif // QT_NO_SHORTCUT
#if QT_CONFIG(movie)
-void QLabelPrivate::_q_movieUpdated(const QRect& rect)
+void QLabelPrivate::movieUpdated(const QRect &rect)
{
Q_Q(QLabel);
if (movie && movie->isValid()) {
@@ -1251,12 +1206,12 @@ void QLabelPrivate::_q_movieUpdated(const QRect& rect)
}
}
-void QLabelPrivate::_q_movieResized(const QSize& size)
+void QLabelPrivate::movieResized(const QSize &size)
{
Q_Q(QLabel);
q->update(); //we need to refresh the whole background in case the new size is smaller
valid_hints = false;
- _q_movieUpdated(QRect(QPoint(0,0), size));
+ movieUpdated(QRect(QPoint(0,0), size));
q->updateGeometry();
}
@@ -1278,8 +1233,10 @@ void QLabel::setMovie(QMovie *movie)
return;
d->movie = movie;
- connect(movie, SIGNAL(resized(QSize)), this, SLOT(_q_movieResized(QSize)));
- connect(movie, SIGNAL(updated(QRect)), this, SLOT(_q_movieUpdated(QRect)));
+ d->movieConnections = {
+ QObjectPrivate::connect(movie, &QMovie::resized, d, &QLabelPrivate::movieResized),
+ QObjectPrivate::connect(movie, &QMovie::updated, d, &QLabelPrivate::movieUpdated),
+ };
// Assume that if the movie is running,
// resize/update signals will come soon enough
@@ -1303,11 +1260,10 @@ void QLabelPrivate::clearContents()
hasShortcut = false;
#ifndef QT_NO_PICTURE
- picture.reset();
+ picture = QPicture();
#endif
- scaledpixmap.reset();
- cachedimage.reset();
- pixmap.reset();
+ scaledpixmap = QPixmap();
+ pixmap = QPixmap();
text.clear();
Q_Q(QLabel);
@@ -1317,10 +1273,8 @@ void QLabelPrivate::clearContents()
shortcutId = 0;
#endif
#if QT_CONFIG(movie)
- if (movie) {
- QObject::disconnect(movie, SIGNAL(resized(QSize)), q, SLOT(_q_movieResized(QSize)));
- QObject::disconnect(movie, SIGNAL(updated(QRect)), q, SLOT(_q_movieUpdated(QRect)));
- }
+ for (const auto &conn : std::as_const(movieConnections))
+ QObject::disconnect(conn);
movie = nullptr;
#endif
#ifndef QT_NO_CURSOR
@@ -1452,10 +1406,8 @@ void QLabel::setScaledContents(bool enable)
if ((bool)d->scaledcontents == enable)
return;
d->scaledcontents = enable;
- if (!enable) {
- d->scaledpixmap.reset();
- d->cachedimage.reset();
- }
+ if (!enable)
+ d->scaledpixmap = QPixmap();
update(contentsRect());
}
@@ -1580,12 +1532,12 @@ void QLabelPrivate::ensureTextControl() const
control->setOpenExternalLinks(openExternalLinks);
control->setPalette(q->palette());
control->setFocus(q->hasFocus());
- QObject::connect(control, SIGNAL(updateRequest(QRectF)),
- q, SLOT(update()));
- QObject::connect(control, SIGNAL(linkHovered(QString)),
- q, SLOT(_q_linkHovered(QString)));
- QObject::connect(control, SIGNAL(linkActivated(QString)),
- q, SIGNAL(linkActivated(QString)));
+ QObject::connect(control, &QWidgetTextControl::updateRequest,
+ q, qOverload<>(&QLabel::update));
+ QObject::connect(control, &QWidgetTextControl::linkActivated,
+ q, &QLabel::linkActivated);
+ QObjectPrivate::connect(control, &QWidgetTextControl::linkHovered,
+ this, &QLabelPrivate::linkHovered);
textLayoutDirty = true;
textDirty = true;
}
@@ -1601,7 +1553,7 @@ void QLabelPrivate::sendControlEvent(QEvent *e)
control->processEvent(e, -layoutRect().topLeft(), q);
}
-void QLabelPrivate::_q_linkHovered(const QString &anchor)
+void QLabelPrivate::linkHovered(const QString &anchor)
{
Q_Q(QLabel);
#ifndef QT_NO_CURSOR