File indexing completed on 2024-05-05 04:49:29
0001 /**************************************************************************************** 0002 * Copyright (c) 2003-2009 Mark Kretschmann <kretschmann@kde.org> * 0003 * Copyright (c) 2005 Gabor Lehel <illissius@gmail.com> * 0004 * Copyright (c) 2008 Dan Meltzer <parallelgrapefruit@gmail.com> * 0005 * * 0006 * This program is free software; you can redistribute it and/or modify it under * 0007 * the terms of the GNU General Public License as published by the Free Software * 0008 * Foundation; either version 2 of the License, or (at your option) any later * 0009 * version. * 0010 * * 0011 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0012 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0013 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License along with * 0016 * this program. If not, see <http://www.gnu.org/licenses/>. * 0017 ****************************************************************************************/ 0018 0019 #ifndef SLIDERWIDGET_H 0020 #define SLIDERWIDGET_H 0021 0022 #include <QList> 0023 #include <QPixmap> 0024 #include <QSlider> 0025 #include <QVector> 0026 0027 class BookmarkTriangle; 0028 0029 0030 namespace Amarok 0031 { 0032 class Slider : public QSlider 0033 { 0034 Q_OBJECT 0035 0036 public: 0037 explicit Slider( Qt::Orientation, uint max = 0, QWidget* parent = nullptr ); 0038 0039 virtual void setValue( int ); 0040 0041 Q_SIGNALS: 0042 //we Q_EMIT this when the user has specifically changed the slider 0043 //so connect to it if valueChanged() is too generic 0044 //Qt also emits valueChanged( int ) 0045 void sliderReleased( int ); 0046 0047 protected: 0048 void wheelEvent( QWheelEvent* ) override; 0049 void mouseMoveEvent( QMouseEvent* ) override; 0050 void mouseReleaseEvent( QMouseEvent* ) override; 0051 void mousePressEvent( QMouseEvent* ) override; 0052 virtual void slideEvent( QMouseEvent* ); 0053 QRect sliderHandleRect( const QRect &slider, qreal percent ) const; 0054 void resizeEvent( QResizeEvent * ) override { m_needsResize = true; } 0055 0056 void paintCustomSlider( QPainter *p, bool paintMoodbar = false ); 0057 0058 bool m_sliding; 0059 bool m_usingCustomStyle; 0060 0061 static const int s_borderWidth = 6; 0062 static const int s_borderHeight = 6; 0063 0064 static const int s_sliderInsertX = 5; 0065 static const int s_sliderInsertY = 5; 0066 0067 private: 0068 0069 bool m_outside; 0070 int m_prevValue; 0071 bool m_needsResize; 0072 0073 QPixmap m_topLeft; 0074 QPixmap m_topRight; 0075 QPixmap m_top; 0076 QPixmap m_bottomRight; 0077 QPixmap m_right; 0078 QPixmap m_bottomLeft; 0079 QPixmap m_bottom; 0080 QPixmap m_left; 0081 0082 Q_DISABLE_COPY( Slider ) 0083 }; 0084 0085 class VolumeSlider: public Slider 0086 { 0087 Q_OBJECT 0088 0089 public: 0090 explicit VolumeSlider( uint max, QWidget *parent, bool customStyle = true ); 0091 0092 // VolumePopupButton needs to access this 0093 void wheelEvent( QWheelEvent *e ) override; 0094 0095 protected: 0096 void paintEvent( QPaintEvent* ) override; 0097 void mousePressEvent( QMouseEvent* ) override; 0098 void contextMenuEvent( QContextMenuEvent* ) override; 0099 0100 private: 0101 Q_DISABLE_COPY( VolumeSlider ) 0102 }; 0103 0104 class TimeSlider : public Amarok::Slider 0105 { 0106 Q_OBJECT 0107 0108 public: 0109 explicit TimeSlider( QWidget *parent ); 0110 0111 void setSliderValue( int value ); 0112 void drawTriangle( const QString &name, int milliSeconds, bool showPopup = false); 0113 void clearTriangles(); 0114 0115 protected: 0116 void paintEvent( QPaintEvent* ) override; 0117 void mousePressEvent( QMouseEvent* ) override; 0118 void resizeEvent( QResizeEvent * event ) override; 0119 void sliderChange( SliderChange change ) override; 0120 bool event( QEvent * event ) override; 0121 0122 private Q_SLOTS: 0123 void slotTriangleClicked( int ); 0124 void slotTriangleFocused( int ); 0125 0126 private: 0127 Q_DISABLE_COPY( TimeSlider ) 0128 0129 QList<BookmarkTriangle*> m_triangles; 0130 int m_knobX; // The position of the current indicator. 0131 }; 0132 } 0133 0134 #endif 0135