File indexing completed on 2024-05-12 05:32:13

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 WRITE setVisible 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     Q_PROPERTY(bool automaticallyHide READ automaticallyHide WRITE setAutomaticallyHide NOTIFY automaticallyHideChanged)
0032 
0033     /**
0034      * The main QML item that will be displayed in the Dialog
0035      */
0036     Q_PROPERTY(QObject *item READ item WRITE setItem NOTIFY itemChanged)
0037 
0038     Q_CLASSINFO("DefaultProperty", "item")
0039 public:
0040     SwitcherItem(QObject *parent = nullptr);
0041     ~SwitcherItem() override;
0042 
0043     QAbstractItemModel *model() const;
0044     QRect screenGeometry() const;
0045     bool isVisible() const;
0046     bool isAllDesktops() const;
0047     int currentIndex() const;
0048     void setCurrentIndex(int index);
0049     QObject *item() const;
0050     void setItem(QObject *item);
0051     bool noModifierGrab() const
0052     {
0053         return m_noModifierGrab;
0054     }
0055     bool compositing();
0056     bool automaticallyHide() const;
0057 
0058     // for usage from outside
0059     void setModel(QAbstractItemModel *model);
0060     void setAllDesktops(bool all);
0061     void setVisible(bool visible);
0062     void setNoModifierGrab(bool set);
0063     void setAutomaticallyHide(bool value);
0064 
0065 Q_SIGNALS:
0066     void visibleChanged();
0067     void currentIndexChanged(int index);
0068     void modelChanged();
0069     void allDesktopsChanged();
0070     void screenGeometryChanged();
0071     void itemChanged();
0072     void noModifierGrabChanged();
0073     void compositingChanged();
0074     void automaticallyHideChanged();
0075 
0076     void aboutToShow();
0077     void aboutToHide();
0078 
0079 private:
0080     QAbstractItemModel *m_model;
0081     QObject *m_item;
0082     bool m_visible;
0083     bool m_allDesktops;
0084     int m_currentIndex;
0085     QMetaObject::Connection m_selectedIndexConnection;
0086     bool m_noModifierGrab = false;
0087     bool m_automaticallyHide = true;
0088 };
0089 
0090 inline QAbstractItemModel *SwitcherItem::model() const
0091 {
0092     return m_model;
0093 }
0094 
0095 inline bool SwitcherItem::isVisible() const
0096 {
0097     return m_visible;
0098 }
0099 
0100 inline bool SwitcherItem::isAllDesktops() const
0101 {
0102     return m_allDesktops;
0103 }
0104 
0105 inline int SwitcherItem::currentIndex() const
0106 {
0107     return m_currentIndex;
0108 }
0109 
0110 inline QObject *SwitcherItem::item() const
0111 {
0112     return m_item;
0113 }
0114 
0115 } // TabBox
0116 } // KWin