Commit a6761883 authored by Marco Martin's avatar Marco Martin
Browse files

port the ksplash kcm to the new design

Summary: redically simplifying the code, port the ksplash kcm to the new design

Test Plan: selecting and preview work correctly, resize behavior is correct

Reviewers: #plasma, #vdg, davidedmundson

Reviewed By: #plasma, davidedmundson

Subscribers: ngraham, abetts, davidedmundson, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D12088
parent 0b91f62e
......@@ -57,7 +57,9 @@ KCMSplashScreen::KCMSplashScreen(QObject* parent, const QVariantList& args)
QHash<int, QByteArray> roles = m_model->roleNames();
roles[PluginNameRole] = "pluginName";
roles[ScreenhotRole] = "screenshot";
roles[DescriptionRole] = "description";
m_model->setItemRoleNames(roles);
loadModel();
}
QList<Plasma::Package> KCMSplashScreen::availablePackages(const QString &component)
......@@ -104,6 +106,7 @@ void KCMSplashScreen::setSelectedPlugin(const QString &plugin)
}
m_selectedPlugin = plugin;
emit selectedPluginChanged();
emit selectedPluginIndexChanged();
}
void KCMSplashScreen::getNewClicked()
......@@ -112,30 +115,18 @@ void KCMSplashScreen::getNewClicked()
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<Plasma::Package> pkgs = availablePackages(QStringLiteral("splashmainscript"));
......@@ -143,8 +134,27 @@ void KCMSplashScreen::load()
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);
}
......
......@@ -38,7 +38,8 @@ class KCMSplashScreen : public KQuickAddons::ConfigModule
public:
enum Roles {
PluginNameRole = Qt::UserRole +1,
ScreenhotRole
ScreenhotRole,
DescriptionRole
};
KCMSplashScreen(QObject* parent, const QVariantList& args);
......@@ -51,6 +52,8 @@ public:
int selectedPluginIndex() const;
void loadModel();
public Q_SLOTS:
void getNewClicked();
void load() override;
......
......@@ -19,152 +19,48 @@
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();
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment