WindowSwitcher.qml 5.75 KB
Newer Older
1
2
3
4
5
6
/********************************************************************
 KWin - the KDE window manager
 This file is part of the KDE project.

Copyright (C) 2011 Martin Gräßlin <mgraesslin@kde.org>
Copyright (C) 2013 Marco Martin <mart@kde.org>
Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
7
Copyright (C) 2016 Kai Uwe Broulik <kde@privat.broulik.de>
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
import QtQuick 2.0
import QtQuick.Layouts 1.1
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
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
32
33
34
    readonly property real screenFactor: screenGeometry.width / screenGeometry.height

    currentIndex: thumbnailListView.currentIndex
35
36
37

    PlasmaCore.Dialog {
        id: dialog
38
        location: Qt.application.layoutDirection === Qt.RightToLeft ? PlasmaCore.Types.RightEdge : PlasmaCore.Types.LeftEdge
39
40
        visible: tabBox.visible
        flags: Qt.X11BypassWindowManagerHint
41
        x: screenGeometry.x + (Qt.application.layoutDirection === Qt.RightToLeft ? screenGeometry.width - width : 0)
42
43
44
45
46
47
48
        y: screenGeometry.y

        mainItem: PlasmaExtras.ScrollArea {
            id: dialogMainItem

            focus: true

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

52
53
54
            LayoutMirroring.enabled: Qt.application.layoutDirection === Qt.RightToLeft
            LayoutMirroring.childrenInherit: true

55
56
57
            ListView {
                id: thumbnailListView
                model: tabBox.model
Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
58
                spacing: units.smallSpacing
59
                highlightMoveDuration: 250
Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
60
                highlightResizeDuration: 0
61
62
63
64
65

                Connections {
                    target: tabBox
                    onCurrentIndexChanged: {
                        thumbnailListView.currentIndex = tabBox.currentIndex;
Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
66
                        thumbnailListView.positionViewAtIndex(thumbnailListView.currentIndex, ListView.Contain)
67
68
69
                    }
                }

Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
70
71
72
73
                delegate: MouseArea {
                    width: thumbnailListView.width
                    height: delegateColumn.implicitHeight + 2 * delegateColumn.y

74
75
76
77
78
79
80
                    onClicked: {
                        if (tabBox.noModifierGrab) {
                            tabBox.model.activate(index);
                        } else {
                            thumbnailListView.currentIndex = index;
                        }
                    }
Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
81
82
83
84
85
86
87
88
89

                    ColumnLayout {
                        id: delegateColumn
                        anchors.horizontalCenter: parent.horizontalCenter
                        // anchors.centerIn causes layouting glitches
                        y: units.smallSpacing
                        width: parent.width - 2 * units.smallSpacing
                        spacing: units.smallSpacing

90
91
92
93
                        focus: index == thumbnailListView.currentIndex
                        Accessible.name: model.caption
                        Accessible.role: Accessible.Client

Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
                        Item {
                            Layout.fillWidth: true
                            Layout.preferredHeight: Math.round(width / tabBox.screenFactor)

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

                        RowLayout {
                            spacing: units.smallSpacing
                            Layout.fillWidth: true

                            PlasmaCore.IconItem {
                                Layout.preferredHeight: units.iconSizes.medium
                                Layout.preferredWidth: units.iconSizes.medium
                                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
                            }
                        }
                    }
127
                }
Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
128
129

                highlight: PlasmaComponents.Highlight {}
130
            }
131
132
133
134
135
136
137

            /*
            * 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: {
138
139
140
141
                if (event.key === Qt.Key_Up) {
                    icons.decrementCurrentIndex();
                } else if (event.key === Qt.Key_Down) {
                    icons.incrementCurrentIndex();
142
                }
143
            }
144
        }
145
146
    }
}
147