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