| 1 |
// SPDX-License-Identifier: GPL-3.0-or-later |
| 2 |
// Copyright 2019 Juan Palacios <[email protected]> |
| 3 |
|
| 4 |
import QtQuick 2.15 |
| 5 |
import QtQuick.Controls 2.15 |
| 6 |
import QtQuick.Layouts 1.15 |
| 7 |
import "Style.js" as Style |
| 8 |
|
| 9 |
Pane { |
| 10 |
id: btn |
| 11 |
|
| 12 |
property alias label: btnText.text |
| 13 |
property string name: "" |
| 14 |
property alias icon : icn.source |
| 15 |
property string exe: "" |
| 16 |
property bool isGlobal: false |
| 17 |
property bool profileActivated: true |
| 18 |
property alias toggledManual: manualSwc.checked |
| 19 |
|
| 20 |
implicitWidth: 240 |
| 21 |
implicitHeight: 60 |
| 22 |
|
| 23 |
padding: 0 |
| 24 |
|
| 25 |
signal clicked() |
| 26 |
signal enableProfile(bool enable) |
| 27 |
signal toggleManualProfile(string name) |
| 28 |
signal edit() |
| 29 |
signal clone() |
| 30 |
signal exportTo() |
| 31 |
signal remove() |
| 32 |
|
| 33 |
ToolTip.delay: Style.ToolTip.delay |
| 34 |
ToolTip.timeout: Style.ToolTip.timeout |
| 35 |
ToolTip.visible: hovered |
| 36 |
ToolTip.text: label |
| 37 |
|
| 38 |
MouseArea { |
| 39 |
anchors.fill: parent |
| 40 |
propagateComposedEvents: true |
| 41 |
onClicked: mouse => btn.clicked() |
| 42 |
} |
| 43 |
|
| 44 |
background: Rectangle { |
| 45 |
color: btn.hovered ? Style.RectItem.background_hover |
| 46 |
: btn.profileActivated ? Style.RectItem.background |
| 47 |
: Style.RectItem.background_alt |
| 48 |
} |
| 49 |
|
| 50 |
RowLayout { |
| 51 |
anchors.fill: parent |
| 52 |
spacing: 0 |
| 53 |
|
| 54 |
Item { |
| 55 |
Layout.fillHeight: true |
| 56 |
Layout.alignment: Qt.AlignLeft |
| 57 |
Layout.leftMargin: Style.RectItem.padding |
| 58 |
|
| 59 |
width: icn.width |
| 60 |
height: icn.height |
| 61 |
|
| 62 |
Image { |
| 63 |
id: icn |
| 64 |
cache: false |
| 65 |
anchors.centerIn: parent |
| 66 |
fillMode: Image.PreserveAspectFit |
| 67 |
width: Style.g_icon.size |
| 68 |
height: Style.g_icon.size |
| 69 |
sourceSize.width: Style.g_icon.source_size |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
Item { |
| 74 |
Layout.fillWidth: true |
| 75 |
Layout.fillHeight: true |
| 76 |
Layout.leftMargin: 10 |
| 77 |
|
| 78 |
Label { |
| 79 |
id: btnText |
| 80 |
|
| 81 |
width: parent.width |
| 82 |
anchors.centerIn: parent |
| 83 |
|
| 84 |
elide: Text.ElideRight |
| 85 |
wrapMode: Text.WordWrap |
| 86 |
|
| 87 |
color: btn.profileActivated ? |
| 88 |
Style.RectItem.text_color : |
| 89 |
Style.RectItem.text_color_alt |
| 90 |
|
| 91 |
onTextChanged: { |
| 92 |
if (parent.height > 0) { |
| 93 |
height = parent.height |
| 94 |
height = Math.min(contentHeight, height) |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
onContentSizeChanged: { |
| 99 |
// set height dynamically, to obtain centered wrapped and unwrapped text |
| 100 |
if (parent.height > 0) |
| 101 |
height = Math.min(contentHeight, parent.height) |
| 102 |
} |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
Switch { |
| 107 |
id: manualSwc |
| 108 |
visible: exe.length == 0 |
| 109 |
|
| 110 |
padding: 0 |
| 111 |
rotation: -90 |
| 112 |
scale: Style.g_tweakScale |
| 113 |
|
| 114 |
Layout.fillHeight: true |
| 115 |
Layout.alignment: Qt.AlignRight |
| 116 |
Layout.preferredWidth: 30 |
| 117 |
|
| 118 |
onToggled: btn.toggleManualProfile(name) |
| 119 |
} |
| 120 |
|
| 121 |
ToolButton { |
| 122 |
id: editBtn |
| 123 |
|
| 124 |
text: Style.g_icon.MENU; |
| 125 |
font.pointSize: Style.g_text.icon_size |
| 126 |
|
| 127 |
Layout.fillHeight: true |
| 128 |
Layout.alignment: Qt.AlignRight |
| 129 |
Layout.preferredWidth: 30 |
| 130 |
|
| 131 |
onClicked: menu.open() |
| 132 |
|
| 133 |
Menu { |
| 134 |
id: menu |
| 135 |
background: Rectangle { |
| 136 |
implicitWidth: 200 |
| 137 |
implicitHeight: 40 |
| 138 |
color: Style.Menu.background |
| 139 |
} |
| 140 |
|
| 141 |
MenuItem { |
| 142 |
text: btn.profileActivated ? qsTr("Disable") : qsTr("Enable") |
| 143 |
enabled: !isGlobal && exe.length > 0 |
| 144 |
onTriggered: btn.enableProfile(!btn.profileActivated) |
| 145 |
} |
| 146 |
|
| 147 |
MenuItem { |
| 148 |
text: qsTr("Edit...") |
| 149 |
enabled: !isGlobal |
| 150 |
onTriggered: btn.edit() |
| 151 |
} |
| 152 |
|
| 153 |
MenuItem { |
| 154 |
text: qsTr("Clone...") |
| 155 |
onTriggered: btn.clone() |
| 156 |
} |
| 157 |
|
| 158 |
MenuItem { |
| 159 |
text: qsTr("Export to...") |
| 160 |
onTriggered: btn.exportTo() |
| 161 |
} |
| 162 |
|
| 163 |
MenuSeparator {} |
| 164 |
|
| 165 |
MenuItem { |
| 166 |
text: qsTr("Remove") |
| 167 |
enabled: !isGlobal |
| 168 |
onTriggered: btn.remove() |
| 169 |
} |
| 170 |
} |
| 171 |
} |
| 172 |
} |
| 173 |
} |