1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
/*
* Copyright 2014 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.12
import QtQuick.Window 2.2
import Lomiri.Components 1.3
Item {
property int time: 0
property alias label: countLabel.text
width: content.childrenRect.width + content.anchors.leftMargin + content.anchors.rightMargin
height: content.childrenRect.height + units.gu(1.5)
rotation: Screen.angleBetween(Screen.primaryOrientation, Screen.orientation)
Behavior on rotation {
RotationAnimator {
duration: LomiriAnimation.BriskDuration
easing: LomiriAnimation.StandardEasing
direction: RotationAnimator.Shortest
}
}
BorderImage {
id: background
anchors.fill: parent
source: "assets/lomiri_shape.sci"
opacity: 0.3
asynchronous: true
cache: false
}
Row {
id: content
anchors {
left: parent.left
leftMargin: units.gu(1)
right: parent.right
rightMargin: units.gu(2)
verticalCenter: parent.verticalCenter
}
height: childrenRect.height
spacing: units.gu(1.5)
Rectangle {
anchors.verticalCenter: countLabel.verticalCenter
radius: units.gu(2)
width: radius
height: radius
color: "#AE1623"
}
Label {
id: countLabel
color: "white"
fontSize: "large"
style: Text.Raised
styleColor: "black"
text: intern.formattedTime()
}
}
QtObject {
id: intern
function pad(text, length) {
while (text.length < length) text = '0' + text;
return text;
}
function formattedTime() {
var prefix = ""
if (time < 0) {
prefix = "-";
time = -time;
}
var seconds_in_minute = 60;
var minutes_in_hour = 60;
var hours_in_day = 24;
var seconds_in_hour = seconds_in_minute * minutes_in_hour;
var hours = String(Math.floor(time / seconds_in_hour) % hours_in_day);
var minutes = String(Math.floor(time / seconds_in_minute) % minutes_in_hour);
var seconds = String(time % seconds_in_minute);
if (hours != "0") {
return "%1%2:%3:%4".arg(prefix).arg(intern.pad(hours, 2)).arg(intern.pad(minutes, 2)).arg(intern.pad(seconds, 2));
} else {
return "%1%2:%3".arg(prefix).arg(intern.pad(minutes, 2)).arg(intern.pad(seconds, 2));
}
}
}
}
|