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

0001 #ifndef oxygentoolboxengine_h
0002 #define oxygentoolboxengine_h
0003 
0004 //////////////////////////////////////////////////////////////////////////////
0005 // oxygentoolboxengine.h
0006 // QToolBox engine
0007 // -------------------
0008 //
0009 // SPDX-FileCopyrightText: 2010 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 "oxygenwidgetstatedata.h"
0017 
0018 namespace Oxygen
0019 {
0020 //* QToolBox animation engine
0021 class ToolBoxEngine : public BaseEngine
0022 {
0023     Q_OBJECT
0024 
0025 public:
0026     //* constructor
0027     explicit ToolBoxEngine(QObject *parent)
0028         : BaseEngine(parent)
0029     {
0030     }
0031 
0032     //* enability
0033     void setEnabled(bool value) override
0034     {
0035         BaseEngine::setEnabled(value);
0036         _data.setEnabled(value);
0037     }
0038 
0039     //* duration
0040     void setDuration(int value) override
0041     {
0042         BaseEngine::setDuration(value);
0043         _data.setDuration(value);
0044     }
0045 
0046     //* register widget
0047     bool registerWidget(QWidget *);
0048 
0049     //* true if widget hover state is changed
0050     bool updateState(const QPaintDevice *, bool);
0051 
0052     //* true if widget is animated
0053     bool isAnimated(const QPaintDevice *);
0054 
0055     //* animation opacity
0056     qreal opacity(const QPaintDevice *object)
0057     {
0058         return isAnimated(object) ? data(object).data()->opacity() : AnimationData::OpacityInvalid;
0059     }
0060 
0061 public Q_SLOTS:
0062 
0063     //* remove widget from map
0064     bool unregisterWidget(QObject *data) override
0065     {
0066         if (!data)
0067             return false;
0068 
0069         // reinterpret_cast is safe here since only the address is used to find
0070         // data in the map
0071         return _data.unregisterWidget(reinterpret_cast<QPaintDevice *>(data));
0072     }
0073 
0074 private:
0075     //* returns data associated to widget
0076     PaintDeviceDataMap<WidgetStateData>::Value data(const QPaintDevice *object)
0077     {
0078         return _data.find(object).data();
0079     }
0080 
0081 private:
0082     //* map
0083     PaintDeviceDataMap<WidgetStateData> _data;
0084 };
0085 }
0086 
0087 #endif