Warning, /plasma/kdeplasma-addons/applets/timer/package/contents/ui/CompactRepresentation.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * SPDX-FileCopyrightText: 2022 Fushan Wen <qydwhotmail@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 import QtQuick 0008 import QtQuick.Layouts 1.15 0009 0010 import org.kde.kirigami 2.20 as Kirigami 0011 import org.kde.plasma.components 3.0 as PlasmaComponents3 0012 import org.kde.plasma.plasmoid 2.0 0013 0014 import org.kde.plasma.private.timer 0.1 as TimerPlasmoid 0015 0016 Item { 0017 id: compactRepresentation 0018 0019 Layout.minimumHeight: root.inPanel ? Layout.preferredHeight : -1 0020 0021 Layout.preferredWidth: grid.width 0022 Layout.preferredHeight: grid.height 0023 0024 enum LayoutType { 0025 HorizontalPanel, 0026 VerticalPanel, 0027 HorizontalDesktop, 0028 VerticalDesktop, 0029 IconOnly 0030 } 0031 0032 property int layoutForm 0033 0034 Binding on layoutForm { 0035 delayed: true 0036 value: { 0037 if (root.inPanel) { 0038 return root.isVertical ? CompactRepresentation.LayoutType.VerticalPanel : CompactRepresentation.LayoutType.HorizontalPanel; 0039 } 0040 if (compactRepresentation.parent.width - iconItem.Layout.preferredWidth >= remainingTimeLabel.contentWidth) { 0041 return CompactRepresentation.LayoutType.HorizontalDesktop; 0042 } 0043 if (compactRepresentation.parent.height - iconItem.Layout.preferredHeight >= remainingTimeLabel.contentHeight) { 0044 return CompactRepresentation.LayoutType.VerticalDesktop; 0045 } 0046 return CompactRepresentation.LayoutType.IconOnly; 0047 } 0048 } 0049 0050 Keys.onUpPressed: adjustSecond(10); 0051 Keys.onDownPressed: adjustSecond(-10); 0052 0053 function adjustSecond(value) { 0054 while (value >= 15 && root.seconds + 1 < 24*60*60) { 0055 root.seconds += 1; 0056 value -= 15; 0057 } 0058 while (value <= -15 && root.seconds - 1 >= 0) { 0059 root.seconds -= 1; 0060 value += 15; 0061 } 0062 return value; 0063 } 0064 0065 WheelHandler { 0066 acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad 0067 enabled: !root.running 0068 onWheel: { 0069 event.accepted = true; 0070 rotation = compactRepresentation.adjustSecond(rotation); 0071 } 0072 } 0073 0074 GridLayout { 0075 id: grid 0076 0077 width: { 0078 switch (compactRepresentation.layoutForm) { 0079 case CompactRepresentation.LayoutType.HorizontalPanel: 0080 case CompactRepresentation.LayoutType.HorizontalDesktop: 0081 return implicitWidth; 0082 case CompactRepresentation.LayoutType.VerticalPanel: 0083 case CompactRepresentation.LayoutType.VerticalDesktop: 0084 return compactRepresentation.parent.width; 0085 case CompactRepresentation.LayoutType.IconOnly: 0086 return iconItem.Layout.preferredWidth; 0087 } 0088 } 0089 height: { 0090 switch (compactRepresentation.layoutForm) { 0091 case CompactRepresentation.LayoutType.HorizontalPanel: 0092 case CompactRepresentation.LayoutType.HorizontalDesktop: 0093 case CompactRepresentation.LayoutType.VerticalDesktop: 0094 return compactRepresentation.parent.height; 0095 case CompactRepresentation.LayoutType.VerticalPanel: 0096 return implicitHeight; 0097 case CompactRepresentation.LayoutType.IconOnly: 0098 return iconItem.Layout.preferredHeight; 0099 } 0100 } 0101 0102 rowSpacing: 0 0103 columnSpacing: rowSpacing 0104 flow: { 0105 switch (compactRepresentation.layoutForm) { 0106 case CompactRepresentation.LayoutType.VerticalPanel: 0107 case CompactRepresentation.LayoutType.VerticalDesktop: 0108 return GridLayout.TopToBottom; 0109 default: 0110 return GridLayout.LeftToRight; 0111 } 0112 } 0113 0114 Item { 0115 id: spacerItem 0116 Layout.fillHeight: true 0117 visible: layoutForm === CompactRepresentation.LayoutType.VerticalDesktop 0118 } 0119 0120 PlasmaComponents3.ToolButton { 0121 id: iconItem 0122 0123 Layout.alignment: Qt.AlignVCenter 0124 Layout.preferredWidth: Math.min(compactRepresentation.parent.width, compactRepresentation.parent.height) 0125 Layout.preferredHeight: Layout.preferredWidth 0126 visible: root.showTimerToggle 0127 0128 display: PlasmaComponents3.AbstractButton.IconOnly 0129 icon.name: { 0130 if (root.running) { 0131 return "chronometer-pause"; 0132 } 0133 return root.seconds > 0 ? "chronometer-start" : "chronometer"; 0134 } 0135 text: root.running ? i18nc("@action:button", "Pause Timer") : i18nc("@action:button", "Start Timer") 0136 0137 onClicked: { 0138 if (root.seconds === 0) { 0139 root.expanded = !root.expanded; 0140 } else { 0141 root.toggleTimer(); 0142 } 0143 } 0144 } 0145 0146 ColumnLayout { 0147 Layout.alignment: Qt.AlignVCenter 0148 Layout.fillWidth: layoutForm === CompactRepresentation.LayoutType.VerticalPanel || layoutForm === CompactRepresentation.LayoutType.VerticalDesktop 0149 Layout.maximumWidth: { 0150 switch (layoutForm) { 0151 case CompactRepresentation.LayoutType.HorizontalPanel: 0152 return Kirigami.Units.gridUnit * 10; 0153 case CompactRepresentation.LayoutType.HorizontalDesktop: 0154 return compactRepresentation.parent.width - iconItem.Layout.preferredWidth; 0155 default: 0156 return -1; 0157 } 0158 } 0159 Layout.maximumHeight: textMetrics.height * 2 0160 visible: compactRepresentation.layoutForm !== CompactRepresentation.LayoutType.IconOnly ? 1 : 0 0161 0162 spacing: parent.columnSpacing 0163 0164 TapHandler { 0165 acceptedButtons: Qt.LeftButton 0166 onTapped: root.expanded = !root.expanded 0167 } 0168 0169 PlasmaComponents3.Label { 0170 id: titleLabel 0171 0172 Layout.fillWidth: true 0173 Layout.fillHeight: true 0174 visible: root.showTitle && root.title !== "" 0175 0176 elide: Text.ElideRight 0177 font.bold: remainingTimeLabel.font.bold 0178 fontSizeMode: remainingTimeLabel.fontSizeMode 0179 horizontalAlignment: remainingTimeLabel.horizontalAlignment 0180 minimumPointSize: remainingTimeLabel.minimumPointSize 0181 text: root.title 0182 textFormat: Text.PlainText 0183 } 0184 0185 PlasmaComponents3.Label { 0186 id: remainingTimeLabel 0187 0188 Layout.fillWidth: parent.Layout.fillWidth 0189 Layout.fillHeight: true 0190 Layout.maximumWidth: Layout.fillWidth ? -1 : textMetrics.width 0191 Layout.minimumWidth: Layout.maximumWidth 0192 visible: root.showRemainingTime 0193 0194 TextMetrics { 0195 id: textMetrics 0196 text: { 0197 if (root.isVertical) { 0198 return i18ncp("remaining time", "%1s", "%1s", root.seconds); 0199 } 0200 // make it not jump around: reserve space for one extra digit than reasonable 0201 return root.showSeconds ? "44:44:444" : "44:444"; 0202 } 0203 font: remainingTimeLabel.font 0204 } 0205 0206 activeFocusOnTab: true 0207 elide: root.inPanel ? Text.ElideRight : Text.ElideNone 0208 font.bold: root.alertMode 0209 fontSizeMode: layoutForm === CompactRepresentation.LayoutType.HorizontalPanel || layoutForm === CompactRepresentation.LayoutType.HorizontalDesktop ? Text.VerticalFit : Text.HorizontalFit 0210 horizontalAlignment: layoutForm === CompactRepresentation.LayoutType.HorizontalPanel || layoutForm === CompactRepresentation.LayoutType.HorizontalDesktop ? Text.AlignJustify : Text.AlignHCenter 0211 minimumPointSize: Kirigami.Theme.smallFont.pointSize 0212 verticalAlignment: Text.AlignVCenter 0213 0214 text: { 0215 if (root.isVertical) { 0216 return i18ncp("remaining time", "%1s", "%1s", root.seconds); 0217 } 0218 0219 return root.showSeconds ? TimerPlasmoid.Timer.secondsToString(root.seconds, "hh:mm:ss") : TimerPlasmoid.Timer.secondsToString(root.seconds, "hh:mm"); 0220 } 0221 textFormat: Text.PlainText 0222 0223 Accessible.name: Plasmoid.toolTipMainText 0224 Accessible.description: Plasmoid.toolTipSubText 0225 Accessible.role: Accessible.Button 0226 } 0227 0228 PlasmaComponents3.ProgressBar { 0229 id: remainingTimeProgressBar 0230 0231 Layout.fillWidth: true 0232 Layout.fillHeight: true 0233 Layout.maximumWidth: (parent.visibleChildren.length > 1) ? Math.max(titleLabel.width, remainingTimeLabel.width) : -1 0234 Layout.minimumWidth: Layout.maximumWidth 0235 visible: root.showProgressBar 0236 0237 from: plasmoid.configuration.seconds 0238 to: 0 0239 value: root.seconds 0240 } 0241 } 0242 0243 Item { 0244 Layout.fillHeight: true 0245 visible: spacerItem.visible 0246 } 0247 } 0248 }