Warning, /plasma/kdeplasma-addons/applets/fuzzy-clock/package/contents/ui/FuzzyClock.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * SPDX-FileCopyrightText: 2013 Heena Mahour <heena393@gmail.com> 0003 * SPDX-FileCopyrightText: 2013 Sebastian Kügler <sebas@kde.org> 0004 * SPDX-FileCopyrightText: 2013 Martin Klapetek <mklapetek@kde.org> 0005 * SPDX-FileCopyrightText: 2014 David Edmundson <davidedmundson@kde.org> 0006 * SPDX-FileCopyrightText: 2014 Kai Uwe Broulik <kde@privat.broulik.de> 0007 * 0008 * SPDX-License-Identifier: GPL-2.0-or-later 0009 */ 0010 0011 import QtQuick 2.15 0012 import QtQuick.Layouts 1.1 0013 0014 import org.kde.plasma.core as PlasmaCore 0015 import org.kde.kirigami 2.20 as Kirigami 0016 import org.kde.plasma.components 3.0 as PlasmaComponents3 0017 import org.kde.plasma.plasmoid 2.0 0018 0019 Item { 0020 id: main 0021 0022 Layout.minimumWidth: vertical ? 0 : sizehelper.paintedWidth + (Kirigami.Units.smallSpacing * 2) 0023 Layout.maximumWidth: vertical ? Infinity : Layout.minimumWidth 0024 Layout.preferredWidth: vertical ? undefined : Layout.minimumWidth 0025 0026 Layout.minimumHeight: vertical ? sizehelper.paintedHeight + (Kirigami.Units.smallSpacing * 2) : 0 0027 Layout.maximumHeight: vertical ? Layout.minimumHeight : Infinity 0028 Layout.preferredHeight: vertical ? Layout.minimumHeight : Kirigami.Units.iconSizes.sizeForLabels * 2 0029 0030 readonly property bool vertical: plasmoid.formFactor == PlasmaCore.Types.Vertical 0031 0032 readonly property int fuzzyness: plasmoid.configuration.fuzzyness 0033 0034 readonly property var hourNames: [ 0035 [ i18n("One o’clock"), 0036 i18n("Five past one"), 0037 i18n("Ten past one"), 0038 i18n("Quarter past one"), 0039 i18n("Twenty past one"), 0040 i18n("Twenty-five past one"), 0041 i18n("Half past one"), 0042 i18n("Twenty-five to two"), 0043 i18n("Twenty to two"), 0044 i18n("Quarter to two"), 0045 i18n("Ten to two"), 0046 i18n("Five to two") ], 0047 [ i18n("Two o’clock"), 0048 i18n("Five past two"), 0049 i18n("Ten past two"), 0050 i18n("Quarter past two"), 0051 i18n("Twenty past two"), 0052 i18n("Twenty-five past two"), 0053 i18n("Half past two"), 0054 i18n("Twenty-five to three"), 0055 i18n("Twenty to three"), 0056 i18n("Quarter to three"), 0057 i18n("Ten to three"), 0058 i18n("Five to three") ], 0059 [ i18n("Three o’clock"), 0060 i18n("Five past three"), 0061 i18n("Ten past three"), 0062 i18n("Quarter past three"), 0063 i18n("Twenty past three"), 0064 i18n("Twenty-five past three"), 0065 i18n("Half past three"), 0066 i18n("Twenty-five to four"), 0067 i18n("Twenty to four"), 0068 i18n("Quarter to four"), 0069 i18n("Ten to four"), 0070 i18n("Five to four") ], 0071 [ i18n("Four o’clock"), 0072 i18n("Five past four"), 0073 i18n("Ten past four"), 0074 i18n("Quarter past four"), 0075 i18n("Twenty past four"), 0076 i18n("Twenty-five past four"), 0077 i18n("Half past four"), 0078 i18n("Twenty-five to five"), 0079 i18n("Twenty to five"), 0080 i18n("Quarter to five"), 0081 i18n("Ten to five"), 0082 i18n("Five to five") ], 0083 [ i18n("Five o’clock"), 0084 i18n("Five past five"), 0085 i18n("Ten past five"), 0086 i18n("Quarter past five"), 0087 i18n("Twenty past five"), 0088 i18n("Twenty-five past five"), 0089 i18n("Half past five"), 0090 i18n("Twenty-five to six"), 0091 i18n("Twenty to six"), 0092 i18n("Quarter to six"), 0093 i18n("Ten to six"), 0094 i18n("Five to six") ], 0095 [ i18n("Six o’clock"), 0096 i18n("Five past six"), 0097 i18n("Ten past six"), 0098 i18n("Quarter past six"), 0099 i18n("Twenty past six"), 0100 i18n("Twenty-five past six"), 0101 i18n("Half past six"), 0102 i18n("Twenty-five to seven"), 0103 i18n("Twenty to seven"), 0104 i18n("Quarter to seven"), 0105 i18n("Ten to seven"), 0106 i18n("Five to seven") ], 0107 [ i18n("Seven o’clock"), 0108 i18n("Five past seven"), 0109 i18n("Ten past seven"), 0110 i18n("Quarter past seven"), 0111 i18n("Twenty past seven"), 0112 i18n("Twenty-five past seven"), 0113 i18n("Half past seven"), 0114 i18n("Twenty-five to eight"), 0115 i18n("Twenty to eight"), 0116 i18n("Quarter to eight"), 0117 i18n("Ten to eight"), 0118 i18n("Five to eight") ], 0119 [ i18n("Eight o’clock"), 0120 i18n("Five past eight"), 0121 i18n("Ten past eight"), 0122 i18n("Quarter past eight"), 0123 i18n("Twenty past eight"), 0124 i18n("Twenty-five past eight"), 0125 i18n("Half past eight"), 0126 i18n("Twenty-five to nine"), 0127 i18n("Twenty to nine"), 0128 i18n("Quarter to nine"), 0129 i18n("Ten to nine"), 0130 i18n("Five to nine") ], 0131 [ i18n("Nine o’clock"), 0132 i18n("Five past nine"), 0133 i18n("Ten past nine"), 0134 i18n("Quarter past nine"), 0135 i18n("Twenty past nine"), 0136 i18n("Twenty-five past nine"), 0137 i18n("Half past nine"), 0138 i18n("Twenty-five to ten"), 0139 i18n("Twenty to ten"), 0140 i18n("Quarter to ten"), 0141 i18n("Ten to ten"), 0142 i18n("Five to ten") ], 0143 [ i18n("Ten o’clock"), 0144 i18n("Five past ten"), 0145 i18n("Ten past ten"), 0146 i18n("Quarter past ten"), 0147 i18n("Twenty past ten"), 0148 i18n("Twenty-five past ten"), 0149 i18n("Half past ten"), 0150 i18n("Twenty-five to eleven"), 0151 i18n("Twenty to eleven"), 0152 i18n("Quarter to eleven"), 0153 i18n("Ten to eleven"), 0154 i18n("Five to eleven") ], 0155 [ i18n("Eleven o’clock"), 0156 i18n("Five past eleven"), 0157 i18n("Ten past eleven"), 0158 i18n("Quarter past eleven"), 0159 i18n("Twenty past eleven"), 0160 i18n("Twenty-five past eleven"), 0161 i18n("Half past eleven"), 0162 i18n("Twenty-five to twelve"), 0163 i18n("Twenty to twelve"), 0164 i18n("Quarter to twelve"), 0165 i18n("Ten to twelve"), 0166 i18n("Five to twelve") ], 0167 [ i18n("Twelve o’clock"), 0168 i18n("Five past twelve"), 0169 i18n("Ten past twelve"), 0170 i18n("Quarter past twelve"), 0171 i18n("Twenty past twelve"), 0172 i18n("Twenty-five past twelve"), 0173 i18n("Half past twelve"), 0174 i18n("Twenty-five to one"), 0175 i18n("Twenty to one"), 0176 i18n("Quarter to one"), 0177 i18n("Ten to one"), 0178 i18n("Five to one") ] 0179 ] 0180 0181 readonly property var halflingTime: [ 0182 i18n("Sleep"), i18n("Breakfast"), i18n("Second Breakfast"), i18n("Elevenses"), 0183 i18n("Lunch"), i18n("Afternoon tea"), i18n("Dinner"), i18n("Supper") 0184 ] 0185 0186 readonly property var dayTime: [ 0187 i18n("Night"), i18n("Early morning"), i18n("Morning"), i18n("Almost noon"), 0188 i18n("Noon"), i18n("Afternoon"), i18n("Evening"), i18n("Late evening") 0189 ] 0190 0191 readonly property var weekTime: [ 0192 i18n("Start of week"), i18n("Middle of week"), i18n("End of week"), i18n("Weekend!") 0193 ] 0194 0195 function timeString() { 0196 var d = new Date(dataSource.data["Local"]["DateTime"]) 0197 var hours = d.getHours() 0198 var minutes = d.getMinutes() 0199 0200 if (main.fuzzyness == 1 || main.fuzzyness == 2) { 0201 var sector = 0 0202 var realHour = 0 0203 0204 if (main.fuzzyness == 1) { 0205 if (minutes > 2) { 0206 sector = (minutes - 3) / 5 + 1 0207 } 0208 } else { 0209 // this formula has been determined by carefully filling a spreadsheet 0210 // and looking at the numbers :) 0211 sector = ((minutes + 7) / 15 * 3) 0212 // now round down to the nearest three 0213 sector = (Math.floor(sector / 3) * 3) 0214 } 0215 0216 if (hours % 12 > 0) { 0217 realHour = hours % 12 - 1 0218 } else { 0219 realHour = 12 - (hours % 12 + 1) 0220 } 0221 0222 sector = Math.floor(sector); 0223 if (sector == 12) { 0224 realHour += 1 0225 if (Math.floor(realHour) >= hourNames.length) { 0226 realHour = 0 0227 } 0228 sector = 0 0229 } 0230 0231 return hourNames[Math.floor(realHour)][sector] 0232 } else if (main.fuzzyness == 3) { 0233 return halflingTime[Math.floor(hours / 3)] 0234 } else if (main.fuzzyness == 4) { 0235 return dayTime[Math.floor(hours / 3)] 0236 } else { 0237 var dow = d.getDay() 0238 0239 var weekTimeId 0240 if (dow == 1) { 0241 weekTimeId = 0 0242 } else if (dow >= 2 && dow <= 4) { 0243 weekTimeId = 1 0244 } else if (dow == 5) { 0245 weekTimeId = 2 0246 } else { 0247 weekTimeId = 3 0248 } 0249 0250 return weekTime[weekTimeId] 0251 } 0252 } 0253 0254 activeFocusOnTab: true 0255 0256 Accessible.name: Plasmoid.title 0257 Accessible.description: timeLabel.text 0258 Accessible.role: Accessible.Button 0259 0260 PlasmaComponents3.Label { 0261 id: timeLabel 0262 font { 0263 weight: plasmoid.configuration.boldText ? Font.Bold : Font.Normal 0264 italic: plasmoid.configuration.italicText 0265 pixelSize: 1024 0266 pointSize: 0 // we need to unset pointSize otherwise it breaks the Text.Fit size mode 0267 } 0268 minimumPixelSize: Kirigami.Units.iconSizes.sizeForLabels 0269 fontSizeMode: Text.Fit 0270 text: timeString() 0271 0272 wrapMode: Text.NoWrap 0273 horizontalAlignment: Text.AlignHCenter 0274 verticalAlignment: Text.AlignVCenter 0275 height: 0 0276 width: 0 0277 anchors { 0278 fill: parent 0279 leftMargin: Kirigami.Units.smallSpacing 0280 rightMargin: Kirigami.Units.smallSpacing 0281 } 0282 } 0283 0284 property bool wasExpanded: false 0285 0286 readonly property alias mouseArea: mouseArea 0287 0288 MouseArea { 0289 id: mouseArea 0290 anchors.fill: parent 0291 hoverEnabled: true 0292 onPressed: wasExpanded = root.expanded 0293 onClicked: root.expanded = !wasExpanded 0294 } 0295 0296 Text { 0297 id: sizehelper 0298 font.weight: timeLabel.font.weight 0299 font.italic: timeLabel.font.italic 0300 font.pixelSize: vertical ? Kirigami.Units.gridUnit * 2 : 1024 // random "big enough" size - this is used as a max pixelSize by the fontSizeMode 0301 minimumPixelSize: Math.round(Kirigami.Units.gridUnit / 2) 0302 horizontalAlignment: Text.AlignHCenter 0303 verticalAlignment: Text.AlignVCenter 0304 text: timeLabel.text 0305 fontSizeMode: vertical ? Text.HorizontalFit : Text.VerticalFit 0306 0307 wrapMode: Text.NoWrap 0308 visible: false 0309 anchors { 0310 fill: parent 0311 leftMargin: Kirigami.Units.smallSpacing 0312 rightMargin: Kirigami.Units.smallSpacing 0313 } 0314 } 0315 }