Commit 3a710355 authored by David Redondo's avatar David Redondo 🏎
Browse files

Use Kirigami icon sizes instead of hardcoded numbers

parent 6c97f2b8
......@@ -9,7 +9,7 @@ Kirigami.OverlaySheet {
onSheetOpenChanged: {
if (sheetOpen) {
comparisonSize = iconSize;
comparisonSlider.value = [8, 16, 22, 32, 48, 64, 128].indexOf(comparisonSize);
comparisonSlider.value = cuttlefish.iconSizes.indexOf(comparisonSize);
}
}
......@@ -32,12 +32,12 @@ Kirigami.OverlaySheet {
running: false
repeat: false
interval: 200
onTriggered: comparisonSize = indexToSize(comparisonSlider.value)
onTriggered: comparisonSize = cuttlefish.iconSizes[comparisonSlider.value]
}
}
QQC2.Label {
Layout.alignment: Qt.AlignHCenter
text: indexToSize(comparisonSlider.value)
text: cuttlefish.iconSizes[comparisonSlider.value]
}
Item {
Layout.fillWidth:true
......@@ -45,8 +45,8 @@ Kirigami.OverlaySheet {
}
contentItem: GridView {
id: comparisonGrid
cellWidth: 128
cellHeight: 128 + 2 * Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing
cellWidth: Kirigami.Units.iconSizes.enormous
cellHeight: cellWidth + 2 * Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing
implicitWidth: {
const availableWidth = cuttlefish.width - leftPadding - rightPadding;
return availableWidth < comparisonGrid.count * cellWidth ? availableWidth - availableWidth % cellWidth : comparisonGrid.count * cellWidth
......@@ -59,8 +59,8 @@ Kirigami.OverlaySheet {
spacing: Kirigami.Units.largeSpacing
Item {
id: wrapper
Layout.preferredWidth: 128
Layout.preferredHeight: 128
Layout.preferredWidth: comparisonGrid.cellWidth
Layout.preferredHeight: comparisonGrid.cellWidth
Kirigami.Icon {
property bool hasIcon : modelData.iconPath
anchors.centerIn: parent
......
/***************************************************************************
* *
* Copyright 2019 Carson Black <uhhadd@gmail.com> *
* Copyright 2020 David Redondo <kde@david-redondo.de> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
......@@ -61,26 +62,27 @@ Item {
Kirigami.Theme.neutralTextColor: "#f67400"
Kirigami.Theme.negativeTextColor: "#da4453"
GridLayout {
RowLayout {
id: previewGrid
anchors.centerIn: parent
columns: sizes.length
rows: 2
property var sizes: [8, 16, 22, 32, 48, 64, 128]
Repeater {
model: previewGrid.sizes.length
delegate: Kirigami.Icon {
model: cuttlefish.iconSizes
delegate: ColumnLayout {
Layout.alignment: Qt.AlignBottom
source: preview.iconName
width: previewGrid.sizes[index]
height: previewGrid.sizes[index]
}
}
Repeater {
model: previewGrid.sizes.length
delegate: QQC2.Label {
Layout.alignment: Qt.AlignTop | Qt.AlignHCenter
text: previewGrid.sizes[index]
Kirigami.Icon {
source: preview.iconName
width: modelData
height: width
}
QQC2.Label {
Layout.alignment: Qt.AlignHCenter
text: modelData
Behavior on color {
ColorAnimation {
duration: Kirigami.Units.longDuration
}
}
}
}
}
}
......@@ -111,26 +113,27 @@ Item {
Kirigami.Theme.positiveTextColor: "#27ae60"
Kirigami.Theme.neutralTextColor: "#f67400"
Kirigami.Theme.negativeTextColor: "#da4453"
GridLayout {
RowLayout {
anchors.centerIn: parent
columns: sizes.length
rows: 2
property var sizes: [8, 16, 22, 32, 48, 64, 128]
Repeater {
model: previewGrid.sizes.length
delegate: Kirigami.Icon {
model: cuttlefish.iconSizes
delegate: ColumnLayout {
Layout.alignment: Qt.AlignBottom
source: preview.iconName
width: previewGrid.sizes[index]
height: previewGrid.sizes[index]
}
}
Repeater {
model: previewGrid.sizes.length
delegate: QQC2.Label {
Layout.alignment: Qt.AlignTop | Qt.AlignHCenter
text: previewGrid.sizes[index]
Kirigami.Icon {
source: preview.iconName
width: modelData
height: width
}
QQC2.Label {
Layout.alignment: Qt.AlignHCenter
text: modelData
Behavior on color {
ColorAnimation {
duration: Kirigami.Units.longDuration
}
}
}
}
}
}
......
......@@ -2,6 +2,8 @@
* *
* Copyright 2014-2017 Sebastian Kügler <sebas@kde.org> *
* Copyright 2019 Carson Black <uhhadd@gmail.com> *
* Copyright 2020 David Redondo <kde@david-redondo.de> *
* *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
......@@ -9,8 +11,8 @@
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
......@@ -110,7 +112,7 @@ Rectangle {
duration: Kirigami.Units.longDuration
}
}
Layout.fillWidth: true
Layout.preferredHeight: screenshotting ? previewGrid.height + (Kirigami.Units.gridUnit * 4) : previewGrid.height
......@@ -121,56 +123,42 @@ Rectangle {
id: previewGrid
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
property var sizes: [8, 16, 22, 32, 48, 64]
property var largeSizes: [128]
GridLayout {
RowLayout {
Layout.alignment: Qt.AlignHCenter
rows: 2
columns: previewGrid.sizes.length
Repeater {
model: previewGrid.sizes.length
delegate: Kirigami.Icon {
model: cuttlefish.iconSizes.slice(0, cuttlefish.iconSizes.length - 1)
delegate: ColumnLayout {
Layout.alignment: Qt.AlignBottom
source: preview.iconName
width: previewGrid.sizes[index]
height: previewGrid.sizes[index]
}
}
Repeater {
model: previewGrid.sizes.length
delegate: QQC2.Label {
Layout.alignment: Qt.AlignTop | Qt.AlignHCenter
text: previewGrid.sizes[index]
Behavior on color {
ColorAnimation {
duration: Kirigami.Units.longDuration
Kirigami.Icon {
source: preview.iconName
width: modelData
height: width
}
QQC2.Label {
Layout.alignment: Qt.AlignHCenter
text: modelData
Behavior on color {
ColorAnimation {
duration: Kirigami.Units.longDuration
}
}
}
}
}
}
GridLayout {
ColumnLayout {
Layout.alignment: Qt.AlignHCenter
rows: 2
columns: previewGrid.largeSizes.length
Repeater {
model: previewGrid.largeSizes.length
delegate: Kirigami.Icon {
Layout.alignment: Qt.AlignBottom
source: preview.iconName
width: previewGrid.largeSizes[index]
height: previewGrid.largeSizes[index]
}
Kirigami.Icon {
source: preview.iconName
width: cuttlefish.iconSizes[cuttlefish.iconSizes.length - 1]
height: width
}
Repeater {
model: previewGrid.largeSizes.length
delegate: QQC2.Label {
Layout.alignment: Qt.AlignTop | Qt.AlignHCenter
text: previewGrid.largeSizes[index]
Behavior on color {
ColorAnimation {
duration: Kirigami.Units.longDuration
}
QQC2.Label {
Layout.alignment: Qt.AlignHCenter
text: cuttlefish.iconSizes[cuttlefish.iconSizes.length - 1]
Behavior on color {
ColorAnimation {
duration: Kirigami.Units.longDuration
}
}
}
......
......@@ -67,20 +67,19 @@ Kirigami.GlobalDrawer {
GridLayout {
id: grid
columns: 2
property var sizes: [8, 16, 22, 32, 48, 64]
Layout.alignment: Qt.AlignHCenter
Repeater {
model: parent.sizes.length
model: cuttlefish.iconSizes.slice(0, cuttlefish.iconSizes.length - 1)
delegate: ColumnLayout {
Layout.alignment: Qt.AlignBottom
Kirigami.Icon {
Layout.alignment: Qt.AlignBottom
source: preview.iconName
width: grid.sizes[index]
height: grid.sizes[index]
width: modelData
height: width
}
QQC2.Label {
Layout.alignment: Qt.AlignTop | Qt.AlignHCenter
text: grid.sizes[index]
text: modelData
Behavior on color {
ColorAnimation {
duration: Kirigami.Units.longDuration
......
......@@ -90,7 +90,7 @@ Rectangle {
onValueChanged: {
sizetimer.restart()
pixelSizeInput.text = indexToSize(sizeslider.value)
pixelSizeInput.text = cuttlefish.iconSizes[sizeslider.value];
root.sliderValueChanged(sizeslider.value)
}
......@@ -99,11 +99,11 @@ Rectangle {
running: false
repeat: false
interval: 200
onTriggered: iconSize = indexToSize(sizeslider.value)
onTriggered: iconSize = cuttlefish.iconSizes[sizeslider.value];
}
Component.onCompleted: {
pixelSizeInput.text = indexToSize(sizeslider.value);
pixelSizeInput.text = cuttlefish.iconSizes[sizeslider.value];
}
}
......
......@@ -62,7 +62,7 @@ Rectangle {
onValueChanged: {
sizetimer.restart()
pixelSizeInput.text = indexToSize(sizeslider.value)
pixelSizeInput.text = cuttlefish.iconSizes[sizeslider.value];
root.sliderValueChanged(sizeslider.value)
}
......@@ -71,11 +71,11 @@ Rectangle {
running: false
repeat: false
interval: 200
onTriggered: iconSize = indexToSize(sizeslider.value)
onTriggered: iconSize = cuttlefish.iconSizes[sizeslider.value];
}
Component.onCompleted: {
pixelSizeInput.text = indexToSize(sizeslider.value);
pixelSizeInput.text = cuttlefish.iconSizes[sizeslider.value];
}
}
......
/***************************************************************************
* *
* Copyright 2014-2015 Sebastian Kügler <sebas@kde.org> *
* Copyright 2019 Carson Black <uhhadd@gmail.com> *
* Copyright 2019 Carson Black <uhhadd@gmail.com>
* Copyright 2020 David Redondo <kde@david-redondo.com>
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
......@@ -42,6 +43,10 @@ Kirigami.ApplicationWindow {
property alias actions: actions.actions
readonly property var iconSizes: [Kirigami.Units.iconSizes.small / 2,
Kirigami.Units.iconSizes.small, Kirigami.Units.iconSizes.smallMedium, Kirigami.Units.iconSizes.medium,
Kirigami.Units.iconSizes.large, Kirigami.Units.iconSizes.huge, Kirigami.Units.iconSizes.enormous]
Loader {
// Use a Loader instead of creating a GMB directly,
// so if the GMB errors, it doesn't affect Cuttlefish's operation
......@@ -84,19 +89,6 @@ Kirigami.ApplicationWindow {
}
}
function indexToSize(ix) {
var sizes = new Array();
sizes[0] = 8;
sizes[1] = 16;
sizes[2] = 22;
sizes[3] = 32;
sizes[4] = 48
sizes[5] = 64;
sizes[6] = 128;
return sizes[ix];
}
Rectangle {
Kirigami.Theme.colorSet: Kirigami.Theme.View
color: Kirigami.Theme.backgroundColor
......
......@@ -144,6 +144,6 @@ int main(int argc, char **argv)
qmlRegisterAnonymousType<CuttleFish::IconModel>("org.kde.plasma.sdk", 1);
qmlRegisterAnonymousType<CuttleFish::ColorSchemes>("org.kde.plasma.sdk", 1);
#endif
app.setAttribute(Qt::AA_UseHighDpiPixmaps);
return app.exec();
}
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