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

0001 #ifndef oxygentoolbarengine_h
0002 #define oxygentoolbarengine_h
0003 
0004 //////////////////////////////////////////////////////////////////////////////
0005 // oxygentoolbarengine.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 "oxygentoolbardata.h"
0017 
0018 namespace Oxygen
0019 {
0020 //* follow-mouse toolbar animation
0021 class ToolBarEngine : public BaseEngine
0022 {
0023     Q_OBJECT
0024 
0025 public:
0026     //* constructor
0027     explicit ToolBarEngine(QObject *parent)
0028         : BaseEngine(parent)
0029         , _followMouseDuration(150)
0030     {
0031     }
0032 
0033     //* register toolbar
0034     void registerWidget(QWidget *);
0035 
0036     //* returns registered widgets
0037     WidgetList registeredWidgets(void) const override;
0038 
0039     //* return true if object is animated
0040     bool isAnimated(const QObject *);
0041 
0042     //* return true if object is animated
0043     bool isFollowMouseAnimated(const QObject *);
0044 
0045     //* animation opacity
0046     qreal opacity(const QObject *object)
0047     {
0048         return isAnimated(object) ? _data.find(object).data()->opacity() : AnimationData::OpacityInvalid;
0049     }
0050 
0051     //* return 'hover' rect position when widget is animated
0052     QRect currentRect(const QObject *);
0053 
0054     //* return 'hover' rect position when widget is animated
0055     QRect animatedRect(const QObject *);
0056 
0057     //* timer
0058     bool isTimerActive(const QObject *);
0059 
0060     //* enable state
0061     void setEnabled(bool value) override
0062     {
0063         BaseEngine::setEnabled(value);
0064         _data.setEnabled(value);
0065     }
0066 
0067     //* duration
0068     void setDuration(int value) override
0069     {
0070         BaseEngine::setDuration(value);
0071         _data.setDuration(value);
0072     }
0073 
0074     //* duration
0075     int followMouseDuration(void) const
0076     {
0077         return _followMouseDuration;
0078     }
0079 
0080     //* duration
0081     void setFollowMouseDuration(int duration)
0082     {
0083         _followMouseDuration = duration;
0084         for (const DataMap<ToolBarData>::Value &value : std::as_const(_data)) {
0085             if (value)
0086                 value.data()->setFollowMouseDuration(duration);
0087         }
0088     }
0089 
0090 protected Q_SLOTS:
0091 
0092     //* remove widget from map
0093     bool unregisterWidget(QObject *object) override
0094     {
0095         return _data.unregisterWidget(object);
0096     }
0097 
0098 private:
0099     //* follow mouse animation duration
0100     int _followMouseDuration = -1;
0101 
0102     //* data map
0103     DataMap<ToolBarData> _data;
0104 };
0105 }
0106 
0107 #endif