Changeset View
Changeset View
Standalone View
Standalone View
src/controls/private/PrivateActionToolButton.qml
Show All 21 Lines | |||||
22 | import QtQuick.Controls 2.2 as Controls | 22 | import QtQuick.Controls 2.2 as Controls | ||
23 | import org.kde.kirigami 2.4 | 23 | import org.kde.kirigami 2.4 | ||
24 | 24 | | |||
25 | Controls.ToolButton { | 25 | Controls.ToolButton { | ||
26 | id: control | 26 | id: control | ||
27 | 27 | | |||
28 | signal menuAboutToShow | 28 | signal menuAboutToShow | ||
29 | 29 | | |||
30 | implicitWidth: menuArrow.visible || (showText && ( kirigamiAction ? kirigamiAction.text.length > 0 : text.length > 0)) | 30 | // implicitWidth: menuArrow.visible || (showText && ( action ? action.text.length > 0 : text.length > 0)) | ||
31 | ? Math.max(layout.implicitWidth + Units.largeSpacing*2, background.implicitWidth) | 31 | // ? background.implicitWidth + menuArrow.width | ||
32 | : implicitHeight | 32 | // : implicitHeight | ||
33 | implicitHeight: background.implicitHeight | 33 | // implicitHeight: background.implicitHeight | ||
34 | 34 | | |||
35 | Theme.colorSet: Theme.Button | 35 | // Theme.colorSet: Theme.Button | ||
36 | Theme.inherit: kirigamiAction && kirigamiAction.icon.color.a === 0 | 36 | // Theme.inherit: action && action.icon.color.a === 0 | ||
37 | Theme.backgroundColor: kirigamiAction && kirigamiAction.icon.color.a ? kirigamiAction.icon.color : undefined | 37 | | ||
38 | Theme.textColor: kirigamiAction && !flat && kirigamiAction.icon.color.a ? Theme.highlightedTextColor : undefined | 38 | | ||
39 | Theme.colorSet: checked && (control.action && control.action.icon.color.a) ? Theme.Selection : Theme.Button | ||||
40 | Theme.inherit: control.action && Theme.colorSet != Theme.Selection && control.action.icon.color.a === 0 | ||||
41 | Theme.backgroundColor: action && action.icon.color.a ? action.icon.color : undefined | ||||
42 | Theme.textColor: action && !flat && action.icon.color.a ? Theme.highlightedTextColor : undefined | ||||
39 | 43 | | |||
40 | hoverEnabled: true | 44 | hoverEnabled: true | ||
41 | flat: !control.kirigamiAction || !control.kirigamiAction.icon.color.a | 45 | flat: !control.action || !control.action.icon.color.a | ||
apol: Remove TODO? | |||||
42 | //TODO: replace with upstream action when we depend on Qt 5.10 | 46 | | ||
43 | property Action kirigamiAction | | |||
44 | property bool showText: true | 47 | property bool showText: true | ||
45 | property bool showMenuArrow: true | 48 | property bool showMenuArrow: true | ||
46 | property alias menu: menu | 49 | property alias menu: menu | ||
47 | 50 | | |||
48 | //we need our own text delegate | 51 | //we need our own text delegate | ||
49 | text: "" | 52 | display: control.showText ? Controls.ToolButton.TextBesideIcon : Controls.ToolButton.IconOnly | ||
50 | checkable: kirigamiAction && kirigamiAction.checkable | 53 | text: (action && action.text && action.text.length > 0) ? action.text : "" | ||
51 | checked: (kirigamiAction && kirigamiAction.checked) || menu.visible | 54 | checkable: action && action.checkable | ||
52 | enabled: kirigamiAction && kirigamiAction.enabled | 55 | checked: (action && action.checked) || menu.visible | ||
56 | enabled: action && action.enabled | ||||
53 | opacity: enabled ? 1 : 0.4 | 57 | opacity: enabled ? 1 : 0.4 | ||
54 | visible: kirigamiAction && kirigamiAction.visible | 58 | visible: action !== null && (!action.hasOwnProperty("visible") || action.visible) | ||
55 | onClicked: { | 59 | onClicked: { | ||
56 | if (kirigamiAction) { | 60 | | ||
57 | kirigamiAction.trigger(); | 61 | if (action.hasOwnProperty("children") && action.children.length > 0 && !menu.visible) { | ||
58 | } | | |||
59 | if (kirigamiAction.children.length > 0 && !menu.visible) { | | |||
60 | control.menuAboutToShow(); | 62 | control.menuAboutToShow(); | ||
61 | menu.popup(control, 0, control.height) | 63 | menu.popup(control, 0, control.height) | ||
62 | } | 64 | } | ||
63 | } | 65 | } | ||
64 | 66 | | |||
65 | ActionsMenu { | 67 | ActionsMenu { | ||
66 | id: menu | 68 | id: menu | ||
67 | y: control.height | 69 | y: control.height | ||
68 | actions: control.kirigamiAction ? control.kirigamiAction.children : null | 70 | actions: control.action && control.action.hasOwnProperty("children") ? control.action.children : null | ||
69 | submenuComponent: Component { | 71 | submenuComponent: Component { | ||
70 | ActionsMenu {} | 72 | ActionsMenu {} | ||
71 | } | 73 | } | ||
72 | } | 74 | } | ||
73 | 75 | | |||
74 | contentItem: MouseArea { | 76 | contentItem.anchors.rightMargin: menuArrow.visible ? Units.iconSizes.small : 0 | ||
apol: Wouldn't it be control.action.icon.name? | |||||
camiloh: yes. fixed now on new commit | |||||
75 | hoverEnabled: true | | |||
76 | onPressed: mouse.accepted = false | | |||
77 | Theme.colorSet: checked && (control.kirigamiAction && control.kirigamiAction.icon.color.a) ? Theme.Selection : control.Theme.colorSet | | |||
78 | Theme.inherit: control.kirigamiAction && Theme.colorSet != Theme.Selection && control.kirigamiAction.icon.color.a === 0 | | |||
79 | GridLayout { | | |||
80 | id: layout | | |||
81 | columns: control.display == Controls.ToolButton.TextUnderIcon ? 1 : 2 + (menuArrow.visible ? 1 : 0) | | |||
82 | rows: control.display == Controls.ToolButton.TextUnderIcon ? 2 : 1 | | |||
83 | 77 | | |||
84 | anchors.centerIn: parent | | |||
85 | Icon { | | |||
86 | id: mainIcon | | |||
87 | Layout.alignment: Qt.AlignCenter | | |||
88 | Layout.minimumWidth: Units.iconSizes.smallMedium | | |||
89 | Layout.minimumHeight: Units.iconSizes.smallMedium | | |||
90 | source: control.kirigamiAction ? (control.kirigamiAction.icon ? control.kirigamiAction.icon.name : control.kirigamiAction.iconName) : "" | | |||
91 | visible: control.kirigamiAction && control.kirigamiAction.iconName != "" && control.display != Controls.ToolButton.TextOnly | | |||
92 | color: control.flat && control.kirigamiAction && control.kirigamiAction.icon && control.kirigamiAction.icon.color.a > 0 ? control.kirigamiAction.icon.color : label.color | | |||
93 | } | | |||
94 | Controls.Label { | | |||
95 | id: label | | |||
96 | MnemonicData.enabled: control.enabled | | |||
97 | MnemonicData.controlType: MnemonicData.ActionElement | | |||
98 | MnemonicData.label: control.kirigamiAction ? control.kirigamiAction.text : "" | | |||
99 | | ||||
100 | text: MnemonicData.richTextLabel | | |||
101 | visible: control.showText && text.length > 0 && control.display != Controls.ToolButton.IconOnly | | |||
102 | | ||||
103 | Shortcut { | | |||
104 | sequence: label.MnemonicData.sequence | | |||
105 | onActivated: control.clicked() | | |||
106 | } | | |||
107 | } | | |||
108 | Icon { | 78 | Icon { | ||
109 | id: menuArrow | 79 | id: menuArrow | ||
110 | Layout.minimumWidth: Units.iconSizes.small | 80 | anchors.left: control.right | ||
111 | Layout.minimumHeight: Units.iconSizes.small | 81 | anchors.verticalCenter: control.verticalCenter | ||
112 | color: mainIcon.color | 82 | color: control.icon.color | ||
113 | source: "arrow-down" | 83 | source: "arrow-down" | ||
84 | height: Units.iconSizes.small | ||||
85 | width: height | ||||
114 | visible: showMenuArrow && menu.actions && menu.actions.length > 0 | 86 | visible: showMenuArrow && menu.actions && menu.actions.length > 0 | ||
115 | } | 87 | } | ||
116 | } | 88 | | ||
117 | } | 89 | | ||
90 | | ||||
91 | // contentItem: MouseArea { | ||||
92 | // hoverEnabled: true | ||||
93 | // onPressed: mouse.accepted = false | ||||
94 | // Theme.colorSet: checked && (control.action && control.action.icon.color.a) ? Theme.Selection : control.Theme.colorSet | ||||
95 | // Theme.inherit: control.action && Theme.colorSet != Theme.Selection && control.action.icon.color.a === 0 | ||||
96 | // GridLayout { | ||||
97 | // id: layout | ||||
98 | // columns: control.display == Controls.ToolButton.TextUnderIcon ? 1 : 2 + (menuArrow.visible ? 1 : 0) | ||||
99 | // rows: control.display == Controls.ToolButton.TextUnderIcon ? 2 : 1 | ||||
100 | // | ||||
101 | // anchors.centerIn: parent | ||||
102 | // Icon { | ||||
103 | // id: mainIcon | ||||
104 | // Layout.alignment: Qt.AlignCenter | ||||
105 | // Layout.minimumWidth: Units.iconSizes.smallMedium | ||||
106 | // Layout.minimumHeight: Units.iconSizes.smallMedium | ||||
107 | // source: control.action ? (control.action.icon ? control.action.icon.name : control.action.iconName) : "" | ||||
108 | // visible: control.action && control.action.iconName != "" && control.display != Controls.ToolButton.TextOnly | ||||
109 | // color: control.flat && control.action && control.action.icon && control.action.icon.color.a > 0 ? control.action.icon.color : label.color | ||||
110 | // } | ||||
111 | // Controls.Label { | ||||
112 | // id: label | ||||
113 | // MnemonicData.enabled: control.enabled | ||||
114 | // MnemonicData.controlType: MnemonicData.ActionElement | ||||
115 | // MnemonicData.label: control.action ? control.action.text : "" | ||||
116 | // | ||||
117 | // text: MnemonicData.richTextLabel | ||||
118 | // visible: control.showText && text.length > 0 && control.display != Controls.ToolButton.IconOnly | ||||
119 | // | ||||
120 | // Shortcut { | ||||
121 | // sequence: label.MnemonicData.sequence | ||||
122 | // onActivated: control.clicked() | ||||
123 | // } | ||||
124 | // } | ||||
125 | // | ||||
126 | // } | ||||
127 | // } | ||||
118 | Controls.ToolTip { | 128 | Controls.ToolTip { | ||
119 | visible: control.hovered && text.length > 0 && !menu.visible && !control.pressed | 129 | visible: control.hovered && text.length > 0 && !menu.visible && !control.pressed | ||
120 | text: kirigamiAction ? (kirigamiAction.tooltip.length ? kirigamiAction.tooltip : kirigamiAction.text) : "" | 130 | text: action && action.hasOwnProperty("tooltip") ? (action.tooltip.length ? action.tooltip : action.text) : "" | ||
121 | delay: Units.toolTipDelay | 131 | delay: Units.toolTipDelay | ||
122 | timeout: 5000 | 132 | timeout: 5000 | ||
123 | y: control.height | 133 | y: control.height | ||
124 | } | 134 | } | ||
135 | | ||||
136 | // background : null //now the button icon is drawn by the conteniTem and the style background | ||||
125 | } | 137 | } |
Remove TODO?