| 1 |
/* |
| 2 |
* Audacity: A Digital Audio Editor |
| 3 |
*/ |
| 4 |
import QtQuick |
| 5 |
|
| 6 |
import Muse.Ui |
| 7 |
import Muse.UiComponents |
| 8 |
|
| 9 |
Item { |
| 10 |
id: root |
| 11 |
|
| 12 |
property alias text: labelItem.text |
| 13 |
property var contextMenuModel: null |
| 14 |
|
| 15 |
property bool selected: false |
| 16 |
|
| 17 |
property alias navigation: navCtrl |
| 18 |
|
| 19 |
signal handleMenuItem(var itemId) |
| 20 |
|
| 21 |
NavigationControl { |
| 22 |
id: navCtrl |
| 23 |
|
| 24 |
name: "SnapChooseItem" |
| 25 |
enabled: root.enabled && root.visible |
| 26 |
accessible.role: MUAccessible.ListItem |
| 27 |
accessible.name: root.text |
| 28 |
|
| 29 |
onActiveChanged: { |
| 30 |
if (!root.activeFocus) { |
| 31 |
root.forceActiveFocus() |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
onTriggered: root.clicked() |
| 36 |
} |
| 37 |
|
| 38 |
Rectangle { |
| 39 |
id: backgroundItem |
| 40 |
anchors.fill: parent |
| 41 |
|
| 42 |
NavigationFocusBorder { navigationCtrl: navCtrl } |
| 43 |
|
| 44 |
color: ui.theme.textFieldColor |
| 45 |
border.color: ui.theme.strokeColor |
| 46 |
border.width: Math.max(ui.theme.borderWidth, 1) |
| 47 |
radius: 3 |
| 48 |
} |
| 49 |
|
| 50 |
StyledTextLabel { |
| 51 |
id: labelItem |
| 52 |
|
| 53 |
anchors.left: parent.left |
| 54 |
anchors.leftMargin: 12 |
| 55 |
anchors.right: dropIconItem.left |
| 56 |
anchors.verticalCenter: parent.verticalCenter |
| 57 |
|
| 58 |
horizontalAlignment: Text.AlignLeft |
| 59 |
wrapMode: Text.Wrap |
| 60 |
maximumLineCount: 1 |
| 61 |
} |
| 62 |
|
| 63 |
MouseArea { |
| 64 |
id: mouseAreaItem |
| 65 |
anchors.fill: parent |
| 66 |
hoverEnabled: true |
| 67 |
|
| 68 |
onClicked: { |
| 69 |
menuLoader.toggleOpened(root.contextMenuModel) |
| 70 |
} |
| 71 |
|
| 72 |
onContainsMouseChanged: { |
| 73 |
if (!labelItem.truncated) { |
| 74 |
return |
| 75 |
} |
| 76 |
|
| 77 |
if (mouseArea.containsMouse) { |
| 78 |
ui.tooltip.show(root, labelItem.text) |
| 79 |
} else { |
| 80 |
ui.tooltip.hide(root) |
| 81 |
} |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
StyledIconLabel { |
| 86 |
id: dropIconItem |
| 87 |
anchors.verticalCenter: parent.verticalCenter |
| 88 |
anchors.right: parent.right |
| 89 |
anchors.rightMargin: 8 |
| 90 |
|
| 91 |
iconCode: IconCode.SMALL_ARROW_DOWN |
| 92 |
} |
| 93 |
|
| 94 |
states: [ |
| 95 |
State { |
| 96 |
name: "HOVERED" |
| 97 |
when: mouseAreaItem.containsMouse && !mouseAreaItem.pressed |
| 98 |
PropertyChanges { target: backgroundItem; border.color: Utils.colorWithAlpha(ui.theme.accentColor, 0.6) } |
| 99 |
}, |
| 100 |
|
| 101 |
State { |
| 102 |
name: "SELECTED" |
| 103 |
when: root.selected |
| 104 |
PropertyChanges { target: backgroundItem; border.color: ui.theme.accentColor } |
| 105 |
} |
| 106 |
] |
| 107 |
|
| 108 |
StyledMenuLoader { |
| 109 |
id: menuLoader |
| 110 |
|
| 111 |
onHandleMenuItem: function(itemId) { |
| 112 |
root.handleMenuItem(itemId) |
| 113 |
} |
| 114 |
} |
| 115 |
} |