[Icon Item] Fix updating implicit size when icon sizes change
The old code was connecting the KIconLoader signal to implicitWidth/HeightChanged but never actually set a new implicit size. Also, while at it use "setImplicitSize" - it's also marked internal but public like setSize and uses qreal instead of QSizeF. Differential Revision: https://phabricator.kde.org/D4011
This commit is contained in:
parent
4b55493568
commit
8875a04a1b
@ -480,5 +480,37 @@ void IconItemTest::paintedSize()
|
||||
QCOMPARE(item->property("paintedHeight").toInt(), 400);
|
||||
}
|
||||
|
||||
void IconItemTest::implicitSize()
|
||||
{
|
||||
KConfigGroup cg(KSharedConfig::openConfig(), "DialogIcons");
|
||||
cg.writeEntry("Size", 22);
|
||||
cg.sync();
|
||||
KIconLoader::global()->reconfigure(QString());
|
||||
|
||||
QQuickItem *item = createIconItem();
|
||||
|
||||
// qreal cast needed as QTest::qCompare<double, int> fails to link
|
||||
QCOMPARE(item->implicitWidth(), qreal(22));
|
||||
QCOMPARE(item->implicitHeight(), qreal(22));
|
||||
|
||||
QSignalSpy widthSpy(item, &QQuickItem::implicitWidthChanged);
|
||||
QVERIFY(widthSpy.isValid());
|
||||
QSignalSpy heightSpy(item, &QQuickItem::implicitHeightChanged);
|
||||
QVERIFY(heightSpy.isValid());
|
||||
|
||||
cg.writeEntry("Size", 64);
|
||||
cg.sync();
|
||||
KIconLoader::global()->reconfigure(QString());
|
||||
// merely changing the setting and calling reconfigure won't emit this signal,
|
||||
// the KCM uses a method "newIconLoader" method which does that but it's deprecated
|
||||
emit KIconLoader::global()->iconLoaderSettingsChanged();
|
||||
|
||||
QCOMPARE(widthSpy.count(), 1);
|
||||
QCOMPARE(heightSpy.count(), 1);
|
||||
|
||||
QCOMPARE(item->implicitWidth(), qreal(64));
|
||||
QCOMPARE(item->implicitHeight(), qreal(64));
|
||||
}
|
||||
|
||||
QTEST_MAIN(IconItemTest)
|
||||
|
||||
|
@ -55,6 +55,7 @@ private Q_SLOTS:
|
||||
void animatingEnabledChange();
|
||||
void windowChanged();
|
||||
void paintedSize();
|
||||
void implicitSize();
|
||||
|
||||
private:
|
||||
QQuickItem *createIconItem();
|
||||
|
@ -62,10 +62,8 @@ IconItem::IconItem(QQuickItem *parent)
|
||||
|
||||
setFlag(ItemHasContents, true);
|
||||
|
||||
connect(KIconLoader::global(), SIGNAL(iconLoaderSettingsChanged()),
|
||||
this, SIGNAL(implicitWidthChanged()));
|
||||
connect(KIconLoader::global(), SIGNAL(iconLoaderSettingsChanged()),
|
||||
this, SIGNAL(implicitHeightChanged()));
|
||||
connect(KIconLoader::global(), &KIconLoader::iconLoaderSettingsChanged,
|
||||
this, &IconItem::updateImplicitSize);
|
||||
|
||||
connect(this, &QQuickItem::enabledChanged,
|
||||
this, &IconItem::enabledChanged);
|
||||
@ -76,15 +74,20 @@ IconItem::IconItem(QQuickItem *parent)
|
||||
connect(this, SIGNAL(overlaysChanged()),
|
||||
this, SLOT(schedulePixmapUpdate()));
|
||||
|
||||
//initialize implicit size to the Dialog size
|
||||
setImplicitWidth(KIconLoader::global()->currentSize(KIconLoader::Dialog));
|
||||
setImplicitHeight(KIconLoader::global()->currentSize(KIconLoader::Dialog));
|
||||
updateImplicitSize();
|
||||
}
|
||||
|
||||
IconItem::~IconItem()
|
||||
{
|
||||
}
|
||||
|
||||
void IconItem::updateImplicitSize()
|
||||
{
|
||||
//initialize implicit size to the Dialog size
|
||||
const int implicitSize = KIconLoader::global()->currentSize(KIconLoader::Dialog);
|
||||
setImplicitSize(implicitSize, implicitSize);
|
||||
}
|
||||
|
||||
void IconItem::setSource(const QVariant &source)
|
||||
{
|
||||
if (source == m_source) {
|
||||
|
@ -177,6 +177,7 @@ private Q_SLOTS:
|
||||
private:
|
||||
void loadPixmap();
|
||||
QSize paintedSize(const QSizeF &containerSize = QSizeF()) const;
|
||||
void updateImplicitSize();
|
||||
|
||||
//all the ways we can set an source. Only one of them will be valid
|
||||
QIcon m_icon;
|
||||
|
Loading…
Reference in New Issue
Block a user