| 1 |
/* |
| 2 |
* Copyright 2014 Canonical Ltd. |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU General Public License as published by |
| 6 |
* the Free Software Foundation; version 3. |
| 7 |
* |
| 8 |
* This program is distributed in the hope that it will be useful, |
| 9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
* GNU General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU General Public License |
| 14 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
import QtQuick 2.12 |
| 18 |
import QtQuick.Window 2.2 |
| 19 |
import Lomiri.Components 1.3 |
| 20 |
|
| 21 |
AbstractButton { |
| 22 |
id: button |
| 23 |
|
| 24 |
property alias iconName: icon.name |
| 25 |
property url iconSource |
| 26 |
property bool on: true |
| 27 |
property string label: "" |
| 28 |
property bool automaticOrientation: true |
| 29 |
property real customRotation: 0 |
| 30 |
|
| 31 |
width: units.gu(5) |
| 32 |
height: width |
| 33 |
|
| 34 |
Image { |
| 35 |
anchors.fill: parent |
| 36 |
source: "../../assets/lomiri_shape.svg" |
| 37 |
opacity: button.pressed ? 0.7 : 0.3 |
| 38 |
sourceSize.width: width |
| 39 |
sourceSize.height: height |
| 40 |
cache: true |
| 41 |
asynchronous: true |
| 42 |
} |
| 43 |
|
| 44 |
Icon { |
| 45 |
id: icon |
| 46 |
anchors { |
| 47 |
fill: parent |
| 48 |
margins: units.gu(1) |
| 49 |
} |
| 50 |
source: name ? "image://theme/%1".arg(name) : button.iconSource |
| 51 |
color: "white" |
| 52 |
opacity: button.on ? (button.enabled ? 1.0 : 0.3): 0.5 |
| 53 |
visible: label === "" |
| 54 |
rotation: automaticOrientation ? Screen.angleBetween(Screen.primaryOrientation, Screen.orientation) : customRotation |
| 55 |
Behavior on rotation { |
| 56 |
RotationAnimator { |
| 57 |
duration: LomiriAnimation.BriskDuration |
| 58 |
easing: LomiriAnimation.StandardEasing |
| 59 |
direction: RotationAnimator.Shortest |
| 60 |
} |
| 61 |
} |
| 62 |
asynchronous: true |
| 63 |
} |
| 64 |
|
| 65 |
Label { |
| 66 |
anchors { |
| 67 |
centerIn: parent |
| 68 |
} |
| 69 |
font.weight: Font.Light |
| 70 |
fontSize: "small" |
| 71 |
color: "white" |
| 72 |
text: label |
| 73 |
opacity: button.on ? (button.enabled ? 1.0 : 0.3): 0.5 |
| 74 |
visible: label !== "" |
| 75 |
rotation: automaticOrientation ? Screen.angleBetween(Screen.primaryOrientation, Screen.orientation) : customRotation |
| 76 |
Behavior on rotation { |
| 77 |
RotationAnimator { |
| 78 |
duration: LomiriAnimation.BriskDuration |
| 79 |
easing: LomiriAnimation.StandardEasing |
| 80 |
direction: RotationAnimator.Shortest |
| 81 |
} |
| 82 |
} |
| 83 |
} |
| 84 |
} |