| 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 Lesser 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 Lesser General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU Lesser General Public License |
| 14 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
import QtQuick 2.4 |
| 18 |
import Lomiri.Components 1.2 |
| 19 |
|
| 20 |
AbstractButton { |
| 21 |
id: button |
| 22 |
|
| 23 |
property real iconWidth: units.gu(2.5) |
| 24 |
property real iconHeight: iconWidth |
| 25 |
|
| 26 |
width: visible ? units.gu(5) : 0 |
| 27 |
height: parent ? parent.height : undefined |
| 28 |
|
| 29 |
property alias color: icon.color |
| 30 |
|
| 31 |
Rectangle { |
| 32 |
visible: button.pressed |
| 33 |
anchors.fill: parent |
| 34 |
color: Theme.palette.selected.background |
| 35 |
} |
| 36 |
|
| 37 |
Icon { |
| 38 |
id: icon |
| 39 |
anchors { |
| 40 |
centerIn: parent |
| 41 |
} |
| 42 |
// prevent trying to render the icon with an invalid source |
| 43 |
// when the button is invisible by setting width and height to 0 |
| 44 |
width: visible ? button.iconWidth : 0 |
| 45 |
height: visible ? button.iconHeight : 0 |
| 46 |
source: visible ? button.iconSource : "" |
| 47 |
color: Qt.rgba(0, 0, 0, 0) |
| 48 |
opacity: button.enabled ? 1.0 : 0.3 |
| 49 |
} |
| 50 |
|
| 51 |
Component { |
| 52 |
id: labelComponent |
| 53 |
Label { |
| 54 |
id: label |
| 55 |
objectName: button.objectName + "_label" |
| 56 |
color: button.color |
| 57 |
opacity: button.enabled ? 1.0 : 0.3 |
| 58 |
text: button.text |
| 59 |
fontSize: "xx-small" |
| 60 |
} |
| 61 |
} |
| 62 |
Loader { |
| 63 |
anchors { |
| 64 |
top: icon.bottom |
| 65 |
topMargin: units.gu(0.5) |
| 66 |
horizontalCenter: parent.horizontalCenter |
| 67 |
} |
| 68 |
sourceComponent: button.state === "IconAndLabel" ? labelComponent : null |
| 69 |
} |
| 70 |
} |