summary refs log tree commit diff
path: root/src/ui/LoadingIndicator.cc
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2017-09-10 12:58:00 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2017-09-10 12:58:00 +0300
commitedff71bc2403c966bd61d5dde391184aa8822aac (patch)
treeb5bb03f52de228110bd30cb0be36183574358aa0 /src/ui/LoadingIndicator.cc
parentAllow port number as part of the hostname (diff)
downloadnheko-edff71bc2403c966bd61d5dde391184aa8822aac.tar.xz
Implement image uploads (#24)
Diffstat (limited to 'src/ui/LoadingIndicator.cc')
-rw-r--r--src/ui/LoadingIndicator.cc86
1 files changed, 86 insertions, 0 deletions
diff --git a/src/ui/LoadingIndicator.cc b/src/ui/LoadingIndicator.cc
new file mode 100644

index 00000000..0fafaf23 --- /dev/null +++ b/src/ui/LoadingIndicator.cc
@@ -0,0 +1,86 @@ +#include "LoadingIndicator.h" + +#include <QDebug> +#include <QPoint> +#include <QtGlobal> + +LoadingIndicator::LoadingIndicator(QWidget *parent) + : QWidget(parent) + , interval_(70) + , angle_(0) + , color_(Qt::black) +{ + setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + setFocusPolicy(Qt::NoFocus); + + timer_ = new QTimer(); + connect(timer_, SIGNAL(timeout()), this, SLOT(onTimeout())); +} + +LoadingIndicator::~LoadingIndicator() +{ + stop(); + + delete timer_; +} + +void +LoadingIndicator::paintEvent(QPaintEvent *e) +{ + Q_UNUSED(e) + + if (!timer_->isActive()) + return; + + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); + + int width = qMin(this->width(), this->height()); + + int outerRadius = (width - 4) * 0.5f; + int innerRadius = outerRadius * 0.78f; + + int capsuleRadius = (outerRadius - innerRadius) / 2; + + for (int i = 0; i < 8; i++) { + QColor color = color_; + + color.setAlphaF(1.0f - (i / 8.0f)); + + painter.setPen(Qt::NoPen); + painter.setBrush(color); + + qreal radius = capsuleRadius * (1.0f - (i / 16.0f)); + + painter.save(); + + painter.translate(rect().center()); + painter.rotate(angle_ - i * 45.0f); + + QPointF center = QPointF(-capsuleRadius, -innerRadius); + painter.drawEllipse(center, radius * 2, radius * 2); + + painter.restore(); + } +} + +void +LoadingIndicator::start() +{ + timer_->start(interval_); + show(); +} + +void +LoadingIndicator::stop() +{ + timer_->stop(); + hide(); +} + +void +LoadingIndicator::onTimeout() +{ + angle_ = (angle_ + 45) % 360; + update(); +}