~zsombi/ubuntu-ui-toolkit/listitemSelectModeBugs

« back to all changes in this revision

Viewing changes to src/Ubuntu/Components/Themes/Ambiance/1.3/ActionBarStyle.qml

  • Committer: Zsombor Egri
  • Date: 2015-11-16 06:35:05 UTC
  • mfrom: (1664.1.1 listitemSelectModeBugs)
  • Revision ID: zsombor.egri@canonical.com-20151116063505-cwn2qfks7qzk10g9
re-sync

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
import QtQuick 2.4
17
17
import Ubuntu.Components 1.3
18
18
import Ubuntu.Components.Popups 1.3
 
19
import Ubuntu.Components.Styles 1.3 as Style
19
20
 
20
 
Item {
 
21
Style.ActionBarStyle {
21
22
    id: actionBarStyle
22
23
    implicitWidth: actionsContainer.implicitWidth
23
24
    implicitHeight: units.gu(5)
24
25
 
25
 
    // FIXME: Add color and label configuration properties or make
26
 
    //  the action delegates configurable.
 
26
    overflowIconName: "contextual-menu"
 
27
 
 
28
    // Unused with the standard action icon buttons, but may be used with a custom delegate.
 
29
    overflowText: "More"
 
30
 
 
31
    /*!
 
32
      The default action delegate if the styled item does
 
33
      not provide a delegate.
 
34
     */
 
35
    defaultDelegate: AbstractButton {
 
36
        style: IconButtonStyle { }
 
37
        objectName: action.objectName + "_button"
 
38
        height: parent ? parent.height : undefined
 
39
        action: modelData
 
40
    }
 
41
 
 
42
    defaultNumberOfSlots: 3
27
43
 
28
44
    Row {
29
45
        id: actionsContainer
39
55
            }
40
56
            return visibleActionList;
41
57
        }
 
58
        property var barActions: overflowAction.visible
 
59
                                 ? visibleActions.slice(0, numberOfSlots.used).concat(overflowAction)
 
60
                                 : visibleActions.slice(0, numberOfSlots.used)
 
61
        property var overflowActions: visibleActions.slice(numberOfSlots.used,
 
62
                                                           numberOfSlots.requested)
42
63
 
43
64
        QtObject {
44
65
            id: numberOfSlots
45
66
            property int requested: actionsContainer.visibleActions.length
46
67
            property int available: styledItem.numberOfSlots
47
 
            property int overflow: actionsOverflowButton.visible ? 1 : 0
 
68
            property int overflow: overflowAction.visible ? 1 : 0
48
69
            // when numberOfSlots < 1, show the overflow button, but set used
49
70
            // to 0 so that all actions will appear in the overflow panel.
50
71
            property int used: Math.min(Math.max(0, available - overflow), requested)
56
77
        }
57
78
 
58
79
        Repeater {
 
80
            id: actionsRepeater
59
81
            objectName: "actions_repeater"
60
 
            model: numberOfSlots.used
61
 
            AbstractButton {
62
 
                style: IconButtonStyle { }
63
 
                id: actionButton
64
 
                objectName: action.objectName + "_action_button"
65
 
                height: actionsContainer.height
66
 
                action: actionsContainer.visibleActions[index]
67
 
            }
 
82
            model: actionsContainer.barActions
 
83
            delegate: styledItem.delegate
68
84
        }
69
85
 
70
 
        AbstractButton {
71
 
            style: IconButtonStyle { }
72
 
            id: actionsOverflowButton
73
 
            objectName: "actions_overflow_button"
74
 
            height: actionsContainer.height
 
86
        Action {
 
87
            id: overflowAction
 
88
            iconSource: actionBarStyle.overflowIconSource
 
89
            iconName: actionBarStyle.overflowIconName
 
90
            text: actionBarStyle.overflowText
 
91
            objectName: "overflow_action"
75
92
            visible: numberOfSlots.requested > numberOfSlots.available
76
 
 
77
 
            // Ensure resetting of X when this button is not visible to avoid
78
 
            // miscalculation of actionsContainer.width. Fixes bug #1408481.
79
 
            onVisibleChanged: if (!visible) x = 0
80
 
            iconName: "contextual-menu"
81
 
            onTriggered: PopupUtils.open(actionsOverflowPopoverComponent, actionsOverflowButton)
82
 
 
83
 
            Component {
84
 
                id: actionsOverflowPopoverComponent
85
 
 
86
 
                OverflowPanel {
87
 
                    id: actionsOverflowPopover
88
 
                    objectName: "actions_overflow_panel"
89
 
 
90
 
                    // Ensure the popover closes when actions change and
91
 
                    // the list item below may be destroyed before its
92
 
                    // onClicked is executed. See bug
93
 
                    // https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1326963
94
 
                    Connections {
95
 
                        target: styledItem
96
 
                        onActionsChanged: {
97
 
                            actionsOverflowPopover.hide();
98
 
                        }
 
93
            onTriggered: {
 
94
                var overflowButton = actionsRepeater.itemAt(actionsRepeater.count - 1);
 
95
                PopupUtils.open(actionsOverflowPopoverComponent, overflowButton);
 
96
            }
 
97
        }
 
98
 
 
99
        Component {
 
100
            id: actionsOverflowPopoverComponent
 
101
            OverflowPanel {
 
102
                id: actionsOverflowPopover
 
103
                objectName: "actions_overflow_panel"
 
104
 
 
105
                // Ensure the popover closes when actions change and
 
106
                // the list item below may be destroyed before its
 
107
                // onClicked is executed. See bug
 
108
                // https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1326963
 
109
                Connections {
 
110
                    target: styledItem
 
111
                    onActionsChanged: {
 
112
                        actionsOverflowPopover.hide();
99
113
                    }
100
 
 
101
 
                    actions: actionsContainer.visibleActions.slice(numberOfSlots.used,
102
 
                                                                   numberOfSlots.requested)
103
114
                }
 
115
                actions: actionsContainer.overflowActions
104
116
            }
105
117
        }
106
118
    }