Warning, /plasma-mobile/mycroft-plasmoid-mobile/plasmoid/contents/ui/DashboardDelegate.qml is written in an unsupported language. File is not indexed.
0001 /* Copyright 2016 Aditya Mehra <aix.m@outlook.com> 0002 0003 This library is free software; you can redistribute it and/or 0004 modify it under the terms of the GNU Lesser General Public 0005 License as published by the Free Software Foundation; either 0006 version 2.1 of the License, or (at your option) version 3, or any 0007 later version accepted by the membership of KDE e.V. (or its 0008 successor approved by the membership of KDE e.V.), which shall 0009 act as a proxy defined in Section 6 of version 3 of the license. 0010 0011 This library is distributed in the hope that it will be useful, 0012 but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 Lesser General Public License for more details. 0015 0016 You should have received a copy of the GNU Lesser General Public 0017 License along with this library. If not, see <http://www.gnu.org/licenses/>. 0018 */ 0019 0020 import QtQuick 2.9 0021 import QtQml.Models 2.2 0022 import QtQuick.Controls 2.2 0023 import QtQuick.Layouts 1.3 0024 import org.kde.plasma.core 2.0 as PlasmaCore 0025 import org.kde.plasma.plasmoid 2.0 0026 import org.kde.plasma.components 2.0 as PlasmaComponents 0027 import org.kde.plasma.components 3.0 as PlasmaComponents3 0028 0029 Item { 0030 id: dashdelegteType 0031 height: dashdelegatelview.height 0032 width: parent.width 0033 property Component delegateComponentDisclaimer: Qt.createComponent("DisclaimerCardDelegate.qml") 0034 property Component delegateComponentWeather: Qt.createComponent("DashWeatherDelegate.qml") 0035 property Component delegateComponentNews: Qt.createComponent("DashNewsDelegate.qml") 0036 property Component delegateComponentCrypto: Qt.createComponent("DashCryptoDelegate.qml") 0037 0038 Component.onCompleted: { 0039 filterSwitchDash(iType, iObj) 0040 } 0041 0042 function filterSwitchDash(iType, iObj){ 0043 switch(iType){ 0044 case "Disclaimer": 0045 filterDashDisclaimerObj() 0046 break 0047 case "DashNews": 0048 filterDashNewsObj(iObj) 0049 break 0050 case "DashWeather": 0051 filterDashWeatherObj(iObj) 0052 break 0053 case "DashCryptoPrice": 0054 filterDashCryptoObj(iObj) 0055 break 0056 } 0057 } 0058 0059 function filterDashDisclaimerObj() { 0060 dashCardCollectionModel.append({itemType: "Disclaimer", itemAt: 0, contents:{}}) 0061 dashdelegatelview.delegate = delegateComponentDisclaimer 0062 } 0063 0064 function filterDashWeatherObj(weatherobj){ 0065 var filteredMetric 0066 if(weatherMetric.indexOf('metric') != -1){ 0067 filteredMetric = "°c" 0068 } 0069 else if (weatherMetric.indexOf('imperial') != -1){ 0070 filteredMetric = "°f" 0071 } 0072 if(weatherobj){ 0073 var filteredWeatherObject = JSON.parse(weatherobj) 0074 var weatherIcnTypeHourZero = "http://openweathermap.org/img/w/" + filteredWeatherObject.list[0].weather[0].icon + ".png" 0075 var weatherIcnTypeHourA = "http://openweathermap.org/img/w/" + filteredWeatherObject.list[1].weather[0].icon + ".png" 0076 var weatherIcnTypeHourB = "http://openweathermap.org/img/w/" + filteredWeatherObject.list[2].weather[0].icon + ".png" 0077 var weatherdateHourZero = filteredWeatherObject.list[0].dt_txt 0078 var weatherdateHourA = filteredWeatherObject.list[1].dt_txt 0079 var weatherdateHourB = filteredWeatherObject.list[2].dt_txt 0080 dashCardCollectionModel.append({itemType: "DashWeather", itemAt: 1, contents:{itemWeatherTempHourZero: filteredWeatherObject.list[0].main.temp, itemWeatherTempHourA: filteredWeatherObject.list[1].main.temp, itemWeatherTempHourB: filteredWeatherObject.list[2].main.temp, itemWeatherTempMinHourZero: filteredWeatherObject.list[0].main.temp_min, itemWeatherTempMinHourA: filteredWeatherObject.list[1].main.temp_min, itemWeatherTempMinHourB: filteredWeatherObject.list[2].main.temp_min, itemWeatherTempMaxHourZero: filteredWeatherObject.list[0].main.temp_max, itemWeatherTempMaxHourA: filteredWeatherObject.list[1].main.temp_max, itemWeatherTempMaxHourB: filteredWeatherObject.list[2].main.temp_max, itemWeatherTempTypeHourZero: filteredWeatherObject.list[0].weather[0].main, itemWeatherTempTypeHourA: filteredWeatherObject.list[1].weather[0].main, itemWeatherTempTypeHourB: filteredWeatherObject.list[2].weather[0].main, itemWeatherMetricType: filteredMetric, itemWeatherIconTypeHourZero: weatherIcnTypeHourZero, itemWeatherIconTypeHourA: weatherIcnTypeHourA, itemWeatherIconTypeHourB: weatherIcnTypeHourB, itemWeatherWindHourZero: filteredWeatherObject.list[0].wind.speed, itemWeatherWindHourA: filteredWeatherObject.list[1].wind.speed, itemWeatherWindHourB: filteredWeatherObject.list[2].wind.speed, itemWeatherCity: filteredWeatherObject.city.name, itemWeatherDateHourZero: weatherdateHourZero, itemWeatherDateHourA: weatherdateHourA, itemWeatherDateHourB: weatherdateHourB}}) 0081 dashdelegatelview.delegate = delegateComponentWeather 0082 } 0083 } 0084 0085 function filterDashNewsObj(newsobj){ 0086 if(newsobj){ 0087 var filteredNewsObject = JSON.parse(newsobj) 0088 for (var i=0; i<filteredNewsObject.totalResults; i++){ 0089 dashCardCollectionModel.append({itemType: "DashNews", itemAt: 2, contents: {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}}) 0090 dashdelegatelview.delegate = delegateComponentNews 0091 } 0092 } 0093 } 0094 0095 function filterDashCryptoObj(cryptobj){ 0096 if(cryptobj){ 0097 var filteredCryptObj = JSON.parse(cryptobj) 0098 var currency1 = filteredCryptObj[innerset.selectedCur1] 0099 var currency2 = filteredCryptObj[innerset.selectedCur2] 0100 var currency3 = filteredCryptObj[innerset.selectedCur3] 0101 dashCardCollectionModel.append({itemType: "DashCryptoPrice", itemAt: 3, contents: {cryptoType: innerset.selectedCrypto, cryptoSymbol1: innerset.selectedCur1, cryptoSymbol2: innerset.selectedCur2, cryptoSymbol3: innerset.selectedCur3, cryptoCurRate1: currency1, cryptoCurRate2: currency2, cryptoCurRate3: currency3}}) 0102 dashdelegatelview.delegate = delegateComponentCrypto 0103 } 0104 } 0105 0106 function removeChildCard(){ 0107 dashLmodel.remove(index) 0108 } 0109 0110 function findIndex(itemType){ 0111 for(var i=0; i<dashboardmodelview.model.count; i++ ){ 0112 0113 if(dashboardmodelview.model.get(i).iType === itemType){ 0114 return i; 0115 } 0116 } 0117 } 0118 0119 Drawer { 0120 id: sharePagePopup 0121 width: parent.width 0122 height: units.gridUnit * 4 0123 edge: Qt.TopEdge 0124 dragMargin: 0 0125 0126 Rectangle { 0127 anchors.fill: parent 0128 color: theme.backgroundColor 0129 0130 Column { 0131 id: menuRectColumn 0132 anchors.fill: parent 0133 0134 Rectangle { 0135 id: shareViaEmailRectbtn 0136 width: parent.width 0137 height: units.gridUnit * 2 0138 color: theme.backgroundColor 0139 0140 Row { 0141 spacing: 5 0142 PlasmaCore.IconItem { 0143 id: shareViaEmailIcon 0144 anchors.verticalCenter: parent.verticalCenter 0145 source: "mail-signed-part" 0146 width: units.gridUnit * 2 0147 height: units.gridUnit * 2 0148 } 0149 Rectangle { 0150 id: shareViaEmailSeperater 0151 width: 1 0152 height: parent.height 0153 color: theme.linkColor 0154 } 0155 PlasmaComponents.Label { 0156 id: shareViaEmailLabel 0157 anchors.verticalCenter: parent.verticalCenter 0158 text: i18n("Share Via Email") 0159 } 0160 } 0161 MouseArea { 0162 anchors.fill: parent 0163 hoverEnabled: true 0164 onEntered: { 0165 shareViaEmailLabel.color = theme.linkColor 0166 } 0167 onExited:{ 0168 shareViaEmailLabel.color = theme.textColor 0169 } 0170 onClicked:{ 0171 Qt.openUrlExternally("mailto://"); 0172 } 0173 } 0174 } 0175 0176 Rectangle { 0177 id: btnshorzSeprEnd 0178 width: parent.width 0179 height: units.gridUnit * 0.75 0180 color: theme.linkColor 0181 0182 PlasmaCore.IconItem { 0183 id: closemenuDrawer 0184 anchors.centerIn: parent 0185 source: "go-up" 0186 width: units.gridUnit * 2 0187 height: units.gridUnit * 2 0188 } 0189 } 0190 } 0191 } 0192 } 0193 0194 ListModel { 0195 id: dashCardCollectionModel 0196 } 0197 0198 FocusScope { 0199 anchors.fill:parent 0200 focus: true 0201 0202 ListView { 0203 id: dashdelegatelview 0204 width: cbwidth - units.gridUnit * 0.25 0205 height: childrenRect.height 0206 spacing: units.gridUnit * 0.3 0207 interactive: true 0208 clip: true; 0209 model: dashCardCollectionModel 0210 0211 onCountChanged: { 0212 if (dashdelegatelview.model.count != 0){ 0213 var root = dashdelegatelview.visibleChildren[0] 0214 var listViewHeight = 0 0215 var listViewWidth = 0 0216 var scrollableHeight 0217 0218 for (var i = 0; i < root.visibleChildren.length; i++) { 0219 listViewHeight = root.visibleChildren[i].height 0220 scrollableHeight += root.visibleChildren[i].height 0221 } 0222 dashdelegatelview.contentHeight = scrollableHeight 0223 } 0224 } 0225 0226 Component.onCompleted: { 0227 if(dashCardCollectionModel.index !== -1){ 0228 dashboardmodelview.forceActiveFocus(); 0229 } 0230 } 0231 } 0232 } 0233 } 0234