File indexing completed on 2024-05-19 05:28:49
0001 /* 0002 * breezetabbardata.cpp 0003 * data container for QTabBar animations 0004 * 0005 * SPDX-FileCopyrightText: 2009, 2014 Hugo Pereira Da Costa <hugo.pereira@free.fr> 0006 * 0007 * SPDX-License-Identifier: GPL-2.0-or-later OR MIT 0008 */ 0009 0010 #include "breezetabbardata.h" 0011 0012 #include <QHoverEvent> 0013 0014 namespace Breeze 0015 { 0016 //______________________________________________ 0017 TabBarData::TabBarData(QObject *parent, QObject *target, int duration) 0018 : AnimationData(parent, target) 0019 { 0020 _current._animation = new Animation(duration, this); 0021 setupAnimation(currentIndexAnimation(), "currentOpacity"); 0022 currentIndexAnimation().data()->setDirection(Animation::Forward); 0023 0024 _previous._animation = new Animation(duration, this); 0025 setupAnimation(previousIndexAnimation(), "previousOpacity"); 0026 previousIndexAnimation().data()->setDirection(Animation::Backward); 0027 } 0028 0029 //______________________________________________ 0030 Animation::Pointer TabBarData::animation(const QPoint &position) const 0031 { 0032 if (!enabled()) { 0033 return Animation::Pointer(); 0034 } 0035 0036 const QTabBar *local(qobject_cast<const QTabBar *>(target().data())); 0037 if (!local) { 0038 return Animation::Pointer(); 0039 } 0040 0041 int index(local->tabAt(position)); 0042 if (index < 0) { 0043 return Animation::Pointer(); 0044 } else if (index == currentIndex()) { 0045 return currentIndexAnimation(); 0046 } else if (index == previousIndex()) { 0047 return previousIndexAnimation(); 0048 } else { 0049 return Animation::Pointer(); 0050 } 0051 } 0052 0053 //______________________________________________ 0054 bool TabBarData::updateState(const QPoint &position, bool hovered) 0055 { 0056 if (!enabled()) { 0057 return false; 0058 } 0059 0060 const QTabBar *local(qobject_cast<const QTabBar *>(target().data())); 0061 if (!local) { 0062 return false; 0063 } 0064 0065 int index(local->tabAt(position)); 0066 if (index < 0) { 0067 return false; 0068 } 0069 0070 if (hovered) { 0071 if (index != currentIndex()) { 0072 if (currentIndex() >= 0) { 0073 setPreviousIndex(currentIndex()); 0074 setCurrentIndex(-1); 0075 previousIndexAnimation().data()->restart(); 0076 } 0077 0078 setCurrentIndex(index); 0079 currentIndexAnimation().data()->restart(); 0080 return true; 0081 0082 } else { 0083 return false; 0084 } 0085 0086 } else if (index == currentIndex()) { 0087 setPreviousIndex(currentIndex()); 0088 setCurrentIndex(-1); 0089 previousIndexAnimation().data()->restart(); 0090 return true; 0091 0092 } else { 0093 return false; 0094 } 0095 } 0096 0097 //______________________________________________ 0098 qreal TabBarData::opacity(const QPoint &position) const 0099 { 0100 if (!enabled()) { 0101 return OpacityInvalid; 0102 } 0103 0104 const QTabBar *local(qobject_cast<const QTabBar *>(target().data())); 0105 if (!local) { 0106 return OpacityInvalid; 0107 } 0108 0109 int index(local->tabAt(position)); 0110 if (index < 0) { 0111 return OpacityInvalid; 0112 } else if (index == currentIndex()) { 0113 return currentOpacity(); 0114 } else if (index == previousIndex()) { 0115 return previousOpacity(); 0116 } else { 0117 return OpacityInvalid; 0118 } 0119 } 0120 0121 }