// SPDX-License-Identifier: GPL-3.0-or-later // The style plugin as an application loads it. // // An edit box's frame -- the box less its contents rect -- doesn't grow with // the box. LibreOffice's Qt backends size edit boxes by it, growing a box by // its frame until the size settles: XPlasma's contents rect was one text line // at any height, so the frame grew with the box, and LibreOffice recursed // until its stack ran out (issue #2). #include #include #include #include #include #include #include #include namespace { QTemporaryDir *scratch() { static QTemporaryDir dir; return &dir; } } // namespace class TestStyle : public QObject { Q_OBJECT private Q_SLOTS: void scrollbarLetsItsParentPaintBehindIt() { QPluginLoader loader(QCoreApplication::applicationDirPath() + QLatin1String("/../../libxplasma.so")); auto *plugin = qobject_cast(loader.instance()); QVERIFY2(plugin, qPrintable(loader.errorString())); QStyle *style = plugin->create(QStringLiteral("XPlasma")); QVERIFY(style); for (const bool opaque : {false, true}) { QScrollBar bar; bar.setAttribute(Qt::WA_OpaquePaintEvent, opaque); style->polish(&bar); QVERIFY(!bar.testAttribute(Qt::WA_OpaquePaintEvent)); style->unpolish(&bar); QCOMPARE(bar.testAttribute(Qt::WA_OpaquePaintEvent), opaque); } delete style; } void editFrameDoesNotGrowWithTheBox() { // (The build's own: tests/app/ is two below it, here and where // ci/release.sh runs the tests.) QPluginLoader loader(QCoreApplication::applicationDirPath() + QLatin1String("/../../libxplasma.so")); auto *plugin = qobject_cast(loader.instance()); QVERIFY2(plugin, qPrintable(loader.errorString())); QStyle *style = plugin->create(QStringLiteral("XPlasma")); QVERIFY(style); QMargins first; for (const int height : {20, 24, 30, 60}) { // (as LibreOffice asks: the frame for a size, then its contents) QStyleOptionFrame frame; frame.rect = QRect(0, 0, 100, height); frame.state = QStyle::State_Enabled | QStyle::State_Sunken; frame.lineWidth = style->pixelMetric(QStyle::PM_DefaultFrameWidth); frame.rect.setSize(style->sizeFromContents(QStyle::CT_LineEdit, &frame, frame.rect.size())); const QRect contents = style->subElementRect(QStyle::SE_LineEditContents, &frame); const QMargins margins(contents.left() - frame.rect.left(), contents.top() - frame.rect.top(), frame.rect.right() - contents.right(), frame.rect.bottom() - contents.bottom()); if (height == 20) first = margins; QCOMPARE(margins, first); } delete style; } }; int main(int argc, char **argv) { // (Before the application: the style reads ~/.config/xplasmarc -- here // a Windows Classic scheme, so its edit box is XPlasma's, not Qt's.) qputenv("XDG_CONFIG_HOME", QFile::encodeName(scratch()->path())); const QString theme = scratch()->filePath(QStringLiteral("classic.theme")); QFile scheme(theme); QFile rc(scratch()->filePath(QStringLiteral("xplasmarc"))); if (!scheme.open(QIODevice::WriteOnly) || scheme.write("[Control Panel\\Colors]\r\nWindow=255 255 255\r\nWindowText=0 0 0\r\nButtonFace=212 208 200\r\n") < 0 || !rc.open(QIODevice::WriteOnly) || rc.write("[Theme]\nPath=" + QFile::encodeName(theme) + "\n") < 0) return 1; scheme.close(); rc.close(); QApplication app(argc, argv); TestStyle test; return QTest::qExec(&test, argc, argv); } #include "test_style.moc"