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

0001 // krazy:excludeall=qclasses
0002 
0003 //////////////////////////////////////////////////////////////////////////////
0004 // oxygencomboboxdata.cpp
0005 // data container for QComboBox transition
0006 // -------------------
0007 //
0008 // SPDX-FileCopyrightText: 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
0009 //
0010 // SPDX-License-Identifier: MIT
0011 //////////////////////////////////////////////////////////////////////////////
0012 
0013 #include "oxygencomboboxdata.h"
0014 
0015 namespace Oxygen
0016 {
0017 //______________________________________________________
0018 ComboBoxData::ComboBoxData(QObject *parent, QComboBox *target, int duration)
0019     : TransitionData(parent, target, duration)
0020     , _target(target)
0021 {
0022     _target.data()->installEventFilter(this);
0023     connect(_target.data(), SIGNAL(destroyed()), SLOT(targetDestroyed()));
0024     connect(_target.data(), SIGNAL(currentIndexChanged(int)), SLOT(indexChanged()));
0025 }
0026 
0027 //___________________________________________________________________
0028 void ComboBoxData::indexChanged(void)
0029 {
0030     if (recursiveCheck())
0031         return;
0032 
0033     if (transition().data()->isAnimated()) {
0034         transition().data()->endAnimation();
0035     }
0036 
0037     if (initializeAnimation())
0038         animate();
0039     else
0040         transition().data()->hide();
0041 }
0042 
0043 //___________________________________________________________________
0044 bool ComboBoxData::eventFilter(QObject *object, QEvent *event)
0045 {
0046     // make sure engine is enabled
0047     if (!(enabled() && object == _target.data())) {
0048         return TransitionData::eventFilter(object, event);
0049     }
0050 
0051     // make sure that target is not editable
0052     if (_target.data()->isEditable()) {
0053         return TransitionData::eventFilter(object, event);
0054     }
0055 
0056     switch (event->type()) {
0057     case QEvent::Show:
0058     case QEvent::Resize:
0059     case QEvent::Move:
0060         if (!recursiveCheck() && _target.data()->isVisible()) {
0061             _timer.start(0, this);
0062         }
0063         break;
0064 
0065     default:
0066         break;
0067     }
0068 
0069     return TransitionData::eventFilter(object, event);
0070 }
0071 
0072 //___________________________________________________________________
0073 void ComboBoxData::timerEvent(QTimerEvent *event)
0074 {
0075     if (event->timerId() == _timer.timerId()) {
0076         _timer.stop();
0077         if (enabled() && transition() && _target && !_target.data()->isVisible()) {
0078             setRecursiveCheck(true);
0079             transition().data()->setEndPixmap(transition().data()->grab(_target.data(), targetRect()));
0080             setRecursiveCheck(false);
0081         }
0082 
0083     } else
0084         return TransitionData::timerEvent(event);
0085 }
0086 
0087 //___________________________________________________________________
0088 bool ComboBoxData::initializeAnimation(void)
0089 {
0090     if (!(enabled() && _target && _target.data()->isVisible()))
0091         return false;
0092     if (_target.data()->isEditable()) {
0093         /*
0094         do nothing for editable comboboxes because
0095         lineEditor animations are handled directly
0096         */
0097         return false;
0098     }
0099 
0100     transition().data()->setOpacity(0);
0101     transition().data()->setGeometry(targetRect());
0102     transition().data()->setStartPixmap(transition().data()->currentPixmap());
0103     transition().data()->show();
0104     transition().data()->raise();
0105     return true;
0106 }
0107 
0108 //___________________________________________________________________
0109 bool ComboBoxData::animate(void)
0110 {
0111     // check enability
0112     if (!enabled())
0113         return false;
0114 
0115     // grab
0116     setRecursiveCheck(true);
0117     transition().data()->setEndPixmap(transition().data()->grab(_target.data(), targetRect()));
0118     setRecursiveCheck(false);
0119 
0120     // start animation
0121     transition().data()->animate();
0122 
0123     return true;
0124 }
0125 
0126 //___________________________________________________________________
0127 void ComboBoxData::targetDestroyed(void)
0128 {
0129     setEnabled(false);
0130     _target.clear();
0131 }
0132 }