WindowSwitcher.qml 5.16 KB
Newer Older
1
/*
2
3
4
    SPDX-FileCopyrightText: 2011 Martin Gräßlin <mgraesslin@kde.org>
    SPDX-FileCopyrightText: 2013 Marco Martin <mart@kde.org>
    SPDX-FileCopyrightText: 2016 Kai Uwe Broulik <kde@privat.broulik.de>
5

6
    SPDX-License-Identifier: GPL-2.0-or-later
7
*/
8
9
10
import QtQuick 2.0
import QtQuick.Layouts 1.1
import org.kde.plasma.core 2.0 as PlasmaCore
11
import org.kde.plasma.components 2.0 as PlasmaComponents // for Highlight
12
13
14
15
16
17
import org.kde.plasma.extras 2.0 as PlasmaExtras
import org.kde.kwin 2.0 as KWin

KWin.Switcher {
    id: tabBox

Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
18
19
20
    readonly property real screenFactor: screenGeometry.width / screenGeometry.height

    currentIndex: thumbnailListView.currentIndex
21
22
23

    PlasmaCore.Dialog {
        id: dialog
24
        location: Qt.application.layoutDirection === Qt.RightToLeft ? PlasmaCore.Types.RightEdge : PlasmaCore.Types.LeftEdge
25
26
        visible: tabBox.visible
        flags: Qt.X11BypassWindowManagerHint
27
        x: screenGeometry.x + (Qt.application.layoutDirection === Qt.RightToLeft ? screenGeometry.width - width : 0)
28
29
30
31
32
33
34
        y: screenGeometry.y

        mainItem: PlasmaExtras.ScrollArea {
            id: dialogMainItem

            focus: true

Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
35
36
37
            width: tabBox.screenGeometry.width * 0.15 + (__verticalScrollBar.visible ? __verticalScrollBar.width : 0)
            height: tabBox.screenGeometry.height - dialog.margins.top - dialog.margins.bottom

38
39
40
            LayoutMirroring.enabled: Qt.application.layoutDirection === Qt.RightToLeft
            LayoutMirroring.childrenInherit: true

41
42
43
            ListView {
                id: thumbnailListView
                model: tabBox.model
Nate Graham's avatar
Nate Graham committed
44
                spacing: PlasmaCore.Units.smallSpacing
45
                highlightMoveDuration: PlasmaCore.Units.longDuration
Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
46
                highlightResizeDuration: 0
47
48
49

                Connections {
                    target: tabBox
Konrad Materka's avatar
Konrad Materka committed
50
                    function onCurrentIndexChanged() {
51
                        thumbnailListView.currentIndex = tabBox.currentIndex;
Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
52
                        thumbnailListView.positionViewAtIndex(thumbnailListView.currentIndex, ListView.Contain)
53
54
55
                    }
                }

Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
56
57
                delegate: MouseArea {
                    width: thumbnailListView.width
58
                    height: delegateColumn.height + 2 * delegateColumn.y
Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
59

60
61
62
63
64
65
66
                    onClicked: {
                        if (tabBox.noModifierGrab) {
                            tabBox.model.activate(index);
                        } else {
                            thumbnailListView.currentIndex = index;
                        }
                    }
Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
67
68
69
70
71

                    ColumnLayout {
                        id: delegateColumn
                        anchors.horizontalCenter: parent.horizontalCenter
                        // anchors.centerIn causes layouting glitches
Nate Graham's avatar
Nate Graham committed
72
73
74
                        y: PlasmaCore.Units.smallSpacing
                        width: parent.width - 2 * PlasmaCore.Units.smallSpacing
                        spacing: PlasmaCore.Units.smallSpacing
Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
75

76
77
78
79
                        focus: index == thumbnailListView.currentIndex
                        Accessible.name: model.caption
                        Accessible.role: Accessible.Client

Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
80
81
                        Item {
                            Layout.fillWidth: true
82
                            implicitHeight: Math.round(delegateColumn.width / tabBox.screenFactor)
Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
83
84
85
86
87
88
89
90

                            KWin.ThumbnailItem {
                                anchors.fill: parent
                                wId: windowId
                            }
                        }

                        RowLayout {
Nate Graham's avatar
Nate Graham committed
91
                            spacing: PlasmaCore.Units.smallSpacing
Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
92
93
94
                            Layout.fillWidth: true

                            PlasmaCore.IconItem {
Nate Graham's avatar
Nate Graham committed
95
96
                                Layout.preferredHeight: PlasmaCore.Units.iconSizes.medium
                                Layout.preferredWidth: PlasmaCore.Units.iconSizes.medium
Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
                                source: model.icon
                                usesPlasmaTheme: false
                            }

                            PlasmaExtras.Heading {
                                Layout.fillWidth: true
                                height: undefined
                                level: 4
                                text: model.caption
                                elide: Text.ElideRight
                                wrapMode: Text.WrapAtWordBoundaryOrAnywhere
                                maximumLineCount: 2
                                lineHeight: 0.95
                            }
                        }
                    }
113
                }
Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
114
115

                highlight: PlasmaComponents.Highlight {}
116
            }
117
118
119
120
121
122
123

            /*
            * Key navigation on outer item for two reasons:
            * @li we have to emit the change signal
            * @li on multiple invocation it does not work on the list view. Focus seems to be lost.
            **/
            Keys.onPressed: {
124
125
126
127
                if (event.key === Qt.Key_Up) {
                    icons.decrementCurrentIndex();
                } else if (event.key === Qt.Key_Down) {
                    icons.incrementCurrentIndex();
128
                }
129
            }
130
        }
131
132
    }
}
133