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

0001 //////////////////////////////////////////////////////////////////////////////
0002 // oxygenmenubarengine.cpp
0003 // stores event filters and maps widgets to timelines for animations
0004 // -------------------
0005 //
0006 // SPDX-FileCopyrightText: 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
0007 //
0008 // SPDX-License-Identifier: MIT
0009 //////////////////////////////////////////////////////////////////////////////
0010 
0011 #include "oxygenmenubarengine.h"
0012 
0013 #include <QEvent>
0014 
0015 namespace Oxygen
0016 {
0017 //____________________________________________________________
0018 MenuBarEngineV1::MenuBarEngineV1(QObject *parent, MenuBarBaseEngine *other)
0019     : MenuBarBaseEngine(parent)
0020 {
0021     if (other) {
0022         const auto otherWidgets = other->registeredWidgets();
0023         for (QWidget *widget : otherWidgets) {
0024             registerWidget(widget);
0025         }
0026     }
0027 }
0028 
0029 //____________________________________________________________
0030 bool MenuBarEngineV1::registerWidget(QWidget *widget)
0031 {
0032     if (!widget)
0033         return false;
0034 
0035     // create new data class
0036     if (!_data.contains(widget))
0037         _data.insert(widget, new MenuBarDataV1(this, widget, duration()), enabled());
0038 
0039     // connect destruction signal
0040     connect(widget, SIGNAL(destroyed(QObject *)), this, SLOT(unregisterWidget(QObject *)), Qt::UniqueConnection);
0041     return true;
0042 }
0043 
0044 //____________________________________________________________
0045 bool MenuBarEngineV1::isAnimated(const QObject *object, const QPoint &position)
0046 {
0047     DataMap<MenuBarDataV1>::Value data(_data.find(object));
0048     if (!data)
0049         return false;
0050     if (Animation::Pointer animation = data.data()->animation(position))
0051         return animation.data()->isRunning();
0052     else
0053         return false;
0054 }
0055 
0056 //____________________________________________________________
0057 BaseEngine::WidgetList MenuBarEngineV1::registeredWidgets(void) const
0058 {
0059     WidgetList out;
0060 
0061     // the typedef is needed to make Krazy happy
0062     typedef DataMap<MenuBarDataV1>::Value Value;
0063     for (const Value &value : std::as_const(_data)) {
0064         if (value)
0065             out.insert(value.data()->target().data());
0066     }
0067 
0068     return out;
0069 }
0070 
0071 //____________________________________________________________
0072 MenuBarEngineV2::MenuBarEngineV2(QObject *parent, MenuBarBaseEngine *other)
0073     : MenuBarBaseEngine(parent)
0074     , _followMouseDuration(150)
0075 {
0076     if (other) {
0077         const auto otherWidgets = other->registeredWidgets();
0078         for (QWidget *widget : otherWidgets) {
0079             registerWidget(widget);
0080         }
0081     }
0082 }
0083 
0084 //____________________________________________________________
0085 bool MenuBarEngineV2::registerWidget(QWidget *widget)
0086 {
0087     if (!widget)
0088         return false;
0089 
0090     // create new data class
0091     if (!_data.contains(widget)) {
0092         DataMap<MenuBarDataV2>::Value value(new MenuBarDataV2(this, widget, duration()));
0093         value.data()->setFollowMouseDuration(followMouseDuration());
0094         _data.insert(widget, value, enabled());
0095     }
0096 
0097     // connect destruction signal
0098     connect(widget, SIGNAL(destroyed(QObject *)), this, SLOT(unregisterWidget(QObject *)), Qt::UniqueConnection);
0099     return true;
0100 }
0101 
0102 //____________________________________________________________
0103 bool MenuBarEngineV2::isAnimated(const QObject *object, const QPoint &)
0104 {
0105     if (!enabled())
0106         return false;
0107     DataMap<MenuBarDataV2>::Value data(_data.find(object));
0108     if (!data)
0109         return false;
0110     if (data.data()->animation() && data.data()->animation().data()->isRunning())
0111         return true;
0112     else if (Animation::Pointer animation = data.data()->progressAnimation())
0113         return animation.data()->isRunning();
0114     else
0115         return false;
0116 }
0117 
0118 //____________________________________________________________
0119 QRect MenuBarEngineV2::currentRect(const QObject *object, const QPoint &)
0120 {
0121     if (!enabled())
0122         return QRect();
0123     DataMap<MenuBarDataV2>::Value data(_data.find(object));
0124     return data ? data.data()->currentRect() : QRect();
0125 }
0126 
0127 //____________________________________________________________
0128 QRect MenuBarEngineV2::animatedRect(const QObject *object)
0129 {
0130     if (!enabled())
0131         return QRect();
0132     DataMap<MenuBarDataV2>::Value data(_data.find(object));
0133     return data ? data.data()->animatedRect() : QRect();
0134 }
0135 
0136 //____________________________________________________________
0137 bool MenuBarEngineV2::isTimerActive(const QObject *object)
0138 {
0139     if (!enabled())
0140         return false;
0141     DataMap<MenuBarDataV2>::Value data(_data.find(object));
0142     return data ? data.data()->timer().isActive() : false;
0143 }
0144 
0145 //____________________________________________________________
0146 BaseEngine::WidgetList MenuBarEngineV2::registeredWidgets(void) const
0147 {
0148     WidgetList out;
0149 
0150     // the typedef is needed to make Krazy happy
0151     typedef DataMap<MenuBarDataV2>::Value Value;
0152     for (const Value &value : std::as_const(_data)) {
0153         if (value)
0154             out.insert(value.data()->target().data());
0155     }
0156 
0157     return out;
0158 }
0159 }