implement linear progress

This commit is contained in:
laserpants 2016-06-19 12:18:05 +03:00
parent 1e908ada5c
commit e756328547
4 changed files with 55 additions and 7 deletions

View File

@ -16,7 +16,7 @@ void ProgressPrivate::init()
}
Progress::Progress(QWidget *parent)
: QWidget(parent),
: QProgressBar(parent),
d_ptr(new ProgressPrivate(this))
{
d_func()->init();
@ -26,9 +26,49 @@ Progress::~Progress()
{
}
void Progress::setProgressType(Material::ProgressType type)
{
Q_D(Progress);
d->progressType = type;
update();
}
Material::ProgressType Progress::progressType() const
{
Q_D(const Progress);
return d->progressType;
}
void Progress::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
Q_UNUSED(event)
painter.drawRect(rect());
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
// painter.drawRect(rect().adjusted(0, 0, -1, -1));
QBrush brush;
brush.setStyle(Qt::SolidPattern);
brush.setColor(Qt::black);
painter.setBrush(brush);
painter.setPen(Qt::NoPen);
//QRectF r(0, 0, width(), 8);
//r.moveCenter(rect().center());
//painter.drawRect(r);
QPainterPath path;
path.addRoundedRect(0, height()/2-4, width(), 8, 3, 3);
painter.setClipPath(path);
painter.drawRect(0, 0, width(), height());
brush.setColor(Qt::blue);
painter.setBrush(brush);
painter.drawRect(0, 0, width()/2, height());
}

View File

@ -1,11 +1,12 @@
#ifndef PROGRESS_H
#define PROGRESS_H
#include <QWidget>
#include <QProgressBar>
#include "lib/theme.h"
class ProgressPrivate;
class Progress : public QWidget
class Progress : public QProgressBar
{
Q_OBJECT
@ -13,6 +14,9 @@ public:
explicit Progress(QWidget *parent = 0);
~Progress();
void setProgressType(Material::ProgressType type);
Material::ProgressType progressType() const;
protected:
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;

View File

@ -2,6 +2,7 @@
#define PROGRESS_P_H
#include <QObject>
#include "lib/theme.h"
class Progress;
@ -17,6 +18,7 @@ public:
void init();
Progress *const q_ptr;
Material::ProgressType progressType;
};
#endif // PROGRESS_P_H

View File

@ -66,7 +66,8 @@ SOURCES += main.cpp\
components/textfield_internal.cpp \
components/drawer.cpp \
components/snackbar_internal.cpp \
components/circularprogress.cpp
components/circularprogress.cpp \
components/circularprogress_internal.cpp
HEADERS += mainwindow.h \
components/appbar.h \
@ -143,7 +144,8 @@ HEADERS += mainwindow.h \
components/snackbar_internal.h \
components/progress_p.h \
components/circularprogress.h \
components/circularprogress_p.h
components/circularprogress_p.h \
components/circularprogress_internal.h
RESOURCES += \
resources.qrc