File indexing completed on 2024-05-19 16:34:45
0001 /* 0002 SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "kwineffects.h" 0010 #include "kwinglobals.h" 0011 0012 #include <QMatrix4x4> 0013 #include <QObject> 0014 #include <QVector> 0015 0016 #include <optional> 0017 0018 namespace KWin 0019 { 0020 0021 class SceneDelegate; 0022 class Scene; 0023 0024 /** 0025 * The Item class is the base class for items in the scene. 0026 */ 0027 class KWIN_EXPORT Item : public QObject 0028 { 0029 Q_OBJECT 0030 0031 public: 0032 explicit Item(Scene *scene, Item *parent = nullptr); 0033 ~Item() override; 0034 0035 Scene *scene() const; 0036 0037 qreal opacity() const; 0038 void setOpacity(qreal opacity); 0039 0040 QPointF position() const; 0041 void setPosition(const QPointF &point); 0042 0043 QSizeF size() const; 0044 void setSize(const QSizeF &size); 0045 0046 int z() const; 0047 void setZ(int z); 0048 0049 /** 0050 * Returns the enclosing rectangle of the item. The rect equals QRect(0, 0, width(), height()). 0051 */ 0052 QRectF rect() const; 0053 /** 0054 * Returns the enclosing rectangle of the item and all of its descendants. 0055 */ 0056 QRectF boundingRect() const; 0057 0058 virtual QVector<QRectF> shape() const; 0059 virtual QRegion opaque() const; 0060 0061 /** 0062 * Returns the visual parent of the item. Note that the visual parent differs from 0063 * the QObject parent. 0064 */ 0065 Item *parentItem() const; 0066 void setParentItem(Item *parent); 0067 QList<Item *> childItems() const; 0068 QList<Item *> sortedChildItems() const; 0069 0070 QPointF rootPosition() const; 0071 0072 QMatrix4x4 transform() const; 0073 void setTransform(const QMatrix4x4 &transform); 0074 0075 /** 0076 * Maps the given @a region from the item's coordinate system to the scene's coordinate 0077 * system. 0078 */ 0079 QRegion mapToGlobal(const QRegion ®ion) const; 0080 /** 0081 * Maps the given @a rect from the item's coordinate system to the scene's coordinate 0082 * system. 0083 */ 0084 QRectF mapToGlobal(const QRectF &rect) const; 0085 /** 0086 * Maps the given @a rect from the scene's coordinate system to the item's coordinate 0087 * system. 0088 */ 0089 QRectF mapFromGlobal(const QRectF &rect) const; 0090 0091 /** 0092 * Moves this item right before the specified @a sibling in the parent's children list. 0093 */ 0094 void stackBefore(Item *sibling); 0095 /** 0096 * Moves this item right after the specified @a sibling in the parent's children list. 0097 */ 0098 void stackAfter(Item *sibling); 0099 0100 bool explicitVisible() const; 0101 bool isVisible() const; 0102 void setVisible(bool visible); 0103 0104 void scheduleRepaint(const QRectF ®ion); 0105 void scheduleRepaint(const QRegion ®ion); 0106 void scheduleFrame(); 0107 QRegion repaints(SceneDelegate *delegate) const; 0108 void resetRepaints(SceneDelegate *delegate); 0109 0110 WindowQuadList quads() const; 0111 virtual void preprocess(); 0112 0113 Q_SIGNALS: 0114 void childAdded(Item *item); 0115 /** 0116 * This signal is emitted when the position of this item has changed. 0117 */ 0118 void positionChanged(); 0119 /** 0120 * This signal is emitted when the size of this item has changed. 0121 */ 0122 void sizeChanged(); 0123 0124 /** 0125 * This signal is emitted when the rectangle that encloses this item and all of its children 0126 * has changed. 0127 */ 0128 void boundingRectChanged(); 0129 0130 protected: 0131 virtual WindowQuadList buildQuads() const; 0132 void discardQuads(); 0133 0134 private: 0135 void addChild(Item *item); 0136 void removeChild(Item *item); 0137 void updateBoundingRect(); 0138 void scheduleRepaintInternal(const QRegion ®ion); 0139 void markSortedChildItemsDirty(); 0140 0141 bool computeEffectiveVisibility() const; 0142 void updateEffectiveVisibility(); 0143 void removeRepaints(SceneDelegate *delegate); 0144 0145 Scene *m_scene; 0146 QPointer<Item> m_parentItem; 0147 QList<Item *> m_childItems; 0148 QMatrix4x4 m_transform; 0149 QRectF m_boundingRect; 0150 QPointF m_position; 0151 QSizeF m_size = QSize(0, 0); 0152 qreal m_opacity = 1; 0153 int m_z = 0; 0154 bool m_explicitVisible = true; 0155 bool m_effectiveVisible = true; 0156 QMap<SceneDelegate *, QRegion> m_repaints; 0157 mutable std::optional<WindowQuadList> m_quads; 0158 mutable std::optional<QList<Item *>> m_sortedChildItems; 0159 }; 0160 0161 } // namespace KWin