ViewSelector.qml 3.54 KB
Newer Older
1
/*
Matthieu Gallien's avatar
Matthieu Gallien committed
2
3
4
   SPDX-FileCopyrightText: 2016 (c) Matthieu Gallien <matthieu_gallien@yahoo.fr>

   SPDX-License-Identifier: LGPL-3.0-or-later
5
6
 */

7
8
import QtQuick 2.11
import QtQuick.Controls 2.4
Alexander Stippich's avatar
Alexander Stippich committed
9
import QtQml.Models 2.2
10
import QtGraphicalEffects 1.0
11
import org.kde.kirigami 2.5 as Kirigami
12
13
import org.kde.elisa 1.0

14
15
FocusScope {
    id: rootFocusScope
16

17
    readonly property alias currentIndex: viewModeView.currentIndex
18
    property double textOpacity
19
    property alias model: pageDelegateModel.model
20

21
    signal switchView(int viewIndex)
22

23
24
25
26
27
28
29
    function setCurrentIndex(index)
    {
        viewModeView.ignoreCurrentItemChanges = true
        viewModeView.currentIndex = index
        viewModeView.ignoreCurrentItemChanges = false
    }

Alexander Stippich's avatar
Alexander Stippich committed
30
    implicitWidth: 225
31

32
33
    ListView {
        id: viewModeView
34

35
        anchors.fill: parent
36

37
        Accessible.role: Accessible.List
38

39
        focus: true
40

41
42
43
        activeFocusOnTab: true
        keyNavigationEnabled: true
        interactive: true
44

45
46
        ScrollBar.vertical: ScrollBar {
            id: scrollBar
47

48
            anchors.topMargin: Kirigami.Units.largeSpacing * 2
49

50
51
52
53
            policy: ScrollBar.AlwaysOn
            active: true
            interactive: true
        }
54

55
56
        boundsBehavior: Flickable.StopAtBounds
        clip: true
57

58
59
60
61
62
        ScrollHelper {
            id: scrollHelper
            flickable: viewModeView
            anchors.fill: viewModeView
        }
63

64
        property bool ignoreCurrentItemChanges: false
65

66
67
        model: DelegateModel {
            id: pageDelegateModel
68

69
70
            delegate: ViewSelectorDelegate {
                id: entry
71

72
                height: Kirigami.Units.iconSizes.smallMedium + 3 * Kirigami.Units.smallSpacing
73
                width: scrollBar.visible ? (!LayoutMirroring.enabled ? viewModeView.width - scrollBar.width : viewModeView.width) : viewModeView.width
74

75
76
77
                focus: true

                isSelected: viewModeView.currentIndex === index
78

79
80
81
82
83
84
85
86
87
88
                colorizeIcon: model.useColorOverlay
                image: model.image
                title: model.display
                secondTitle: model.secondTitle
                useSecondTitle: model.useSecondTitle
                databaseId: model.databaseId

                onClicked: {
                    viewModeView.currentIndex = index
                    entry.forceActiveFocus()
89
90
91
                }
            }
        }
92
93

        onCurrentItemChanged: if (!ignoreCurrentItemChanges) switchView(currentIndex)
94
    }
95
96

    Connections {
97
        target: ElisaApplication
98
99

        onInitializationDone: {
100
            viewModeView.currentIndex = 3
101
102
        }
    }
103
104
105

    Behavior on implicitWidth {
        NumberAnimation {
106
107
            easing.type: Easing.InOutQuad
            duration: Kirigami.Units.longDuration
108
109
110
111
112
        }
    }

    Behavior on width {
        NumberAnimation {
113
114
            easing.type: Easing.InOutQuad
            duration: Kirigami.Units.longDuration
115
116
117
118
119
120
        }
    }

    states: [
        State {
            name: 'iconsAndText'
121
            when: mainWindow.width >= elisaTheme.viewSelectorSmallSizeThreshold
122
123
124
            PropertyChanges {
                target: rootFocusScope
                textOpacity: 1
Alexander Stippich's avatar
Alexander Stippich committed
125
                implicitWidth: 225
126
127
128
129
            }
        },
        State {
            name: 'iconsOnly'
130
            when: mainWindow.width < elisaTheme.viewSelectorSmallSizeThreshold
131
132
133
            PropertyChanges {
                target: rootFocusScope
                textOpacity: 0
134
                implicitWidth: Kirigami.Units.iconSizes.smallMedium + 2 * Kirigami.Units.largeSpacing
135

136
137
138
            }
        }
    ]
139
}