Commit 0b91f62e authored by Marco Martin's avatar Marco Martin
Browse files

port the look and feel kcm to new design

Summary:
use the new design for the look and feel kcm, together with
a massive code simplification

Test Plan: pply does work, as preview of themes

Reviewers: #plasma, #vdg, davidedmundson

Reviewed By: #plasma, davidedmundson

Subscribers: davidedmundson, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D12090
parent 254c1446
......@@ -83,6 +83,7 @@ KCMLookandFeel::KCMLookandFeel(QObject* parent, const QVariantList& args)
m_model = new QStandardItemModel(this);
QHash<int, QByteArray> roles = m_model->roleNames();
roles[PluginNameRole] = "pluginName";
roles[DescriptionRole] = "description";
roles[ScreenhotRole] = "screenshot";
roles[FullScreenPreviewRole] = "fullScreenPreview";
roles[HasSplashRole] = "hasSplash";
......@@ -98,6 +99,7 @@ KCMLookandFeel::KCMLookandFeel(QObject* parent, const QVariantList& args)
roles[HasWindowSwitcherRole] = "hasWindowSwitcher";
roles[HasDesktopSwitcherRole] = "hasDesktopSwitcher";
m_model->setItemRoleNames(roles);
loadModel();
}
KCMLookandFeel::~KCMLookandFeel()
......@@ -109,7 +111,7 @@ void KCMLookandFeel::getNewStuff()
if (!m_newStuffDialog) {
m_newStuffDialog = new KNS3::DownloadDialog( QLatin1String("lookandfeel.knsrc") );
m_newStuffDialog.data()->setWindowTitle(i18n("Download New Look And Feel Packages"));
connect(m_newStuffDialog.data(), &KNS3::DownloadDialog::accepted, this, &KCMLookandFeel::load);
connect(m_newStuffDialog.data(), &KNS3::DownloadDialog::accepted, this, &KCMLookandFeel::loadModel);
}
m_newStuffDialog.data()->show();
}
......@@ -181,21 +183,8 @@ QList<Plasma::Package> KCMLookandFeel::availablePackages(const QStringList &comp
return packages;
}
void KCMLookandFeel::load()
void KCMLookandFeel::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);
}
if (!m_package.metadata().isValid()) {
return;
}
setSelectedPlugin(m_package.metadata().pluginName());
m_model->clear();
const QList<Plasma::Package> pkgs = availablePackages({"defaults", "layouts"});
......@@ -205,6 +194,7 @@ void KCMLookandFeel::load()
}
QStandardItem* row = new QStandardItem(pkg.metadata().name());
row->setData(pkg.metadata().pluginName(), PluginNameRole);
row->setData(pkg.metadata().comment(), DescriptionRole);
row->setData(pkg.filePath("preview"), ScreenhotRole);
row->setData(pkg.filePath("fullscreenpreview"), FullScreenPreviewRole);
......@@ -248,6 +238,24 @@ void KCMLookandFeel::load()
m_model->appendRow(row);
}
emit selectedPluginIndexChanged();
}
void KCMLookandFeel::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);
}
if (!m_package.metadata().isValid()) {
return;
}
setSelectedPlugin(m_package.metadata().pluginName());
setNeedsSave(false);
}
......
......@@ -53,6 +53,7 @@ public:
PluginNameRole = Qt::UserRole +1,
ScreenhotRole,
FullScreenPreviewRole,
DescriptionRole,
HasSplashRole,
HasLockScreenRole,
HasRunCommandRole,
......@@ -105,6 +106,8 @@ public:
bool resetDefaultLayout() const;
void setResetDefaultLayout(bool reset);
void loadModel();
Q_INVOKABLE void getNewStuff();
public Q_SLOTS:
......
/*
Copyright (c) 2014 Marco Martin <mart@kde.org>
Copyright (c) 2018 Marco Martin <mart@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
......@@ -16,205 +16,63 @@
Boston, MA 02110-1301, USA.
*/
import QtQuick 2.1
import QtQuick 2.6
import QtQuick.Layouts 1.1
import QtQuick.Window 2.2
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
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.kcm 1.0
import QtQuick.Controls 2.3 as QtControls
import org.kde.kirigami 2.4 as Kirigami
import org.kde.kcm 1.1 as KCM
Item {
id: root
implicitWidth: Units.gridUnit * 20
implicitHeight: Units.gridUnit * 20
KCM.GridViewKCM {
KCM.ConfigModule.quickHelp: i18n("This module lets you configure the look and feel theme.")
ConfigModule.quickHelp: i18n("This module lets you configure the look of the whole workspace with some ready to go presets.")
view.model: kcm.lookAndFeelModel
view.currentIndex: kcm.selectedPluginIndex
view.delegate: KCM.GridDelegate {
id: delegate
// HACK QtQuick Controls 1 Button does not update its styleOption palette when it changes, since QQC1 is basically
// unmaintained and we're eventually moving to QQC2 and this is the first impression the user gets when playing with
// look and feel feature, we destroy and re-create the GHNS button when its color would change to avoid this.
SystemPalette {
id: syspal
onButtonChanged: {
ghnsButtonLoader.active = false;
ghnsButtonLoader.active = true;
}
}
text: model.display
toolTip: model.description
ColumnLayout {
anchors.fill: parent
QtControls.Label {
text: i18nd("kcm_lookandfeel", "Select an overall theme for your workspace (including plasma theme, color scheme, mouse cursor, window and desktop switcher, splash screen, lock screen etc.)")
wrapMode: Text.WordWrap
Layout.fillWidth: true
thumbnailAvailable: model.screenshot
thumbnail: Image {
anchors.fill: parent
source: model.screenshot || ""
}
QtControls.ScrollView {
Layout.fillWidth: true
Layout.fillHeight: true
GridView {
id: grid
model: kcm.lookAndFeelModel
cellWidth: Math.floor(root.width / Math.max(Math.floor(root.width / (Units.gridUnit*12)), 3)) - Units.gridUnit
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
}
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 {
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: Qt.rgba(0, 0, 0, 0.5)
}
}
QtControls.Label {
anchors {
horizontalCenter: parent.horizontalCenter
}
color: "white"
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
resetCheckbox.checked = false;
}
Timer {
interval: 1000 // FIXME TODO: Use platform value for tooltip activation delay.
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.fullScreenPreview != ""
iconSource: "media-playback-start"
tooltip: i18n("Show Preview")
flat: false
onClicked: {
previewWindow.url = model.fullScreenPreview;
previewWindow.showFullScreen();
}
opacity: parent.containsMouse ? 1 : 0
Behavior on opacity {
PropertyAnimation {
duration: Units.longDuration
easing.type: Easing.OutQuad
}
}
}
}
}
actions: [
Kirigami.Action {
visible: model.fullScreenPreview != ""
iconName: "media-playback-start"
tooltip: i18n("Test Splashscreen")
onTriggered: {
previewWindow.url = model.fullScreenPreview;
previewWindow.showFullScreen();
}
}
]
onClicked: {
kcm.selectedPlugin = model.pluginName;
view.forceActiveFocus();
resetCheckbox.checked = false;
}
QtControls.Label {
text: i18nd("kcm_lookandfeel", "Warning: your Plasma Desktop layout will be lost and reset to the default layout provided by the selected theme.")
visible: resetCheckbox.checked
wrapMode: Text.WordWrap
Layout.fillWidth: true
}
footer: RowLayout {
QtControls.CheckBox {
id: resetCheckbox
checked: kcm.resetDefaultLayout
text: i18n("Use Desktop Layout from theme")
onCheckedChanged: kcm.resetDefaultLayout = checked;
}
Connections {
target: kcm
onNeedsSaveChanged: {
if (!needsSave) {
resetCheckbox.checked = false;
}
}
Item {
Layout.fillWidth: true
}
RowLayout {
QtControls.CheckBox {
id: resetCheckbox
checked: kcm.resetDefaultLayout
text: i18n("Use Desktop Layout from theme")
onCheckedChanged: kcm.resetDefaultLayout = checked;
}
Item {
Layout.fillWidth: true
}
Loader {
id: ghnsButtonLoader
anchors.right: parent.right
sourceComponent: QtControls.Button {
text: i18n("Get New Looks...")
iconName: "get-hot-new-stuff"
onClicked: kcm.getNewStuff();
}
}
QtControls.Button {
text: i18n("Get New Looks...")
icon.name: "get-hot-new-stuff"
onClicked: kcm.getNewStuff();
}
}
Window {
id: previewWindow
property alias url: previewImage.source
......@@ -234,12 +92,12 @@ Item {
top: parent.top
right: parent.right
}
iconName: "window-close"
icon.name: "window-close"
onClicked: previewWindow.visible = false;
}
QtControls.Action {
onTriggered: previewWindow.visible = false;
shortcut: "Esc"
Shortcut {
onActivated: previewWindow.visible = false;
sequence: "Esc"
}
}
}
......
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