forked from qt-creator/qt-creator
Make progress bar a widget independent from QProgressBar.
Solves a problem with infinitely running QProgressBar animation in QMacStyle. Reviewed-by: Roberto Raggi
This commit is contained in:
@@ -39,7 +39,7 @@
|
||||
#define PROGRESSBAR_HEIGHT 11
|
||||
|
||||
ProgressBar::ProgressBar(QWidget *parent)
|
||||
: QProgressBar(parent), m_error(false)
|
||||
: QWidget(parent), m_error(false), m_minimum(1), m_maximum(100), m_value(1)
|
||||
{
|
||||
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
|
||||
setMouseTracking(true);
|
||||
@@ -49,6 +49,32 @@ ProgressBar::~ProgressBar()
|
||||
{
|
||||
}
|
||||
|
||||
void ProgressBar::reset()
|
||||
{
|
||||
m_value = m_minimum;
|
||||
update();
|
||||
}
|
||||
|
||||
void ProgressBar::setRange(int minimum, int maximum)
|
||||
{
|
||||
m_minimum = minimum;
|
||||
m_maximum = maximum;
|
||||
if (m_value < m_minimum || m_value > m_maximum)
|
||||
m_value = m_minimum;
|
||||
update();
|
||||
}
|
||||
|
||||
void ProgressBar::setValue(int value)
|
||||
{
|
||||
if (m_value == value
|
||||
|| m_value < m_minimum
|
||||
|| m_value > m_maximum) {
|
||||
return;
|
||||
}
|
||||
m_value = value;
|
||||
update();
|
||||
}
|
||||
|
||||
QString ProgressBar::title() const
|
||||
{
|
||||
return m_title;
|
||||
@@ -62,6 +88,7 @@ bool ProgressBar::hasError() const
|
||||
void ProgressBar::setTitle(const QString &title)
|
||||
{
|
||||
m_title = title;
|
||||
update();
|
||||
}
|
||||
|
||||
void ProgressBar::setError(bool on)
|
||||
@@ -88,7 +115,7 @@ void ProgressBar::mousePressEvent(QMouseEvent *event)
|
||||
emit clicked();
|
||||
return;
|
||||
}
|
||||
QProgressBar::mousePressEvent(event);
|
||||
QWidget::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void ProgressBar::mouseMoveEvent(QMouseEvent *)
|
||||
|
@@ -35,7 +35,7 @@
|
||||
#include <QtGui/QProgressBar>
|
||||
#include <QtGui/QMouseEvent>
|
||||
|
||||
class ProgressBar : public QProgressBar
|
||||
class ProgressBar : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
@@ -51,6 +51,12 @@ public:
|
||||
void paintEvent(QPaintEvent *);
|
||||
void mouseMoveEvent(QMouseEvent *);
|
||||
|
||||
int minimum() const { return m_minimum; }
|
||||
int maximum() const { return m_maximum; }
|
||||
int value() const { return m_value; }
|
||||
void reset();
|
||||
void setRange(int minimum, int maximum);
|
||||
void setValue(int value);
|
||||
signals:
|
||||
void clicked();
|
||||
|
||||
@@ -62,6 +68,10 @@ private:
|
||||
QString m_title;
|
||||
bool m_error;
|
||||
int m_progressHeight;
|
||||
|
||||
int m_minimum;
|
||||
int m_maximum;
|
||||
int m_value;
|
||||
};
|
||||
|
||||
#endif // PROGRESSPIE_H
|
||||
|
Reference in New Issue
Block a user