WindowSwitcher.qml 6.16 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/********************************************************************
 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>

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.kquickcontrolsaddons 2.0
import org.kde.kwin 2.0 as KWin

KWin.Switcher {
    id: tabBox
    property real screenFactor: screenGeometry.width/screenGeometry.height
    currentIndex: thumbnailListView.currentIndex

    // just to get the margin sizes
    PlasmaCore.FrameSvgItem {
        id: hoverItem
        imagePath: "widgets/viewitem"
        prefix: "hover"
        visible: false
    }

    PlasmaCore.Dialog {
        id: dialog
        location: PlasmaCore.Types.Floating
        visible: tabBox.visible
        flags: Qt.X11BypassWindowManagerHint
        x: screenGeometry.x
        y: screenGeometry.y

        mainItem: PlasmaExtras.ScrollArea {
            id: dialogMainItem

            property bool canStretchX: false
            property bool canStretchY: false
55
            width: tabBox.screenGeometry.width * 0.15 + (__verticalScrollBar.visible ? __verticalScrollBar.width : 0)
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
            height: tabBox.screenGeometry.height
            clip: true
            focus: true

            ListView {
                id: thumbnailListView
                orientation: ListView.Vertical
                model: tabBox.model
                anchors.fill: parent
                property int delegateWidth: thumbnailListView.width
                spacing: 5
                highlightMoveDuration: 250

                clip: true
                delegate: Item {
                    id: delegateItem
                    width: thumbnailListView.delegateWidth
                    height: Math.round(thumbnailItem.height + label.height + 30)
                    Item {
                        id: thumbnailItem
                        width: parent.width - hoverItem.margins.left - hoverItem.margins.right
                        height: Math.round(thumbnailListView.delegateWidth*(1.0/screenFactor) - hoverItem.margins.top)
                        anchors {
                            top: parent.top
                            left: parent.left
                            leftMargin: hoverItem.margins.left
                            rightMargin: hoverItem.margins.right
                            topMargin: hoverItem.margins.top
                        }
                        KWin.ThumbnailItem {
                            wId: windowId
                            anchors.fill: parent
                        }
                    }
                    RowLayout {
                        id: label
                        spacing: 4

                        anchors {
                            left: parent.left
                            right: parent.right
                            bottom: parent.bottom
                            leftMargin: hoverItem.margins.left
                            rightMargin: hoverItem.margins.right
                            bottomMargin: hoverItem.margins.bottom
                        }
                        QIconItem {
                            id: iconItem
                            icon: model.icon
                            property int iconSize: 32
                            width: iconSize
                            height: iconSize
                            Layout.preferredHeight: iconSize
                            Layout.preferredWidth: iconSize
                        }
                        PlasmaComponents.Label {
                            text: model.caption
                            elide: Text.ElideMiddle

                            Layout.fillWidth: true
                            Layout.maximumWidth: label.maximumWidth - iconItem.iconSize - label.spacing * 2
                        }
                    }
                    MouseArea {
                        anchors.fill: parent
                        onClicked: {
                            thumbnailListView.currentIndex = index;
                        }
                    }
                }
                highlight: PlasmaCore.FrameSvgItem {
                    id: highlightItem
                    imagePath: "widgets/viewitem"
                    prefix: "hover"
                    width: thumbnailListView.currentItem.width
                    height: thumbnailListView.currentItem.height
                }
                boundsBehavior: Flickable.StopAtBounds
                Connections {
                    target: tabBox
                    onCurrentIndexChanged: {
                        thumbnailListView.currentIndex = tabBox.currentIndex;
                        thumbnailListView.positionViewAtIndex(thumbnailListView.currentIndex, ListView.Contain);
                    }
                }
            }

            /*
            * 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: {
                if (event.key == Qt.Key_Up) {
                    thumbnailListView.decrementCurrentIndex();
                } else if (event.key == Qt.Key_Down) {
                    thumbnailListView.incrementCurrentIndex();
                }
            }
        }
    }
}
158