diff --git a/kcms/ksplash/kcm.h b/kcms/ksplash/kcm.h --- a/kcms/ksplash/kcm.h +++ b/kcms/ksplash/kcm.h @@ -38,7 +38,8 @@ public: enum Roles { PluginNameRole = Qt::UserRole +1, - ScreenhotRole + ScreenhotRole, + DescriptionRole }; KCMSplashScreen(QObject* parent, const QVariantList& args); @@ -51,6 +52,8 @@ int selectedPluginIndex() const; + void loadModel(); + public Q_SLOTS: void getNewClicked(); void load() override; diff --git a/kcms/ksplash/kcm.cpp b/kcms/ksplash/kcm.cpp --- a/kcms/ksplash/kcm.cpp +++ b/kcms/ksplash/kcm.cpp @@ -57,7 +57,9 @@ QHash roles = m_model->roleNames(); roles[PluginNameRole] = "pluginName"; roles[ScreenhotRole] = "screenshot"; + roles[DescriptionRole] = "description"; m_model->setItemRoleNames(roles); + loadModel(); } QList KCMSplashScreen::availablePackages(const QString &component) @@ -104,47 +106,55 @@ } m_selectedPlugin = plugin; emit selectedPluginChanged(); + emit selectedPluginIndexChanged(); } void KCMSplashScreen::getNewClicked() { KNS3::DownloadDialog dialog("ksplash.knsrc", 0); if (dialog.exec()) { KNS3::Entry::List list = dialog.changedEntries(); if (list.count() > 0) { - load(); + loadModel(); } } } -void KCMSplashScreen::load() +void KCMSplashScreen::loadModel() { - m_package = Plasma::PluginLoader::self()->loadPackage(QStringLiteral("Plasma/LookAndFeel")); - KConfigGroup cg(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), "KDE"); - const QString packageName = cg.readEntry("LookAndFeelPackage", QString()); - if (!packageName.isEmpty()) { - m_package.setPath(packageName); - } - - QString currentPlugin = m_configGroup.readEntry("Theme", QString()); - if (currentPlugin.isEmpty()) { - currentPlugin = m_package.metadata().pluginName(); - } - setSelectedPlugin(currentPlugin); - m_model->clear(); QStandardItem* row = new QStandardItem(i18n("None")); row->setData("None", PluginNameRole); + row->setData(i18n("No splash screen will be shown"), DescriptionRole); m_model->appendRow(row); const QList pkgs = availablePackages(QStringLiteral("splashmainscript")); for (const Plasma::Package &pkg : pkgs) { QStandardItem* row = new QStandardItem(pkg.metadata().name()); row->setData(pkg.metadata().pluginName(), PluginNameRole); row->setData(pkg.filePath("previews", QStringLiteral("splash.png")), ScreenhotRole); + row->setData(pkg.metadata().comment(), DescriptionRole); m_model->appendRow(row); } + emit selectedPluginIndexChanged(); +} + +void KCMSplashScreen::load() +{ + m_package = Plasma::PluginLoader::self()->loadPackage(QStringLiteral("Plasma/LookAndFeel")); + KConfigGroup cg(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), "KDE"); + const QString packageName = cg.readEntry("LookAndFeelPackage", QString()); + if (!packageName.isEmpty()) { + m_package.setPath(packageName); + } + + QString currentPlugin = m_configGroup.readEntry("Theme", QString()); + if (currentPlugin.isEmpty()) { + currentPlugin = m_package.metadata().pluginName(); + } + setSelectedPlugin(currentPlugin); + setNeedsSave(false); } diff --git a/kcms/ksplash/package/contents/ui/main.qml b/kcms/ksplash/package/contents/ui/main.qml --- a/kcms/ksplash/package/contents/ui/main.qml +++ b/kcms/ksplash/package/contents/ui/main.qml @@ -19,152 +19,49 @@ import QtQuick 2.1 import QtQuick.Layouts 1.1 import QtQuick.Controls 1.0 as QtControls -import org.kde.kquickcontrolsaddons 2.0 -import QtQuick.Controls.Private 1.0 -import org.kde.kirigami 2.0 // for Units -import org.kde.plasma.components 2.0 as PlasmaComponents +import org.kde.kirigami 2.4 as Kirigami +import org.kde.kcm 1.1 as KCM -Item { - implicitWidth: Units.gridUnit * 20 - implicitHeight: Units.gridUnit * 20 +KCM.GridViewKCM { + KCM.ConfigModule.quickHelp: i18n("This module lets you configure the splash screen theme.") - SystemPalette {id: syspal} - ColumnLayout { - anchors.fill: parent - QtControls.ScrollView { - Layout.fillWidth: true - Layout.fillHeight: true - GridView { - id: grid - model: kcm.splashModel - cellWidth: Math.floor(grid.width / Math.max(Math.floor(grid.width / (Units.gridUnit*12)), 3)) - cellHeight: cellWidth / 1.6 - - onCountChanged: { - grid.currentIndex = kcm.selectedPluginIndex; - grid.positionViewAtIndex(grid.currentIndex, GridView.Visible) - } - - delegate: Item { - width: grid.cellWidth - height: grid.cellHeight - Rectangle { - anchors { - fill: parent - margins: Units.smallSpacing - } + view.model: kcm.splashModel + //NOTE: pay attention to never break this binding + view.currentIndex: kcm.selectedPluginIndex + view.delegate: KCM.GridDelegate { + id: delegate - Connections { - target: kcm - onSelectedPluginChanged: { - if (kcm.selectedPlugin == model.pluginName) { - grid.currentIndex = index - } - } - } - QIconItem { - id: icon - anchors.centerIn: parent - width: Units.iconSizes.large - height: width - icon: "view-preview" - } - Image { - id: image - anchors { - fill: parent - margins: Units.smallSpacing * 2 - } - source: model.screenshot || "" - Rectangle { - anchors { - left: parent.left - right: parent.right - bottom: parent.bottom - } - height: childrenRect.height - gradient: Gradient { - GradientStop { - position: 0.0 - color: "transparent" - } - GradientStop { - position: 1.0 - color: image.status == Image.Ready ? Qt.rgba(0, 0, 0, 0.5) : "transparent" - } - } - QtControls.Label { - anchors { - horizontalCenter: parent.horizontalCenter - } - color: image.status == Image.Ready ? "white" : "gray" - text: model.display - } - } - } - Rectangle { - opacity: grid.currentIndex == index ? 1.0 : 0 - anchors.fill: parent - border.width: Units.smallSpacing * 2 - border.color: syspal.highlight - color: "transparent" - Behavior on opacity { - PropertyAnimation { - duration: Units.longDuration - easing.type: Easing.OutQuad - } - } - } - MouseArea { - anchors.fill: parent - hoverEnabled: true - onClicked: { - grid.currentIndex = index - kcm.selectedPlugin = model.pluginName - } - Timer { - interval: 1000 // FIXME TODO: Use platform value for tooltip activation delay. + text: model.display + toolTip: model.description - running: parent.containsMouse && !parent.pressedButtons - - onTriggered: { - Tooltip.showText(parent, Qt.point(parent.mouseX, parent.mouseY), model.display); - } - } - PlasmaComponents.ToolButton { - anchors { - top: parent.top - right: parent.right - margins: Units.smallSpacing - } - visible: model.pluginName != "None" - iconSource: "media-playback-start" - tooltip: i18n("Test Splashscreen") - flat: false - onClicked: kcm.test(model.pluginName) - opacity: parent.containsMouse ? 1 : 0 - Behavior on opacity { - PropertyAnimation { - duration: Units.longDuration - easing.type: Easing.OutQuad - } - } - } - } - } - } - } + thumbnailAvailable: model.screenshot + thumbnail: Image { + anchors.fill: parent + source: model.screenshot || "" } - RowLayout { - Item { - Layout.fillWidth: true - } - QtControls.Button { - iconName: "get-hot-new-stuff" - text: i18n("&Get New Theme...") - onClicked: kcm.getNewClicked(); - enabled: kcm.canInstall + actions: [ + Kirigami.Action { + visible: model.pluginName != "None" + iconName: "media-playback-start" + tooltip: i18n("Test Splashscreen") + onTriggered: kcm.test(model.pluginName) } + ] + onClicked: { + kcm.selectedPlugin = model.pluginName; + view.forceActiveFocus(); + } + } + + footer: RowLayout { + Item { + Layout.fillWidth: true + } + QtControls.Button { + iconName: "get-hot-new-stuff" + text: i18n("&Get New Theme...") + onClicked: kcm.getNewClicked(); + enabled: kcm.canInstall } } }