implement determinate progress mode
This commit is contained in:
parent
37d58b4a75
commit
70a1f106cb
|
@ -182,10 +182,10 @@ void CircularProgress::paintEvent(QPaintEvent *event)
|
|||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
painter.drawRect(rect());
|
||||
|
||||
painter.translate(width()/2, height()/2);
|
||||
painter.rotate(d->delegate->angle());
|
||||
if (Material::IndeterminateProgress == d->progressType) {
|
||||
painter.translate(width()/2, height()/2);
|
||||
painter.rotate(d->delegate->angle());
|
||||
}
|
||||
|
||||
QPen pen;
|
||||
pen.setCapStyle(Qt::RoundCap);
|
||||
|
@ -206,6 +206,17 @@ void CircularProgress::paintEvent(QPaintEvent *event)
|
|||
}
|
||||
else
|
||||
{
|
||||
painter.setPen(pen);
|
||||
|
||||
const qreal x = (width()-d->size)/2;
|
||||
const qreal y = (height()-d->size)/2;
|
||||
|
||||
const qreal a = 360*(value()-minimum())/(maximum()-minimum());
|
||||
|
||||
QPainterPath path;
|
||||
path.arcMoveTo(x, y, d->size, d->size, 0);
|
||||
path.arcTo(x, y, d->size, d->size, 0, a);
|
||||
|
||||
painter.drawPath(path);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "progress.h"
|
||||
#include <QPainter>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QDebug>
|
||||
#include "progress_p.h"
|
||||
#include "progress_internal.h"
|
||||
#include "lib/style.h"
|
||||
|
@ -140,9 +141,13 @@ void Progress::paintEvent(QPaintEvent *event)
|
|||
brush.setColor(progressColor());
|
||||
painter.setBrush(brush);
|
||||
|
||||
if (Material::IndeterminateProgress == d->progressType) {
|
||||
if (Material::IndeterminateProgress == d->progressType)
|
||||
{
|
||||
painter.drawRect(d->delegate->offset()*width()*2-width(), 0, width(), height());
|
||||
} else {
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
qreal p = static_cast<qreal>(width())*(value()-minimum())/(maximum()-minimum());
|
||||
painter.drawRect(0, 0, p, height());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,10 @@ AppBarExamples::AppBarExamples(QWidget *parent)
|
|||
: QWidget(parent)
|
||||
{
|
||||
Progress *p = new Progress;
|
||||
p->setProgressType(Material::DeterminateProgress);
|
||||
p->setMinimum(0);
|
||||
p->setMaximum(99);
|
||||
p->setValue(22);
|
||||
|
||||
QVBoxLayout *l = new QVBoxLayout;
|
||||
|
||||
|
@ -21,11 +25,17 @@ AppBarExamples::AppBarExamples(QWidget *parent)
|
|||
l->addWidget(p);
|
||||
|
||||
CircularProgress *cp = new CircularProgress;
|
||||
cp->setSize(30);
|
||||
cp->setProgressType(Material::DeterminateProgress);
|
||||
cp->setMinimum(0);
|
||||
cp->setMaximum(99);
|
||||
cp->setValue(90);
|
||||
|
||||
l->addWidget(cp);
|
||||
|
||||
QProgressBar *pb = new QProgressBar;
|
||||
pb->setMinimum(0);
|
||||
pb->setMaximum(99);
|
||||
pb->setValue(50);
|
||||
|
||||
QPushButton *b = new QPushButton;
|
||||
|
||||
|
|
Loading…
Reference in New Issue