KWin
Loading...
Searching...
No Matches
layoutpreview.h
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2009, 2011 Martin Gräßlin <mgraesslin@kde.org>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9#pragma once
10
11#include <QAbstractListModel>
12#include <QQuickView>
13#include <QRect>
14
15#include "thumbnailitem.h"
16
17namespace KWin
18{
19
20namespace TabBox
21{
22
23class SwitcherItem;
24
25class LayoutPreview : public QObject
26{
27 Q_OBJECT
28public:
29 explicit LayoutPreview(const QString &path, bool showDesktopThumbnail = false, QObject *parent = nullptr);
30 ~LayoutPreview() override;
31
32 bool eventFilter(QObject *object, QEvent *event) override;
33
34private:
35 SwitcherItem *m_item;
36};
37
38class ExampleClientModel : public QAbstractListModel
39{
40 Q_OBJECT
41public:
42 enum {
43 CaptionRole = Qt::UserRole + 1,
49 };
50
51 explicit ExampleClientModel(QObject *parent = nullptr);
52 ~ExampleClientModel() override;
53
54 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
55 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
56 QHash<int, QByteArray> roleNames() const override;
57 Q_INVOKABLE QString longestCaption() const;
58
59 void showDesktopThumbnail(bool showDesktop);
60
61private:
62 struct ThumbnailInfo
63 {
65 QString caption;
66 QString icon;
67
68 bool operator==(const ThumbnailInfo &other) const
69 {
70 return wId == other.wId;
71 }
72 };
73
74 void init();
75 QList<ThumbnailInfo> m_thumbnails;
76};
77
78class SwitcherItem : public QObject
79{
80 Q_OBJECT
81 Q_PROPERTY(QAbstractItemModel *model READ model NOTIFY modelChanged)
83 Q_PROPERTY(bool visible READ isVisible NOTIFY visibleChanged)
84 Q_PROPERTY(bool allDesktops READ isAllDesktops NOTIFY allDesktopsChanged)
86
90 Q_PROPERTY(QObject *item READ item WRITE setItem NOTIFY itemChanged)
91
92 Q_CLASSINFO("DefaultProperty", "item")
93public:
94 SwitcherItem(QObject *parent = nullptr);
95 ~SwitcherItem() override;
96
97 QAbstractItemModel *model() const;
98 QRect screenGeometry() const;
99 bool isVisible() const;
100 bool isAllDesktops() const;
101 int currentIndex() const;
102 void setCurrentIndex(int index);
103 QObject *item() const;
104 void setItem(QObject *item);
105
106 void setVisible(bool visible);
107 void incrementIndex();
108 void decrementIndex();
109
110Q_SIGNALS:
112 void currentIndexChanged(int index);
117
120
121private:
122 QAbstractItemModel *m_model;
123 QObject *m_item;
124 int m_currentIndex;
125 bool m_visible;
126};
127
128inline QAbstractItemModel *SwitcherItem::model() const
129{
130 return m_model;
131}
132
133inline bool SwitcherItem::isVisible() const
134{
135 return m_visible;
136}
137
139{
140 return true;
141}
142
144{
145 return m_currentIndex;
146}
147
148inline QObject *SwitcherItem::item() const
149{
150 return m_item;
151}
152
154{
155 Q_OBJECT
156 Q_PROPERTY(QVariant activity MEMBER m_activity)
157 Q_PROPERTY(QVariant desktop MEMBER m_desktop)
158 Q_PROPERTY(QString outputName MEMBER m_outputName)
159
160public:
161 DesktopBackground(QQuickItem *parent = nullptr);
162
163private Q_SLOTS:
164 void stretchToScreen();
165
166private:
167 // Just for mock-up purposes.
168 QVariant m_activity;
169 QVariant m_desktop;
170 QString m_outputName;
171};
172
173} // namespace TabBox
174} // namespace KWin
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
ExampleClientModel(QObject *parent=nullptr)
void showDesktopThumbnail(bool showDesktop)
Q_INVOKABLE QString longestCaption() const
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QHash< int, QByteArray > roleNames() const override
bool eventFilter(QObject *object, QEvent *event) override
LayoutPreview(const QString &path, bool showDesktopThumbnail=false, QObject *parent=nullptr)
QAbstractItemModel * model
void currentIndexChanged(int index)
void setVisible(bool visible)
void setItem(QObject *item)
#define private