File indexing completed on 2024-05-05 04:49:22
0001 /**************************************************************************************** 0002 * Copyright (c) 2008 Nikolaj Hald Nielsen <nhn@kde.org> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #ifndef PROGRESSBAR_H 0018 #define PROGRESSBAR_H 0019 0020 #include "amarok_export.h" 0021 0022 #include <QFrame> 0023 #include <QHBoxLayout> 0024 #include <QLabel> 0025 #include <QProgressBar> 0026 #include <QToolButton> 0027 0028 #include <functional> 0029 0030 #define POST_COMPLETION_DELAY 2000 0031 0032 /** 0033 * A widget that encapsulates a progress bar, a description string and a cancel button. 0034 */ 0035 class AMAROK_EXPORT ProgressBar : public QFrame 0036 { 0037 Q_OBJECT 0038 0039 public: 0040 explicit ProgressBar( QWidget *parent ); 0041 ~ProgressBar() override; 0042 0043 void setDescription( const QString &description ); 0044 0045 template<class Receiver, class Func> 0046 ProgressBar *setAbortSlot( Receiver receiver, Func slot, 0047 Qt::ConnectionType type = Qt::AutoConnection ) 0048 { 0049 cancelButton()->setHidden( false ); 0050 if( receiver ) 0051 connect( this, &ProgressBar::cancelled, receiver, slot, type ); 0052 connect( cancelButton(), &QAbstractButton::clicked, this, &ProgressBar::cancel ); 0053 0054 return this; 0055 } 0056 0057 QToolButton *cancelButton() { return m_cancelButton; } 0058 QProgressBar *progressBar() { return m_progressBar; } 0059 QLabel *descriptionLabel() { return m_descriptionLabel; } 0060 0061 int maximum() { return m_progressBar->maximum(); } 0062 void setMaximum( int max ) { m_progressBar->setMaximum( max ); } 0063 int value() { return m_progressBar->value(); } 0064 void setValue( int value ); 0065 int percentage(); 0066 0067 public Q_SLOTS: 0068 void cancel(); 0069 void delayedDone(); 0070 void slotTotalSteps( int steps ) { m_progressBar->setMaximum( steps ); } 0071 0072 Q_SIGNALS: 0073 void cancelled( ProgressBar * ); 0074 void complete( ProgressBar * ); 0075 void percentageChanged( int ); 0076 0077 private: 0078 QToolButton *m_cancelButton; 0079 QProgressBar *m_progressBar; 0080 QLabel *m_descriptionLabel; 0081 }; 0082 0083 #endif