diff --git a/cuttlefish/package/contents/ui/Comparison.qml b/cuttlefish/package/contents/ui/Comparison.qml new file mode 100644 --- /dev/null +++ b/cuttlefish/package/contents/ui/Comparison.qml @@ -0,0 +1,83 @@ +import QtQuick 2.0 +import QtQuick.Controls 2.5 as QQC2 +import QtQuick.Layouts 1.0 + +import org.kde.kirigami 2.8 as Kirigami + +Kirigami.OverlaySheet { + property int comparisonSize + + background: Rectangle { + id:background + color: cuttlefish.bgcolor + 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 + 2 * Kirigami.Units.largeSpacing + 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: 0 + Kirigami.Icon { + source: modelData.iconPath + Layout.preferredWidth: comparisonSize + Layout.preferredHeight: comparisonSize + Layout.alignment: Qt.AlignCenter + Layout.topMargin: comparisonSize == 128 ? 0 : themeName.height + Layout.bottomMargin: Kirigami.Units.largeSpacing + } + QQC2.Label { + id: themeName + text: modelData.themeName + horizontalAlignment: Text.AlignHCenter + Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom + } + } + } + } +} diff --git a/cuttlefish/package/contents/ui/Preview.qml b/cuttlefish/package/contents/ui/Preview.qml --- a/cuttlefish/package/contents/ui/Preview.qml +++ b/cuttlefish/package/contents/ui/Preview.qml @@ -305,6 +305,12 @@ } } } + 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 } diff --git a/cuttlefish/package/contents/ui/ResponsivePreview.qml b/cuttlefish/package/contents/ui/ResponsivePreview.qml --- a/cuttlefish/package/contents/ui/ResponsivePreview.qml +++ b/cuttlefish/package/contents/ui/ResponsivePreview.qml @@ -90,6 +90,11 @@ 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 { diff --git a/cuttlefish/package/contents/ui/cuttlefish.qml b/cuttlefish/package/contents/ui/cuttlefish.qml --- a/cuttlefish/package/contents/ui/cuttlefish.qml +++ b/cuttlefish/package/contents/ui/cuttlefish.qml @@ -207,6 +207,9 @@ active: !cuttlefish.widescreen source: "ResponsivePreview.qml" } + Comparison { + id: comparison + } Connections { target: tools onColorschemeChanged: (index) => { diff --git a/cuttlefish/src/iconmodel.h b/cuttlefish/src/iconmodel.h --- a/cuttlefish/src/iconmodel.h +++ b/cuttlefish/src/iconmodel.h @@ -27,6 +27,7 @@ #include #include #include +#include namespace CuttleFish { @@ -59,6 +60,7 @@ explicit IconModel(QObject *parent = nullptr); + Q_INVOKABLE QVariantList inOtherThemes(const QString& iconName, int size); QHash roleNames() const override; int rowCount(const QModelIndex &parent) const override; diff --git a/cuttlefish/src/iconmodel.cpp b/cuttlefish/src/iconmodel.cpp --- a/cuttlefish/src/iconmodel.cpp +++ b/cuttlefish/src/iconmodel.cpp @@ -409,3 +409,14 @@ 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; +}