| 1 | import QtQuick |
| 2 | |
| 3 | // One block of the bar: icon, caps label, optional second icon with its own click (activated2), anything else declared |
| 4 | // inside goes after them (the battery capsule, the clock). Side by side in the top bar, stacked in the vertical one. |
| 5 | // Hover = a rounded highlight. |
| 6 | Item { |
| 7 | id: p |
| 8 | property string icon: "" |
| 9 | property string text: "" |
| 10 | property color tint: Theme.fg |
| 11 | property color underline: "transparent" // old style, unused |
| 12 | property string icon2: "" |
| 13 | property color tint2: Theme.fg |
| 14 | property bool vertical: Theme.barVertical |
| 15 | default property alias extra: row.data |
| 16 | signal activated(int button) |
| 17 | signal activated2(int button) |
| 18 | signal scrolled(int dir) |
| 19 | |
| 20 | implicitWidth: vertical ? Theme.barSize : row.implicitWidth + 22 |
| 21 | implicitHeight: vertical ? row.implicitHeight + 16 : Theme.barSize |
| 22 | |
| 23 | Rectangle { |
| 24 | anchors.fill: parent |
| 25 | anchors.topMargin: p.vertical ? 0 : 5 |
| 26 | anchors.bottomMargin: p.vertical ? 0 : 5 |
| 27 | anchors.leftMargin: p.vertical ? 5 : 0 |
| 28 | anchors.rightMargin: p.vertical ? 5 : 0 |
| 29 | radius: Math.min(width, height) / 2 |
| 30 | color: m.containsMouse ? Theme.s2 : "transparent" |
| 31 | } |
| 32 | // a row, or a column in the vertical bar. Only `columns` flips (rows and columns both changing pass through 1x1 and |
| 33 | // warn), and it must match the shown items exactly: Grid leaves a gap for every empty column. |
| 34 | Grid { |
| 35 | id: row |
| 36 | anchors.centerIn: parent |
| 37 | columns: p.vertical ? 1 : Math.max(1, visibleChildren.length) |
| 38 | spacing: p.vertical ? 5 : 7 |
| 39 | horizontalItemAlignment: Grid.AlignHCenter |
| 40 | verticalItemAlignment: Grid.AlignVCenter |
| 41 | Icon { |
| 42 | visible: p.icon !== "" |
| 43 | text: p.icon |
| 44 | font.pixelSize: 16 |
| 45 | color: p.tint |
| 46 | } |
| 47 | Lb { |
| 48 | visible: p.text !== "" |
| 49 | text: p.text |
| 50 | px: 11 |
| 51 | color: p.tint |
| 52 | } |
| 53 | Icon { |
| 54 | id: second |
| 55 | visible: p.icon2 !== "" |
| 56 | text: p.icon2 |
| 57 | font.pixelSize: 16 |
| 58 | color: p.tint2 |
| 59 | } |
| 60 | } |
| 61 | MouseArea { |
| 62 | id: m |
| 63 | anchors.fill: parent |
| 64 | hoverEnabled: true |
| 65 | cursorShape: Qt.PointingHandCursor |
| 66 | acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton |
| 67 | onClicked: mouse => { |
| 68 | // split at the middle of the gap before the second icon |
| 69 | var at = p.vertical ? mouse.y - row.y - second.y : mouse.x - row.x - second.x |
| 70 | if (second.visible && at >= -row.spacing / 2) p.activated2(mouse.button) |
| 71 | else p.activated(mouse.button) |
| 72 | } |
| 73 | onWheel: w => p.scrolled(w.angleDelta.y > 0 ? 1 : -1) |
| 74 | } |
| 75 | } |