Commit 66d7bc83 authored by David Redondo's avatar David Redondo 🏎
Browse files

[Cuttlefish] Compare an icon in different themes

Summary: The icon in different installed themes is shown in an overlay sheet.

Test Plan: {F7473301}

Reviewers: #plasma, #vdg, ngraham

Reviewed By: #vdg, ngraham

Subscribers: ngraham, filipf, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D24305
parent 37763ba7
import QtQuick 2.4
import QtQuick.Controls 2.5 as QQC2
import QtQuick.Layouts 1.3
import org.kde.kirigami 2.8 as Kirigami
Kirigami.OverlaySheet {
property int comparisonSize
background: Rectangle {
id:background
color: cuttlefish.viewbgcolor
anchors.fill: parent
}
onSheetOpenChanged: {
if (sheetOpen) {
comparisonSize = iconSize;
comparisonSlider.value = [8, 16, 22, 32, 48, 64, 128].indexOf(comparisonSize);
}
}
ColumnLayout {
Kirigami.Theme.textColor: cuttlefish.textcolor
Kirigami.Theme.highlightColor: cuttlefish.highlightcolor
Kirigami.Theme.highlightedTextColor: cuttlefish.highlightedtextcolor
Kirigami.Theme.positiveTextColor: cuttlefish.positivetextcolor
Kirigami.Theme.neutralTextColor: cuttlefish.neutraltextcolor
Kirigami.Theme.negativeTextColor: cuttlefish.negativetextcolor
RowLayout {
Layout.alignment: Qt.AlignHCenter
QQC2.Slider {
Layout.preferredWidth: comparisonGrid.width * 0.75
id: comparisonSlider
to: 6.0
stepSize: 1.0
snapMode: QQC2.Slider.SnapAlways
onValueChanged: {
comparisonTimer.restart()
}
Timer {
id: comparisonTimer
running: false
repeat: false
interval: 200
onTriggered: comparisonSize = indexToSize(comparisonSlider.value)
}
}
QQC2.Label {
text: indexToSize(comparisonSlider.value)
}
}
GridView {
Layout.fillWidth: true
Layout.preferredHeight: contentHeight
id: comparisonGrid
cellWidth: 128
cellHeight: 128 + 2 * Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing
model: sheetOpen ? iconModel.inOtherThemes(preview.iconName, comparisonSize) : []
delegate: ColumnLayout {
id: iconColumn
width: comparisonGrid.cellWidth
height: comparisonGrid.cellHeight
spacing: Kirigami.Units.largeSpacing
Item {
id: wrapper
Layout.preferredWidth: 128
Layout.preferredHeight: 128
Kirigami.Icon {
property bool hasIcon : modelData.iconPath
anchors.centerIn: parent
width: comparisonSize
height: width
source: hasIcon ? modelData.iconPath : "paint-none"
color: hasIcon ? "" : Kirigami.Theme.disabledTextColor
isMask: !hasIcon
}
}
QQC2.Label {
id: themeName
text: modelData.themeName
horizontalAlignment: Text.AlignHCenter
Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom
}
}
}
}
}
......@@ -305,6 +305,12 @@ Rectangle {
}
}
}
QQC2.Button {
Layout.alignment: Qt.AlignCenter
text: i18n("View icon in other themes")
icon.name: "document-equal"
onClicked: comparison.sheetOpen = true
}
Item {
Layout.fillHeight: true
}
......
......@@ -90,6 +90,11 @@ Kirigami.GlobalDrawer {
onTriggered: iconPreview.shot("active")
text: i18n("Active Color Scheme")
}
},
Kirigami.Action {
text: i18n("View icon in other themes")
icon.name: "document-equal"
onTriggered: comparison.sheetOpen = true
}
]
Kirigami.Heading {
......
......@@ -207,6 +207,9 @@ Kirigami.ApplicationWindow {
active: !cuttlefish.widescreen
source: "ResponsivePreview.qml"
}
Comparison {
id: comparison
}
Connections {
target: tools
onColorschemeChanged: (index) => {
......
......@@ -409,3 +409,14 @@ void IconModel::output(const QString& text)
cout.flush();
}
QVariantList IconModel::inOtherThemes(const QString& name, int iconSize)
{
QVariantList list;
const QStringList themes = KIconTheme::list();
for (const auto& themeName : themes) {
const KIconTheme theme(themeName);
const QString iconPath = theme.iconPathByName(name, iconSize, KIconLoader::MatchBest);
list.append(QVariantMap({{"themeName", themeName}, {"iconPath", iconPath}}));
}
return list;
}
......@@ -27,6 +27,7 @@
#include <QJsonObject>
#include <QFileInfo>
#include <QVariantMap>
#include <QVariantList>
namespace CuttleFish {
......@@ -59,6 +60,7 @@ public:
explicit IconModel(QObject *parent = nullptr);
Q_INVOKABLE QVariantList inOtherThemes(const QString& iconName, int size);
QHash<int, QByteArray> roleNames() const override;
int rowCount(const QModelIndex &parent) const override;
......
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