| 1 |
/* |
| 2 |
* Copyright (C) 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 version 3 as |
| 6 |
* published by the Free Software Foundation. |
| 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 |
* Author: Filippo Scognamiglio <[email protected]> |
| 17 |
*/ |
| 18 |
import QtQuick 2.4 |
| 19 |
import Lomiri.Components 1.3 |
| 20 |
|
| 21 |
Rectangle { |
| 22 |
id: container |
| 23 |
|
| 24 |
property string name |
| 25 |
property string short_name |
| 26 |
|
| 27 |
property var model: [] |
| 28 |
property real keyWidth: units.gu(5) |
| 29 |
property real keyHeight: units.gu(5) |
| 30 |
|
| 31 |
// External signals. |
| 32 |
signal simulateKey(int key, int mod); |
| 33 |
signal simulateCommand(string command); |
| 34 |
|
| 35 |
// Internal variables |
| 36 |
property int _firstVisibleIndex: gridView.contentX / keyWidth |
| 37 |
property int _lastVisibleIndex: _firstVisibleIndex + gridView.width / keyWidth |
| 38 |
property int _avgIndex: (_lastVisibleIndex + _firstVisibleIndex) / 2 |
| 39 |
|
| 40 |
color: "black" |
| 41 |
property color textColor |
| 42 |
|
| 43 |
GridView { |
| 44 |
id: gridView |
| 45 |
model: parent.model |
| 46 |
anchors.fill: parent |
| 47 |
cellWidth: keyWidth |
| 48 |
cellHeight: keyHeight |
| 49 |
delegate: keyDelegate |
| 50 |
flow: GridView.TopToBottom |
| 51 |
snapMode: GridView.SnapToRow |
| 52 |
} |
| 53 |
|
| 54 |
Rectangle { |
| 55 |
id: scrollBar |
| 56 |
anchors.bottom: parent.bottom |
| 57 |
height: units.dp(2) |
| 58 |
// FIXME |
| 59 |
color: LomiriColors.orange; |
| 60 |
|
| 61 |
width: gridView.visibleArea.widthRatio * gridView.width |
| 62 |
x: gridView.visibleArea.xPosition * gridView.width |
| 63 |
visible: gridView.visibleArea.widthRatio != 1.0 |
| 64 |
} |
| 65 |
|
| 66 |
Component { |
| 67 |
id: keyDelegate |
| 68 |
Item { |
| 69 |
id: delegateContainer |
| 70 |
property int modelIndex: index |
| 71 |
property string modelText: container.model[index].text |
| 72 |
property var modelActions: container.model[index].actions |
| 73 |
property Action modelMainAction: container.model[index].mainAction |
| 74 |
width: keyWidth |
| 75 |
height: keyHeight |
| 76 |
|
| 77 |
Loader { |
| 78 |
anchors.fill: parent |
| 79 |
sourceComponent: (delegateContainer.modelActions.length > 0) ? expandable : nonExpandable |
| 80 |
} |
| 81 |
Component { |
| 82 |
id: nonExpandable |
| 83 |
KeyboardButton { |
| 84 |
anchors.fill: parent |
| 85 |
text: delegateContainer.modelText |
| 86 |
mainAction: delegateContainer.modelMainAction |
| 87 |
textColor: container.textColor |
| 88 |
} |
| 89 |
} |
| 90 |
Component { |
| 91 |
id: expandable |
| 92 |
ExpandableKeyboardButton { |
| 93 |
anchors.fill: parent |
| 94 |
text: delegateContainer.modelText |
| 95 |
mainAction: delegateContainer.modelMainAction |
| 96 |
actions: delegateContainer.modelActions |
| 97 |
expandable: !gridView.movingHorizontally |
| 98 |
expandRight: delegateContainer.modelIndex <= container._avgIndex |
| 99 |
backgroundColor: container.color |
| 100 |
textColor: container.textColor |
| 101 |
} |
| 102 |
} |
| 103 |
} |
| 104 |
} |
| 105 |
} |