Skip to content

Commit 07652a3

Browse files
committed
build: compiling failed with Qt 6.9
Signed-off-by: ComixHe <heyuming@deepin.org>
1 parent 00b28eb commit 07652a3

File tree

2 files changed

+51
-15
lines changed

2 files changed

+51
-15
lines changed

src/widgets/dlabel.cpp

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <DPaletteHelper>
1010

11+
#include <private/qhexstring_p.h>
1112
#include <private/qlabel_p.h>
1213

1314
DWIDGET_BEGIN_NAMESPACE
@@ -257,11 +258,16 @@ void DLabel::paintEvent(QPaintEvent *event)
257258
}
258259
} else
259260
#endif
260-
if (d->pixmap && !d->pixmap->isNull()) {
261-
QPixmap pix;
262-
if (d->scaledcontents) {
263-
QSize scaledSize = cr.size() * devicePixelRatioF();
264-
if (!d->scaledpixmap || d->scaledpixmap->size() != scaledSize) {
261+
#if QT_VERSION < QT_VERSION_CHECK(6, 9, 0)
262+
if (d->pixmap && !d->pixmap->isNull()) {
263+
#else
264+
if (d->icon && !d->icon->isNull()) {
265+
#endif
266+
#if QT_VERSION < QT_VERSION_CHECK(6, 9, 0)
267+
QPixmap pix;
268+
if (d->scaledcontents) {
269+
QSize scaledSize = cr.size() * devicePixelRatioF();
270+
if (!d->scaledpixmap || d->scaledpixmap->size() != scaledSize) {
265271
#if QT_VERSION < QT_VERSION_CHECK(6, 8, 0)
266272
if (!d->cachedimage)
267273
#endif
@@ -290,15 +296,45 @@ void DLabel::paintEvent(QPaintEvent *event)
290296
#endif
291297
#endif
292298
d->scaledpixmap->setDevicePixelRatio(devicePixelRatioF());
293-
}
299+
}
294300
pix = *d->scaledpixmap;
295-
} else
296-
pix = *d->pixmap;
297-
QStyleOption opt;
298-
opt.initFrom(this);
299-
if (!isEnabled())
300-
pix = style->generatedIconPixmap(QIcon::Disabled, pix, &opt);
301-
style->drawItemPixmap(&painter, cr, align, pix);
301+
} else
302+
pix = *d->pixmap;
303+
QStyleOption opt;
304+
opt.initFrom(this);
305+
if (!isEnabled())
306+
pix = style->generatedIconPixmap(QIcon::Disabled, pix, &opt);
307+
style->drawItemPixmap(&painter, cr, align, pix);
308+
#else
309+
// pick up from
310+
// https://github.com/qt/qtbase/blob/25986746947798e1a22d0830d3bcb11a55fcd3ae/src/widgets/widgets/qlabel.cpp#L1052
311+
const qreal dpr = devicePixelRatio();
312+
const QSize size = d->scaledcontents ? cr.size() : d->pixmapSize;
313+
const auto mode = isEnabled() ? QIcon::Normal : QIcon::Disabled;
314+
QPixmap pix = d->icon->pixmap(size, dpr, mode);
315+
if (d->scaledcontents && pix.size() != size * dpr) {
316+
using namespace Qt::StringLiterals;
317+
const QString key =
318+
"qt_label_"_L1 % HexString<quint64>(pix.cacheKey()) %
319+
HexString<quint8>(mode) % HexString<uint>(size.width()) %
320+
HexString<uint>(size.height()) %
321+
HexString<quint16>(qRound(dpr * 1000));
322+
if (!QPixmapCache::find(key, &pix)) {
323+
pix = pix.scaled(size * dpr, Qt::IgnoreAspectRatio,
324+
Qt::SmoothTransformation);
325+
pix.setDevicePixelRatio(dpr);
326+
// using QIcon to cache the newly create pixmap is not possible
327+
// because QIcon does not clear this cache (so we grow indefinitely)
328+
// and also uses the newly added pixmap as starting point for new
329+
// scaled pixmap which makes it very blurry.
330+
// Therefore use QPixmapCache here.
331+
QPixmapCache::insert(key, pix);
332+
}
333+
}
334+
QStyleOption opt;
335+
opt.initFrom(this);
336+
style->drawItemPixmap(&painter, cr, align, pix);
337+
#endif
302338
}
303339
}
304340

src/widgets/dtitlebarsettings.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,6 @@ DTitlebarSettingsImpl *DTitlebarSettings::impl()
6060
return d->impl;
6161
}
6262

63-
#include "moc_dtitlebarsettings.cpp"
64-
6563
DWIDGET_END_NAMESPACE
64+
65+
#include "moc_dtitlebarsettings.cpp"

0 commit comments

Comments
 (0)