File indexing completed on 2024-04-28 05:26:22
0001 /* 0002 * SPDX-FileCopyrightText: 2014 Hugo Pereira Da Costa <hugo.pereira@free.fr> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QEvent> 0010 #include <QObject> 0011 #include <QSet> 0012 0013 #include <QPaintEvent> 0014 #include <QPointer> 0015 #include <QWidget> 0016 0017 #include "breezetileset.h" 0018 0019 namespace Breeze 0020 { 0021 class ShadowHelper; 0022 0023 //* frame shadow 0024 /** this allows the shadow to be painted over the widgets viewport */ 0025 class MdiWindowShadow : public QWidget 0026 { 0027 Q_OBJECT 0028 0029 public: 0030 //* constructor 0031 explicit MdiWindowShadow(QWidget *, const TileSet &); 0032 0033 //* update geometry 0034 void updateGeometry(); 0035 0036 //* update ZOrder 0037 void updateZOrder(); 0038 0039 //* set associated window 0040 void setWidget(QWidget *value) 0041 { 0042 _widget = value; 0043 } 0044 0045 //* associated window 0046 QWidget *widget() const 0047 { 0048 return _widget; 0049 } 0050 0051 protected: 0052 //* painting 0053 void paintEvent(QPaintEvent *) override; 0054 0055 private: 0056 //* associated widget 0057 QWidget *_widget = nullptr; 0058 0059 //* tileset rect, used for painting 0060 QRect _shadowTilesRect; 0061 0062 //* tileset used to draw shadow 0063 TileSet _shadowTiles; 0064 }; 0065 0066 //* shadow manager 0067 class MdiWindowShadowFactory : public QObject 0068 { 0069 Q_OBJECT 0070 0071 public: 0072 //* constructor 0073 explicit MdiWindowShadowFactory(QObject *); 0074 0075 //* set shadow helper 0076 void setShadowHelper(ShadowHelper *shadowHelper) 0077 { 0078 _shadowHelper = shadowHelper; 0079 } 0080 0081 //* register widget 0082 bool registerWidget(QWidget *); 0083 0084 //* unregister 0085 void unregisterWidget(QWidget *); 0086 0087 //* true if widget is registered 0088 bool isRegistered(const QObject *widget) const 0089 { 0090 return _registeredWidgets.contains(widget); 0091 } 0092 0093 //* event filter 0094 bool eventFilter(QObject *, QEvent *) override; 0095 0096 protected: 0097 //* find shadow matching a given object 0098 MdiWindowShadow *findShadow(QObject *) const; 0099 0100 //* install shadows on given widget 0101 void installShadow(QObject *); 0102 0103 //* remove shadows from widget 0104 void removeShadow(QObject *); 0105 0106 //* hide shadows 0107 void hideShadows(QObject *object) const 0108 { 0109 if (MdiWindowShadow *windowShadow = findShadow(object)) { 0110 windowShadow->hide(); 0111 } 0112 } 0113 0114 //* update ZOrder 0115 void updateShadowZOrder(QObject *object) const 0116 { 0117 if (MdiWindowShadow *windowShadow = findShadow(object)) { 0118 if (!windowShadow->isVisible()) { 0119 windowShadow->show(); 0120 } 0121 windowShadow->updateZOrder(); 0122 } 0123 } 0124 0125 //* update shadows geometry 0126 void updateShadowGeometry(QObject *object) const 0127 { 0128 if (MdiWindowShadow *windowShadow = findShadow(object)) { 0129 windowShadow->updateGeometry(); 0130 } 0131 } 0132 0133 //* update shadows 0134 void update(QObject *object) const 0135 { 0136 if (MdiWindowShadow *windowShadow = findShadow(object)) { 0137 windowShadow->update(); 0138 } 0139 } 0140 0141 protected Q_SLOTS: 0142 0143 //* triggered by object destruction 0144 void widgetDestroyed(QObject *); 0145 0146 private: 0147 //* set of registered widgets 0148 QSet<const QObject *> _registeredWidgets; 0149 0150 //* shadow helper used to generate the shadows 0151 QPointer<ShadowHelper> _shadowHelper; 0152 }; 0153 0154 }