Changeset View
Changeset View
Standalone View
Standalone View
src/controls/private/PrivateActionToolButton.qml
Show All 11 Lines | |||||
12 | * GNU Library General Public License for more details | 12 | * GNU Library General Public License for more details | ||
13 | * | 13 | * | ||
14 | * You should have received a copy of the GNU Library General Public | 14 | * You should have received a copy of the GNU Library General Public | ||
15 | * License along with this program; if not, write to the | 15 | * License along with this program; if not, write to the | ||
16 | * Free Software Foundation, Inc., | 16 | * Free Software Foundation, Inc., | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | import QtQuick 2.6 | 20 | import QtQuick 2.7 | ||
21 | import QtQuick.Layouts 1.2 | 21 | import QtQuick.Layouts 1.2 | ||
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 | ||
apol: Remove TODO? | |||||
apol: Wouldn't it be control.action.icon.name? | |||||
camiloh: yes. fixed now on new commit | |||||
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 && ( kirigamiAction ? kirigamiAction.text.length > 0 : text.length > 0)) | ||
31 | ? Math.max(layout.implicitWidth + Units.largeSpacing*2, background.implicitWidth) | 31 | ? Math.max(layout.implicitWidth + Units.largeSpacing*2, background.implicitWidth) | ||
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: kirigamiAction && kirigamiAction.icon.color.a === 0 | ||
37 | Theme.backgroundColor: kirigamiAction && kirigamiAction.icon.color.a ? kirigamiAction.icon.color : undefined | 37 | Theme.backgroundColor: kirigamiAction && kirigamiAction.icon.color.a ? kirigamiAction.icon.color : undefined | ||
38 | Theme.textColor: kirigamiAction && !flat && kirigamiAction.icon.color.a ? Theme.highlightedTextColor : undefined | 38 | Theme.textColor: kirigamiAction && !flat && kirigamiAction.icon.color.a ? Theme.highlightedTextColor : undefined | ||
39 | 39 | | |||
40 | hoverEnabled: true | 40 | hoverEnabled: true | ||
41 | flat: !control.kirigamiAction || !control.kirigamiAction.icon.color.a | 41 | flat: !control.kirigamiAction || !control.kirigamiAction.icon.color.a | ||
42 | //TODO: replace with upstream action when we depend on Qt 5.10 | 42 | //TODO: replace with upstream action when we depend on Qt 5.10 | ||
43 | property Action kirigamiAction | 43 | property QtObject kirigamiAction | ||
44 | property bool showText: true | 44 | property bool showText: true | ||
45 | property bool showMenuArrow: true | 45 | property bool showMenuArrow: true | ||
46 | property alias menu: menu | 46 | property alias menu: menu | ||
47 | 47 | | |||
48 | //we need our own text delegate | 48 | //we need our own text delegate | ||
49 | text: "" | 49 | text: "" | ||
50 | checkable: kirigamiAction && kirigamiAction.checkable | 50 | checkable: kirigamiAction && kirigamiAction.checkable | ||
51 | checked: (kirigamiAction && kirigamiAction.checked) || menu.visible | 51 | checked: (kirigamiAction && kirigamiAction.checked) || menu.visible | ||
52 | enabled: kirigamiAction && kirigamiAction.enabled | 52 | enabled: kirigamiAction && kirigamiAction.enabled | ||
53 | opacity: enabled ? 1 : 0.4 | 53 | opacity: enabled ? 1 : 0.4 | ||
54 | visible: kirigamiAction && kirigamiAction.visible | 54 | visible: kirigamiAction && kirigamiAction.visible | ||
55 | onClicked: { | 55 | onClicked: { | ||
56 | | ||||
57 | console.log(kirigamiAction.text) | ||||
56 | if (kirigamiAction) { | 58 | if (kirigamiAction) { | ||
57 | kirigamiAction.trigger(); | 59 | kirigamiAction.trigger(); | ||
58 | } | 60 | } | ||
59 | if (kirigamiAction.children.length > 0 && !menu.visible) { | 61 | if (kirigamiAction.hasOwnProperty("children") && 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.kirigamiAction && kirigamiAction.hasOwnProperty("children") ? control.kirigamiAction.children : null | ||
69 | submenuComponent: Component { | 71 | submenuComponent: Component { | ||
70 | ActionsMenu {} | 72 | ActionsMenu {} | ||
71 | } | 73 | } | ||
72 | } | 74 | } | ||
73 | 75 | | |||
74 | contentItem: MouseArea { | 76 | contentItem: MouseArea { | ||
75 | hoverEnabled: true | 77 | hoverEnabled: true | ||
76 | onPressed: mouse.accepted = false | 78 | onPressed: mouse.accepted = false | ||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |
Remove TODO?