Verified Commit 67650efc authored by Fushan Wen's avatar Fushan Wen 💬
Browse files

applets/timer: give heading a background

parent 89928976
......@@ -17,8 +17,6 @@ Row {
property bool editable: true
// in alert mode 2nd set of digits from svg file will be drawn
property bool alertMode: false
// display seconds in addition to hours and minutes (default: enabled)
readonly property bool showSeconds: plasmoid.configuration.showSeconds;
signal digitModified(int valueDelta)
......@@ -26,7 +24,7 @@ Row {
id: internal
readonly property string digitSuffix: alertMode ? "_1" : ""
// digits count include separators with 50% of digit width
readonly property real digits: showSeconds ? 7 : 4.5;
readonly property real digits: root.showSeconds ? 7 : 4.5;
readonly property int digitH: (parent.height / 2) * digits < parent.width ? parent.height : parent.width / digits * 2
readonly property int digitW: digitH / 2;
property string valueString: "000000"
......@@ -46,6 +44,8 @@ Row {
MouseArea {
anchors.fill: parent
enabled: editable
propagateComposedEvents: true
onWheel: {
wheel.accepted = true
if (wheel.angleDelta.y > mouseWheelAngleThreshold) {
......@@ -116,11 +116,11 @@ Row {
}
}
Loader { sourceComponent: showSeconds ? separator : undefined } // ":"
Loader { sourceComponent: root.showSeconds ? separator : undefined } // ":"
Loader {
id: second1
sourceComponent: showSeconds ? digit : undefined
sourceComponent: root.showSeconds ? digit : undefined
onLoaded: {
item.meaning = 10 //10s
item.num = internal.valueString[4]
......@@ -128,7 +128,7 @@ Row {
}
Loader {
id: second2
sourceComponent: showSeconds ? digit : undefined
sourceComponent: root.showSeconds ? digit : undefined
onLoaded: {
item.meaning = 1 //1s
item.num = internal.valueString[5]
......
......@@ -5,33 +5,69 @@
* SPDX-License-Identifier: GPL-2.0-or-later
*/
import QtQuick 2.2
import QtQuick 2.15
import QtQuick.Layouts 1.15
import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 3.0 as PlasmaComponents3
import org.kde.plasma.extras 2.0 as PlasmaExtras
import org.kde.kquickcontrolsaddons 2.0 as QtExtra
Item {
id: main
readonly property int secondsForAlert: 60
MouseArea {
Layout.preferredWidth: Math.max(Plasmoid.compactRepresentationItem.width, PlasmaCore.Units.gridUnit * 10)
Layout.preferredHeight: main.implicitHeight
onClicked: root.toggleTimer()
Component {
id: popupHeadingComponent
Column {
PlasmaExtras.PlasmoidHeading {
leftPadding: PlasmaCore.Units.smallSpacing * 2
rightPadding: PlasmaCore.Units.smallSpacing * 2
contentItem: PlasmaExtras.Heading {
level: 3
elide: Text.ElideRight
horizontalAlignment: Text.AlignHCenter
text: root.title
}
}
}
Text {
id: titleLabel
Component {
id: desktopHeadingComponent
PlasmaComponents3.Label {
elide: Text.ElideRight
font.pixelSize: 0.3 * timerDigits.height
text: root.title
visible: root.showTitle;
horizontalAlignment: Text.AlignHCenter
height: 0.25 * main.height
font.pixelSize: 0.5 * height
}
}
ColumnLayout {
id: main
width: parent.width
Loader {
Layout.fillWidth: true
active: root.showTitle
sourceComponent: root.inPanel ? popupHeadingComponent : desktopHeadingComponent
}
TimerEdit {
id: timerDigits
Layout.fillWidth: true
value: root.seconds
editable: !root.running
alertMode: root.running && (root.seconds < main.secondsForAlert)
width: main.width
height: main.height - titleLabel.height
alertMode: root.alertMode
onDigitModified: root.seconds += valueDelta
SequentialAnimation on opacity {
running: root.suspended;
......@@ -56,31 +92,14 @@ Item {
}
}
}
}
MouseArea {
anchors.fill: parent;
onClicked: {
if (root.running) {
root.stopTimer();
} else {
root.startTimer();
}
function resetOpacity() {
timerDigits.opacity = 1.0;
}
}
function resetOpacity() {
timerDigits.opacity = 1.0;
}
PlasmaCore.ToolTipArea {
anchors.fill: parent
mainText: Plasmoid.toolTipMainText
subText: Plasmoid.toolTipSubText;
}
Component.onCompleted: {
root.opacityNeedsReset.connect(resetOpacity);
Component.onCompleted: {
root.opacityNeedsReset.connect(resetOpacity);
}
}
}
......@@ -4,7 +4,7 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import QtQuick 2.2
import QtQuick 2.15
import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.kquickcontrolsaddons 2.0 as QtExtra
......@@ -16,6 +16,8 @@ Item {
Plasmoid.backgroundHints: PlasmaCore.Types.ShadowBackground | PlasmaCore.Types.ConfigurableBackground
// Display seconds in addition to hours and minutes (default: enabled)
readonly property bool showSeconds: Plasmoid.configuration.showSeconds
property int seconds : restoreToSeconds(plasmoid.configuration.running, plasmoid.configuration.savedAt, plasmoid.configuration.seconds);
// show notification on timer completion (default: enabled)
......@@ -27,6 +29,7 @@ Item {
// show title (can be customized in the settings dialog, default: disabled)
readonly property bool showTitle: plasmoid.configuration.showTitle;
readonly property string title: plasmoid.configuration.title;
readonly property bool alertMode: root.running && root.seconds < 60
property bool running: (plasmoid.configuration.running > 0) ? true : false;
property bool suspended: false;
......@@ -54,6 +57,14 @@ Item {
Plasmoid.compactRepresentation: TimerView { }
Plasmoid.fullRepresentation: TimerView { }
function toggleTimer() {
if (root.running) {
root.stopTimer();
} else {
root.startTimer();
}
}
PlasmaCore.DataSource {
id: notificationSource
engine: "notifications"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment