File indexing completed on 2024-05-05 04:49:24
0001 /**************************************************************************************** 0002 * Copyright (c) 2009 Thomas Luebking <thomas.luebking@web.de> * 0003 * Copyright (c) 2010 Mark Kretschmann <kretschmann@kde.org> * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify it under * 0006 * the terms of the GNU General Public License as published by the Free Software * 0007 * Foundation; either version 2 of the License, or (at your option) any later * 0008 * version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0011 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0012 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0013 * * 0014 * You should have received a copy of the GNU General Public License along with * 0015 * this program. If not, see <http://www.gnu.org/licenses/>. * 0016 ****************************************************************************************/ 0017 0018 #ifndef ANIMATEDLABELSTACK_H 0019 #define ANIMATEDLABELSTACK_H 0020 0021 #include <QWidget> 0022 0023 class AnimatedLabelStack : public QWidget 0024 { 0025 Q_OBJECT 0026 0027 public: 0028 explicit AnimatedLabelStack( const QStringList &data, QWidget *parent = nullptr, Qt::WindowFlags f = {} ); 0029 inline const QStringList &data() const { return m_data; } 0030 inline int opacity() { return m_targetOpacity; } 0031 void pulse( int cycles = -1, int minimum = 3 ); 0032 void setAlign( Qt::Alignment ); 0033 void setBold( bool bold ); 0034 void setData( const QStringList &data ); 0035 inline void setOpacity( int alpha ) { m_targetOpacity = qMin(qMax(0, alpha), 255); } 0036 void setPadding( int left, int right ); 0037 /** 0038 The rect that's actually available for the tex, i.e. honoring the padding 0039 */ 0040 inline QRect textRect() const { return rect().adjusted( m_padding[0], 0, -m_padding[1], 0 ); } 0041 0042 public Q_SLOTS: 0043 void setAnimated( bool on = true ); 0044 inline void setStill( bool off = true ) { setAnimated( !off ); } 0045 0046 Q_SIGNALS: 0047 void pulsing( bool ); 0048 void clicked( const QString ¤t ); 0049 0050 protected: 0051 void enterEvent( QEvent * ) override; 0052 void hideEvent( QHideEvent * ) override; 0053 void leaveEvent( QEvent * ) override; 0054 void paintEvent( QPaintEvent * ) override; 0055 void mouseReleaseEvent( QMouseEvent * ) override; 0056 void mousePressEvent( QMouseEvent * ) override; 0057 void showEvent( QShowEvent * ) override; 0058 void timerEvent( QTimerEvent * ) override; 0059 void wheelEvent( QWheelEvent * ) override; 0060 0061 private: 0062 void ensureAnimationStatus(); 0063 void setPulsating( bool on ); 0064 void sleep( int ms ); 0065 void wakeUp(); 0066 0067 private Q_SLOTS: 0068 void activateOnEnter(); 0069 0070 private: 0071 /** 0072 * Creates an elided version of a string that fits in this widget. 0073 * 0074 * @return elided version of given string 0075 */ 0076 QString elidedText( const QString& text ) const; 0077 0078 Qt::Alignment m_align; 0079 int m_animTimer, m_sleepTimer; 0080 int m_time, m_fadeTime, m_displayTime; 0081 int m_index, m_visibleIndex; 0082 int m_opacity, m_targetOpacity; 0083 bool m_animated, m_pulsating, m_pulseRequested, m_explicit; 0084 int m_isClick; 0085 int m_padding[2]; 0086 QStringList m_data; 0087 }; 0088 0089 0090 #endif // end include guard