Something went wrong. Try again.
Bring Windows XP themes to your KDE Plasma environment! xplasma.hotsocket.fyi
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395// SPDX-License-Identifier: GPL-3.0-or-later#include "app/editor/displayproperties.h"
#include "app/editor/abouttab.h"#include "app/editor/advanced.h"#include "app/editor/extras.h"#include "app/editor/jobs.h"#include "app/editor/setupdialog.h"#include "app/editor/soundstab.h"#include "app/editor/colourpicker.h"#include "app/paths.h"#include "app/session.h"#include "app/state.h"#include "app/themepack.h"#include "core/config.h"#include "core/themefile.h"
#include <QApplication>#include <QCheckBox>#include <QComboBox>#include <QCryptographicHash>#include <QDir>#include <QFileDialog>#include <QFileInfo>#include <QGridLayout>#include <QGroupBox>#include <QHBoxLayout>#include <QInputDialog>#include <QKeyEvent>#include <QLabel>#include <QLineEdit>#include <QListWidget>#include <QMessageBox>#include <QPainter>#include <QPushButton>#include <QScrollBar>#include <QStyledItemDelegate>#include <QTabBar>#include <QTabWidget>#include <QTimer>#include <QUrl>#include <QVBoxLayout>
namespace xpl::editor {
namespace {
// Theme combo rows that aren't themes.constexpr const char *kBrowse = "browse";constexpr const char *kSetup = "setup";
// XP's Position drop-down, as Plasma FillModes.// (Plasma's FillMode values. XP had the first three; Fit and Fill are later// Windows' names for Plasma's "Scaled, Keep Proportions" and "Scaled and// Cropped"; the last two tile one way only.)const std::pair<const char *, int> kPositions[] = {{"Center", 6}, {"Tile", 3}, {"Stretch", 0}, {"Fit", 1}, {"Fill", 2}, {"Tile Across", 5}, {"Tile Down", 4}};
// The desktop the session shows now (Plasma's first image or colour// wallpaper), for the Desktop tab to open on.Wallpaper currentDesktop(){ Wallpaper w{QString(), 2, QColor(58, 110, 165)}; QFile f(paths::config() + QLatin1String("/plasma-org.kde.plasma.desktop-appletsrc")); if (!f.open(QIODevice::ReadOnly)) return w; QString group; for (const QString &line : QString::fromUtf8(f.readAll()).split(QLatin1Char('\n'))) { if (line.startsWith(QLatin1Char('['))) { group = line.trimmed(); continue; } const bool image = group.startsWith(QLatin1String("[Containments]")) && group.endsWith(QLatin1String("[Wallpaper][org.kde.image][General]")); const bool colour = group.startsWith(QLatin1String("[Containments]")) && group.endsWith(QLatin1String("[Wallpaper][org.kde.color][General]")); if (!image && !colour) continue; const QString key = line.section(QLatin1Char('='), 0, 0), value = line.section(QLatin1Char('='), 1).trimmed(); if (image && key == QLatin1String("Image") && w.image.isEmpty()) w.image = value.startsWith(QLatin1String("file:")) ? QUrl(value).toLocalFile() : value; else if (image && key == QLatin1String("FillMode")) w.fill = value.toInt(); else if (key == QLatin1String("Color")) w.colour = QColor(value.startsWith(QLatin1Char('#')) ? value : QStringLiteral("#3a6ea5")); } if (!QFileInfo(w.image).isFile()) w.image.clear(); return w;}
// What a look draws from: the style and variant, or the Classic scheme's// contents (which Advanced edits).QString lookKey(const Look &look){ if (look.classic()) { ThemeFile file; look.system.writeTo(file); return QStringLiteral("classic:") + QString::fromLatin1(QCryptographicHash::hash(file.toBytes(), QCryptographicHash::Sha1).toHex()); } return QFileInfo(look.stylePath).canonicalFilePath() + QLatin1Char(':') + look.variant.toUpper() + (look.adjust.isIdentity() ? QString() : QLatin1Char(':') + look.adjust.tint.toString() + QLatin1Char(':') + look.adjust.overrides.toJson());}
bool sameDesktop(const Wallpaper &a, const Wallpaper &b){ return a.image == b.image && a.fill == b.fill && a.colour == b.colour;}
bool shiftHeld(){ return QGuiApplication::queryKeyboardModifiers().testFlag(Qt::ShiftModifier);}
QLabel *sampleBox(QSize size){ auto *label = new QLabel; label->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); label->setFixedSize(size + QSize(6, 6)); label->setAlignment(Qt::AlignCenter); return label;}
// XP's Customize list (measured, Mouse Properties > Pointers): a role's name// on the left, its pointer at its own size in a column at the right, rows// 34px tall. (The pointer: the item's Qt::DecorationRole, a QImage.)class PointerRowDelegate : public QStyledItemDelegate{public: using QStyledItemDelegate::QStyledItemDelegate; // (The column is a 32px pointer and the outline's pixel either side, kept // whether the outline's on or not: toggling it neither scales the // pointers nor moves them.) static constexpr int kRowHeight = 34, kCursorBox = 34, kTextIndent = 5, kRightGap = 3; static constexpr int kPadRole = Qt::UserRole + 1; // pixels added up and left of the pointer (the outline's)
void paint(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const override { QStyleOptionViewItem o = option; initStyleOption(&o, index); const QImage cursor = index.data(Qt::DecorationRole).value<QImage>(); o.icon = QIcon(); o.features &= ~QStyleOptionViewItem::HasDecoration; o.text.clear(); const QWidget *w = option.widget; QStyle *style = w ? w->style() : QApplication::style(); style->drawControl(QStyle::CE_ItemViewItem, &o, p, w); // (the row and its selection) const QRect box(option.rect.right() - kRightGap - kCursorBox + 1, option.rect.top() + (option.rect.height() - kCursorBox) / 2, kCursorBox, kCursorBox); const QRect text = option.rect.adjusted(kTextIndent, 0, -(kCursorBox + kRightGap + kTextIndent), 0); const bool selected = option.state & QStyle::State_Selected; p->save(); p->setPen(option.palette.color(option.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled, selected ? QPalette::HighlightedText : QPalette::Text)); p->drawText(text, Qt::AlignLeft | Qt::AlignVCenter, index.data(Qt::DisplayRole).toString()); if (!cursor.isNull()) { // At its own size, the pointer's own pixels in the same place // whatever's added round them: the outline grows a pixel up and // left (kPadRole), the shadow down and right. (Only a pointer far // too big for a row is scaled.) const int pad = index.data(kPadRole).toInt(); QImage shown = cursor; if (shown.width() > 2 * kCursorBox || shown.height() > 2 * kCursorBox) shown = shown.scaled(kCursorBox, kCursorBox, Qt::KeepAspectRatio, Qt::FastTransformation); p->setClipRect(option.rect); p->drawImage(box.left() + 1 - pad, box.top() + 1 - pad, shown); } p->restore(); } QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override { return QSize(QStyledItemDelegate::sizeHint(option, index).width() + kCursorBox, kRowHeight); }};
} // namespace
DisplayProperties::DisplayProperties(QWidget *parent) : QDialog(parent){ setWindowTitle(QStringLiteral("XPlasma Properties")); auto *root = new QVBoxLayout(this); m_tabs = new QTabWidget; // (Every tab in view, as XP's: the dialog is at least as wide as its row.) m_tabs->setUsesScrollButtons(false); m_tabs->addTab(themesTab(), QStringLiteral("Themes")); m_tabs->addTab(desktopTab(), QStringLiteral("Desktop")); m_tabs->addTab(appearanceTab(), QStringLiteral("Appearance")); m_tabs->addTab(pointersTab(), QStringLiteral("Pointers")); m_sounds = new SoundsTab; m_tabs->addTab(m_sounds, QStringLiteral("Sounds")); connect(m_sounds, &SoundsTab::changed, this, &DisplayProperties::updateApply); auto *about = new AboutTab; m_tabs->addTab(about, QStringLiteral("About")); // The dialog's width: its widest tab's but About's (whose paragraphs // wrap to it), and room for every tab's name. int pageWidth = 0; for (int i = 0; i < m_tabs->count(); ++i) if (m_tabs->widget(i) != about) pageWidth = qMax(pageWidth, m_tabs->widget(i)->sizeHint().width()); const int frame = m_tabs->sizeHint().width() - m_tabs->currentWidget()->sizeHint().width(); pageWidth = qMax(pageWidth, m_tabs->tabBar()->sizeHint().width() + 4 - frame); for (int i = 0; i < m_tabs->count(); ++i) m_tabs->widget(i)->setMinimumWidth(pageWidth); about->fitWidth(pageWidth); root->addWidget(m_tabs, 1); // A property sheet: its size is its contents', not the user's to change. root->setSizeConstraint(QLayout::SetFixedSize);
auto *row = new QHBoxLayout; row->addStretch(1); auto *ok = new QPushButton(QStringLiteral("OK")); auto *cancel = new QPushButton(QStringLiteral("Cancel")); m_apply = new QPushButton(QStringLiteral("Apply")); m_apply->setToolTip(QStringLiteral("Hold Shift to rebuild and apply everything, changed or not.")); ok->setDefault(true); for (QPushButton *b : {ok, cancel, m_apply}) row->addWidget(b); root->addLayout(row); connect(ok, &QPushButton::clicked, this, [this] { if (apply()) accept(); }); connect(cancel, &QPushButton::clicked, this, &QDialog::reject); connect(m_apply, &QPushButton::clicked, this, &DisplayProperties::apply); // (Shift, wherever the focus is in the dialog.) qApp->installEventFilter(this);
loadLibrary(); // Open on what's applied now. const State state = State::load(); m_loading = true; m_adjust = appliedAdjustments(state); if (state.appliedKind == QLatin1String("classic")) { if (const auto s = schemes::load(state.scheme)) m_scheme = *s; } fillStyles(); for (int i = 0; i < m_styles.size(); ++i) if (state.appliedKind == QLatin1String("style") && m_styles.at(i).path == state.style) m_style->setCurrentIndex(i); if (state.appliedKind == QLatin1String("classic")) m_style->setCurrentIndex(m_styles.size()); fillColours(); if (state.appliedKind == QLatin1String("style") && m_style->currentIndex() < m_styles.size()) if (const StyleVariant *v = m_styles.at(m_style->currentIndex()).variant(state.variant)) { m_colour->setCurrentIndex(m_colour->findData(v->colour)); fillSizes(); m_size->setCurrentIndex(m_size->findData(v->size)); } fillSizes(); const Wallpaper desktop = currentDesktop(); fillWallpapers(); for (int i = 0; i < m_wallpapers->count(); ++i) if (m_wallpapers->item(i)->data(Qt::UserRole).toString() == desktop.image) m_wallpapers->setCurrentRow(i); if (m_wallpapers->currentRow() < 0 && !desktop.image.isEmpty()) { auto *item = new QListWidgetItem(QFileInfo(desktop.image).completeBaseName()); item->setData(Qt::UserRole, desktop.image); m_wallpapers->addItem(item); m_wallpapers->setCurrentItem(item); } if (m_wallpapers->currentRow() < 0) m_wallpapers->setCurrentRow(0); for (int i = 0; i < m_position->count(); ++i) if (m_position->itemData(i).toInt() == desktop.fill.value_or(2)) m_position->setCurrentIndex(i); m_desktopColour->setColour(desktop.colour); m_themeFile = state.themeFile; for (int i = 0; i < m_themes->count(); ++i) if (m_themes->itemData(i).toString() == state.themeFile) m_themes->setCurrentIndex(i); // (the applied theme shown: its buttons as showBundle sets them) m_delete->setEnabled(!m_themeFile.isEmpty() && presets::owned(m_themeFile)); m_export->setEnabled(m_themeFile.endsWith(QLatin1String(".theme"), Qt::CaseInsensitive)); m_loading = false; // What's applied: the look XPlasma recorded, if the dialog could show it, // and the desktop as the dialog shows it. QString applied; if (state.appliedKind == QLatin1String("style")) applied = QFileInfo(state.style).canonicalFilePath() + QLatin1Char(':') + state.variant.toUpper() + (m_adjust.isIdentity() ? QString() : QLatin1Char(':') + m_adjust.tint.toString() + QLatin1Char(':') + m_adjust.overrides.toJson()); else if (state.appliedKind == QLatin1String("classic")) if (const auto s = schemes::load(state.scheme)) applied = lookKey(Look::fromScheme(*s)); // (made by an older XPlasma: not what this one would make, so Apply // stays ready until it's rebuilt) m_outdated = lookOutdated(state); m_appliedLook = applied == lookKey(look()) && !m_outdated ? applied : QString(); m_appliedDesktop = wallpaper(); m_appliedThemeFile = state.themeFile; // Pointers: what XPlasma applied, or "(None)" (Plasma's own). m_pointerSchemes = pointers::schemes(); m_appliedPointers = pointers::applied(state); m_appliedPointerOutline = m_pointerOutline = state.settings.value(QStringLiteral("pointerOutline")).toBool(true); if (m_appliedPointers) { m_pointers = m_appliedPointers->first; m_pointerShadow = m_appliedPointers->second; } fillPointerSchemes(); showPointers(); m_appliedStartExtras = m_startExtras = StartButtonExtras::fromJson(state.settings.value(QLatin1String(kStartButtonKey)).toObject()); // First start -- nothing of XPlasma's on the desktop yet: the "Windows // XP" theme chosen, as if picked (Luna, Bliss...), with XP's own // pointers, and Apply ready -- so Apply alone gives XP's desktop. if (state.appliedKind.isEmpty() && !m_appliedPointers) { if (const int xp = m_themes->findText(QStringLiteral("Windows XP")); xp >= 0) { m_themes->setCurrentIndex(xp); themePicked(xp); } if (!m_pointerSchemes.isEmpty()) { m_pointers = pointers::defaultScheme(); m_pointerShadow = true; fillPointerSchemes(); showPointers(); } } updateApply(); if (!m_previewer.styleAvailable()) m_appearanceSample->setToolTip(QStringLiteral("XPlasma's style plugin isn't installed: the samples can't be drawn")); renderThemes(); renderDesktop(); renderAppearance();}
// --- tabs ----------------------------------------------------------------------------------
QWidget *DisplayProperties::themesTab(){ auto *page = new QWidget; auto *layout = new QVBoxLayout(page); auto *blurb = new QLabel(QStringLiteral("A theme is a background plus a set of sounds, icons, and other elements to help you " "personalize your computer with one click.")); blurb->setWordWrap(true); layout->addWidget(blurb); layout->addWidget(new QLabel(QStringLiteral("Theme:"))); // The theme on a row of its own, its buttons under it (the user's // layout: room for Export beside XP's two). m_themes = new QComboBox; m_themes->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon); m_themes->setMinimumContentsLength(1); layout->addWidget(m_themes); auto *row = new QHBoxLayout; auto *saveAsButton = new QPushButton(QStringLiteral("Save As...")); m_delete = new QPushButton(QStringLiteral("Delete")); m_delete->setEnabled(false); // (a theme of the user's own shown: showBundle) m_export = new QPushButton(QStringLiteral("Export")); m_export->setToolTip(QStringLiteral("Save this theme as one file, with its background and pointers, to share.")); m_export->setEnabled(false); // (a theme chosen: showBundle) auto *openButton = new QPushButton(QStringLiteral("Open...")); openButton->setToolTip(QStringLiteral("Add a theme pack (.themepack) to your themes.")); row->addWidget(saveAsButton); row->addWidget(m_delete); row->addWidget(m_export); row->addStretch(1); row->addWidget(openButton); layout->addLayout(row); connect(m_export, &QPushButton::clicked, this, &DisplayProperties::exportTheme); connect(openButton, &QPushButton::clicked, this, [this] { openThemePack(QString()); }); layout->addWidget(new QLabel(QStringLiteral("Sample:"))); m_themeSample = sampleBox(preview::kThemesSize); layout->addWidget(m_themeSample, 0, Qt::AlignHCenter); layout->addStretch(1); connect(m_themes, &QComboBox::activated, this, &DisplayProperties::themePicked); connect(saveAsButton, &QPushButton::clicked, this, &DisplayProperties::saveAs); connect(m_delete, &QPushButton::clicked, this, &DisplayProperties::deleteTheme); return page;}
QWidget *DisplayProperties::desktopTab(){ auto *page = new QWidget; auto *layout = new QVBoxLayout(page); m_desktopSample = sampleBox(QSize(200, 170)); m_desktopSample->setFrameStyle(QFrame::NoFrame); layout->addWidget(m_desktopSample, 0, Qt::AlignHCenter); auto *grid = new QGridLayout; grid->addWidget(new QLabel(QStringLiteral("Background:")), 0, 0); m_wallpapers = new QListWidget; m_wallpapers->setFixedHeight(122); grid->addWidget(m_wallpapers, 1, 0); auto *column = new QVBoxLayout; auto *browse = new QPushButton(QStringLiteral("Browse...")); column->addWidget(browse); column->addSpacing(8); column->addWidget(new QLabel(QStringLiteral("Position:"))); m_position = new QComboBox; for (const auto &[name, fill] : kPositions) m_position->addItem(QLatin1String(name), fill); column->addWidget(m_position); column->addSpacing(8); column->addWidget(new QLabel(QStringLiteral("Color:"))); m_desktopColour = new ColourButton; column->addWidget(m_desktopColour); column->addStretch(1); grid->addLayout(column, 1, 1); grid->setColumnStretch(0, 1); layout->addLayout(grid); layout->addStretch(1); connect(m_wallpapers, &QListWidget::currentRowChanged, this, &DisplayProperties::desktopChanged); connect(m_position, &QComboBox::activated, this, &DisplayProperties::desktopChanged); connect(m_desktopColour, &ColourButton::picked, this, &DisplayProperties::desktopChanged); connect(browse, &QPushButton::clicked, this, [this] { const QString file = QFileDialog::getOpenFileName(this, QStringLiteral("Browse"), paths::wallpapers(), QStringLiteral("Pictures (*.jpg *.jpeg *.png *.bmp *.gif)")); if (file.isEmpty()) return; auto *item = new QListWidgetItem(QFileInfo(file).completeBaseName()); item->setData(Qt::UserRole, file); m_wallpapers->addItem(item); m_wallpapers->setCurrentItem(item); }); return page;}
QWidget *DisplayProperties::appearanceTab(){ auto *page = new QWidget; auto *layout = new QVBoxLayout(page); m_appearanceSample = sampleBox(preview::kAppearanceSize); layout->addWidget(m_appearanceSample, 0, Qt::AlignHCenter); auto *grid = new QGridLayout; m_style = new QComboBox; m_colour = new QComboBox; m_size = new QComboBox; m_advanced = new QPushButton(QStringLiteral("Advanced")); // (Where XP had Effects...: XPlasma's own, the Start button's label and logo.) m_extras = new QPushButton(QStringLiteral("Extras...")); grid->addWidget(new QLabel(QStringLiteral("Windows and buttons:")), 0, 0); grid->addWidget(m_style, 1, 0); grid->addWidget(new QLabel(QStringLiteral("Color scheme:")), 2, 0); grid->addWidget(m_colour, 3, 0); grid->addWidget(new QLabel(QStringLiteral("Font size:")), 4, 0); grid->addWidget(m_size, 5, 0); grid->addWidget(m_extras, 3, 2); grid->addWidget(m_advanced, 5, 2); grid->setColumnStretch(0, 5); grid->setColumnMinimumWidth(1, 40); layout->addLayout(grid); layout->addStretch(1); connect(m_style, &QComboBox::activated, this, [this] { fillColours(); fillSizes(); appearanceChanged(); }); connect(m_colour, &QComboBox::activated, this, [this] { fillSizes(); appearanceChanged(); }); connect(m_size, &QComboBox::activated, this, &DisplayProperties::appearanceChanged); connect(m_advanced, &QPushButton::clicked, this, &DisplayProperties::openAdvanced); connect(m_extras, &QPushButton::clicked, this, &DisplayProperties::openExtras); return page;}
QWidget *DisplayProperties::pointersTab(){ // XP's Mouse Properties > Pointers, the parts that mean something here. auto *page = new QWidget; auto *layout = new QVBoxLayout(page); auto *top = new QHBoxLayout; auto *schemeBox = new QGroupBox(QStringLiteral("Scheme")); auto *schemeRow = new QVBoxLayout(schemeBox); m_pointerScheme = new QComboBox; schemeRow->addWidget(m_pointerScheme); // (XP's: under the scheme, on the right.) auto *schemeButtons = new QHBoxLayout; m_pointerSaveAs = new QPushButton(QStringLiteral("Sa&ve As...")); m_pointerDelete = new QPushButton(QStringLiteral("&Delete")); schemeButtons->addStretch(1); schemeButtons->addWidget(m_pointerSaveAs); schemeButtons->addWidget(m_pointerDelete); schemeRow->addLayout(schemeButtons); connect(m_pointerSaveAs, &QPushButton::clicked, this, &DisplayProperties::savePointerScheme); connect(m_pointerDelete, &QPushButton::clicked, this, &DisplayProperties::deletePointerScheme); top->addWidget(schemeBox, 1); m_pointerPreview = new QLabel; m_pointerPreview->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); m_pointerPreview->setFixedSize(80, 80); // (XP's) m_pointerPreview->setAlignment(Qt::AlignCenter); m_pointerPreview->setAutoFillBackground(true); m_pointerPreview->setBackgroundRole(QPalette::Base); top->addWidget(m_pointerPreview, 0, Qt::AlignBottom); layout->addLayout(top); layout->addWidget(new QLabel(QStringLiteral("Customize:"))); m_pointerList = new QListWidget; m_pointerList->setItemDelegate(new PointerRowDelegate(m_pointerList)); m_pointerList->setUniformItemSizes(true); layout->addWidget(m_pointerList, 1); auto *row = new QHBoxLayout; m_pointerOutlineBox = new QCheckBox(QStringLiteral("Outline")); // (XPlasma's own, beside XP's one box) m_pointerOutlineBox->setToolTip(QStringLiteral("A subtle gray outline keeps pointers visible on dark backgrounds.")); m_pointerShadowBox = new QCheckBox(QStringLiteral("Enable pointer shadow")); m_pointerDefault = new QPushButton(QStringLiteral("Use Default")); m_pointerBrowse = new QPushButton(QStringLiteral("Browse...")); row->addWidget(m_pointerShadowBox); row->addWidget(m_pointerOutlineBox); row->addStretch(1); row->addWidget(m_pointerDefault); row->addWidget(m_pointerBrowse); layout->addLayout(row); m_pointerTimer = new QTimer(this); m_pointerTimer->setSingleShot(true); connect(m_pointerTimer, &QTimer::timeout, this, [this] { ++m_previewFrame; previewPointer(); }); connect(m_pointerScheme, &QComboBox::activated, this, [this](int index) { const QString name = m_pointerScheme->itemData(index).toString(); m_pointers.reset(); for (const pointers::Scheme &s : std::as_const(m_pointerSchemes)) if (s.name == name) m_pointers = s; showPointers(); pointersChanged(); }); connect(m_pointerList, &QListWidget::currentRowChanged, this, [this] { m_previewFrame = 0; previewPointer(); }); connect(m_pointerOutlineBox, &QCheckBox::toggled, this, [this](bool on) { m_pointerOutline = on; showPointers(); pointersChanged(); }); connect(m_pointerShadowBox, &QCheckBox::toggled, this, [this](bool on) { m_pointerShadow = on; showPointers(); pointersChanged(); }); connect(m_pointerDefault, &QPushButton::clicked, this, [this] { const int role = m_pointerList->currentRow(); if (!m_pointers || role < 0) return; m_pointers->files[role].clear(); showPointers(); pointersChanged(); }); connect(m_pointerBrowse, &QPushButton::clicked, this, [this] { const int role = m_pointerList->currentRow(); if (!m_pointers || role < 0) return; const QString file = QFileDialog::getOpenFileName(this, QStringLiteral("Browse"), paths::home(), QStringLiteral("Cursors (*.cur *.ani)")); if (file.isEmpty()) return; m_pointers->files[role] = file; showPointers(); pointersChanged(); }); return page;}
void DisplayProperties::fillPointerSchemes(){ m_pointerScheme->clear(); m_pointerScheme->addItem(QStringLiteral("(None)"), QString()); for (const pointers::Scheme &s : std::as_const(m_pointerSchemes)) m_pointerScheme->addItem(s.name, s.name); m_pointerScheme->setCurrentIndex(qMax(0, m_pointerScheme->findData(m_pointers ? m_pointers->name : QString()))); m_pointerScheme->setEnabled(!m_pointerSchemes.isEmpty()); if (m_pointerSchemes.isEmpty()) m_pointerScheme->setToolTip(QStringLiteral("XP's pointers come from its install media: set it up under Themes > More themes."));}
QList<CursorFrame> DisplayProperties::pointerFrames(int role){ const pointers::Scheme scheme = m_pointers.value_or(pointers::defaultScheme()); const QString file = scheme.files.value(role); const QString key = (file.isEmpty() ? QStringLiteral("default:%1").arg(role) : file) + (m_pointerShadow ? QStringLiteral("+shadow") : QString()) + (m_pointerOutline ? QStringLiteral("+outline") : QString()); auto it = m_cursorCache.find(key); if (it == m_cursorCache.end()) { QList<CursorFrame> frames = pointers::frames(scheme, role); if (m_pointerOutline) frames = pointers::withOutline(frames); if (m_pointerShadow) frames = pointers::withShadow(frames); it = m_cursorCache.insert(key, frames); } return *it;}
void DisplayProperties::showPointers(){ // "(None)" shows Windows Default's, unchosen: Plasma's own pointers stay. const int current = qMax(0, m_pointerList->currentRow()); const int scroll = m_pointerList->verticalScrollBar()->value(); m_pointerList->clear(); m_pointerShadowBox->setChecked(m_pointerShadow); m_pointerOutlineBox->setChecked(m_pointerOutline); if (m_pointerSchemes.isEmpty()) { m_pointerList->setEnabled(false); m_pointerShadowBox->setEnabled(false); m_pointerDefault->setEnabled(false); m_pointerBrowse->setEnabled(false); m_pointerSaveAs->setEnabled(false); m_pointerDelete->setEnabled(false); return; } for (int role = 0; role < pointers::RoleCount; ++role) { const QList<CursorFrame> frames = pointerFrames(role); auto *item = new QListWidgetItem(pointers::roleName(role)); if (!frames.isEmpty()) { item->setData(Qt::DecorationRole, frames.first().image); // (drawn by PointerRowDelegate) item->setData(PointerRowDelegate::kPadRole, m_pointerOutline ? 1 : 0); } m_pointerList->addItem(item); } m_pointerList->setEnabled(m_pointers.has_value()); m_pointerSaveAs->setEnabled(m_pointers.has_value()); m_pointerDelete->setEnabled(m_pointers && !m_pointers->folder.isEmpty()); // (the user's own only) m_pointerShadowBox->setEnabled(m_pointers.has_value()); m_pointerDefault->setEnabled(m_pointers.has_value()); m_pointerBrowse->setEnabled(m_pointers.has_value()); m_pointerList->setCurrentRow(current); m_pointerList->verticalScrollBar()->setValue(scroll); m_previewFrame = 0; previewPointer();}
void DisplayProperties::previewPointer(){ // The chosen pointer, animated as it would be. m_pointerTimer->stop(); const int role = m_pointerList->currentRow(); const QList<CursorFrame> frames = role >= 0 ? pointerFrames(role) : QList<CursorFrame>(); if (frames.isEmpty()) { m_pointerPreview->clear(); return; } const CursorFrame &f = frames.at(m_previewFrame % frames.size()); // (The outline's pixel kept round it when it's off, so the pointer // doesn't shift as it's toggled.) QImage shown = f.image; if (!m_pointerOutline) { shown = QImage(f.image.size() + QSize(2, 2), QImage::Format_ARGB32_Premultiplied); shown.fill(Qt::transparent); QPainter p(&shown); p.drawImage(1, 1, f.image); } m_pointerPreview->setPixmap(QPixmap::fromImage(shown)); if (frames.size() > 1) m_pointerTimer->start(qMax(16, f.delayMs));}
void DisplayProperties::savePointerScheme(){ if (!m_pointers) return; // XP's Save Scheme dialog. bool ok = false; const QString suggested = m_pointers->name == QLatin1String(pointers::kDefaultScheme) ? QString() : m_pointers->name; const QString name = QInputDialog::getText(this, QStringLiteral("Save Scheme"), QStringLiteral("Save this cursor scheme as:"), QLineEdit::Normal, suggested, &ok) .trimmed(); if (!ok || name.isEmpty()) return; const bool exists = QFileInfo::exists(pointers::savedSchemeFolder(name)); if (exists && QMessageBox::warning(this, QStringLiteral("Save Scheme"), QStringLiteral("%1 already exists.\nDo you want to replace it?").arg(name), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes) return; QString error; const auto saved = pointers::saveScheme(*m_pointers, name, exists, &error); if (!saved) { QMessageBox::warning(this, QStringLiteral("Save Scheme"), error); return; } m_pointerSchemes = pointers::schemes(); m_pointers = *saved; fillPointerSchemes(); showPointers(); pointersChanged();}
void DisplayProperties::deletePointerScheme(){ if (!m_pointers || m_pointers->folder.isEmpty()) return; if (QMessageBox::question(this, QStringLiteral("Delete Scheme"), QStringLiteral("Are you sure you want to delete the scheme '%1'?").arg(m_pointers->name)) != QMessageBox::Yes) return; QString error; if (!pointers::deleteScheme(*m_pointers, &error)) { QMessageBox::warning(this, QStringLiteral("Delete Scheme"), error); return; } // (What's chosen stays as it is, a scheme of its own no longer: its // pointers were in the folder, so it's back to the applied ones or none.) m_pointerSchemes = pointers::schemes(); m_pointers = m_appliedPointers && m_appliedPointers->first.folder != m_pointers->folder ? std::optional(m_appliedPointers->first) : std::nullopt; fillPointerSchemes(); showPointers(); pointersChanged();}
void DisplayProperties::pointersChanged(){ if (m_loading) return; updateApply();}
bool DisplayProperties::pointersDiffer() const{ if (m_pointerOutline != m_appliedPointerOutline) return true; if (!m_pointers) return m_appliedPointers.has_value(); return !m_appliedPointers || !(m_appliedPointers->first == *m_pointers) || m_appliedPointers->second != m_pointerShadow;}
// --- the library ---------------------------------------------------------------------------
void DisplayProperties::loadLibrary(){ m_library = Library::scan(); m_styles.clear(); for (const StyleInfo &s : std::as_const(m_library.styles)) if (s.readable()) m_styles.append(s); fillThemes();}
void DisplayProperties::fillThemes(){ m_themes->clear(); for (const ThemeBundle &t : std::as_const(m_library.themes)) if (t.styleMissing.isEmpty()) m_themes->addItem(t.label, t.path); m_themes->insertSeparator(m_themes->count()); m_themes->addItem(QStringLiteral("More themes..."), QLatin1String(kSetup)); m_themes->addItem(QStringLiteral("Browse..."), QLatin1String(kBrowse));}
void DisplayProperties::fillStyles(){ m_style->clear(); for (const StyleInfo &s : std::as_const(m_styles)) m_style->addItem(s.label, s.path); m_style->addItem(QStringLiteral("Windows Classic style"));}
void DisplayProperties::fillColours(){ const QString previous = m_colour->currentData().toString(); m_colour->clear(); const int i = m_style->currentIndex(); if (i >= 0 && i < m_styles.size()) { for (const StyleOption &c : m_styles.at(i).colours) m_colour->addItem(c.label, c.key); } else { // Classic: the stock and saved schemes (a size is the Font size's). const QString base = schemes::split(m_scheme.name).first; for (const QString &name : schemes::bases()) m_colour->addItem(name, name); if (m_colour->findData(base) < 0) m_colour->insertItem(0, base, base); m_colour->setCurrentIndex(m_colour->findData(base)); return; } const int keep = m_colour->findData(previous); m_colour->setCurrentIndex(keep >= 0 ? keep : 0);}
void DisplayProperties::fillSizes(){ const QString previous = m_size->currentData().toString(); m_size->clear(); const int i = m_style->currentIndex(); if (i >= 0 && i < m_styles.size()) { for (const StyleOption &s : m_styles.at(i).sizesFor(m_colour->currentData().toString())) m_size->addItem(s.label, s.key); } else { const QString base = m_colour->currentData().toString(); for (const FontSize &s : fontSizes()) if (schemes::sizeAvailable(base, QLatin1String(s.key))) m_size->addItem(QLatin1String(s.label), QLatin1String(s.key)); const int keep = m_size->findData(schemes::split(m_scheme.name).second); m_size->setCurrentIndex(keep >= 0 ? keep : 0); return; } const int keep = m_size->findData(previous.isEmpty() ? QStringLiteral("NORMAL") : previous); m_size->setCurrentIndex(keep >= 0 ? keep : 0);}
void DisplayProperties::fillWallpapers(){ m_wallpapers->clear(); auto *none = new QListWidgetItem(QStringLiteral("(None)")); m_wallpapers->addItem(none); QFileInfoList files = QDir(paths::wallpapers()).entryInfoList({QStringLiteral("*.jpg"), QStringLiteral("*.jpeg"), QStringLiteral("*.png"), QStringLiteral("*.bmp"), QStringLiteral("*.gif")}, QDir::Files, QDir::Name | QDir::IgnoreCase); for (const QFileInfo &f : std::as_const(files)) { auto *item = new QListWidgetItem(f.completeBaseName()); item->setData(Qt::UserRole, f.absoluteFilePath()); m_wallpapers->addItem(item); }}
// --- choices ----------------------------------------------------------------------------------
Look DisplayProperties::look() const{ const int i = m_style->currentIndex(); if (i >= 0 && i < m_styles.size()) { const StyleInfo &s = m_styles.at(i); const QString ini = s.ini(m_colour->currentData().toString(), m_size->currentData().toString()); if (auto look = Look::fromStyle(s.path, ini)) return look->adjusted(m_adjust); } return Look::fromScheme(m_scheme);}
Wallpaper DisplayProperties::wallpaper() const{ Wallpaper w; if (QListWidgetItem *item = m_wallpapers->currentItem()) w.image = item->data(Qt::UserRole).toString(); w.fill = m_position->currentData().toInt(); w.colour = m_desktopColour->colour(); return w;}
void DisplayProperties::themePicked(int index){ const QString data = m_themes->itemData(index).toString(); if (data == QLatin1String(kSetup)) { SetupDialog dialog(this); dialog.exec(); if (dialog.changedLibrary()) { loadLibrary(); fillStyles(); fillColours(); fillSizes(); fillWallpapers(); } return; } if (data == QLatin1String(kBrowse)) { const QString file = QFileDialog::getOpenFileName(this, QStringLiteral("Open Theme"), paths::themes(), QStringLiteral("Themes (*.theme)")); if (file.isEmpty()) return; // (Only a theme: a visual style, or anything else, read as one is // an empty Windows Classic look, applied without a word.) QFile head(file); const bool style = file.endsWith(QLatin1String(".msstyles"), Qt::CaseInsensitive) || (head.open(QIODevice::ReadOnly) && head.read(2) == "MZ"); const auto theme = style ? std::nullopt : ThemeFile::load(file); if (style || !theme || theme->sections().isEmpty()) { QMessageBox::warning(this, QStringLiteral("Open Theme"), style ? QStringLiteral("%1 is a visual style, not a theme. Put its folder in %2, then choose it on the " "Appearance tab.") .arg(QFileInfo(file).fileName(), paths::userThemes()) : QStringLiteral("%1 isn't a Windows theme (.theme) file.").arg(QFileInfo(file).fileName())); return; } const ThemeBundle bundle = Library::bundle(file); if (!bundle.styleMissing.isEmpty()) { QMessageBox::warning(this, QStringLiteral("Open Theme"), QStringLiteral("%1 names a visual style that isn't here (%2).") .arg(QFileInfo(file).fileName(), bundle.styleMissing)); return; } m_themes->insertItem(0, bundle.label, bundle.path); m_themes->setCurrentIndex(0); showBundle(bundle); return; } for (const ThemeBundle &b : std::as_const(m_library.themes)) if (b.path == data) showBundle(b);}
void DisplayProperties::showBundle(const ThemeBundle &b){ m_loading = true; m_themeFile = b.path; const auto file = ThemeFile::load(b.path); const ClassicScheme colours = file ? ClassicScheme::fromThemeFile(*file) : ClassicScheme(); if (b.classic()) { m_scheme = colours; m_scheme.name = b.label; m_style->setCurrentIndex(m_styles.size()); fillColours(); fillSizes(); } else { // (A theme saved here brings its style's adjustments; any other, none.) m_adjust = b.adjust; for (int i = 0; i < m_styles.size(); ++i) if (QFileInfo(m_styles.at(i).path).canonicalFilePath() == QFileInfo(b.style).canonicalFilePath()) m_style->setCurrentIndex(i); fillColours(); const StyleInfo &s = m_styles.value(m_style->currentIndex()); const StyleVariant *v = s.variant(b.variant.isEmpty() ? s.defaultVariant : b.variant); if (v) m_colour->setCurrentIndex(m_colour->findData(v->colour)); fillSizes(); if (v) m_size->setCurrentIndex(m_size->findData(v->size)); } // The desktop the theme brings. int row = 0; for (int i = 0; i < m_wallpapers->count(); ++i) if (!b.wallpaper.isEmpty() && QFileInfo(m_wallpapers->item(i)->data(Qt::UserRole).toString()) == QFileInfo(b.wallpaper)) row = i; if (row == 0 && !b.wallpaper.isEmpty()) { auto *item = new QListWidgetItem(QFileInfo(b.wallpaper).completeBaseName()); item->setData(Qt::UserRole, b.wallpaper); m_wallpapers->addItem(item); row = m_wallpapers->count() - 1; } m_wallpapers->setCurrentRow(row); for (int i = 0; i < m_position->count(); ++i) if (m_position->itemData(i).toInt() == b.fill.value_or(0)) m_position->setCurrentIndex(i); m_desktopColour->setColour(colours.colour(u"Background")); // Its pointers and sounds, when it names them, as XP's themes do (XP's // own: Windows Default's): a theme chosen is all of it. if (!b.cursors.isEmpty() && !m_pointerSchemes.isEmpty()) { pointers::Scheme s; s.name = b.cursorScheme.isEmpty() ? b.label : b.cursorScheme; s.files = b.cursors; while (s.files.size() < pointers::RoleCount) s.files << QString(); // (One of the user's own, if it's that one: then it can be deleted.) for (const pointers::Scheme &known : std::as_const(m_pointerSchemes)) if (known == s) s.folder = known.folder; m_pointers = s; fillPointerSchemes(); showPointers(); } if (!b.sounds.isEmpty()) { sounds::Scheme s; s.name = b.soundScheme; for (const sounds::Event &e : sounds::events()) if (const QString sound = b.sounds.value(sounds::appKey(e) + QLatin1Char('\\') + e.key); !sound.isEmpty()) s.sounds.insert(e.key, sound); m_sounds->showScheme(s); } // ...and its Start button's label and logo: any theme's, XP's own // bringing back "start" and the flag. m_startExtras = b.startButton; m_loading = false; m_delete->setEnabled(presets::owned(b.path)); m_export->setEnabled(b.path.endsWith(QLatin1String(".theme"), Qt::CaseInsensitive)); renderThemes(); renderDesktop(); renderAppearance(); updateApply();}
void DisplayProperties::appearanceChanged(){ if (m_loading) return; const int i = m_style->currentIndex(); if (i >= m_styles.size()) { // A Classic scheme picked by name and size. const QString base = m_colour->currentData().toString(); const QString sizeKey = m_size->currentData().toString(); QString name = base; for (const FontSize &s : fontSizes()) if (sizeKey == QLatin1String(s.key)) name += QLatin1String(s.suffix); if (const auto s = schemes::load(name)) m_scheme = *s; } m_themeFile.clear(); renderAppearance(); renderThemes(); updateApply();}
void DisplayProperties::desktopChanged(){ if (m_loading) return; m_themeFile.clear(); renderDesktop(); renderThemes(); updateApply();}
void DisplayProperties::openExtras(){ ExtrasDialog dialog(look(), m_startExtras, this); if (dialog.exec() != QDialog::Accepted) return; // (Part of the theme now: changed, it's the theme as modified.) if (dialog.extras() != m_startExtras) m_themeFile.clear(); m_startExtras = dialog.extras(); renderThemes(); updateApply();}
void DisplayProperties::done(int result){ // Not applied (or applied, all the same): every window as xplasmarc has // it. (A KWin reconfigure ends a preview too; apps' styles don't hear one.) if (m_previewedLive) { sendLookPreview(configuredAdjustments()); // ...and the taskbar's Start button as applied. LiveSession session; endStartButtonPreview(session, look().id); } QDialog::done(result);}
void DisplayProperties::openAdvanced(){ if (m_style->currentIndex() < m_styles.size()) { // A visual style: its items' colours, sizes and fonts as adjustments, // every open window following as they're edited. AdvancedDialog dialog(look().adjusted({}), m_adjust, &m_previewer, this); const int result = dialog.exec(); m_previewedLive = true; // (whichever way it closed, windows may have moved) if (result != QDialog::Accepted) return; m_adjust = dialog.adjustments(); m_themeFile.clear(); renderAppearance(); renderThemes(); updateApply(); return; } AdvancedDialog dialog(m_scheme, &m_previewer, this); if (dialog.exec() != QDialog::Accepted) return; m_scheme = dialog.scheme(); m_themeFile.clear(); m_loading = true; fillColours(); fillSizes(); m_loading = false; renderAppearance(); renderThemes(); updateApply();}
void DisplayProperties::saveAs(){ bool ok = false; const QString name = QInputDialog::getText(this, QStringLiteral("Save Theme"), QStringLiteral("Save this theme as:"), QLineEdit::Normal, m_themes->currentText(), &ok) .trimmed(); if (!ok || name.isEmpty()) return; presets::Preset p; p.name = name; const Look l = look(); if (!l.classic()) { p.style = l.stylePath; const StyleInfo &s = m_styles.at(m_style->currentIndex()); if (const StyleVariant *v = s.variant(l.variant)) { for (const StyleOption &c : s.colours) if (c.key == v->colour) p.colorStyle = c.name; for (const StyleOption &z : s.sizes) if (z.key == v->size) p.size = z.name; } p.adjust = l.adjust; } else { p.scheme = m_scheme; } const Wallpaper w = wallpaper(); p.desktop = presets::Desktop{w.image, w.fill.value_or(2), w.colour}; // Its pointers, as the Pointers tab has them (none chosen: none named). if (m_pointers) { p.cursorScheme = m_pointers->name; p.cursors = m_pointers->files; } // ...and its sounds, as the Sounds tab has them (each event, a quiet one empty). const sounds::Scheme sound = m_sounds->scheme(); p.soundScheme = sound.name; for (const sounds::Event &e : sounds::events()) p.sounds.insert(sounds::appKey(e) + QLatin1Char('\\') + e.key, sound.sounds.value(e.key)); // ...and its Start button's label and logo, as Extras... has them. p.startButton = m_startExtras; if (m_themeFile.endsWith(QLatin1String(".theme"), Qt::CaseInsensitive)) p.base = m_themeFile; // Already saved under that name: replaced only if the user says so. const bool exists = QFileInfo::exists(presets::savedPath(name)); if (exists && QMessageBox::warning(this, QStringLiteral("Save Theme"), QStringLiteral("%1 already exists.\nDo you want to replace it?").arg(name), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes) return; QString path, error; if (!presets::save(p, &path, &error, exists)) { QMessageBox::warning(this, QStringLiteral("Save Theme"), error); return; } m_library = Library::scan(); fillThemes(); m_themes->setCurrentIndex(m_themes->findData(path)); m_themeFile = path; m_delete->setEnabled(true); m_export->setEnabled(true); updateApply();}
void DisplayProperties::exportTheme(){ const QString path = m_themes->currentData().toString(); if (path.isEmpty()) return; // (A theme changed since it was chosen goes as it's saved: Save As first.) const QString suggested = QDir(paths::documents()).filePath(m_themes->currentText() + QLatin1String(themepack::kSuffix)); QString out = QFileDialog::getSaveFileName(this, QStringLiteral("Export Theme"), suggested, QStringLiteral("Theme packs (*.themepack)")); if (out.isEmpty()) return; if (!out.endsWith(QLatin1String(themepack::kSuffix), Qt::CaseInsensitive)) out += QLatin1String(themepack::kSuffix); QString error; if (!themepack::write(path, out, &error)) QMessageBox::warning(this, QStringLiteral("Export Theme"), error);}
void DisplayProperties::openThemePack(const QString &given){ QString pack = given; if (pack.isEmpty()) pack = QFileDialog::getOpenFileName(this, QStringLiteral("Open Theme"), paths::documents(), QStringLiteral("Theme packs (*.themepack *.deskthemepack)")); if (pack.isEmpty()) return; QString error; const auto name = themepack::name(pack, &error); if (!name) { QMessageBox::warning(this, QStringLiteral("Open Theme"), error); return; } // A theme of that name is either an opened pack (a folder) or one saved // here (a .theme file): either asks first, and is replaced, not joined // by a second of the same name. const bool packThere = QFileInfo::exists(themepack::installFolder(*name)); const QString saved = presets::savedPath(*name); const bool savedThere = QFileInfo::exists(saved) && presets::owned(saved); if ((packThere || savedThere) && QMessageBox::warning(this, QStringLiteral("Open Theme"), QStringLiteral("%1 already exists.\nDo you want to replace it?").arg(*name), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes) return; const auto installed = themepack::install(pack, packThere, &error); if (installed && savedThere) QFile::remove(saved); if (!installed) { QMessageBox::warning(this, QStringLiteral("Open Theme"), error); return; } // In the list (its style too, a fan style it carries), and chosen // (Apply puts it on). loadLibrary(); fillStyles(); m_tabs->setCurrentIndex(0); if (const int i = m_themes->findData(*installed); i >= 0) { m_themes->setCurrentIndex(i); themePicked(i); }}
void DisplayProperties::deleteTheme(){ const QString path = m_themes->currentData().toString(); if (!presets::owned(path)) { QMessageBox::information(this, QStringLiteral("Delete"), QStringLiteral("Only themes saved here can be deleted; XP's own and your collection's are left alone.")); return; } if (QMessageBox::question(this, QStringLiteral("Delete"), QStringLiteral("Delete the saved theme \"%1\"?").arg(m_themes->currentText())) != QMessageBox::Yes) return; // (A pack opened here is a folder of its own: it goes whole.) const QFileInfo theme(path); if (QDir(theme.absolutePath()) != QDir(paths::userThemes())) QDir(theme.absolutePath()).removeRecursively(); else QFile::remove(path); m_library = Library::scan(); fillThemes(); // (None chosen, rather than whichever is first: what's set stays as it // was, a theme of its own no longer.) m_themes->setCurrentIndex(-1); m_themeFile.clear(); m_delete->setEnabled(false); m_export->setEnabled(false); renderThemes(); updateApply();}
bool DisplayProperties::apply(){ const Look l = look(); const Wallpaper desktop = wallpaper(); // Shift: everything, as if nothing were applied. const bool everything = shiftHeld(); const bool lookChanged = everything || lookKey(l) != m_appliedLook; const bool desktopChanged = everything || !sameDesktop(desktop, m_appliedDesktop); const bool pointersChanged = pointersDiffer() || (everything && m_pointers); const bool startChanged = m_startExtras != m_appliedStartExtras; if (!lookChanged && !desktopChanged && !pointersChanged && !startChanged && m_themeFile == m_appliedThemeFile) return m_sounds->apply();
QString error; bool ok = true; if (startChanged) { // (Kept first: a look applied now draws its Start button with them.) State state = State::load(); if (m_startExtras.isDefault()) state.settings.remove(QLatin1String(kStartButtonKey)); else state.settings.insert(QLatin1String(kStartButtonKey), m_startExtras.toJson()); state.save(); } if (lookChanged) { ApplyOptions o; if (desktopChanged) o.wallpaper = desktop; o.themeFile = m_themeFile; o.regenerate = everything; // (Shift: made anew, every part) QStringList notices; ok = runJob(this, QStringLiteral("Applying %1").arg(l.name), [&](const JobContext &c, QString *e) { ApplyOptions options = o; options.progress = c.say; options.notice = [¬ices](const QString &text) { notices << text; }; options.cancel = c.cancel; LiveSession session; return applyLook(session, l, options, e); }, &error); // (once it's done: "log out and back in...") for (const QString &text : std::as_const(notices)) QMessageBox::information(this, QStringLiteral("XPlasma"), text); } else if (desktopChanged || m_themeFile != m_appliedThemeFile) { if (desktopChanged) { LiveSession session; applyWallpaper(session, desktop); } // (The same look, now from this theme: only the record changes.) State state = State::load(); state.themeFile = m_themeFile; state.save(); } if (startChanged && !lookChanged) { ok = runJob(this, QStringLiteral("Applying the Start button"), [&](const JobContext &, QString *e) { LiveSession session; return applyStartButton(session, l, e); }, &error); } if (ok && startChanged) m_appliedStartExtras = m_startExtras; if (ok) { if (lookChanged) { m_appliedLook = lookKey(l); m_outdated = false; } m_appliedDesktop = desktop; m_appliedThemeFile = m_themeFile; } if (ok && pointersChanged) { LiveSession session; State state = State::load(); state.settings.insert(QStringLiteral("pointerOutline"), m_pointerOutline); if (m_pointers) ok = pointers::apply(session, state, *m_pointers, m_pointerShadow, &error); else pointers::revert(session, state); if (ok) { state.save(); m_appliedPointerOutline = m_pointerOutline; m_appliedPointers.reset(); if (m_pointers) m_appliedPointers = std::pair(*m_pointers, m_pointerShadow); } } if (!ok) QMessageBox::warning(this, QStringLiteral("Apply"), error); // (after the look, which may have put Windows Default on itself) if (ok) ok = m_sounds->apply(); updateApply(); return ok;}
void DisplayProperties::updateApply(){ m_apply->setToolTip(m_outdated ? QStringLiteral("XPlasma has been updated since this look was applied. Apply rebuilds it with this " "version.\nHold Shift to rebuild and apply everything, changed or not.") : QStringLiteral("Hold Shift to rebuild and apply everything, changed or not.")); m_apply->setEnabled(shiftHeld() || lookKey(look()) != m_appliedLook || !sameDesktop(wallpaper(), m_appliedDesktop) || m_themeFile != m_appliedThemeFile || pointersDiffer() || m_startExtras != m_appliedStartExtras || m_sounds->pending());}
bool DisplayProperties::eventFilter(QObject *watched, QEvent *event){ if ((event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) && static_cast<QKeyEvent *>(event)->key() == Qt::Key_Shift && isActiveWindow()) QTimer::singleShot(0, this, &DisplayProperties::updateApply); return QDialog::eventFilter(watched, event);}
// --- samples -----------------------------------------------------------------------------------
void DisplayProperties::renderThemes(){ if (m_loading) return; m_themeSample->setPixmap(QPixmap::fromImage(m_previewer.theme(look(), wallpaper(), preview::kThemesSize, m_startExtras)));}
void DisplayProperties::renderDesktop(){ if (m_loading) return; m_desktopSample->setPixmap(QPixmap::fromImage(m_previewer.desktop(wallpaper(), QSize(200, 170))));}
void DisplayProperties::renderAppearance(){ if (m_loading) return; const Look l = look(); m_appearanceSample->setPixmap(QPixmap::fromImage(m_previewer.appearance(l, preview::kAppearanceSize, l.system.colour(u"Background"))));}
void DisplayProperties::showTab(const QString &name){ for (int i = 0; i < m_tabs->count(); ++i) if (m_tabs->tabText(i).remove(QLatin1Char('&')).compare(name, Qt::CaseInsensitive) == 0) m_tabs->setCurrentIndex(i);}
void DisplayProperties::reapply(){ // (Once shown, as the user would press it: its progress and any error in // the dialog as usual.) if (m_outdated) QTimer::singleShot(0, this, [this] { apply(); });}
bool DisplayProperties::saveScreenshots(const QString &dir){ QDir().mkpath(dir); setAttribute(Qt::WA_DontShowOnScreen); show(); bool ok = true; m_sounds->showForScreenshot(); const char *const names[] = {"themes", "desktop", "appearance", "pointers", "sounds", "about"}; for (int i = 0; i < m_tabs->count(); ++i) { m_tabs->setCurrentIndex(i); QApplication::processEvents(); ok &= grab().save(QDir(dir).filePath(QLatin1String(names[i]) + QLatin1String(".png"))); } AdvancedDialog advanced(m_scheme, &m_previewer, this); advanced.setAttribute(Qt::WA_DontShowOnScreen); advanced.show(); QApplication::processEvents(); ok &= advanced.grab().save(QDir(dir).filePath(QStringLiteral("advanced.png"))); ExtrasDialog extras(look(), m_startExtras, this); extras.setAttribute(Qt::WA_DontShowOnScreen); extras.show(); QApplication::processEvents(); ok &= extras.grab().save(QDir(dir).filePath(QStringLiteral("extras.png"))); if (m_style->currentIndex() < m_styles.size()) { AdvancedDialog styleAdvanced(look().adjusted({}), m_adjust, &m_previewer, this); styleAdvanced.setAttribute(Qt::WA_DontShowOnScreen); styleAdvanced.showItemNamed(QStringLiteral("Inactive Title Bar")); // (a linked one: its box shown) styleAdvanced.show(); QApplication::processEvents(); ok &= styleAdvanced.grab().save(QDir(dir).filePath(QStringLiteral("advanced-style.png"))); styleAdvanced.showItemNamed(QStringLiteral("Start Button")); // (its overlap box shown) QApplication::processEvents(); ok &= styleAdvanced.grab().save(QDir(dir).filePath(QStringLiteral("advanced-start.png"))); } ColourPicker picker(QColor(58, 110, 165), this); picker.setAttribute(Qt::WA_DontShowOnScreen); picker.show(); QApplication::processEvents(); ok &= picker.grab().save(QDir(dir).filePath(QStringLiteral("colour.png"))); return ok;}
} // namespace xpl::editor