Changeset View
Standalone View
kcms/ksplash/package/contents/ui/main.qml
Show All 13 Lines | 1 | /* | |||
---|---|---|---|---|---|
14 | along with this library; see the file COPYING.LIB. If not, write to | 14 | along with this library; see the file COPYING.LIB. If not, write to | ||
15 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 15 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
16 | Boston, MA 02110-1301, USA. | 16 | Boston, MA 02110-1301, USA. | ||
17 | */ | 17 | */ | ||
18 | 18 | | |||
19 | import QtQuick 2.1 | 19 | import QtQuick 2.1 | ||
20 | import QtQuick.Layouts 1.1 | 20 | import QtQuick.Layouts 1.1 | ||
21 | import QtQuick.Controls 1.0 as QtControls | 21 | import QtQuick.Controls 1.0 as QtControls | ||
22 | import org.kde.kquickcontrolsaddons 2.0 | 22 | import org.kde.kirigami 2.4 as Kirigami | ||
23 | import QtQuick.Controls.Private 1.0 | 23 | import org.kde.kcm 1.1 as KCM | ||
24 | import org.kde.kirigami 2.0 // for Units | | |||
25 | import org.kde.plasma.components 2.0 as PlasmaComponents | | |||
26 | 24 | | |||
27 | Item { | 25 | KCM.GridViewKCM { | ||
28 | implicitWidth: Units.gridUnit * 20 | 26 | KCM.ConfigModule.quickHelp: i18n("This module lets you configure the splash screen theme.") | ||
29 | implicitHeight: Units.gridUnit * 20 | | |||
30 | 27 | | |||
31 | SystemPalette {id: syspal} | 28 | view.model: kcm.splashModel | ||
32 | ColumnLayout { | 29 | //NOTE: pay attention to never break this binding | ||
33 | anchors.fill: parent | 30 | view.currentIndex: kcm.selectedPluginIndex | ||
34 | QtControls.ScrollView { | 31 | view.delegate: KCM.GridDelegate { | ||
35 | Layout.fillWidth: true | 32 | id: delegate | ||
36 | Layout.fillHeight: true | | |||
37 | GridView { | | |||
38 | id: grid | | |||
39 | model: kcm.splashModel | | |||
40 | cellWidth: Math.floor(grid.width / Math.max(Math.floor(grid.width / (Units.gridUnit*12)), 3)) | | |||
41 | cellHeight: cellWidth / 1.6 | | |||
42 | | ||||
43 | onCountChanged: { | | |||
44 | grid.currentIndex = kcm.selectedPluginIndex; | | |||
45 | grid.positionViewAtIndex(grid.currentIndex, GridView.Visible) | | |||
46 | } | | |||
47 | | ||||
48 | delegate: Item { | | |||
49 | width: grid.cellWidth | | |||
50 | height: grid.cellHeight | | |||
51 | Rectangle { | | |||
52 | anchors { | | |||
53 | fill: parent | | |||
54 | margins: Units.smallSpacing | | |||
55 | } | | |||
56 | | ||||
57 | Connections { | | |||
58 | target: kcm | | |||
59 | onSelectedPluginChanged: { | | |||
60 | if (kcm.selectedPlugin == model.pluginName) { | | |||
61 | grid.currentIndex = index | | |||
62 | } | | |||
63 | } | | |||
64 | } | | |||
65 | QIconItem { | | |||
66 | id: icon | | |||
67 | anchors.centerIn: parent | | |||
68 | width: Units.iconSizes.large | | |||
69 | height: width | | |||
70 | icon: "view-preview" | | |||
71 | } | | |||
72 | Image { | | |||
73 | id: image | | |||
74 | anchors { | | |||
75 | fill: parent | | |||
76 | margins: Units.smallSpacing * 2 | | |||
77 | } | | |||
78 | source: model.screenshot || "" | | |||
79 | Rectangle { | | |||
80 | anchors { | | |||
81 | left: parent.left | | |||
82 | right: parent.right | | |||
83 | bottom: parent.bottom | | |||
84 | } | | |||
85 | height: childrenRect.height | | |||
86 | gradient: Gradient { | | |||
87 | GradientStop { | | |||
88 | position: 0.0 | | |||
89 | color: "transparent" | | |||
90 | } | | |||
91 | GradientStop { | | |||
92 | position: 1.0 | | |||
93 | color: image.status == Image.Ready ? Qt.rgba(0, 0, 0, 0.5) : "transparent" | | |||
94 | } | | |||
95 | } | | |||
96 | QtControls.Label { | | |||
97 | anchors { | | |||
98 | horizontalCenter: parent.horizontalCenter | | |||
99 | } | | |||
100 | color: image.status == Image.Ready ? "white" : "gray" | | |||
101 | text: model.display | | |||
102 | } | | |||
103 | } | | |||
104 | } | | |||
105 | Rectangle { | | |||
106 | opacity: grid.currentIndex == index ? 1.0 : 0 | | |||
107 | anchors.fill: parent | | |||
108 | border.width: Units.smallSpacing * 2 | | |||
109 | border.color: syspal.highlight | | |||
110 | color: "transparent" | | |||
111 | Behavior on opacity { | | |||
112 | PropertyAnimation { | | |||
113 | duration: Units.longDuration | | |||
114 | easing.type: Easing.OutQuad | | |||
115 | } | | |||
116 | } | | |||
117 | } | | |||
118 | MouseArea { | | |||
119 | anchors.fill: parent | | |||
120 | hoverEnabled: true | | |||
121 | onClicked: { | | |||
122 | grid.currentIndex = index | | |||
123 | kcm.selectedPlugin = model.pluginName | | |||
124 | } | | |||
125 | Timer { | | |||
126 | interval: 1000 // FIXME TODO: Use platform value for tooltip activation delay. | | |||
127 | 33 | | |||
128 | running: parent.containsMouse && !parent.pressedButtons | 34 | text: model.display | ||
35 | toolTip: model.description | ||||
129 | 36 | | |||
130 | onTriggered: { | 37 | thumbnailAvailable: model.screenshot != "" | ||
131 | Tooltip.showText(parent, Qt.point(parent.mouseX, parent.mouseY), model.display); | 38 | thumbnail: Image { | ||
132 | } | 39 | anchors.fill: parent | ||
133 | } | 40 | source: model.screenshot || "" | ||
134 | PlasmaComponents.ToolButton { | | |||
135 | anchors { | | |||
136 | top: parent.top | | |||
137 | right: parent.right | | |||
138 | margins: Units.smallSpacing | | |||
139 | } | 41 | } | ||
42 | actions: [ | ||||
43 | Kirigami.Action { | ||||
140 | visible: model.pluginName != "None" | 44 | visible: model.pluginName != "None" | ||
141 | iconSource: "media-playback-start" | 45 | iconName: "media-playback-start" | ||
142 | tooltip: i18n("Test Splashscreen") | 46 | tooltip: i18n("Test Splashscreen") | ||
143 | flat: false | 47 | onTriggered: kcm.test(model.pluginName) | ||
144 | onClicked: kcm.test(model.pluginName) | | |||
145 | opacity: parent.containsMouse ? 1 : 0 | | |||
146 | Behavior on opacity { | | |||
147 | PropertyAnimation { | | |||
148 | duration: Units.longDuration | | |||
149 | easing.type: Easing.OutQuad | | |||
150 | } | | |||
151 | } | | |||
152 | } | | |||
153 | } | | |||
154 | } | | |||
155 | } | 48 | } | ||
49 | ] | ||||
50 | onClicked: { | ||||
51 | kcm.selectedPlugin = model.pluginName; | ||||
52 | view.forceActiveFocus(); | ||||
davidedmundson: Doing this *and* the conection on line 64 seems wrong. | |||||
156 | } | 53 | } | ||
157 | } | 54 | } | ||
158 | RowLayout { | 55 | | ||
56 | footer: RowLayout { | ||||
159 | Item { | 57 | Item { | ||
160 | Layout.fillWidth: true | 58 | Layout.fillWidth: true | ||
161 | } | 59 | } | ||
162 | QtControls.Button { | 60 | QtControls.Button { | ||
163 | iconName: "get-hot-new-stuff" | 61 | iconName: "get-hot-new-stuff" | ||
davidedmundson: redundant given the onCurrentIndexChanged binding above | |||||
the onCountChanged connection thinghie it's an hack that serves at startup: we don't have a signal from listview "i'm done populating" which happens way after component.oncompleted, so the only way we have is when the list gets populated, which also means that its contents grow in size. *probably* i can remove onCurrentIndexChanged mart: the onCountChanged connection thinghie it's an hack that serves at startup: we don't have a… | |||||
You shouldn't have told me that :) I have one consistent rule about working round Qt bugs, it needs an upstream report and a link in the code. but in any case, your comment doesn't explain why we need: If we've just changed the index, we'll run onCurrentIndexChanged which does it's own view.positionViewAt() . Unless we need to position the view even when we don't change the index? davidedmundson: You shouldn't have told me that :)
I have one consistent rule about working round Qt bugs, it… | |||||
I am not completely sure is actually a Qt bug... not sure it would be possible to have some finished signal, as depending on how the model behaves, you can never be sure that the representation is "completed" as the model can change at any moment? mart: >You shouldn't have told me that :)
>I have one consistent rule about working round Qt bugs, it… | |||||
It must know internally as it has that separate populate and add transition. It shouldn't need an external signal. In a perfect world: ListView { model: someValidModel currentIndex: 4 } should "just work" davidedmundson: >ou can never be sure that the representation is "completed" as the model can change at any… | |||||
ListView { annoyingly, you are right :p now, loading the model in the ctor and just relying on one single binding for currentIndex works perfectly. note: i removed onCurrentIndexChanged: positionViewAtIndex as i want to put it on the gridview kcm component itself, as i think it belongs there. mart: ListView {
model: someValidModel
currentIndex: 4
}
annoyingly, you are right :p
this actually… | |||||
164 | text: i18n("&Get New Theme...") | 62 | text: i18n("&Get New Theme...") | ||
165 | onClicked: kcm.getNewClicked(); | 63 | onClicked: kcm.getNewClicked(); | ||
166 | enabled: kcm.canInstall | | |||
167 | } | | |||
168 | } | 64 | } | ||
169 | } | 65 | } | ||
170 | } | 66 | } |
Doing this *and* the conection on line 64 seems wrong.