Changeset View
Changeset View
Standalone View
Standalone View
plasmoid/contents/ui/DashboardDelegate.qml
Show All 28 Lines | 28 | Rectangle { | |||
---|---|---|---|---|---|
29 | id: dashdelegteType | 29 | id: dashdelegteType | ||
30 | height: dashdelegatelview.height | 30 | height: dashdelegatelview.height | ||
31 | width: parent.width | 31 | width: parent.width | ||
32 | color: theme.backgroundColor | 32 | color: theme.backgroundColor | ||
33 | property alias dashnewsLmodel: dashnewsListModel | 33 | property alias dashnewsLmodel: dashnewsListModel | ||
34 | property alias dashweatherLmodel: dashweatherListModel | 34 | property alias dashweatherLmodel: dashweatherListModel | ||
35 | 35 | | |||
36 | Component.onCompleted: { | 36 | Component.onCompleted: { | ||
37 | //console.log(iType, iObj) | | |||
38 | filterSwitchDash(iType, iObj) | 37 | filterSwitchDash(iType, iObj) | ||
39 | } | 38 | } | ||
40 | 39 | | |||
41 | function filterSwitchDash(iType, iObj){ | 40 | function filterSwitchDash(iType, iObj){ | ||
42 | switch(iType){ | 41 | switch(iType){ | ||
43 | case "Disclaimer": | 42 | case "Disclaimer": | ||
44 | filterDashDisclaimerObj() | 43 | filterDashDisclaimerObj() | ||
45 | console.log("Disclaimer HERE") | | |||
46 | break | 44 | break | ||
47 | case "DashNews": | 45 | case "DashNews": | ||
48 | filterDashNewsObj(iObj) | 46 | filterDashNewsObj(iObj) | ||
49 | break | 47 | break | ||
50 | case "DashWeather": | 48 | case "DashWeather": | ||
51 | filterDashWeatherObj(iObj) | 49 | filterDashWeatherObj(iObj) | ||
52 | break | 50 | break | ||
53 | } | 51 | } | ||
54 | } | 52 | } | ||
55 | 53 | | |||
56 | function filterDashDisclaimerObj() { | 54 | function filterDashDisclaimerObj() { | ||
57 | dashdelegatelview.model = disclaimerListModel | 55 | dashdelegatelview.model = disclaimerListModel | ||
58 | disclaimerListModel.append({itemType: "Disclaimer"}) | 56 | disclaimerListModel.append({itemType: "Disclaimer"}) | ||
59 | } | 57 | } | ||
60 | 58 | | |||
61 | function filterDashWeatherObj(weatherobj){ | 59 | function filterDashWeatherObj(weatherobj){ | ||
60 | var filteredMetric | ||||
61 | if(weatherMetric.indexOf('metric') != -1){ | ||||
62 | filteredMetric = "°c" | ||||
63 | } | ||||
64 | else if (weatherMetric.indexOf('imperial') != -1){ | ||||
65 | filteredMetric = "°k" | ||||
66 | } | ||||
62 | if(weatherobj){ | 67 | if(weatherobj){ | ||
63 | var filteredWeatherObject = JSON.parse(weatherobj) | 68 | var filteredWeatherObject = JSON.parse(weatherobj) | ||
64 | dashdelegatelview.model = dashweatherLmodel | 69 | dashdelegatelview.model = dashweatherLmodel | ||
65 | dashweatherLmodel.append({itemType: "DashWeather", itemWeatherTemp: filteredWeatherObject.main.temp, itemWeatherTempMin: filteredWeatherObject.main.temp_min, itemWeatherTempMax: filteredWeatherObject.main.temp_max, itemWeatherTempType: filteredWeatherObject.weather[0].main}) | 70 | dashweatherLmodel.append({itemType: "DashWeather", itemWeatherTemp: filteredWeatherObject.main.temp, itemWeatherTempMin: filteredWeatherObject.main.temp_min, itemWeatherTempMax: filteredWeatherObject.main.temp_max, itemWeatherTempType: filteredWeatherObject.weather[0].main, itemWeatherMetricType: filteredMetric}) | ||
66 | } | 71 | } | ||
67 | } | 72 | } | ||
68 | 73 | | |||
69 | function filterDashNewsObj(newsobj){ | 74 | function filterDashNewsObj(newsobj){ | ||
70 | if(newsobj){ | 75 | if(newsobj){ | ||
71 | var filteredNewsObject = JSON.parse(newsobj) | 76 | var filteredNewsObject = JSON.parse(newsobj) | ||
72 | for (var i=0; i<filteredNewsObject.totalResults; i++){ | 77 | for (var i=0; i<filteredNewsObject.totalResults; i++){ | ||
73 | dashdelegatelview.model = dashnewsLmodel | 78 | dashdelegatelview.model = dashnewsLmodel | ||
74 | dashnewsLmodel.append({itemType: "DashNews", newsSource: filteredNewsObject.articles[i].source.name, newsTitle: filteredNewsObject.articles[i].title, newsDescription: filteredNewsObject.articles[i].description, newsURL: filteredNewsObject.articles[i].url, newsImgURL: filteredNewsObject.articles[i].urlToImage}) | 79 | dashnewsLmodel.append({itemType: "DashNews", newsSource: filteredNewsObject.articles[i].source.name, newsTitle: filteredNewsObject.articles[i].title, newsDescription: filteredNewsObject.articles[i].description, newsURL: filteredNewsObject.articles[i].url, newsImgURL: filteredNewsObject.articles[i].urlToImage}) | ||
75 | } | 80 | } | ||
76 | } | 81 | } | ||
77 | } | 82 | } | ||
78 | 83 | | |||
84 | function removeChildCard(){ | ||||
85 | dashLmodel.remove(index) | ||||
86 | } | ||||
87 | | ||||
88 | Drawer { | ||||
89 | id: sharePagePopup | ||||
90 | width: parent.width | ||||
91 | height: units.gridUnit * 4 | ||||
92 | edge: Qt.TopEdge | ||||
93 | dragMargin: 0 | ||||
94 | | ||||
95 | Rectangle { | ||||
96 | anchors.fill: parent | ||||
97 | color: theme.backgroundColor | ||||
98 | | ||||
99 | Column { | ||||
100 | id: menuRectColumn | ||||
101 | anchors.fill: parent | ||||
102 | | ||||
103 | Rectangle { | ||||
104 | id: shareViaEmailRectbtn | ||||
105 | width: parent.width | ||||
106 | height: units.gridUnit * 2 | ||||
107 | color: theme.backgroundColor | ||||
108 | | ||||
109 | Row { | ||||
110 | spacing: 5 | ||||
111 | PlasmaCore.IconItem { | ||||
112 | id: shareViaEmailIcon | ||||
113 | anchors.verticalCenter: parent.verticalCenter | ||||
114 | source: "mail-signed-part" | ||||
115 | width: units.gridUnit * 2 | ||||
116 | height: units.gridUnit * 2 | ||||
117 | } | ||||
118 | Rectangle { | ||||
119 | id: shareViaEmailSeperater | ||||
120 | width: 1 | ||||
121 | height: parent.height | ||||
122 | color: theme.linkColor | ||||
123 | } | ||||
124 | PlasmaComponents.Label { | ||||
125 | id: shareViaEmailLabel | ||||
126 | anchors.verticalCenter: parent.verticalCenter | ||||
127 | text: "Share Via Email" | ||||
128 | } | ||||
129 | } | ||||
130 | MouseArea { | ||||
131 | anchors.fill: parent | ||||
132 | hoverEnabled: true | ||||
133 | onEntered: { | ||||
134 | shareViaEmailLabel.color = theme.linkColor | ||||
135 | } | ||||
136 | onExited:{ | ||||
137 | shareViaEmailLabel.color = theme.textColor | ||||
138 | } | ||||
139 | onClicked:{ | ||||
140 | Qt.openUrlExternally("mailto://"); | ||||
141 | } | ||||
142 | } | ||||
143 | } | ||||
144 | | ||||
145 | Rectangle { | ||||
146 | id: btnshorzSeprEnd | ||||
147 | width: parent.width | ||||
148 | height: units.gridUnit * 0.75 | ||||
149 | color: theme.linkColor | ||||
150 | | ||||
151 | PlasmaCore.IconItem { | ||||
152 | id: closemenuDrawer | ||||
153 | anchors.centerIn: parent | ||||
154 | source: "go-up" | ||||
155 | width: units.gridUnit * 2 | ||||
156 | height: units.gridUnit * 2 | ||||
157 | } | ||||
158 | } | ||||
159 | } | ||||
160 | } | ||||
161 | } | ||||
162 | | ||||
79 | ListModel { | 163 | ListModel { | ||
80 | id: dashnewsListModel | 164 | id: dashnewsListModel | ||
81 | } | 165 | } | ||
82 | 166 | | |||
83 | ListModel { | 167 | ListModel { | ||
84 | id: dashweatherListModel | 168 | id: dashweatherListModel | ||
85 | } | 169 | } | ||
86 | ListModel { | 170 | ListModel { | ||
87 | id: disclaimerListModel | 171 | id: disclaimerListModel | ||
88 | } | 172 | } | ||
89 | 173 | | |||
90 | ListView { | 174 | ListView { | ||
91 | id: dashdelegatelview | 175 | id: dashdelegatelview | ||
92 | width: cbwidth | 176 | width: cbwidth | ||
93 | spacing: units.gridUnit * 0.5 | 177 | spacing: units.gridUnit * 0.5 | ||
94 | focus: false | 178 | focus: false | ||
95 | interactive: true | 179 | interactive: true | ||
96 | clip: true; | 180 | clip: true; | ||
97 | delegate: Component{ | 181 | delegate: Loader{ | ||
98 | Loader{ | 182 | id: dashcardLoader | ||
99 | source: switch(itemType){ | 183 | source: switch(itemType){ | ||
100 | case "Disclaimer": return "DisclaimerCardDelegate.qml" | 184 | case "Disclaimer": return "DisclaimerCardDelegate.qml" | ||
101 | case "DashNews": return "DashNewsDelegate.qml" | 185 | case "DashNews": return "DashNewsDelegate.qml" | ||
102 | case "DashWeather": return "DashWeatherDelegate.qml" | 186 | case "DashWeather": return "DashWeatherDelegate.qml" | ||
103 | } | 187 | } | ||
104 | } | 188 | } | ||
105 | } | | |||
106 | 189 | | |||
107 | onCountChanged: { | 190 | onCountChanged: { | ||
191 | if (dashdelegatelview.model.count != 0){ | ||||
108 | var root = dashdelegatelview.visibleChildren[0] | 192 | var root = dashdelegatelview.visibleChildren[0] | ||
109 | var listViewHeight = 0 | 193 | var listViewHeight = 0 | ||
110 | var listViewWidth = 0 | 194 | var listViewWidth = 0 | ||
111 | 195 | | |||
112 | for (var i = 0; i < root.visibleChildren.length; i++) { | 196 | for (var i = 0; i < root.visibleChildren.length; i++) { | ||
113 | listViewHeight += root.visibleChildren[i].height | 197 | listViewHeight += root.visibleChildren[i].height | ||
114 | listViewWidth = Math.max(listViewWidth, root.visibleChildren[i].width) | 198 | listViewWidth = Math.max(listViewWidth, root.visibleChildren[i].width) | ||
115 | } | 199 | } | ||
116 | dashdelegatelview.height = listViewHeight + units.gridUnit * 2 | 200 | dashdelegatelview.height = listViewHeight + units.gridUnit * 2 | ||
117 | } | 201 | } | ||
118 | } | 202 | } | ||
119 | } | 203 | } | ||
204 | } | ||||
120 | 205 | |