Changeset View
Standalone View
kcms/icons/package/contents/ui/IconSizePopup.qml
Show All 30 Lines | 26 | QtControls.Popup { | |||
---|---|---|---|---|---|
31 | 31 | | |||
32 | onOpened: { | 32 | onOpened: { | ||
33 | // can we do this automatically with "focus: true" somewhere? | 33 | // can we do this automatically with "focus: true" somewhere? | ||
34 | iconTypeList.forceActiveFocus(); | 34 | iconTypeList.forceActiveFocus(); | ||
35 | } | 35 | } | ||
36 | 36 | | |||
37 | onVisibleChanged: { | 37 | onVisibleChanged: { | ||
38 | if (visible) { | 38 | if (visible) { | ||
39 | iconSizeSlider.updateSizes(); | 39 | iconSizeSlider.sizes = kcm.availableIconSizes(iconTypeList.currentIndex); | ||
40 | iconSizeSlider.updateSizes() | ||||
40 | } | 41 | } | ||
41 | } | 42 | } | ||
42 | 43 | | |||
43 | Connections { | 44 | Connections { | ||
44 | target: kcm | 45 | target: iconTypeList | ||
45 | onIconSizesChanged: iconSizeSlider.updateSizes() | 46 | onCurrentIndexChanged: { | ||
broulik: Do you not need to leave this (or a similar) connect in place? | |||||
This one is replaced (and that fix bug described above by call onVisibleChange) bport: This one is replaced (and that fix bug described above by call onVisibleChange)
and with… | |||||
47 | iconSizeSlider.sizes = kcm.availableIconSizes(iconTypeList.currentIndex); | ||||
48 | } | ||||
46 | } | 49 | } | ||
47 | 50 | | |||
48 | RowLayout { | 51 | RowLayout { | ||
49 | anchors.fill: parent | 52 | anchors.fill: parent | ||
50 | 53 | | |||
I don't like this duplication, especially since sometimes you use currentIndex and sometimes the currentCategory broulik: I don't like this duplication, especially since sometimes you use `currentIndex` and sometimes… | |||||
bport: I wiil look if I can simplify that | |||||
I like the intent of trying to have names instead of just indices everywhere... but that might not be feasible without extra complexity we'll want to avoid indeed. I think the more fundamental problem is that the settings are based on those names, while the invokables (most notably availableIconSizes) are based on indices. Probably something to address, like have names everywhere and just a function to map from index to name in the iconTypeList. ervin: I like the intent of trying to have names instead of just indices everywhere... but that might… | |||||
51 | ColumnLayout { | 54 | ColumnLayout { | ||
52 | id: iconSizeColumn | 55 | id: iconSizeColumn | ||
53 | Layout.fillWidth: true | 56 | Layout.fillWidth: true | ||
54 | 57 | | |||
55 | QtControls.ItemDelegate { // purely for metrics... | 58 | QtControls.ItemDelegate { // purely for metrics... | ||
56 | id: measureDelegate | 59 | id: measureDelegate | ||
57 | visible: false | 60 | visible: false | ||
58 | } | 61 | } | ||
Show All 9 Lines | 63 | QtControls.ScrollView { | |||
68 | 71 | | |||
69 | ListView { | 72 | ListView { | ||
70 | id: iconTypeList | 73 | id: iconTypeList | ||
71 | activeFocusOnTab: true | 74 | activeFocusOnTab: true | ||
72 | keyNavigationEnabled: true | 75 | keyNavigationEnabled: true | ||
73 | keyNavigationWraps: true | 76 | keyNavigationWraps: true | ||
74 | highlightMoveDuration: 0 | 77 | highlightMoveDuration: 0 | ||
75 | 78 | | |||
76 | model: kcm.iconGroups | 79 | model: kcm.iconSizeCategoryModel | ||
80 | currentIndex: 0 // Initialize with the first item | ||||
77 | 81 | | |||
78 | Keys.onLeftPressed: { | 82 | Keys.onLeftPressed: { | ||
I think I'd have expected that logic on the C++ side actually. Others might disagree. :-) ervin: I think I'd have expected that logic on the C++ side actually. Others might disagree. :-) | |||||
ervin: Not on the C++ side still? | |||||
79 | LayoutMirroring.enabled ? iconSizeSlider.increase() : iconSizeSlider.decrease() | 83 | LayoutMirroring.enabled ? iconSizeSlider.increase() : iconSizeSlider.decrease() | ||
80 | iconSizeSlider.moved(); | 84 | iconSizeSlider.moved(); | ||
81 | } | 85 | } | ||
82 | Keys.onRightPressed: { | 86 | Keys.onRightPressed: { | ||
83 | LayoutMirroring.enabled ? iconSizeSlider.decrease() : iconSizeSlider.increase() | 87 | LayoutMirroring.enabled ? iconSizeSlider.decrease() : iconSizeSlider.increase() | ||
84 | iconSizeSlider.moved(); | 88 | iconSizeSlider.moved(); | ||
85 | } | 89 | } | ||
86 | 90 | | |||
87 | delegate: QtControls.ItemDelegate { | 91 | delegate: QtControls.ItemDelegate { | ||
88 | width: ListView.view.width | 92 | width: ListView.view.width | ||
ervin: Urgh, I'd assert than silently swallow that I think. | |||||
ervin: Still not addressed | |||||
89 | highlighted: ListView.isCurrentItem | 93 | highlighted: ListView.isCurrentItem | ||
90 | text: [ | 94 | text: model.display | ||
91 | i18n("Desktop"), | 95 | readonly property string configKey: model.configKey | ||
92 | i18n("Toolbar"), | | |||
93 | i18n("Main Toolbar"), | | |||
94 | i18n("Small Icons"), | | |||
95 | i18n("Panel"), | | |||
96 | i18n("Dialogs") | | |||
97 | ][index] | | |||
98 | | ||||
99 | onClicked: { | 96 | onClicked: { | ||
100 | ListView.view.currentIndex = index; | 97 | ListView.view.currentIndex = index; | ||
101 | ListView.view.forceActiveFocus(); | 98 | ListView.view.forceActiveFocus(); | ||
102 | } | 99 | } | ||
103 | } | 100 | } | ||
104 | } | 101 | } | ||
105 | } | 102 | } | ||
106 | 103 | | |||
107 | QtControls.Slider { | 104 | QtControls.Slider { | ||
108 | id: iconSizeSlider | 105 | id: iconSizeSlider | ||
109 | readonly property var sizes: kcm.availableIconSizes(iconTypeList.currentIndex) | 106 | property var sizes: kcm.availableIconSizes(iconTypeList.currentIndex) | ||
110 | readonly property int currentSize: iconSizeSlider.sizes[iconSizeSlider.value] || 0 | | |||
111 | 107 | | |||
112 | Layout.fillWidth: true | 108 | Layout.fillWidth: true | ||
113 | from: 0 | 109 | from: 0 | ||
114 | to: sizes.length - 1 | 110 | to: sizes.length - 1 | ||
115 | stepSize: 1.0 | 111 | stepSize: 1.0 | ||
116 | snapMode: QtControls.Slider.SnapAlways | 112 | snapMode: QtControls.Slider.SnapAlways | ||
117 | enabled: sizes.length > 0 | 113 | enabled: sizes.length > 0 | ||
118 | 114 | | |||
119 | onMoved: kcm.setIconSize(iconTypeList.currentIndex, currentSize) | 115 | onMoved: { | ||
116 | kcm.iconsSettings[iconTypeList.currentItem.configKey] = iconSizeSlider.sizes[iconSizeSlider.value] || 0 | ||||
117 | } | ||||
120 | 118 | | |||
121 | function updateSizes() { | 119 | function updateSizes() { | ||
122 | // since the icon sizes are queried using invokables, always force an update when opening | 120 | // since the icon sizes are queried using invokables, always force an update when opening | ||
123 | // in case the user clicked Default or something | 121 | // in case the user clicked Default or something | ||
124 | value = Qt.binding(function() { | 122 | value = Qt.binding(function() { | ||
125 | var iconSize = kcm.iconSize(iconTypeList.currentIndex) | 123 | var iconSize = kcm.iconsSettings[iconTypeList.currentItem.configKey] | ||
126 | 124 | | |||
127 | // I have no idea what this code does but it works and is just copied from the old KCM | 125 | // I have no idea what this code does but it works and is just copied from the old KCM | ||
128 | var index = -1; | 126 | var index = -1; | ||
129 | var delta = 1000; | 127 | var delta = 1000; | ||
130 | for (var i = 0, length = sizes.length; i < length; ++i) { | 128 | for (var i = 0, length = sizes.length; i < length; ++i) { | ||
131 | var dw = Math.abs(iconSize - sizes[i]); | 129 | var dw = Math.abs(iconSize - sizes[i]); | ||
132 | if (dw < delta) { | 130 | if (dw < delta) { | ||
133 | delta = dw; | 131 | delta = dw; | ||
Show All 14 Lines | 142 | ColumnLayout { | |||
148 | 146 | | |||
149 | Item { | 147 | Item { | ||
150 | Layout.fillWidth: true | 148 | Layout.fillWidth: true | ||
151 | Layout.fillHeight: true | 149 | Layout.fillHeight: true | ||
152 | clip: true | 150 | clip: true | ||
153 | 151 | | |||
154 | Kirigami.Icon { | 152 | Kirigami.Icon { | ||
155 | anchors.centerIn: parent | 153 | anchors.centerIn: parent | ||
156 | width: iconSizeSlider.currentSize | 154 | width: kcm.iconsSettings[iconTypeList.currentItem.configKey] | ||
157 | height: width | 155 | height: width | ||
158 | source: "folder" | 156 | source: "folder" | ||
159 | } | 157 | } | ||
160 | } | 158 | } | ||
161 | 159 | | |||
162 | QtControls.Label { | 160 | QtControls.Label { | ||
163 | id: iconSizeLabel | 161 | id: iconSizeLabel | ||
164 | Layout.fillWidth: true | 162 | Layout.fillWidth: true | ||
165 | horizontalAlignment: Text.AlignHCenter | 163 | horizontalAlignment: Text.AlignHCenter | ||
166 | text: iconSizeSlider.currentSize | 164 | text: kcm.iconsSettings[iconTypeList.currentItem.configKey] | ||
167 | } | 165 | } | ||
168 | } | 166 | } | ||
169 | } | 167 | } | ||
170 | } | 168 | } |
Do you not need to leave this (or a similar) connect in place?