File indexing completed on 2024-05-19 05:35:20
0001 ////////////////////////////////////////////////////////////////////////////// 0002 // oxygenmenubardata.cpp 0003 // data container for QMenuBar 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 "oxygenmenubardata.h" 0012 0013 #include <QTextStream> 0014 0015 namespace Oxygen 0016 { 0017 //______________________________________________ 0018 MenuBarData::MenuBarData(QObject *parent, QWidget *target) 0019 : AnimationData(parent, target) 0020 , _isMenu(qobject_cast<QMenu *>(target)) 0021 , _motions(-1) 0022 { 0023 } 0024 0025 //______________________________________________ 0026 MenuBarDataV1::MenuBarDataV1(QObject *parent, QWidget *target, int duration) 0027 : MenuBarData(parent, target) 0028 { 0029 target->installEventFilter(this); 0030 0031 // setup timeLine 0032 _current._animation = new Animation(duration, this); 0033 setupAnimation(currentAnimation(), "currentOpacity"); 0034 currentAnimation().data()->setDirection(Animation::Forward); 0035 0036 _previous._animation = new Animation(duration, this); 0037 setupAnimation(previousAnimation(), "previousOpacity"); 0038 previousAnimation().data()->setDirection(Animation::Backward); 0039 } 0040 0041 //______________________________________________ 0042 bool MenuBarDataV1::eventFilter(QObject *object, QEvent *event) 0043 { 0044 if (!(enabled() && object == target().data())) { 0045 return AnimationData::eventFilter(object, event); 0046 } 0047 0048 // check event type 0049 switch (event->type()) { 0050 case QEvent::Enter: { 0051 // first need to call proper event processing 0052 // then implement transition 0053 object->event(event); 0054 enterEvent(object); 0055 if (_isMenu) 0056 _motions = -1; 0057 break; 0058 } 0059 0060 case QEvent::Leave: { 0061 // first need to call proper event processing 0062 // then implement transition 0063 object->event(event); 0064 leaveEvent(object); 0065 break; 0066 } 0067 0068 case QEvent::MouseMove: { 0069 // first need to call proper event processing 0070 // then implement transition 0071 if (!_isMenu || _motions++ > 0) 0072 object->event(event); 0073 mouseMoveEvent(object); 0074 break; 0075 } 0076 0077 case QEvent::MouseButtonPress: { 0078 // first need to call proper event processing 0079 // then implement transition 0080 mousePressEvent(object); 0081 break; 0082 } 0083 0084 default: 0085 break; 0086 } 0087 0088 // always forward event 0089 return AnimationData::eventFilter(object, event); 0090 } 0091 0092 //______________________________________________ 0093 MenuBarDataV2::MenuBarDataV2(QObject *parent, QWidget *target, int duration) 0094 : MenuBarData(parent, target) 0095 , _opacity(0) 0096 , _progress(0) 0097 , _entered(true) 0098 { 0099 target->installEventFilter(this); 0100 0101 _animation = new Animation(duration, this); 0102 animation().data()->setDirection(Animation::Forward); 0103 animation().data()->setStartValue(0.0); 0104 animation().data()->setEndValue(1.0); 0105 animation().data()->setTargetObject(this); 0106 animation().data()->setPropertyName("opacity"); 0107 0108 _progressAnimation = new Animation(duration, this); 0109 progressAnimation().data()->setDirection(Animation::Forward); 0110 progressAnimation().data()->setStartValue(0); 0111 progressAnimation().data()->setEndValue(1); 0112 progressAnimation().data()->setTargetObject(this); 0113 progressAnimation().data()->setPropertyName("progress"); 0114 progressAnimation().data()->setEasingCurve(QEasingCurve::Linear); 0115 } 0116 0117 //______________________________________________ 0118 bool MenuBarDataV2::eventFilter(QObject *object, QEvent *event) 0119 { 0120 if (!enabled()) 0121 return false; 0122 0123 // check event type 0124 switch (event->type()) { 0125 case QEvent::Enter: { 0126 // first need to call proper event processing 0127 // then implement transition 0128 object->event(event); 0129 enterEvent(object); 0130 if (!_isMenu) 0131 _motions = -1; 0132 break; 0133 } 0134 0135 case QEvent::Hide: 0136 case QEvent::Leave: { 0137 // first need to call proper event processing 0138 // then implement transition 0139 object->event(event); 0140 if (_timer.isActive()) 0141 _timer.stop(); 0142 _timer.start(100, this); 0143 break; 0144 } 0145 0146 case QEvent::MouseMove: { 0147 // first need to call proper event processing 0148 // then implement transition 0149 if (!_isMenu || _motions++ > 0) 0150 object->event(event); 0151 mouseMoveEvent(object); 0152 break; 0153 } 0154 0155 default: 0156 break; 0157 } 0158 0159 // always forward event 0160 return false; 0161 } 0162 0163 //____________________________________________________________ 0164 void MenuBarDataV2::updateAnimatedRect(void) 0165 { 0166 // check rect validity 0167 if (!(currentRect().isValid() && previousRect().isValid())) { 0168 _animatedRect = QRect(); 0169 return; 0170 } 0171 0172 // compute rect located 'between' previous and current 0173 _animatedRect.setLeft(previousRect().left() + progress() * (currentRect().left() - previousRect().left())); 0174 _animatedRect.setRight(previousRect().right() + progress() * (currentRect().right() - previousRect().right())); 0175 _animatedRect.setTop(previousRect().top() + progress() * (currentRect().top() - previousRect().top())); 0176 _animatedRect.setBottom(previousRect().bottom() + progress() * (currentRect().bottom() - previousRect().bottom())); 0177 0178 // trigger update 0179 setDirty(); 0180 0181 return; 0182 } 0183 0184 //___________________________________________________________ 0185 void MenuBarDataV2::timerEvent(QTimerEvent *event) 0186 { 0187 if (event->timerId() != _timer.timerId()) 0188 return AnimationData::timerEvent(event); 0189 _timer.stop(); 0190 leaveEvent(target().data()); 0191 } 0192 }