| 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 Lomiri.Components 1.3 |
| 19 |
|
| 20 |
AbstractButton { |
| 21 |
id: optionValueButton |
| 22 |
|
| 23 |
implicitHeight: units.gu(5) |
| 24 |
|
| 25 |
property alias label: label.text |
| 26 |
property alias iconName: icon.name |
| 27 |
property alias iconSource: icon.source |
| 28 |
property bool selected |
| 29 |
property bool isLast |
| 30 |
property int columnWidth |
| 31 |
property int marginSize: units.gu(1) |
| 32 |
|
| 33 |
width: marginSize + iconLabelGroup.width + marginSize |
| 34 |
|
| 35 |
Item { |
| 36 |
property bool showIcon: iconName !== "" || (iconName == "" && iconSource.toString().match(/^file:\/\//)) |
| 37 |
id: iconLabelGroup |
| 38 |
width: (icon.width * showIcon) + label.width |
| 39 |
height: icon.height |
| 40 |
|
| 41 |
anchors { |
| 42 |
left: parent.left |
| 43 |
leftMargin: marginSize |
| 44 |
verticalCenter: parent.verticalCenter |
| 45 |
topMargin: marginSize |
| 46 |
bottomMargin: marginSize |
| 47 |
} |
| 48 |
|
| 49 |
Icon { |
| 50 |
id: icon |
| 51 |
anchors { |
| 52 |
verticalCenter: parent.verticalCenter |
| 53 |
left: parent.left |
| 54 |
} |
| 55 |
width: optionValueButton.height - optionValueButton.marginSize * 2 |
| 56 |
color: "white" |
| 57 |
opacity: optionValueButton.selected ? 1.0 : 0.5 |
| 58 |
visible: iconLabelGroup.showIcon |
| 59 |
asynchronous: true |
| 60 |
} |
| 61 |
|
| 62 |
Label { |
| 63 |
id: label |
| 64 |
anchors { |
| 65 |
left: iconLabelGroup.showIcon ? icon.right : parent.left |
| 66 |
leftMargin: iconLabelGroup.showIcon ? units.gu(1) : 0 |
| 67 |
verticalCenter: parent.verticalCenter |
| 68 |
} |
| 69 |
|
| 70 |
color: "white" |
| 71 |
opacity: optionValueButton.selected ? 1.0 : 0.5 |
| 72 |
width: paintedWidth |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
Rectangle { |
| 77 |
anchors { |
| 78 |
left: parent.left |
| 79 |
bottom: parent.bottom |
| 80 |
} |
| 81 |
width: parent.columnWidth |
| 82 |
height: units.dp(1) |
| 83 |
color: "white" |
| 84 |
opacity: 0.5 |
| 85 |
visible: !optionValueButton.isLast |
| 86 |
} |
| 87 |
} |