// SPDX-FileCopyrightText: 2026 Matvey Shcherbinin // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL #include "StyleSelector.h" #include #include #include namespace koutnet { namespace { bool hasKdeDesktopStyle() { const QString qmlBase = QLibraryInfo::path(QLibraryInfo::QmlImportsPath); return QDir(qmlBase + QStringLiteral("/org/kde/desktop")).exists(); } } // namespace QString defaultStyleName() { // The desktop style is the one the interface is built for; Fusion is the // fallback where the plugin is not installed, such as a bare Windows box. // Fusion is the only Qt Quick Controls style that honours a custom QPalette // the same way on every platform, which is what ThemePalette needs so the // window paints identically on Linux and Windows. return hasKdeDesktopStyle() ? QStringLiteral("org.kde.desktop") : QStringLiteral("Fusion"); } StyleSelector::StyleSelector(KOutNetSettings *settings, QObject *parent) : QObject(parent) , m_settings(settings) { } QString StyleSelector::style() const { const QString style = m_settings->qqc2Style(); return style.isEmpty() ? defaultStyleName() : style; } void StyleSelector::setStyle(const QString &style) { if (m_settings->qqc2Style() == style) return; m_settings->setQqc2Style(style); Q_EMIT styleChanged(); } QString StyleSelector::runningStyle() const { const QString running = QQuickStyle::name(); return running.isEmpty() ? defaultStyleName() : running; } QStringList StyleSelector::availableStyles() const { if (m_stylesCached) return m_styles; // Only styles this UI is known to work well with: the KDE desktop style // (primary Kirigami target) and Fusion (cross-platform fallback, including // Windows). FluentWinUI3 is deliberately not offered: it only styles the // plain Qt Quick Controls and leaves every Kirigami component beside them // unchanged, so a window mixing the two reads as half native and half not; // it also wants Qt 6.8, above this project's 6.4 floor. Other Qt Quick // Controls styles (e.g. Imagine/Material/Universal/Basic) are intentionally // not offered because they conflict with Kirigami theming/custom palettes // or require assets this application does not ship. const QStringList allowed = { QStringLiteral("org.kde.desktop"), QStringLiteral("Fusion"), }; QStringList discovered; const QDir controlsDirectory(QLibraryInfo::path(QLibraryInfo::QmlImportsPath) + QStringLiteral("/QtQuick/Controls")); const QStringList entries = controlsDirectory.entryList(QDir::Dirs | QDir::NoDotAndDotDot); for (const QString &entry : entries) { if (!entry.isEmpty() && entry.at(0).isUpper()) discovered << entry; } // The desktop style lives outside QtQuick/Controls, under the KDE import // path, so include it when actually available. if (hasKdeDesktopStyle()) discovered << QStringLiteral("org.kde.desktop"); QStringList styles; for (const QString &style : allowed) { if (discovered.contains(style) && !styles.contains(style)) styles << style; } // Always keep at least one usable fallback in the list. if (styles.isEmpty()) styles << defaultStyleName(); styles.sort(Qt::CaseInsensitive); m_styles = styles; m_stylesCached = true; return m_styles; } } // namespace koutnet