Something went wrong. Try again.
Bring Windows XP themes to your KDE Plasma environment! xplasma.hotsocket.fyi
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110// SPDX-License-Identifier: GPL-3.0-or-later#pragma once// One visual style, loaded: its variant tables, the chosen variant's layout// INI, and its bitmaps (decoded on first use).
#include "dib.h"#include "ini.h"#include "pe.h"#include "adjust.h"#include "tint.h"
#include <QHash>#include <QMutex>#include <QSet>#include <QStringList>
#include <memory>
namespace xpl {
// The style's own variant bookkeeping (see msstyles_parse.variant_table):// COLORNAMES / SIZENAMES are what a .theme's ColorStyle= / Size= name, and// FILERESNAMES is the layout INI for each (colour, size), colour-major.struct VariantTable{ QStringList iniNames; // every TEXTFILE resource, upper-case, sorted QStringList colourNames; QStringList sizeNames; QStringList fileNames; // upper-case QString themesIni; // THEMES_INI, the display names};
class Theme{public: // `variant` is a layout INI resource name ("NORMALBLUE_INI"); empty picks // the style's own default, which is FILERESNAMES[0] -- not the // alphabetically first NORMAL*_INI. static std::shared_ptr<const Theme> load(const QString &path, const QString &variant = QString(), QString *error = nullptr); static std::shared_ptr<const Theme> fromData(const QByteArray &file, const QString &variant = QString(), QString *error = nullptr); // The same style with its colours moved by `spec` (tint.h): each section's // colour properties by the tint its rule gives it; its bitmaps by the // renderer, each frame by the part and state it's cut for (tinterFor), // so a strip's active and inactive frames can differ. Shares `base`'s // data; cheap to make, so a tint can follow a slider. An identity spec // gives `base` back. static std::shared_ptr<const Theme> tinted(const std::shared_ptr<const Theme> &base, const TintSpec &spec) { return adjusted(base, {spec, {}}); } static std::shared_ptr<const Theme> tinted(const std::shared_ptr<const Theme> &base, const Tint &tint) { return tinted(base, TintSpec::uniform(tint)); } // ...and then its property overrides (adjust.h) laid over the INI: an // exact value set wins over a tint. An override for a section the style // hasn't got makes one, which uxtheme's lookup then finds first. static std::shared_ptr<const Theme> adjusted(const std::shared_ptr<const Theme> &base, const Adjustments &adjustments); const TintSpec &tint() const { return m_spec; } const Adjustments &adjustments() const { return m_adjustments; } // The tint for a part in a state (names as the INI's, lower-case), null // for none. Shared per distinct tint, so its colour memo is too. std::shared_ptr<const Tinter> tinterFor(QStringView sub, QStringView cls, QStringView part, QStringView state) const; // A frame of a part's art, tinted in place, `keep` (0x00RRGGBB) left. Art // that carries a neighbour's colours -- Luna's Start button ends in the // taskbar's blue, where it curves into the bar -- has those pixels, by // how near their hue is to each part's colour hint, turned by the // neighbour's tint, so the two still meet when only one is tinted. A // section's XPlasmaSharedEdge (an override) names its neighbour instead, // a selector as tint.h's, or "none" for a single tint. void tintFrame(QImage &frame, QStringView sub, QStringView cls, QStringView part, QStringView state, const QSet<QRgb> &keep) const;
const VariantTable &variants() const { return m_variants; } QString variant() const { return m_variant; } const Ini &ini() const { return m_ini; }
std::optional<QString> property(QStringView cls, QStringView part, QStringView state, QStringView property, QStringView sub = {}) const { return m_ini.lookup(sub, cls, part, state, property); }
// The bitmap an ImageFile-style property names ("Luna\Button.bmp"), // decoded but without colour keying or tint (the renderer's business). // Resource names are the path upper-cased with every non-alphanumeric // character turned into '_' ("LUNA_BUTTON_BMP"). Dib bitmap(const QString &imageFile) const; static QString resourceName(const QString &imageFile); QStringList bitmapNames() const;
private: Theme() = default;
VariantTable m_variants; QString m_variant; Ini m_ini; QHash<QString, QByteArray> m_bitmapData; // resource name -> raw DIB TintSpec m_spec; // (a tinted copy's) Adjustments m_adjustments; // (an adjusted copy's: m_spec and the overrides) std::shared_ptr<const Theme> m_untinted; // (a tinted copy's: whose bitmaps it draws) mutable QHash<QString, std::shared_ptr<const Tinter>> m_tinters; // tint text -> its mapping mutable QMutex m_cacheLock; mutable QHash<QString, Dib> m_bitmaps;};
} // namespace xpl