File indexing completed on 2024-11-10 04:56:52
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2009, 2011 Martin Gräßlin <mgraesslin@kde.org> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 #pragma once 0010 0011 #include <QAbstractListModel> 0012 #include <QQuickView> 0013 #include <QRect> 0014 0015 #include "thumbnailitem.h" 0016 0017 namespace KWin 0018 { 0019 0020 namespace TabBox 0021 { 0022 0023 class SwitcherItem; 0024 0025 class LayoutPreview : public QObject 0026 { 0027 Q_OBJECT 0028 public: 0029 explicit LayoutPreview(const QString &path, bool showDesktopThumbnail = false, QObject *parent = nullptr); 0030 ~LayoutPreview() override; 0031 0032 bool eventFilter(QObject *object, QEvent *event) override; 0033 0034 private: 0035 SwitcherItem *m_item; 0036 }; 0037 0038 class ExampleClientModel : public QAbstractListModel 0039 { 0040 Q_OBJECT 0041 public: 0042 enum { 0043 CaptionRole = Qt::UserRole + 1, 0044 MinimizedRole, 0045 DesktopNameRole, 0046 IconRole, 0047 WindowIdRole, 0048 CloseableRole, 0049 }; 0050 0051 explicit ExampleClientModel(QObject *parent = nullptr); 0052 ~ExampleClientModel() override; 0053 0054 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0055 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0056 QHash<int, QByteArray> roleNames() const override; 0057 Q_INVOKABLE QString longestCaption() const; 0058 0059 void showDesktopThumbnail(bool showDesktop); 0060 0061 private: 0062 struct ThumbnailInfo 0063 { 0064 WindowThumbnailItem::Thumbnail wId; 0065 QString caption; 0066 QString icon; 0067 0068 bool operator==(const ThumbnailInfo &other) const 0069 { 0070 return wId == other.wId; 0071 } 0072 }; 0073 0074 void init(); 0075 QList<ThumbnailInfo> m_thumbnails; 0076 }; 0077 0078 class SwitcherItem : public QObject 0079 { 0080 Q_OBJECT 0081 Q_PROPERTY(QAbstractItemModel *model READ model NOTIFY modelChanged) 0082 Q_PROPERTY(QRect screenGeometry READ screenGeometry NOTIFY screenGeometryChanged) 0083 Q_PROPERTY(bool visible READ isVisible NOTIFY visibleChanged) 0084 Q_PROPERTY(bool allDesktops READ isAllDesktops NOTIFY allDesktopsChanged) 0085 Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) 0086 0087 /** 0088 * The main QML item that will be displayed in the Dialog 0089 */ 0090 Q_PROPERTY(QObject *item READ item WRITE setItem NOTIFY itemChanged) 0091 0092 Q_CLASSINFO("DefaultProperty", "item") 0093 public: 0094 SwitcherItem(QObject *parent = nullptr); 0095 ~SwitcherItem() override; 0096 0097 QAbstractItemModel *model() const; 0098 QRect screenGeometry() const; 0099 bool isVisible() const; 0100 bool isAllDesktops() const; 0101 int currentIndex() const; 0102 void setCurrentIndex(int index); 0103 QObject *item() const; 0104 void setItem(QObject *item); 0105 0106 void setVisible(bool visible); 0107 void incrementIndex(); 0108 void decrementIndex(); 0109 0110 Q_SIGNALS: 0111 void visibleChanged(); 0112 void currentIndexChanged(int index); 0113 void modelChanged(); 0114 void allDesktopsChanged(); 0115 void screenGeometryChanged(); 0116 void itemChanged(); 0117 0118 void aboutToShow(); 0119 void aboutToHide(); 0120 0121 private: 0122 QAbstractItemModel *m_model; 0123 QObject *m_item; 0124 int m_currentIndex; 0125 bool m_visible; 0126 }; 0127 0128 inline QAbstractItemModel *SwitcherItem::model() const 0129 { 0130 return m_model; 0131 } 0132 0133 inline bool SwitcherItem::isVisible() const 0134 { 0135 return m_visible; 0136 } 0137 0138 inline bool SwitcherItem::isAllDesktops() const 0139 { 0140 return true; 0141 } 0142 0143 inline int SwitcherItem::currentIndex() const 0144 { 0145 return m_currentIndex; 0146 } 0147 0148 inline QObject *SwitcherItem::item() const 0149 { 0150 return m_item; 0151 } 0152 0153 class DesktopBackground : public WindowThumbnailItem 0154 { 0155 Q_OBJECT 0156 Q_PROPERTY(QVariant activity MEMBER m_activity) 0157 Q_PROPERTY(QVariant desktop MEMBER m_desktop) 0158 Q_PROPERTY(QString outputName MEMBER m_outputName) 0159 0160 public: 0161 DesktopBackground(QQuickItem *parent = nullptr); 0162 0163 private Q_SLOTS: 0164 void stretchToScreen(); 0165 0166 private: 0167 // Just for mock-up purposes. 0168 QVariant m_activity; 0169 QVariant m_desktop; 0170 QString m_outputName; 0171 }; 0172 0173 } // namespace TabBox 0174 } // namespace KWin