Something went wrong. Try again.
Bring Windows XP themes to your KDE Plasma environment! xplasma.hotsocket.fyi
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798// 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 <QApplication>#include <QFile>#include <QPluginLoader>#include <QScrollBar>#include <QStyleOptionFrame>#include <QStylePlugin>#include <QTemporaryDir>#include <QTest>
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<QStylePlugin *>(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<QStylePlugin *>(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"