Commit 41772f39 authored by Martin Tobias Holmedahl Sandsmark's avatar Martin Tobias Holmedahl Sandsmark
Browse files

Make the progress box prettier

 - 60 fps
 - Vary the length of the arcs
 - Make sure the progress box always fits the size of the text
 - Make the arcs start growing from 0
parent d1d1b01f
......@@ -9,6 +9,7 @@
#include "scan.h"
#include "mainWindow.h"
#include "radialMap/radialMap.h"
#include <KFormat>
#include <KIO/Job>
......@@ -19,6 +20,7 @@
#include <QFontDatabase>
#include <math.h>
#include <limits.h>
ProgressBox::ProgressBox(QWidget *parent, Filelight::MainWindow *mainWindow, Filelight::ScanManager *scanManager)
: QWidget(parent)
......@@ -30,10 +32,11 @@ ProgressBox::ProgressBox(QWidget *parent, Filelight::MainWindow *mainWindow, Fil
setObjectName(QStringLiteral( "ProgressBox" ));
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
setText(INT_MAX, SSIZE_MAX);
Please register or sign in to reply
setText(999999, 0);
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
setMinimumSize(300, 300);
const int textSize = qMax(m_textWidth + LABEL_TEXT_HMARGIN, m_textHeight + LABEL_TEXT_VMARGIN);
setMinimumSize(qMax(textSize, 300), qMax(textSize, 300));
connect(&m_timer, &QTimer::timeout, this, &ProgressBox::report);
connect(mainWindow, &Filelight::MainWindow::started, this, &ProgressBox::start);
......@@ -44,16 +47,19 @@ ProgressBox::ProgressBox(QWidget *parent, Filelight::MainWindow *mainWindow, Fil
void
ProgressBox::start() //slot
{
m_timer.start(50); //20 times per second - very smooth
// 60 fps, because Qt has that hardcoded everywhere and I'm not in the mood to
// manually get the display FPS on all platforms.
m_timer.start(16);
report();
show();
m_tick = 0;
}
void
ProgressBox::report() //slot
{
setText(m_manager->files(), m_manager->totalSize());
update(); //repaint();
update();
}
void
......@@ -79,8 +85,8 @@ ProgressBox::setText(int files, size_t totalSize)
}
#define PIECES_NUM 4
static const float angleFactor[] = { -0.25, 0.9, -1.0, 0.3 };
static const float length[] = { 1.0, 1.0, 1.0, 1.0 };
static const float angleFactor[] = { -0.15, 0.25, -0.3, 0.1 };
static const float length[] = { 1.0, 1.0, 0.75, 0.9 };
static const int aLength[] = { 2000, 2000, 2000, 2000 };
void ProgressBox::paintEvent(QPaintEvent*)
......@@ -89,19 +95,18 @@ void ProgressBox::paintEvent(QPaintEvent*)
QPainter paint(this);
paint.setPen(Qt::transparent);
paint.setRenderHint(QPainter::Antialiasing);
static int tick = 0;
tick+=16;
m_tick += 16;
for (int i=0; i<PIECES_NUM; i++) {
const qreal size = qMin(width(), height()) * length[i];
const QRectF rect(width() / 2 - size / 2, height() / 2 - size / 2, size, size);
int angle = angleFactor[i] + tick*angleFactor[i];
int angle = angleFactor[i] + m_tick * angleFactor[i];
QRadialGradient gradient(rect.center(), sin(angle/160.0f) * 100);
gradient.setColorAt(0, QColor::fromHsv(abs(angle/16) % 360 , 160, 255));
gradient.setColorAt(1, QColor::fromHsv(abs(angle/16) % 360 , 160, 128));
QBrush brush(gradient);
paint.setBrush(brush);
paint.drawPie(QRectF(rect), angle, aLength[i]);
paint.drawPie(QRectF(rect), angle, qMin(m_tick/1600., 1.0) * aLength[i]);
}
paint.translate(0.5, 0.5);
......
......@@ -39,8 +39,9 @@ private:
QTimer m_timer;
Filelight::ScanManager* m_manager;
QString m_text;
int m_textWidth;
int m_textHeight;
int m_textWidth = 0;
int m_textHeight = 0;
int m_tick = 0;
KColorScheme m_colorScheme;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment