File indexing completed on 2024-05-19 16:34:54

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2013 Martin Gräßlin <mgraesslin@kde.org>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 #pragma once
0010 
0011 #include <QObject>
0012 #include <QRect>
0013 
0014 class QAbstractItemModel;
0015 
0016 namespace KWin
0017 {
0018 namespace TabBox
0019 {
0020 
0021 class SwitcherItem : public QObject
0022 {
0023     Q_OBJECT
0024     Q_PROPERTY(QAbstractItemModel *model READ model NOTIFY modelChanged)
0025     Q_PROPERTY(QRect screenGeometry READ screenGeometry NOTIFY screenGeometryChanged)
0026     Q_PROPERTY(bool visible READ isVisible NOTIFY visibleChanged)
0027     Q_PROPERTY(bool allDesktops READ isAllDesktops NOTIFY allDesktopsChanged)
0028     Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
0029     Q_PROPERTY(bool noModifierGrab READ noModifierGrab NOTIFY noModifierGrabChanged)
0030     Q_PROPERTY(bool compositing READ compositing NOTIFY compositingChanged)
0031 
0032     /**
0033      * The main QML item that will be displayed in the Dialog
0034      */
0035     Q_PROPERTY(QObject *item READ item WRITE setItem NOTIFY itemChanged)
0036 
0037     Q_CLASSINFO("DefaultProperty", "item")
0038 public:
0039     SwitcherItem(QObject *parent = nullptr);
0040     ~SwitcherItem() override;
0041 
0042     QAbstractItemModel *model() const;
0043     QRect screenGeometry() const;
0044     bool isVisible() const;
0045     bool isAllDesktops() const;
0046     int currentIndex() const;
0047     void setCurrentIndex(int index);
0048     QObject *item() const;
0049     void setItem(QObject *item);
0050     bool noModifierGrab() const
0051     {
0052         return m_noModifierGrab;
0053     }
0054     bool compositing();
0055 
0056     // for usage from outside
0057     void setModel(QAbstractItemModel *model);
0058     void setAllDesktops(bool all);
0059     void setVisible(bool visible);
0060     void setNoModifierGrab(bool set);
0061 
0062 Q_SIGNALS:
0063     void visibleChanged();
0064     void currentIndexChanged(int index);
0065     void modelChanged();
0066     void allDesktopsChanged();
0067     void screenGeometryChanged();
0068     void itemChanged();
0069     void noModifierGrabChanged();
0070     void compositingChanged();
0071 
0072 private:
0073     QAbstractItemModel *m_model;
0074     QObject *m_item;
0075     bool m_visible;
0076     bool m_allDesktops;
0077     int m_currentIndex;
0078     QMetaObject::Connection m_selectedIndexConnection;
0079     bool m_noModifierGrab = false;
0080 };
0081 
0082 inline QAbstractItemModel *SwitcherItem::model() const
0083 {
0084     return m_model;
0085 }
0086 
0087 inline bool SwitcherItem::isVisible() const
0088 {
0089     return m_visible;
0090 }
0091 
0092 inline bool SwitcherItem::isAllDesktops() const
0093 {
0094     return m_allDesktops;
0095 }
0096 
0097 inline int SwitcherItem::currentIndex() const
0098 {
0099     return m_currentIndex;
0100 }
0101 
0102 inline QObject *SwitcherItem::item() const
0103 {
0104     return m_item;
0105 }
0106 
0107 } // TabBox
0108 } // KWin