| 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 |
import Lomiri.Components.Styles 1.2 as Style |
| 20 |
|
| 21 |
Style.ComboButtonStyle { |
| 22 |
id: comboStyle |
| 23 |
|
| 24 |
// configurations |
| 25 |
dropDownWidth: units.gu(5) |
| 26 |
dropDownSeparatorWidth: units.dp(2) |
| 27 |
comboListMargin: units.gu(0.8) |
| 28 |
comboListHolder: comboListContent |
| 29 |
comboListPanel: panelItem |
| 30 |
defaultColor: mainButton.defaultColor |
| 31 |
defaultGradient: mainButton.defaultGradient |
| 32 |
defaultDropdownColor: combo.expanded ? Qt.rgba(0, 0, 0, 0.05) : defaultColor |
| 33 |
defaultFont: mainButton.defaultFont |
| 34 |
|
| 35 |
|
| 36 |
width: combo.width |
| 37 |
height: combo.collapsedHeight |
| 38 |
|
| 39 |
property ComboButton combo: styledItem |
| 40 |
|
| 41 |
implicitWidth: mainButton.implicitWidth |
| 42 |
implicitHeight: mainButton.implicitHeight |
| 43 |
|
| 44 |
LayoutMirroring.enabled: Qt.application.layoutDirection == Qt.RightToLeft |
| 45 |
LayoutMirroring.childrenInherit: true |
| 46 |
|
| 47 |
ButtonStyle { |
| 48 |
id: mainButton |
| 49 |
anchors { |
| 50 |
left: parent.left |
| 51 |
top: parent.top |
| 52 |
right: parent.right |
| 53 |
} |
| 54 |
height: combo.collapsedHeight |
| 55 |
// overrides |
| 56 |
backgroundSource: comboFace |
| 57 |
buttonFaceOffset: -dropDownWidth/2 - dropDownSeparatorWidth |
| 58 |
horizontalPadding: units.gu(4) - dropDownSeparatorWidth |
| 59 |
minimumWidth: units.gu(36) |
| 60 |
|
| 61 |
// FIXME: use hardcoded color while we get the theme palette updated |
| 62 |
defaultColor: "#b2b2b2" |
| 63 |
defaultGradient: null |
| 64 |
|
| 65 |
// button face |
| 66 |
ShaderEffectSource { |
| 67 |
id: comboFace |
| 68 |
sourceItem: content |
| 69 |
hideSource: true |
| 70 |
// FIXME: visible: false prevents rendering so make it a nearly |
| 71 |
// transparent 1x1 pixel instead |
| 72 |
opacity: 0.01 |
| 73 |
width: 1 |
| 74 |
height: 1 |
| 75 |
} |
| 76 |
|
| 77 |
Item { |
| 78 |
id: content |
| 79 |
width: mainButton.width |
| 80 |
height: mainButton.height |
| 81 |
|
| 82 |
Rectangle { |
| 83 |
anchors { |
| 84 |
fill: parent |
| 85 |
rightMargin: comboStyle.dropDownSeparatorWidth + comboStyle.dropDownWidth |
| 86 |
} |
| 87 |
color: combo.color |
| 88 |
gradient: mainButton.isGradient ? combo.gradient : null |
| 89 |
} |
| 90 |
|
| 91 |
// distancer |
| 92 |
Item { |
| 93 |
anchors { |
| 94 |
right: dropDownButton.right |
| 95 |
top: parent.top |
| 96 |
bottom: parent.bottom |
| 97 |
} |
| 98 |
width: comboStyle.dropDownSeparatorWidth |
| 99 |
} |
| 100 |
|
| 101 |
Rectangle { |
| 102 |
id: dropDownButton |
| 103 |
objectName: "combobutton_dropdown_visuals" |
| 104 |
anchors { |
| 105 |
right: parent.right |
| 106 |
top: parent.top |
| 107 |
bottom: parent.bottom |
| 108 |
} |
| 109 |
width: comboStyle.dropDownWidth |
| 110 |
color: mainButton.__colorHack(combo.dropdownColor) |
| 111 |
Image { |
| 112 |
source: Qt.resolvedUrl("../artwork/chevron.png") |
| 113 |
anchors.centerIn: parent |
| 114 |
rotation: combo.expanded ? -90 : 90 |
| 115 |
} |
| 116 |
} |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
Item { |
| 121 |
id: panelItem |
| 122 |
objectName: "combobutton_combopanel" |
| 123 |
anchors { |
| 124 |
left: parent.left |
| 125 |
top: mainButton.bottom |
| 126 |
right: parent.right |
| 127 |
} |
| 128 |
opacity: combo.expanded && (combo.comboList.length > 0)? 1.0 : 0.0 |
| 129 |
|
| 130 |
ShaderEffectSource { |
| 131 |
id: listContent |
| 132 |
sourceItem: comboListContent |
| 133 |
hideSource: true |
| 134 |
// FIXME: visible: false prevents rendering so make it a nearly |
| 135 |
// transparent 1x1 pixel instead |
| 136 |
opacity: 0.01 |
| 137 |
width: 1 |
| 138 |
height: 1 |
| 139 |
} |
| 140 |
Rectangle { |
| 141 |
id: comboListContent |
| 142 |
anchors { |
| 143 |
fill: parent |
| 144 |
topMargin: comboListMargin |
| 145 |
} |
| 146 |
clip: true |
| 147 |
color: mainButton.__colorHack(combo.dropdownColor) |
| 148 |
} |
| 149 |
|
| 150 |
BorderImage { |
| 151 |
id: shadow |
| 152 |
anchors { |
| 153 |
fill: parent |
| 154 |
leftMargin: -units.gu(0.5) |
| 155 |
topMargin: comboListMargin - units.gu(0.5) |
| 156 |
rightMargin: -units.gu(0.5) |
| 157 |
bottomMargin: -units.gu(0.5) |
| 158 |
} |
| 159 |
source: Qt.resolvedUrl("../artwork/bubble_shadow.sci") |
| 160 |
} |
| 161 |
LomiriShape { |
| 162 |
id: shape |
| 163 |
anchors { |
| 164 |
fill: parent |
| 165 |
topMargin: comboListMargin |
| 166 |
} |
| 167 |
visible: true |
| 168 |
borderSource: "radius_idle.sci" |
| 169 |
image: listContent |
| 170 |
} |
| 171 |
|
| 172 |
Image { |
| 173 |
source: Qt.resolvedUrl("../artwork/bubble_arrow.png") |
| 174 |
rotation: 180 |
| 175 |
anchors { |
| 176 |
bottom: shape.top |
| 177 |
bottomMargin: -1 |
| 178 |
right: parent.right |
| 179 |
rightMargin: dropDownWidth / 2 - units.gu(0.5) |
| 180 |
} |
| 181 |
|
| 182 |
} |
| 183 |
|
| 184 |
Behavior on height { |
| 185 |
NumberAnimation { |
| 186 |
duration: LomiriAnimation.FastDuration |
| 187 |
easing: LomiriAnimation.StandardEasing |
| 188 |
} |
| 189 |
} |
| 190 |
Behavior on opacity { |
| 191 |
NumberAnimation { |
| 192 |
duration: LomiriAnimation.FastDuration |
| 193 |
easing: LomiriAnimation.StandardEasing |
| 194 |
} |
| 195 |
} |
| 196 |
} |
| 197 |
} |