implement basic indeterminate progress animations
This commit is contained in:
parent
e756328547
commit
fff7078542
|
@ -9,6 +9,8 @@
|
||||||
|
|
||||||
CircularProgressPrivate::CircularProgressPrivate(CircularProgress *q)
|
CircularProgressPrivate::CircularProgressPrivate(CircularProgress *q)
|
||||||
: q_ptr(q),
|
: q_ptr(q),
|
||||||
|
delegate(0),
|
||||||
|
progressType(Material::IndeterminateProgress),
|
||||||
size(64),
|
size(64),
|
||||||
angle(0),
|
angle(0),
|
||||||
penWidth(6.25),
|
penWidth(6.25),
|
||||||
|
@ -107,7 +109,6 @@ bool CircularProgress::useThemeColors() const
|
||||||
return d->useThemeColors;
|
return d->useThemeColors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CircularProgress::setLineWidth(qreal width)
|
void CircularProgress::setLineWidth(qreal width)
|
||||||
{
|
{
|
||||||
Q_D(CircularProgress);
|
Q_D(CircularProgress);
|
||||||
|
@ -155,7 +156,6 @@ QColor CircularProgress::color() const
|
||||||
} else {
|
} else {
|
||||||
return d->color;
|
return d->color;
|
||||||
}
|
}
|
||||||
return d->color;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize CircularProgress::sizeHint() const
|
QSize CircularProgress::sizeHint() const
|
||||||
|
@ -185,6 +185,8 @@ void CircularProgress::paintEvent(QPaintEvent *event)
|
||||||
pen.setWidthF(d->penWidth);
|
pen.setWidthF(d->penWidth);
|
||||||
pen.setColor(color());
|
pen.setColor(color());
|
||||||
|
|
||||||
|
if (Material::IndeterminateProgress == d->progressType)
|
||||||
|
{
|
||||||
QVector<qreal> pattern;
|
QVector<qreal> pattern;
|
||||||
pattern << d->delegate->dashLength()*d->size/50 << 30*d->size/50;
|
pattern << d->delegate->dashLength()*d->size/50 << 30*d->size/50;
|
||||||
|
|
||||||
|
@ -194,6 +196,11 @@ void CircularProgress::paintEvent(QPaintEvent *event)
|
||||||
painter.setPen(pen);
|
painter.setPen(pen);
|
||||||
|
|
||||||
painter.drawEllipse(QPoint(0, 0), d->size/2, d->size/2);
|
painter.drawEllipse(QPoint(0, 0), d->size/2, d->size/2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CircularProgress::timerEvent(QTimerEvent *event)
|
void CircularProgress::timerEvent(QTimerEvent *event)
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
#include "circularprogress.h"
|
#include "circularprogress.h"
|
||||||
|
|
||||||
CircularProgressDelegate::CircularProgressDelegate(CircularProgress *parent)
|
CircularProgressDelegate::CircularProgressDelegate(CircularProgress *parent)
|
||||||
: progress(parent),
|
: QObject(parent),
|
||||||
|
progress(parent),
|
||||||
_dashOffset(0),
|
_dashOffset(0),
|
||||||
_dashLength(89)
|
_dashLength(89)
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,7 +13,7 @@ class CircularProgressDelegate : public QObject
|
||||||
Q_PROPERTY(qreal dashLength WRITE setDashLength READ dashLength)
|
Q_PROPERTY(qreal dashLength WRITE setDashLength READ dashLength)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CircularProgressDelegate(CircularProgress *parent = 0);
|
CircularProgressDelegate(CircularProgress *parent);
|
||||||
~CircularProgressDelegate();
|
~CircularProgressDelegate();
|
||||||
|
|
||||||
void setDashOffset(qreal offset);
|
void setDashOffset(qreal offset);
|
||||||
|
|
|
@ -1,9 +1,15 @@
|
||||||
#include "progress.h"
|
#include "progress.h"
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QPropertyAnimation>
|
||||||
#include "progress_p.h"
|
#include "progress_p.h"
|
||||||
|
#include "progress_internal.h"
|
||||||
|
#include "lib/style.h"
|
||||||
|
|
||||||
ProgressPrivate::ProgressPrivate(Progress *q)
|
ProgressPrivate::ProgressPrivate(Progress *q)
|
||||||
: q_ptr(q)
|
: q_ptr(q),
|
||||||
|
delegate(0),
|
||||||
|
progressType(Material::IndeterminateProgress),
|
||||||
|
useThemeColors(true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +19,22 @@ ProgressPrivate::~ProgressPrivate()
|
||||||
|
|
||||||
void ProgressPrivate::init()
|
void ProgressPrivate::init()
|
||||||
{
|
{
|
||||||
|
Q_Q(Progress);
|
||||||
|
|
||||||
|
delegate = new ProgressDelegate(q);
|
||||||
|
|
||||||
|
QPropertyAnimation *animation;
|
||||||
|
|
||||||
|
animation = new QPropertyAnimation(q);
|
||||||
|
animation->setPropertyName("offset");
|
||||||
|
animation->setTargetObject(delegate);
|
||||||
|
animation->setStartValue(0);
|
||||||
|
animation->setEndValue(1);
|
||||||
|
animation->setDuration(1000);
|
||||||
|
|
||||||
|
animation->setLoopCount(-1);
|
||||||
|
|
||||||
|
animation->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
Progress::Progress(QWidget *parent)
|
Progress::Progress(QWidget *parent)
|
||||||
|
@ -41,34 +63,86 @@ Material::ProgressType Progress::progressType() const
|
||||||
return d->progressType;
|
return d->progressType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Progress::setUseThemeColors(bool state)
|
||||||
|
{
|
||||||
|
Q_D(Progress);
|
||||||
|
|
||||||
|
d->useThemeColors = state;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Progress::useThemeColors() const
|
||||||
|
{
|
||||||
|
Q_D(const Progress);
|
||||||
|
|
||||||
|
return d->useThemeColors;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Progress::setProgressColor(const QColor &color)
|
||||||
|
{
|
||||||
|
Q_D(Progress);
|
||||||
|
|
||||||
|
d->progressColor = color;
|
||||||
|
setUseThemeColors(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
QColor Progress::progressColor() const
|
||||||
|
{
|
||||||
|
Q_D(const Progress);
|
||||||
|
|
||||||
|
if (d->useThemeColors || !d->progressColor.isValid()) {
|
||||||
|
return Style::instance().themeColor("primary1");
|
||||||
|
} else {
|
||||||
|
return d->progressColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Progress::setBackgroundColor(const QColor &color)
|
||||||
|
{
|
||||||
|
Q_D(Progress);
|
||||||
|
|
||||||
|
d->backgroundColor = color;
|
||||||
|
setUseThemeColors(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
QColor Progress::backgroundColor() const
|
||||||
|
{
|
||||||
|
Q_D(const Progress);
|
||||||
|
|
||||||
|
if (d->useThemeColors || !d->backgroundColor.isValid()) {
|
||||||
|
return Style::instance().themeColor("accent3");
|
||||||
|
} else {
|
||||||
|
return d->backgroundColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Progress::paintEvent(QPaintEvent *event)
|
void Progress::paintEvent(QPaintEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(event)
|
Q_UNUSED(event)
|
||||||
|
|
||||||
|
Q_D(Progress);
|
||||||
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
painter.setRenderHint(QPainter::Antialiasing);
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
|
|
||||||
// painter.drawRect(rect().adjusted(0, 0, -1, -1));
|
|
||||||
|
|
||||||
QBrush brush;
|
QBrush brush;
|
||||||
brush.setStyle(Qt::SolidPattern);
|
brush.setStyle(Qt::SolidPattern);
|
||||||
brush.setColor(Qt::black);
|
brush.setColor(backgroundColor());
|
||||||
painter.setBrush(brush);
|
painter.setBrush(brush);
|
||||||
painter.setPen(Qt::NoPen);
|
painter.setPen(Qt::NoPen);
|
||||||
|
|
||||||
//QRectF r(0, 0, width(), 8);
|
|
||||||
//r.moveCenter(rect().center());
|
|
||||||
|
|
||||||
//painter.drawRect(r);
|
|
||||||
|
|
||||||
QPainterPath path;
|
QPainterPath path;
|
||||||
path.addRoundedRect(0, height()/2-4, width(), 8, 3, 3);
|
path.addRoundedRect(0, height()/2-3, width(), 6, 3, 3);
|
||||||
painter.setClipPath(path);
|
painter.setClipPath(path);
|
||||||
|
|
||||||
painter.drawRect(0, 0, width(), height());
|
painter.drawRect(0, 0, width(), height());
|
||||||
|
|
||||||
brush.setColor(Qt::blue);
|
brush.setColor(progressColor());
|
||||||
painter.setBrush(brush);
|
painter.setBrush(brush);
|
||||||
|
|
||||||
painter.drawRect(0, 0, width()/2, height());
|
if (Material::IndeterminateProgress == d->progressType) {
|
||||||
|
painter.drawRect(d->delegate->offset()*width()*2-width(), 0, width(), height());
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,9 @@ class Progress : public QProgressBar
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
Q_PROPERTY(QColor progressColor WRITE setProgressColor READ progressColor)
|
||||||
|
Q_PROPERTY(QColor backgroundColor WRITE setProgressColor READ backgroundColor)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Progress(QWidget *parent = 0);
|
explicit Progress(QWidget *parent = 0);
|
||||||
~Progress();
|
~Progress();
|
||||||
|
@ -17,6 +20,15 @@ public:
|
||||||
void setProgressType(Material::ProgressType type);
|
void setProgressType(Material::ProgressType type);
|
||||||
Material::ProgressType progressType() const;
|
Material::ProgressType progressType() const;
|
||||||
|
|
||||||
|
void setUseThemeColors(bool state);
|
||||||
|
bool useThemeColors() const;
|
||||||
|
|
||||||
|
void setProgressColor(const QColor &color);
|
||||||
|
QColor progressColor() const;
|
||||||
|
|
||||||
|
void setBackgroundColor(const QColor &color);
|
||||||
|
QColor backgroundColor() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
#include "progress_internal.h"
|
||||||
|
#include "progress.h"
|
||||||
|
|
||||||
|
ProgressDelegate::ProgressDelegate(Progress *parent)
|
||||||
|
: QObject(parent),
|
||||||
|
progress(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
ProgressDelegate::~ProgressDelegate()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProgressDelegate::setOffset(qreal offset)
|
||||||
|
{
|
||||||
|
_offset = offset;
|
||||||
|
progress->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
qreal ProgressDelegate::offset() const
|
||||||
|
{
|
||||||
|
return _offset;
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
#ifndef PROGRESS_INTERNAL_H
|
||||||
|
#define PROGRESS_INTERNAL_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class Progress;
|
||||||
|
|
||||||
|
class ProgressDelegate : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
Q_PROPERTY(qreal offset WRITE setOffset READ offset)
|
||||||
|
|
||||||
|
public:
|
||||||
|
ProgressDelegate(Progress *parent);
|
||||||
|
~ProgressDelegate();
|
||||||
|
|
||||||
|
void setOffset(qreal offset);
|
||||||
|
qreal offset() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Q_DISABLE_COPY(ProgressDelegate)
|
||||||
|
|
||||||
|
Progress *const progress;
|
||||||
|
qreal _offset;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PROGRESS_INTERNAL_H
|
|
@ -5,6 +5,7 @@
|
||||||
#include "lib/theme.h"
|
#include "lib/theme.h"
|
||||||
|
|
||||||
class Progress;
|
class Progress;
|
||||||
|
class ProgressDelegate;
|
||||||
|
|
||||||
class ProgressPrivate
|
class ProgressPrivate
|
||||||
{
|
{
|
||||||
|
@ -18,7 +19,11 @@ public:
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
Progress *const q_ptr;
|
Progress *const q_ptr;
|
||||||
|
ProgressDelegate *delegate;
|
||||||
Material::ProgressType progressType;
|
Material::ProgressType progressType;
|
||||||
|
QColor progressColor;
|
||||||
|
QColor backgroundColor;
|
||||||
|
bool useThemeColors;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PROGRESS_P_H
|
#endif // PROGRESS_P_H
|
||||||
|
|
|
@ -67,7 +67,8 @@ SOURCES += main.cpp\
|
||||||
components/drawer.cpp \
|
components/drawer.cpp \
|
||||||
components/snackbar_internal.cpp \
|
components/snackbar_internal.cpp \
|
||||||
components/circularprogress.cpp \
|
components/circularprogress.cpp \
|
||||||
components/circularprogress_internal.cpp
|
components/circularprogress_internal.cpp \
|
||||||
|
components/progress_internal.cpp
|
||||||
|
|
||||||
HEADERS += mainwindow.h \
|
HEADERS += mainwindow.h \
|
||||||
components/appbar.h \
|
components/appbar.h \
|
||||||
|
@ -145,7 +146,8 @@ HEADERS += mainwindow.h \
|
||||||
components/progress_p.h \
|
components/progress_p.h \
|
||||||
components/circularprogress.h \
|
components/circularprogress.h \
|
||||||
components/circularprogress_p.h \
|
components/circularprogress_p.h \
|
||||||
components/circularprogress_internal.h
|
components/circularprogress_internal.h \
|
||||||
|
components/progress_internal.h
|
||||||
|
|
||||||
RESOURCES += \
|
RESOURCES += \
|
||||||
resources.qrc
|
resources.qrc
|
||||||
|
|
Loading…
Reference in New Issue