1 /************************************************************************* 2 * Copyright (C) 2014 by Hugo Pereira Da Costa <hugo.pereira@free.fr> * 3 * * 4 * This program is free software; you can redistribute it and/or modify * 5 * it under the terms of the GNU General Public License as published by * 6 * the Free Software Foundation; either version 2 of the License, or * 7 * (at your option) any later version. * 8 * * 9 * This program is distributed in the hope that it will be useful, * 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 * GNU General Public License for more details. * 13 * * 14 * You should have received a copy of the GNU General Public License * 15 * along with this program; if not, write to the * 16 * Free Software Foundation, Inc., * 17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * 18 *************************************************************************/ 19 20 #ifndef ADWAITA_HEADER_VIEW_DATA_H 21 #define ADWAITA_HEADER_VIEW_DATA_H 22 23 #include "adwaitaanimationdata.h" 24 #include "adwaitaqt_export.h" 25 26 #include <QHeaderView> 27 28 namespace Adwaita 29 { 30 //* headerviews 31 class ADWAITAQT_EXPORT HeaderViewData : public AnimationData 32 { 33 Q_OBJECT 34 35 //* declare opacity property 36 Q_PROPERTY(qreal currentOpacity READ currentOpacity WRITE setCurrentOpacity) 37 Q_PROPERTY(qreal previousOpacity READ previousOpacity WRITE setPreviousOpacity) 38 public: 39 //* constructor 40 HeaderViewData(QObject *parent, QWidget *target, int duration); 41 42 //* destructor ~HeaderViewData()43 virtual ~HeaderViewData() 44 { 45 } 46 47 //* duration setDuration(int duration)48 void setDuration(int duration) 49 { 50 currentIndexAnimation().data()->setDuration(duration); 51 previousIndexAnimation().data()->setDuration(duration); 52 } 53 54 //* update state 55 bool updateState(const QPoint &, bool); 56 57 //*@name current index handling 58 //@{ 59 60 //* current opacity currentOpacity()61 virtual qreal currentOpacity() const 62 { 63 return _current._opacity; 64 } 65 66 //* current opacity setCurrentOpacity(qreal value)67 virtual void setCurrentOpacity(qreal value) 68 { 69 value = digitize(value); 70 if (_current._opacity == value) { 71 return; 72 } 73 74 _current._opacity = value; 75 setDirty(); 76 } 77 78 //* current index currentIndex()79 virtual int currentIndex() const 80 { 81 return _current._index; 82 } 83 84 //* current index setCurrentIndex(int index)85 virtual void setCurrentIndex(int index) 86 { 87 _current._index = index; 88 } 89 90 //* current index animation currentIndexAnimation()91 virtual const Animation::Pointer ¤tIndexAnimation() const 92 { 93 return _current._animation; 94 } 95 96 //@} 97 98 //*@name previous index handling 99 //@{ 100 101 //* previous opacity previousOpacity()102 virtual qreal previousOpacity() const 103 { 104 return _previous._opacity; 105 } 106 107 //* previous opacity setPreviousOpacity(qreal value)108 virtual void setPreviousOpacity(qreal value) 109 { 110 value = digitize(value); 111 if (_previous._opacity == value) { 112 return; 113 } 114 115 _previous._opacity = value; 116 setDirty(); 117 } 118 119 //* previous index previousIndex()120 virtual int previousIndex() const 121 { 122 return _previous._index; 123 } 124 125 //* previous index setPreviousIndex(int index)126 virtual void setPreviousIndex(int index) 127 { 128 _previous._index = index; 129 } 130 131 //* previous index Animation previousIndexAnimation()132 virtual const Animation::Pointer &previousIndexAnimation() const 133 { 134 return _previous._animation; 135 } 136 137 //@} 138 139 //* return Animation associated to action at given position, if any 140 virtual Animation::Pointer animation(const QPoint &position) const; 141 142 //* return opacity associated to action at given position, if any 143 virtual qreal opacity(const QPoint &position) const; 144 145 protected: 146 //* dirty 147 virtual void setDirty() const; 148 149 private: 150 //* container for needed animation data 151 class Data 152 { 153 public: 154 //* default constructor Data()155 Data() 156 : _opacity(0) 157 , _index(-1) 158 { 159 } 160 161 Animation::Pointer _animation; 162 qreal _opacity; 163 int _index; 164 }; 165 166 //* current tab animation data (for hover enter animations) 167 Data _current; 168 169 //* previous tab animations data (for hover leave animations) 170 Data _previous; 171 }; 172 173 } // namespace Adwaita 174 175 #endif // ADWAITA_HEADER_VIEW_DATA_H 176