File indexing completed on 2024-05-19 05:35:20

0001 #ifndef oxygenmenubarengine_h
0002 #define oxygenmenubarengine_h
0003 
0004 //////////////////////////////////////////////////////////////////////////////
0005 // oxygenmenubarengine.h
0006 // stores event filters and maps widgets to timelines for animations
0007 // -------------------
0008 //
0009 // SPDX-FileCopyrightText: 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
0010 //
0011 // SPDX-License-Identifier: MIT
0012 //////////////////////////////////////////////////////////////////////////////
0013 
0014 #include "oxygenbaseengine.h"
0015 #include "oxygendatamap.h"
0016 #include "oxygenmenubardata.h"
0017 
0018 namespace Oxygen
0019 {
0020 //* stores menubar hovered action and timeLine
0021 class MenuBarBaseEngine : public BaseEngine
0022 {
0023     Q_OBJECT
0024 
0025 public:
0026     //* constructor
0027     explicit MenuBarBaseEngine(QObject *parent)
0028         : BaseEngine(parent)
0029     {
0030     }
0031 
0032     //* register menubar
0033     virtual bool registerWidget(QWidget *) = 0;
0034 
0035     //* true if widget is animated
0036     virtual bool isAnimated(const QObject *, const QPoint &)
0037     {
0038         return false;
0039     }
0040 
0041     //* animation opacity
0042     virtual qreal opacity(const QObject *, const QPoint &)
0043     {
0044         return -1;
0045     }
0046 
0047     //* return 'hover' rect position when widget is animated
0048     virtual QRect currentRect(const QObject *, const QPoint &)
0049     {
0050         return QRect();
0051     }
0052 
0053     //* animated rect
0054     virtual QRect animatedRect(const QObject *)
0055     {
0056         return QRect();
0057     }
0058 
0059     //* timer
0060     virtual bool isTimerActive(const QObject *)
0061     {
0062         return false;
0063     }
0064 
0065     //* enable state
0066     void setEnabled(bool) override = 0;
0067 
0068     //* duration
0069     void setDuration(int) override = 0;
0070 
0071     //* duration
0072     virtual void setFollowMouseDuration(int)
0073     {
0074     }
0075 };
0076 
0077 //* fading menubar animation
0078 class MenuBarEngineV1 : public MenuBarBaseEngine
0079 {
0080     Q_OBJECT
0081 
0082 public:
0083     //* constructor
0084     explicit MenuBarEngineV1(QObject *parent)
0085         : MenuBarBaseEngine(parent)
0086     {
0087     }
0088 
0089     //* constructor
0090     MenuBarEngineV1(QObject *parent, MenuBarBaseEngine *other);
0091 
0092     //* register menubar
0093     bool registerWidget(QWidget *) override;
0094 
0095     //* true if widget is animated
0096     bool isAnimated(const QObject *object, const QPoint &point) override;
0097 
0098     //* animation opacity
0099     qreal opacity(const QObject *object, const QPoint &point) override
0100     {
0101         return isAnimated(object, point) ? _data.find(object).data()->opacity(point) : AnimationData::OpacityInvalid;
0102     }
0103 
0104     //* return 'hover' rect position when widget is animated
0105     QRect currentRect(const QObject *object, const QPoint &point) override
0106     {
0107         return isAnimated(object, point) ? _data.find(object).data()->currentRect(point) : QRect();
0108     }
0109 
0110     //* enable state
0111     void setEnabled(bool value) override
0112     {
0113         BaseEngine::setEnabled(value);
0114         _data.setEnabled(value);
0115     }
0116 
0117     //* duration
0118     void setDuration(int duration) override
0119     {
0120         BaseEngine::setDuration(duration);
0121         _data.setDuration(duration);
0122     }
0123 
0124     //* return list of registered widgets
0125     WidgetList registeredWidgets(void) const override;
0126 
0127 protected Q_SLOTS:
0128 
0129     //* remove widget from map
0130     bool unregisterWidget(QObject *object) override
0131     {
0132         return _data.unregisterWidget(object);
0133     }
0134 
0135 private:
0136     //* data map
0137     DataMap<MenuBarDataV1> _data;
0138 };
0139 
0140 //* follow-mouse menubar animation
0141 class MenuBarEngineV2 : public MenuBarBaseEngine
0142 {
0143     Q_OBJECT
0144 
0145 public:
0146     //* constructor
0147     explicit MenuBarEngineV2(QObject *parent)
0148         : MenuBarBaseEngine(parent)
0149     {
0150     }
0151 
0152     //* constructor
0153     MenuBarEngineV2(QObject *parent, MenuBarBaseEngine *other);
0154 
0155     //* register menubar
0156     bool registerWidget(QWidget *) override;
0157 
0158     //* true if widget is animated
0159     bool isAnimated(const QObject *object, const QPoint &point) override;
0160 
0161     //* animation opacity
0162     qreal opacity(const QObject *object, const QPoint &point) override
0163     {
0164         return isAnimated(object, point) ? _data.find(object).data()->opacity() : AnimationData::OpacityInvalid;
0165     }
0166 
0167     //* return 'hover' rect position when widget is animated
0168     QRect currentRect(const QObject *, const QPoint &) override;
0169 
0170     //* return 'hover' rect position when widget is animated
0171     QRect animatedRect(const QObject *) override;
0172 
0173     //* timer associated to the data
0174     bool isTimerActive(const QObject *) override;
0175 
0176     //* enable state
0177     void setEnabled(bool value) override
0178     {
0179         BaseEngine::setEnabled(value);
0180         _data.setEnabled(value);
0181     }
0182 
0183     //* duration
0184     void setDuration(int value) override
0185     {
0186         BaseEngine::setDuration(value);
0187         _data.setDuration(value);
0188     }
0189 
0190     //* duration
0191     int followMouseDuration(void) const
0192     {
0193         return _followMouseDuration;
0194     }
0195 
0196     //* duration
0197     void setFollowMouseDuration(int duration) override
0198     {
0199         _followMouseDuration = duration;
0200         for (const DataMap<MenuBarDataV2>::Value &value : std::as_const(_data)) {
0201             if (value)
0202                 value.data()->setFollowMouseDuration(duration);
0203         }
0204     }
0205 
0206     //* return list of registered widgets
0207     WidgetList registeredWidgets(void) const override;
0208 
0209 protected Q_SLOTS:
0210 
0211     //* remove widget from map
0212     bool unregisterWidget(QObject *object) override
0213     {
0214         return _data.unregisterWidget(object);
0215     }
0216 
0217 private:
0218     //* follow mouse animation duration
0219     int _followMouseDuration;
0220 
0221     //* data map
0222     DataMap<MenuBarDataV2> _data;
0223 };
0224 }
0225 
0226 #endif