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