File indexing completed on 2024-05-12 05:28:38
0001 ////////////////////////////////////////////////////////////////////////////// 0002 // breezestackedwidgetdata.cpp 0003 // data container for QStackedWidget transition 0004 // ------------------- 0005 // 0006 // SPDX-FileCopyrightText: 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr> 0007 // 0008 // SPDX-License-Identifier: MIT 0009 ////////////////////////////////////////////////////////////////////////////// 0010 0011 #include "breezestackedwidgetdata.h" 0012 0013 namespace Breeze 0014 { 0015 //______________________________________________________ 0016 StackedWidgetData::StackedWidgetData(QObject *parent, QStackedWidget *target, int duration) 0017 : TransitionData(parent, target, duration) 0018 , _target(target) 0019 , _index(target->currentIndex()) 0020 { 0021 // configure transition 0022 connect(_target.data(), &QObject::destroyed, this, &StackedWidgetData::targetDestroyed); 0023 connect(_target.data(), SIGNAL(currentChanged(int)), SLOT(animate())); 0024 0025 // disable focus 0026 transition().data()->setAttribute(Qt::WA_NoMousePropagation, true); 0027 transition().data()->setFlag(TransitionWidget::PaintOnWidget, true); 0028 0029 setMaxRenderTime(50); 0030 } 0031 0032 //___________________________________________________________________ 0033 bool StackedWidgetData::initializeAnimation() 0034 { 0035 // check enability 0036 if (!(_target && _target.data()->isVisible())) { 0037 return false; 0038 } 0039 0040 // check index 0041 if (_target.data()->currentIndex() == _index) { 0042 return false; 0043 } 0044 0045 // do not animate if either index or currentIndex is not valid 0046 // but update _index none the less 0047 if (_target.data()->currentIndex() < 0 || _index < 0) { 0048 _index = _target.data()->currentIndex(); 0049 return false; 0050 } 0051 0052 // get old widget (matching _index) and initialize transition 0053 if (QWidget *widget = _target.data()->widget(_index)) { 0054 transition().data()->setOpacity(0); 0055 startClock(); 0056 transition().data()->setGeometry(widget->geometry()); 0057 transition().data()->setStartPixmap(transition().data()->grab(widget)); 0058 0059 _index = _target.data()->currentIndex(); 0060 return !slow(); 0061 0062 } else { 0063 _index = _target.data()->currentIndex(); 0064 return false; 0065 } 0066 } 0067 0068 //___________________________________________________________________ 0069 bool StackedWidgetData::animate() 0070 { 0071 // check enability 0072 if (!enabled()) { 0073 return false; 0074 } 0075 0076 // initialize animation 0077 if (!initializeAnimation()) { 0078 return false; 0079 } 0080 0081 // show transition widget 0082 transition().data()->show(); 0083 transition().data()->raise(); 0084 transition().data()->animate(); 0085 return true; 0086 } 0087 0088 //___________________________________________________________________ 0089 void StackedWidgetData::finishAnimation() 0090 { 0091 // disable updates on currentWidget 0092 if (_target && _target.data()->currentWidget()) { 0093 _target.data()->currentWidget()->setUpdatesEnabled(false); 0094 } 0095 0096 // hide transition 0097 transition().data()->hide(); 0098 0099 // reenable updates and repaint 0100 if (_target && _target.data()->currentWidget()) { 0101 _target.data()->currentWidget()->setUpdatesEnabled(true); 0102 _target.data()->currentWidget()->repaint(); 0103 } 0104 0105 // invalidate start widget 0106 transition().data()->resetStartPixmap(); 0107 } 0108 0109 //___________________________________________________________________ 0110 void StackedWidgetData::targetDestroyed() 0111 { 0112 setEnabled(false); 0113 _target.clear(); 0114 } 0115 0116 }