Changeset View
Changeset View
Standalone View
Standalone View
kcms/icons/package/contents/ui/IconSizePopup.qml
Show First 20 Lines • Show All 71 Lines • ▼ Show 20 Line(s) | 63 | QtControls.ScrollView { | |||
---|---|---|---|---|---|
72 | ListView { | 72 | ListView { | ||
73 | id: iconTypeList | 73 | id: iconTypeList | ||
74 | activeFocusOnTab: true | 74 | activeFocusOnTab: true | ||
75 | keyNavigationEnabled: true | 75 | keyNavigationEnabled: true | ||
76 | keyNavigationWraps: true | 76 | keyNavigationWraps: true | ||
77 | highlightMoveDuration: 0 | 77 | highlightMoveDuration: 0 | ||
78 | 78 | | |||
79 | model: kcm.iconGroups | 79 | model: kcm.iconGroups | ||
80 | 80 | currentIndex: 0 // Initialize with the first item | |||
81 | property var sizesMap: [ | | |||
82 | {"settingName":"desktopSize", "displayName": i18n("Desktop")}, | | |||
83 | {"settingName":"toolbarSize", "displayName": i18n("Toolbar")}, | | |||
84 | {"settingName":"mainToolbarSize", "displayName": i18n("Main Toolbar")}, | | |||
85 | {"settingName":"smallSize", "displayName": i18n("Small Icons")}, | | |||
86 | {"settingName":"panelSize", "displayName": i18n("Panel")}, | | |||
87 | {"settingName":"dialogSize", "displayName": i18n("Dialogs")} | | |||
88 | ] | | |||
89 | | ||||
90 | function sizeDisplayName(index) { | | |||
91 | index = index <0 ? 0 : index; | | |||
92 | return iconTypeList.sizesMap[index].displayName; | | |||
93 | } | | |||
94 | | ||||
95 | function sizeSettingName(index) { | | |||
96 | index = index <0 ? 0 : index; | | |||
97 | return iconTypeList.sizesMap[index].settingName; | | |||
98 | } | | |||
99 | 81 | | |||
100 | Keys.onLeftPressed: { | 82 | Keys.onLeftPressed: { | ||
101 | LayoutMirroring.enabled ? iconSizeSlider.increase() : iconSizeSlider.decrease() | 83 | LayoutMirroring.enabled ? iconSizeSlider.increase() : iconSizeSlider.decrease() | ||
102 | iconSizeSlider.moved(); | 84 | iconSizeSlider.moved(); | ||
103 | } | 85 | } | ||
104 | Keys.onRightPressed: { | 86 | Keys.onRightPressed: { | ||
105 | LayoutMirroring.enabled ? iconSizeSlider.decrease() : iconSizeSlider.increase() | 87 | LayoutMirroring.enabled ? iconSizeSlider.decrease() : iconSizeSlider.increase() | ||
106 | iconSizeSlider.moved(); | 88 | iconSizeSlider.moved(); | ||
107 | } | 89 | } | ||
108 | 90 | | |||
109 | delegate: QtControls.ItemDelegate { | 91 | delegate: QtControls.ItemDelegate { | ||
110 | width: ListView.view.width | 92 | width: ListView.view.width | ||
111 | highlighted: ListView.isCurrentItem | 93 | highlighted: ListView.isCurrentItem | ||
112 | text: iconTypeList.sizeDisplayName(index) | 94 | text: kcm.sizeDisplay(index) | ||
113 | 95 | | |||
114 | onClicked: { | 96 | onClicked: { | ||
115 | ListView.view.currentIndex = index; | 97 | ListView.view.currentIndex = index; | ||
116 | ListView.view.forceActiveFocus(); | 98 | ListView.view.forceActiveFocus(); | ||
117 | } | 99 | } | ||
118 | } | 100 | } | ||
119 | } | 101 | } | ||
120 | } | 102 | } | ||
121 | 103 | | |||
122 | QtControls.Slider { | 104 | QtControls.Slider { | ||
123 | id: iconSizeSlider | 105 | id: iconSizeSlider | ||
124 | property var sizes: kcm.availableIconSizes(iconTypeList.currentIndex) | 106 | property var sizes: kcm.availableIconSizes(iconTypeList.currentIndex) | ||
125 | 107 | | |||
126 | Layout.fillWidth: true | 108 | Layout.fillWidth: true | ||
127 | from: 0 | 109 | from: 0 | ||
128 | to: sizes.length - 1 | 110 | to: sizes.length - 1 | ||
129 | stepSize: 1.0 | 111 | stepSize: 1.0 | ||
130 | snapMode: QtControls.Slider.SnapAlways | 112 | snapMode: QtControls.Slider.SnapAlways | ||
131 | enabled: sizes.length > 0 | 113 | enabled: sizes.length > 0 | ||
132 | 114 | | |||
133 | onMoved: { | 115 | onMoved: { | ||
134 | kcm.iconsSettings[iconTypeList.sizeSettingName(iconTypeList.currentIndex)] = iconSizeSlider.sizes[iconSizeSlider.value] || 0 | 116 | kcm.iconsSettings[kcm.sizeSettingName(iconTypeList.currentIndex)] = iconSizeSlider.sizes[iconSizeSlider.value] || 0 | ||
135 | } | 117 | } | ||
136 | 118 | | |||
137 | function updateSizes() { | 119 | function updateSizes() { | ||
138 | // 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 | ||
139 | // in case the user clicked Default or something | 121 | // in case the user clicked Default or something | ||
140 | value = Qt.binding(function() { | 122 | value = Qt.binding(function() { | ||
141 | var iconSize = kcm.iconsSettings[iconTypeList.sizeSettingName(iconTypeList.currentIndex)] | 123 | var iconSize = kcm.iconsSettings[kcm.sizeSettingName(iconTypeList.currentIndex)] | ||
142 | 124 | | |||
143 | // 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 | ||
144 | var index = -1; | 126 | var index = -1; | ||
145 | var delta = 1000; | 127 | var delta = 1000; | ||
146 | for (var i = 0, length = sizes.length; i < length; ++i) { | 128 | for (var i = 0, length = sizes.length; i < length; ++i) { | ||
147 | var dw = Math.abs(iconSize - sizes[i]); | 129 | var dw = Math.abs(iconSize - sizes[i]); | ||
148 | if (dw < delta) { | 130 | if (dw < delta) { | ||
149 | delta = dw; | 131 | delta = dw; | ||
Show All 14 Lines | 142 | ColumnLayout { | |||
164 | 146 | | |||
165 | Item { | 147 | Item { | ||
166 | Layout.fillWidth: true | 148 | Layout.fillWidth: true | ||
167 | Layout.fillHeight: true | 149 | Layout.fillHeight: true | ||
168 | clip: true | 150 | clip: true | ||
169 | 151 | | |||
170 | Kirigami.Icon { | 152 | Kirigami.Icon { | ||
171 | anchors.centerIn: parent | 153 | anchors.centerIn: parent | ||
172 | width: kcm.iconsSettings[iconTypeList.sizeSettingName(iconTypeList.currentIndex)] | 154 | width: kcm.iconsSettings[kcm.sizeSettingName(iconTypeList.currentIndex)] | ||
173 | height: width | 155 | height: width | ||
174 | source: "folder" | 156 | source: "folder" | ||
175 | } | 157 | } | ||
176 | } | 158 | } | ||
177 | 159 | | |||
178 | QtControls.Label { | 160 | QtControls.Label { | ||
179 | id: iconSizeLabel | 161 | id: iconSizeLabel | ||
180 | Layout.fillWidth: true | 162 | Layout.fillWidth: true | ||
181 | horizontalAlignment: Text.AlignHCenter | 163 | horizontalAlignment: Text.AlignHCenter | ||
182 | text: kcm.iconsSettings[iconTypeList.sizeSettingName(iconTypeList.currentIndex)] | 164 | text: kcm.iconsSettings[kcm.sizeSettingName(iconTypeList.currentIndex)] | ||
183 | } | 165 | } | ||
184 | } | 166 | } | ||
185 | } | 167 | } | ||
186 | } | 168 | } |