Commit c1910621 authored by David Edmundson's avatar David Edmundson

Add edit button to desktop theme

Summary:
This option is only visible in plasmathemeexplorer is installed. This
makes it easy to edit themes, without cluttering the UI of normal users.

Edit button is made similar to the action buttons in the wallpaper
delegate. (though this is copying an existing bug of of using
plasmacomponents where they shouldn't be)

MouseArea got collapsed into the parent Item in the delegate as it makes
for more readable implicit z-ordering to have the button on top.

Test Plan:
Clicked on one, explorer for that theme appeared.
Faked not having theme explorer by temporarily putting a typo in the service name. No buttons showed

Reviewers: #plasma, apol

Reviewed By: apol

Subscribers: jensreuterberg, apol, abetts, ngraham, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D8006
parent 26720403
......@@ -44,6 +44,7 @@ K_PLUGIN_FACTORY_WITH_JSON(KCMDesktopThemeFactory, "kcm_desktoptheme.json", regi
KCMDesktopTheme::KCMDesktopTheme(QObject *parent, const QVariantList &args)
: KQuickAddons::ConfigModule(parent, args)
, m_defaultTheme(new Plasma::Theme(this))
, m_haveThemeExplorerInstalled(false)
{
//This flag seems to be needed in order for QQuickWidget to work
//see https://bugreports.qt-project.org/browse/QTBUG-40765
......@@ -63,6 +64,8 @@ KCMDesktopTheme::KCMDesktopTheme(QObject *parent, const QVariantList &args)
roles[ThemeNameRole] = QByteArrayLiteral("themeName");
roles[IsLocalRole] = QByteArrayLiteral("isLocal");
m_model->setItemRoleNames(roles);
m_haveThemeExplorerInstalled = !QStandardPaths::findExecutable(QStringLiteral("plasmathemeexplorer")).isEmpty();
}
KCMDesktopTheme::~KCMDesktopTheme()
......@@ -243,6 +246,16 @@ void KCMDesktopTheme::defaults()
setSelectedPlugin(QStringLiteral("default"));
}
bool KCMDesktopTheme::canEditThemes() const
{
return m_haveThemeExplorerInstalled;
}
void KCMDesktopTheme::editTheme(const QString &theme)
{
QProcess::startDetached(QStringLiteral("plasmathemeexplorer -t ") % theme);
}
void KCMDesktopTheme::updateNeedsSave()
{
setNeedsSave(!m_pendingRemoval.isEmpty() || m_selectedPlugin != m_defaultTheme->themeName());
......
......@@ -35,6 +35,7 @@ class KCMDesktopTheme : public KQuickAddons::ConfigModule
Q_OBJECT
Q_PROPERTY(QStandardItemModel *desktopThemeModel READ desktopThemeModel CONSTANT)
Q_PROPERTY(QString selectedPlugin READ selectedPlugin WRITE setSelectedPlugin NOTIFY selectedPluginChanged)
Q_PROPERTY(bool canEditThemes READ canEditThemes CONSTANT)
public:
enum Roles {
......@@ -51,6 +52,7 @@ public:
QString selectedPlugin() const;
void setSelectedPlugin(const QString &plugin);
bool canEditThemes() const;
Q_INVOKABLE void getNewThemes();
Q_INVOKABLE void installThemeFromFile(const QUrl &file);
......@@ -60,6 +62,8 @@ public:
Q_INVOKABLE int indexOf(const QString &themeName) const;
Q_INVOKABLE void editTheme(const QString &themeName);
Q_SIGNALS:
void selectedPluginChanged(const QString &plugin);
void showInfoMessage(const QString &infoMessage);
......@@ -78,6 +82,7 @@ private:
QStringList m_pendingRemoval;
Plasma::Theme *m_defaultTheme;
QHash<QString, Plasma::Theme*> m_themes;
bool m_haveThemeExplorerInstalled;
};
Q_DECLARE_LOGGING_CATEGORY(KCM_DESKTOP_THEME)
......
......@@ -25,6 +25,7 @@ import QtQuick.Controls 1.0 as QtControls
import org.kde.kcm 1.0
import org.kde.kirigami 2.0 // for units
import org.kde.plasma.components 2.0 as PlasmaComponents //the round toolbutton
Item {
implicitWidth: Units.gridUnit * 20
......@@ -77,11 +78,25 @@ Item {
}
}
Item {
MouseArea {
anchors {
fill: parent
margins: Units.smallSpacing * 2
}
hoverEnabled: true
onClicked: {
grid.currentIndex = index
kcm.selectedPlugin = model.pluginName
}
Timer {
interval: 1000
running: parent.containsMouse && !parent.pressedButtons
onTriggered: {
Tooltip.showText(parent, Qt.point(parent.mouseX, parent.mouseY), model.themeName);
}
}
ThemePreview {
id: preview
anchors {
......@@ -92,6 +107,27 @@ Item {
}
themeName: model.pluginName
}
PlasmaComponents.ToolButton {
anchors {
bottom: preview.bottom
right: preview.right
margins: units.smallSpacing
}
iconSource: "document-edit"
tooltip: i18("Edit theme")
flat: false
onClicked: kcm.editTheme(model.pluginName)
visible: kcm.canEditThemes
opacity: parent.containsMouse ? 1 : 0
Behavior on opacity {
PropertyAnimation {
duration: units.longDuration
easing.type: Easing.OutQuad
}
}
}
QtControls.Label {
id: label
anchors {
......@@ -122,21 +158,6 @@ Item {
}
}
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
onClicked: {
grid.currentIndex = index
kcm.selectedPlugin = model.pluginName
}
Timer {
interval: 1000
running: parent.containsMouse && !parent.pressedButtons
onTriggered: {
Tooltip.showText(parent, Qt.point(parent.mouseX, parent.mouseY), model.themeName);
}
}
}
}
}
Timer {
......
Markdown is supported
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