File indexing completed on 2024-05-19 05:28:49

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 "breezebaseengine.h"
0010 #include "breezedatamap.h"
0011 #include "breezespinboxdata.h"
0012 
0013 namespace Breeze
0014 {
0015 //* handle spinbox arrows hover effect
0016 class SpinBoxEngine : public BaseEngine
0017 {
0018     Q_OBJECT
0019 
0020 public:
0021     //* constructor
0022     explicit SpinBoxEngine(QObject *parent)
0023         : BaseEngine(parent)
0024     {
0025     }
0026 
0027     //* register widget
0028     bool registerWidget(QObject *target);
0029 
0030     //* state
0031     bool updateState(const QObject *object, QStyle::SubControl subControl, bool value)
0032     {
0033         if (DataMap<SpinBoxData>::Value data = _data.find(object)) {
0034             return data.data()->updateState(subControl, value);
0035         } else {
0036             return false;
0037         }
0038     }
0039 
0040     //* true if widget is animated
0041     bool isAnimated(const QObject *object, QStyle::SubControl subControl)
0042     {
0043         if (DataMap<SpinBoxData>::Value data = _data.find(object)) {
0044             return data.data()->isAnimated(subControl);
0045         } else {
0046             return false;
0047         }
0048     }
0049 
0050     //* animation opacity
0051     qreal opacity(const QObject *object, QStyle::SubControl subControl)
0052     {
0053         if (DataMap<SpinBoxData>::Value data = _data.find(object)) {
0054             return data.data()->opacity(subControl);
0055         } else {
0056             return AnimationData::OpacityInvalid;
0057         }
0058     }
0059 
0060     //* enability
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 public Q_SLOTS:
0075 
0076     //* remove widget from map
0077     bool unregisterWidget(QObject *object) override
0078     {
0079         return _data.unregisterWidget(object);
0080     }
0081 
0082 private:
0083     //* data map
0084     DataMap<SpinBoxData> _data;
0085 };
0086 
0087 }