2020-08-13 21:08:54 +02:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2016 David Rosca <nowrep@gmail.com>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: LGPL-2.0-or-later
|
|
|
|
*/
|
2016-02-27 21:24:45 +01:00
|
|
|
|
|
|
|
#include "iconitemtest.h"
|
|
|
|
|
|
|
|
#include <QIcon>
|
|
|
|
#include <QQmlEngine>
|
|
|
|
#include <QQmlContext>
|
|
|
|
#include <QQmlComponent>
|
|
|
|
#include <QQuickItemGrabResult>
|
2018-11-06 07:23:52 +01:00
|
|
|
#include <QSignalSpy>
|
2016-02-27 21:24:45 +01:00
|
|
|
|
|
|
|
#include <KIconLoader>
|
|
|
|
#include <KIconEngine>
|
2016-04-27 13:37:45 +02:00
|
|
|
#include <KIconTheme>
|
2016-02-27 21:24:45 +01:00
|
|
|
|
|
|
|
#include "plasma/theme.h"
|
|
|
|
#include "plasma/svg.h"
|
|
|
|
|
2019-07-25 00:43:38 +02:00
|
|
|
#include "utils.h"
|
|
|
|
|
2016-02-27 21:24:45 +01:00
|
|
|
static bool imageIsEmpty(const QImage &img)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < img.width(); ++i) {
|
|
|
|
for (int j = 0; j < img.height(); ++j) {
|
2016-02-28 10:36:57 +01:00
|
|
|
if (img.pixel(i, j) != 0) {
|
2016-02-27 21:24:45 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IconItemTest::initTestCase()
|
|
|
|
{
|
2019-07-25 01:15:30 +02:00
|
|
|
Plasma::TestUtils::installPlasmaTheme("breeze");
|
|
|
|
Plasma::TestUtils::installPlasmaTheme("breeze-light");
|
|
|
|
Plasma::TestUtils::installPlasmaTheme("breeze-dark");
|
|
|
|
|
2019-07-25 00:43:38 +02:00
|
|
|
qputenv("XDG_DATA_DIRS", qgetenv("XDG_DATA_DIRS") + ":" + QFINDTESTDATA("data").toLocal8Bit());
|
2016-02-27 19:40:54 +01:00
|
|
|
|
|
|
|
QString configPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation);
|
|
|
|
|
|
|
|
if(!QDir(configPath).mkpath(QStringLiteral("."))) {
|
|
|
|
qFatal("Failed to create test configuration directory.");
|
|
|
|
}
|
|
|
|
|
|
|
|
QFile::remove(configPath);
|
|
|
|
|
2016-03-06 16:13:54 +01:00
|
|
|
QIcon::setThemeSearchPaths({QFINDTESTDATA("data/icons")});
|
|
|
|
QIcon::setThemeName("test-theme");
|
|
|
|
|
2016-05-18 13:50:11 +02:00
|
|
|
KIconTheme::forceThemeForTests("test-theme");
|
2016-04-27 13:34:43 +02:00
|
|
|
KIconTheme::reconfigure();
|
|
|
|
KIconLoader::global()->reconfigure(QString());
|
|
|
|
|
2016-02-27 21:24:45 +01:00
|
|
|
m_view = new QQuickView();
|
|
|
|
m_view->setSource(QUrl::fromLocalFile(QFINDTESTDATA("data/view.qml")));
|
|
|
|
m_view->show();
|
2017-12-06 08:17:21 +01:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(m_view));
|
2016-02-29 22:29:51 +01:00
|
|
|
|
|
|
|
if (!m_view->rootObject() || !m_view->rootObject()->grabToImage()) {
|
|
|
|
QSKIP("Cannot grab item to image.");
|
|
|
|
}
|
2016-02-27 21:24:45 +01:00
|
|
|
}
|
|
|
|
|
2016-03-04 23:44:57 +01:00
|
|
|
void IconItemTest::cleanupTestCase()
|
|
|
|
{
|
|
|
|
delete m_view;
|
|
|
|
}
|
|
|
|
|
2016-07-12 10:01:29 +02:00
|
|
|
void IconItemTest::init()
|
|
|
|
{
|
|
|
|
Plasma::Theme().setThemeName(QStringLiteral("default"));
|
|
|
|
}
|
|
|
|
|
2016-02-27 21:24:45 +01:00
|
|
|
void IconItemTest::cleanup()
|
|
|
|
{
|
|
|
|
qDeleteAll(m_view->rootObject()->childItems());
|
|
|
|
}
|
|
|
|
|
|
|
|
QQuickItem *IconItemTest::createIconItem()
|
|
|
|
{
|
|
|
|
QByteArray iconQml =
|
|
|
|
"import QtQuick 2.0;"
|
|
|
|
"import org.kde.plasma.core 2.0 as PlasmaCore;"
|
|
|
|
"PlasmaCore.IconItem {"
|
|
|
|
" id: root;"
|
|
|
|
"}";
|
|
|
|
|
|
|
|
QQmlComponent component(m_view->engine());
|
|
|
|
|
|
|
|
QSignalSpy spy(&component, SIGNAL(statusChanged(QQmlComponent::Status)));
|
|
|
|
component.setData(iconQml, QUrl("test://iconTest"));
|
|
|
|
if (component.status() != QQmlComponent::Ready) {
|
|
|
|
spy.wait();
|
|
|
|
}
|
|
|
|
|
|
|
|
QQuickItem *item = qobject_cast<QQuickItem*>(component.create(m_view->engine()->rootContext()));
|
|
|
|
Q_ASSERT(item && qstrcmp(item->metaObject()->className(), "IconItem") == 0);
|
|
|
|
item->setParentItem(m_view->rootObject());
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage IconItemTest::grabImage(QQuickItem *item)
|
|
|
|
{
|
|
|
|
QSharedPointer<QQuickItemGrabResult> grab = item->grabToImage();
|
|
|
|
QSignalSpy spy(grab.data(), SIGNAL(ready()));
|
|
|
|
spy.wait();
|
|
|
|
return grab->image();
|
|
|
|
}
|
|
|
|
|
2016-02-27 19:40:54 +01:00
|
|
|
Plasma::Svg *IconItemTest::findPlasmaSvg(QQuickItem *item)
|
|
|
|
{
|
|
|
|
return item->findChild<Plasma::Svg *>();
|
|
|
|
}
|
|
|
|
|
2016-02-29 22:28:58 +01:00
|
|
|
void IconItemTest::changeTheme(Plasma::Theme *theme, const QString &themeName)
|
|
|
|
{
|
|
|
|
if (theme->themeName() != themeName) {
|
|
|
|
QSignalSpy spy(theme, SIGNAL(themeChanged()));
|
|
|
|
theme->setThemeName(themeName);
|
|
|
|
spy.wait();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-27 21:24:45 +01:00
|
|
|
// ------ Tests
|
2016-03-04 01:20:29 +01:00
|
|
|
|
|
|
|
void IconItemTest::loadPixmap()
|
|
|
|
{
|
|
|
|
QScopedPointer<QQuickItem> item(createIconItem());
|
|
|
|
QPixmap sourcePixmap(QFINDTESTDATA("data/test_image.png"));
|
|
|
|
|
2017-02-21 11:59:55 +01:00
|
|
|
item->setSize(sourcePixmap.size());
|
2016-03-04 01:20:29 +01:00
|
|
|
item->setProperty("source", sourcePixmap);
|
|
|
|
QVERIFY(item->property("valid").toBool());
|
|
|
|
|
|
|
|
QImage capture = grabImage(item.data());
|
|
|
|
QCOMPARE(capture, sourcePixmap.toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied));
|
2016-03-04 23:44:57 +01:00
|
|
|
QCOMPARE(sourcePixmap, item->property("source").value<QPixmap>());
|
2016-03-04 01:20:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//tests setting icon from a QImage
|
|
|
|
void IconItemTest::loadImage()
|
|
|
|
{
|
|
|
|
QScopedPointer<QQuickItem> item(createIconItem());
|
|
|
|
QImage sourceImage(QFINDTESTDATA("data/test_image.png"));
|
|
|
|
|
2017-02-21 11:59:55 +01:00
|
|
|
item->setSize(sourceImage.size());
|
2016-03-04 01:20:29 +01:00
|
|
|
item->setProperty("source", sourceImage);
|
|
|
|
QVERIFY(item->property("valid").toBool());
|
|
|
|
|
|
|
|
QImage capture = grabImage(item.data());
|
|
|
|
QCOMPARE(capture, sourceImage.convertToFormat(QImage::Format_ARGB32_Premultiplied));
|
2016-03-04 23:44:57 +01:00
|
|
|
QCOMPARE(sourceImage, item->property("source").value<QImage>());
|
2016-03-04 01:20:29 +01:00
|
|
|
}
|
|
|
|
|
2016-02-27 21:24:45 +01:00
|
|
|
void IconItemTest::invalidIcon()
|
|
|
|
{
|
|
|
|
QString name("tst-plasma-framework-invalid-icon-name");
|
|
|
|
KIconLoader iconLoader("tst_plasma-framework");
|
|
|
|
if (iconLoader.hasIcon(name)) {
|
|
|
|
QSKIP("Current icon theme has 'tst-plasma-framework-invalid-icon-name' icon.");
|
|
|
|
}
|
|
|
|
|
|
|
|
QQuickItem *item = createIconItem();
|
|
|
|
item->setProperty("source", name);
|
|
|
|
QVERIFY(!item->property("valid").toBool());
|
|
|
|
QVERIFY(imageIsEmpty(grabImage(item)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void IconItemTest::usesPlasmaTheme()
|
|
|
|
{
|
|
|
|
// usesPlasmaTheme = true (default)
|
|
|
|
QQuickItem *item1 = createIconItem();
|
|
|
|
item1->setProperty("source", "konversation");
|
|
|
|
QVERIFY(item1->property("valid").toBool());
|
2016-03-04 23:44:57 +01:00
|
|
|
QCOMPARE(QStringLiteral("konversation"), item1->property("source").toString());
|
2016-02-27 21:24:45 +01:00
|
|
|
|
|
|
|
Plasma::Svg svg;
|
|
|
|
svg.setContainsMultipleImages(true);
|
|
|
|
svg.setImagePath("icons/konversation");
|
|
|
|
|
|
|
|
QImage img1 = grabImage(item1);
|
|
|
|
QImage img2 = svg.image(QSize(item1->width(), item1->height()), "konversation");
|
|
|
|
QVERIFY(!imageIsEmpty(img1));
|
|
|
|
QVERIFY(!imageIsEmpty(img2));
|
|
|
|
QCOMPARE(img1, img2);
|
|
|
|
|
|
|
|
// usesPlasmaTheme = false
|
|
|
|
QQuickItem *item2 = createIconItem();
|
|
|
|
item2->setProperty("usesPlasmaTheme", false);
|
|
|
|
item2->setProperty("source", "konversation");
|
|
|
|
|
|
|
|
img1 = grabImage(item2);
|
|
|
|
// This depends on konversation icon being different in Plasma Breeze theme
|
2016-02-27 19:40:54 +01:00
|
|
|
// and our test icon theme
|
2016-02-27 21:24:45 +01:00
|
|
|
QVERIFY(img1 != img2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IconItemTest::animation()
|
|
|
|
{
|
|
|
|
// animated = true (default)
|
|
|
|
QQuickItem *item1 = createIconItem();
|
|
|
|
item1->setProperty("source", "user-away");
|
|
|
|
// first icon is not animated
|
|
|
|
QImage userAwayImg = grabImage(item1);
|
|
|
|
|
|
|
|
item1->setProperty("source", "user-busy");
|
|
|
|
grabImage(item1);
|
|
|
|
item1->setProperty("source", "user-away");
|
|
|
|
// animation from user-busy -> user-away
|
|
|
|
QVERIFY(userAwayImg != grabImage(item1));
|
|
|
|
|
|
|
|
// animated = false
|
|
|
|
QQuickItem *item2 = createIconItem();
|
|
|
|
item2->setProperty("animated", false);
|
|
|
|
item2->setProperty("source", "user-busy");
|
|
|
|
QImage userBusyImg = grabImage(item2);
|
|
|
|
|
|
|
|
item2->setProperty("source", "user-away");
|
|
|
|
QCOMPARE(userAwayImg, grabImage(item2));
|
|
|
|
|
|
|
|
item2->setProperty("source", "user-busy");
|
|
|
|
QCOMPARE(userBusyImg, grabImage(item2));
|
|
|
|
}
|
|
|
|
|
|
|
|
void IconItemTest::animationAfterHide()
|
|
|
|
{
|
|
|
|
QQuickItem *item1 = createIconItem();
|
|
|
|
QQuickItem *item2 = createIconItem();
|
|
|
|
item1->setProperty("source", "user-away");
|
|
|
|
item2->setProperty("source", "user-busy");
|
|
|
|
// first icon is not animated
|
|
|
|
QImage userAwayImg = grabImage(item1);
|
|
|
|
QImage userBusyImg = grabImage(item2);
|
|
|
|
|
|
|
|
item1->setProperty("source", "user-busy");
|
|
|
|
grabImage(item1);
|
|
|
|
item1->setProperty("visible", "false");
|
|
|
|
item1->setProperty("visible", "true");
|
|
|
|
item1->setProperty("source", "user-away");
|
|
|
|
// icon was hidden, no animation
|
|
|
|
QCOMPARE(userAwayImg, grabImage(item1));
|
|
|
|
|
|
|
|
item1->setProperty("source", "user-busy");
|
|
|
|
QVERIFY(userBusyImg != grabImage(item1));
|
|
|
|
}
|
|
|
|
|
|
|
|
void IconItemTest::bug_359388()
|
|
|
|
{
|
2016-04-27 15:29:54 +02:00
|
|
|
if (!KIconTheme::list().contains("hicolor")) {
|
|
|
|
// This test depends on hicolor icon theme to resolve the icon.
|
|
|
|
QSKIP("hicolor icon theme not available");
|
|
|
|
}
|
|
|
|
|
2016-02-27 21:24:45 +01:00
|
|
|
QString name("bug359388");
|
|
|
|
KIconLoader iconLoader("tst_plasma-framework");
|
2016-02-27 19:40:54 +01:00
|
|
|
QIcon customThemeIcon(new KIconEngine(name, &iconLoader));
|
2016-02-27 21:24:45 +01:00
|
|
|
if (iconLoader.hasIcon(name)) {
|
|
|
|
QSKIP("Current icon theme has 'bug359388' icon.");
|
|
|
|
}
|
|
|
|
|
2016-02-27 19:40:54 +01:00
|
|
|
iconLoader.addAppDir("tst_plasma-framework", QFINDTESTDATA("data/bug359388"));
|
2016-02-27 21:24:45 +01:00
|
|
|
|
|
|
|
QQuickItem *item1 = createIconItem();
|
|
|
|
item1->setProperty("source", customThemeIcon);
|
|
|
|
QVERIFY(item1->property("valid").toBool());
|
2016-03-04 23:44:57 +01:00
|
|
|
QCOMPARE(customThemeIcon, item1->property("source").value<QIcon>());
|
2016-02-27 21:24:45 +01:00
|
|
|
|
|
|
|
QQuickItem *item2 = createIconItem();
|
2016-02-27 19:40:54 +01:00
|
|
|
item2->setProperty("source", QIcon(QFINDTESTDATA("data/bug359388/hicolor/22x22/apps/" + name + ".svg")));
|
2016-02-27 21:24:45 +01:00
|
|
|
QVERIFY(item2->property("valid").toBool());
|
|
|
|
|
|
|
|
QCOMPARE(grabImage(item1), grabImage(item2));
|
|
|
|
}
|
|
|
|
|
2016-02-27 19:40:54 +01:00
|
|
|
void IconItemTest::loadSvg()
|
|
|
|
{
|
|
|
|
QString name("tst-plasma-framework-test-icon");
|
|
|
|
|
|
|
|
QQuickItem *item = createIconItem();
|
|
|
|
item->setProperty("animated", false);
|
|
|
|
item->setSize(QSize(22, 22));
|
|
|
|
item->setProperty("source", name);
|
|
|
|
QVERIFY(item->property("valid").toBool());
|
|
|
|
|
|
|
|
Plasma::Svg *svg;
|
|
|
|
svg = findPlasmaSvg(item);
|
|
|
|
Q_ASSERT(svg);
|
|
|
|
QCOMPARE(svg->imagePath(), QFINDTESTDATA("data/icons/test-theme/apps/22/" + name + ".svg"));
|
|
|
|
|
|
|
|
// we only have 32x32 and 22x22 version in the theme, thus 32x32 is a better match.
|
|
|
|
item->setSize(QSize(64, 64));
|
|
|
|
// just to update the icon
|
|
|
|
grabImage(item);
|
|
|
|
svg = findPlasmaSvg(item);
|
|
|
|
Q_ASSERT(svg);
|
|
|
|
QCOMPARE(svg->imagePath(), QFINDTESTDATA("data/icons/test-theme/apps/32/" + name + ".svg"));
|
|
|
|
}
|
|
|
|
|
2016-02-29 22:28:58 +01:00
|
|
|
void IconItemTest::themeChange()
|
|
|
|
{
|
|
|
|
// Icon from Plasma theme
|
|
|
|
QQuickItem *item1 = createIconItem();
|
|
|
|
item1->setProperty("animated", false);
|
|
|
|
item1->setProperty("source", "zoom-fit-height");
|
|
|
|
Plasma::Svg *svg1 = item1->findChild<Plasma::Svg*>();
|
|
|
|
changeTheme(svg1->theme(), "breeze-light");
|
|
|
|
QImage img1 = grabImage(item1);
|
|
|
|
changeTheme(svg1->theme(), "breeze-dark");
|
|
|
|
QImage img2 = grabImage(item1);
|
|
|
|
QVERIFY(img1 != img2);
|
|
|
|
|
|
|
|
// Icon from icon theme
|
|
|
|
QQuickItem *item2 = createIconItem();
|
|
|
|
item2->setProperty("animated", false);
|
|
|
|
item2->setProperty("width", 22);
|
|
|
|
item2->setProperty("height", 22);
|
|
|
|
item2->setProperty("source", "tst-plasma-framework-test-icon");
|
|
|
|
Plasma::Svg *svg2 = item2->findChild<Plasma::Svg*>();
|
|
|
|
changeTheme(svg2->theme(), "breeze-light");
|
|
|
|
img1 = grabImage(item2);
|
|
|
|
changeTheme(svg2->theme(), "breeze-dark");
|
|
|
|
img2 = grabImage(item2);
|
|
|
|
QVERIFY(img1 != img2);
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:44:57 +01:00
|
|
|
void IconItemTest::qiconFromTheme()
|
|
|
|
{
|
|
|
|
// Icon from Plasma theme
|
|
|
|
QQuickItem *item1 = createIconItem();
|
2016-03-05 10:46:19 +01:00
|
|
|
QIcon icon1 = QIcon::fromTheme("konversation");
|
|
|
|
item1->setProperty("source", icon1);
|
2016-03-04 23:44:57 +01:00
|
|
|
QVERIFY(item1->findChild<Plasma::Svg*>());
|
|
|
|
QVERIFY(!imageIsEmpty(grabImage(item1)));
|
|
|
|
QCOMPARE(icon1, item1->property("source").value<QIcon>());
|
|
|
|
|
|
|
|
// Icon from icon theme
|
|
|
|
QQuickItem *item2 = createIconItem();
|
|
|
|
QIcon icon2 = QIcon::fromTheme("tst-plasma-framework-test-icon");
|
|
|
|
item2->setProperty("source", icon2);
|
|
|
|
QVERIFY(item2->findChild<Plasma::Svg*>());
|
|
|
|
QVERIFY(!imageIsEmpty(grabImage(item2)));
|
|
|
|
QCOMPARE(icon2, item2->property("source").value<QIcon>());
|
|
|
|
}
|
|
|
|
|
2016-03-10 12:58:18 +01:00
|
|
|
void IconItemTest::changeColorGroup()
|
|
|
|
{
|
|
|
|
// Icon from Plasma theme
|
|
|
|
QQuickItem *item = createIconItem();
|
|
|
|
item->setProperty("animated", false);
|
|
|
|
item->setProperty("source", "zoom-fit-height");
|
|
|
|
Plasma::Svg *svg = item->findChild<Plasma::Svg*>();
|
|
|
|
// not using "breeze" theme as that one follows system color scheme
|
|
|
|
// and that one might not have a complementary group or a broken one
|
|
|
|
changeTheme(svg->theme(), "breeze-light");
|
|
|
|
QSignalSpy spy(svg, SIGNAL(repaintNeeded()));
|
|
|
|
QVERIFY(spy.isValid());
|
|
|
|
QImage img1 = grabImage(item);
|
|
|
|
item->setProperty("colorGroup", Plasma::Theme::ComplementaryColorGroup);
|
|
|
|
QTRY_VERIFY(spy.count() == 1);
|
|
|
|
QImage img2 = grabImage(item);
|
|
|
|
QVERIFY(img1 != img2);
|
|
|
|
}
|
|
|
|
|
2016-03-11 14:07:44 +01:00
|
|
|
void IconItemTest::animatingActiveChange()
|
|
|
|
{
|
|
|
|
QQuickItem *item1 = createIconItem();
|
|
|
|
item1->setProperty("animated", false);
|
|
|
|
item1->setProperty("source", "tst-plasma-framework-test-icon");
|
|
|
|
QImage img1 = grabImage(item1);
|
|
|
|
|
|
|
|
QQuickItem *item2 = createIconItem();
|
|
|
|
item2->setProperty("animated", false);
|
|
|
|
item2->setProperty("active", true);
|
|
|
|
item2->setProperty("source", "tst-plasma-framework-test-icon");
|
|
|
|
QImage img2 = grabImage(item2);
|
|
|
|
QVERIFY(img1 != img2);
|
|
|
|
|
|
|
|
item1->setProperty("active", true);
|
|
|
|
img1 = grabImage(item1);
|
|
|
|
QVERIFY(img1 != img2); // animation is running
|
|
|
|
}
|
|
|
|
|
|
|
|
void IconItemTest::animatingEnabledChange()
|
|
|
|
{
|
|
|
|
QQuickItem *item1 = createIconItem();
|
|
|
|
item1->setProperty("animated", false);
|
|
|
|
item1->setProperty("source", "tst-plasma-framework-test-icon");
|
|
|
|
QImage img1 = grabImage(item1);
|
|
|
|
|
|
|
|
QQuickItem *item2 = createIconItem();
|
|
|
|
item2->setProperty("animated", false);
|
|
|
|
item2->setProperty("enabled", false);
|
|
|
|
item2->setProperty("source", "tst-plasma-framework-test-icon");
|
|
|
|
QImage img2 = grabImage(item2);
|
|
|
|
QVERIFY(img1 != img2);
|
|
|
|
|
|
|
|
item1->setProperty("enabled", false);
|
|
|
|
img1 = grabImage(item1);
|
|
|
|
QVERIFY(img1 != img2); // animation is running
|
|
|
|
}
|
|
|
|
|
2016-03-12 13:01:07 +01:00
|
|
|
void IconItemTest::windowChanged()
|
|
|
|
{
|
|
|
|
QQuickItem *item = createIconItem();
|
|
|
|
item->setProperty("animated", false);
|
|
|
|
item->setProperty("source", "tst-plasma-framework-test-icon");
|
|
|
|
QImage img = grabImage(item);
|
|
|
|
|
|
|
|
QQuickView newView;
|
|
|
|
newView.setSource(QUrl::fromLocalFile(QFINDTESTDATA("data/view.qml")));
|
|
|
|
newView.show();
|
2017-12-06 08:17:21 +01:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&newView));
|
2016-03-12 13:01:07 +01:00
|
|
|
|
|
|
|
item->setProperty("visible", false);
|
|
|
|
item->setParentItem(newView.rootObject());
|
|
|
|
item->setProperty("visible", true);
|
|
|
|
QCOMPARE(grabImage(item), img);
|
|
|
|
}
|
|
|
|
|
2017-01-05 15:15:14 +01:00
|
|
|
void IconItemTest::paintedSize()
|
|
|
|
{
|
|
|
|
QQuickItem *item = createIconItem();
|
|
|
|
|
|
|
|
QCOMPARE(item->property("paintedWidth").toInt(), item->property("implicitWidth").toInt());
|
|
|
|
QCOMPARE(item->property("paintedHeight").toInt(), item->property("implicitHeight").toInt());
|
|
|
|
|
|
|
|
item->setWidth(40);
|
|
|
|
item->setHeight(40);
|
|
|
|
|
|
|
|
QCOMPARE(item->property("paintedWidth").toInt(), 32);
|
|
|
|
QCOMPARE(item->property("paintedHeight").toInt(), 32);
|
|
|
|
|
|
|
|
QIcon landscapeIcon(QPixmap(40, 35));
|
|
|
|
item->setProperty("source", landscapeIcon);
|
|
|
|
grabImage(item); // basically just to force loading the pixmap
|
|
|
|
|
|
|
|
// expanded to fit IconItem size whilst keeping aspect ratio
|
|
|
|
// width should be rounded to icon size, ie. 32 is next smallest
|
|
|
|
QCOMPARE(item->property("paintedWidth").toInt(), 32);
|
|
|
|
// height should still match aspect ratio, so *not* 24!
|
|
|
|
QCOMPARE(item->property("paintedHeight").toInt(), 28);
|
|
|
|
|
|
|
|
QIcon portraitIcon(QPixmap(15, 40));
|
|
|
|
item->setProperty("source", portraitIcon);
|
|
|
|
grabImage(item);
|
|
|
|
|
|
|
|
QCOMPARE(item->property("paintedWidth").toInt(), 12);
|
|
|
|
QCOMPARE(item->property("paintedHeight").toInt(), 32);
|
|
|
|
|
|
|
|
item->setWidth(400);
|
|
|
|
item->setHeight(400);
|
|
|
|
|
|
|
|
grabImage(item);
|
|
|
|
|
|
|
|
QCOMPARE(item->property("paintedWidth").toInt(), 150);
|
|
|
|
QCOMPARE(item->property("paintedHeight").toInt(), 400);
|
|
|
|
}
|
|
|
|
|
2017-01-08 16:16:59 +01:00
|
|
|
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
|
2021-01-18 12:08:40 +01:00
|
|
|
Q_EMIT KIconLoader::global()->iconLoaderSettingsChanged();
|
2017-01-08 16:16:59 +01:00
|
|
|
|
|
|
|
QCOMPARE(widthSpy.count(), 1);
|
|
|
|
QCOMPARE(heightSpy.count(), 1);
|
|
|
|
|
|
|
|
QCOMPARE(item->implicitWidth(), qreal(64));
|
|
|
|
QCOMPARE(item->implicitHeight(), qreal(64));
|
|
|
|
}
|
|
|
|
|
2018-01-15 10:22:18 +01:00
|
|
|
void IconItemTest::nonSquareImplicitSize()
|
|
|
|
{
|
|
|
|
QQuickItem *item1 = createIconItem();
|
|
|
|
|
|
|
|
// Both file:///foo and /foo must behave the same
|
|
|
|
item1->setProperty("source", QFINDTESTDATA("data/test_nonsquare.png"));
|
|
|
|
|
|
|
|
QCOMPARE(item1->implicitWidth(), qreal(150));
|
|
|
|
QCOMPARE(item1->implicitHeight(), qreal(50));
|
|
|
|
|
|
|
|
QQuickItem *item2 = createIconItem();
|
|
|
|
|
|
|
|
item2->setProperty("source", QUrl::fromLocalFile(QFINDTESTDATA("data/test_nonsquare.png")));
|
|
|
|
|
|
|
|
QCOMPARE(item2->implicitWidth(), item1->implicitWidth());
|
|
|
|
QCOMPARE(item2->implicitHeight(), item1->implicitHeight());
|
|
|
|
}
|
|
|
|
|
2017-02-26 11:27:58 +01:00
|
|
|
void IconItemTest::roundToIconSize()
|
|
|
|
{
|
|
|
|
QQuickItem *item = createIconItem();
|
|
|
|
|
|
|
|
item->setWidth(25);
|
|
|
|
item->setHeight(25);
|
|
|
|
QVERIFY(item->property("paintedWidth").toInt() != 25);
|
|
|
|
QVERIFY(item->property("paintedHeight").toInt() != 25);
|
|
|
|
|
|
|
|
QSignalSpy paintedSizeSpy(item, SIGNAL(paintedSizeChanged()));
|
|
|
|
QSignalSpy roundToIconSizeSpy(item, SIGNAL(roundToIconSizeChanged()));
|
|
|
|
|
|
|
|
item->setProperty("roundToIconSize", false);
|
|
|
|
|
|
|
|
QTRY_COMPARE(paintedSizeSpy.count(), 1);
|
|
|
|
QTRY_COMPARE(roundToIconSizeSpy.count(), 1);
|
|
|
|
QVERIFY(item->property("paintedWidth").toInt() == 25);
|
|
|
|
QVERIFY(item->property("paintedHeight").toInt() == 25);
|
|
|
|
}
|
|
|
|
|
2016-02-27 21:24:45 +01:00
|
|
|
QTEST_MAIN(IconItemTest)
|
|
|
|
|