Files
Sourcetrail/src/lib_gui/qt/element/QtProgressBar.cpp
T
Eberhard Graether ff65a3f285 logic: Added update checker connecting to online API
* connects to https://www.sourcetrail.com/api/v1/versions/latest
* sends information about OS, platform, license type, current version and a unique user token
* Automatic update check is enabled via Startscreen and performed once every 24 hours on window focus
* Update check can be forced by clicking on "check for new version" on start screen
* renamed TimePoint to TimeStamp

fortune cookie message = In Träumen und im Leben ist nichts unmöglich.
2017-08-08 14:18:14 +02:00

84 lines
1.3 KiB
C++

#include "qt/element/QtProgressBar.h"
#include <QTimer>
#include <QPainter>
#include <QPaintEvent>
#include <QPixmap>
#include "utility/ResourcePaths.h"
QtProgressBar::QtProgressBar(QWidget* parent)
: QWidget(parent)
, m_percent(0)
, m_count(0)
, m_pixmap((ResourcePaths::getGuiPath().str() + "indexing_dialog/progress_bar_element.png").c_str())
{
m_timer = new QTimer(this);
connect(m_timer, &QTimer::timeout, this, &QtProgressBar::animate);
m_pixmap.scaleToHeight(20);
}
void QtProgressBar::showProgress(size_t percent)
{
m_percent = percent;
stop();
show();
update();
}
void QtProgressBar::showUnknownProgressAnimated()
{
start();
show();
}
void QtProgressBar::paintEvent(QPaintEvent* event)
{
QPainter painter(this);
if (m_count)
{
const QPixmap& pixmap = m_pixmap.pixmap();
for (int x = -36 + (m_count % 36); x < geometry().width(); x += 18)
{
painter.drawPixmap(QPointF(x, -5), pixmap);
}
}
else
{
painter.fillRect(0, 2, geometry().width() * m_percent / 100, 6, "white");
}
}
void QtProgressBar::start()
{
m_TimeStamp = TimeStamp::now();
m_timer->start(25);
}
void QtProgressBar::stop()
{
m_timer->stop();
m_count = 0;
}
void QtProgressBar::animate()
{
TimeStamp t = TimeStamp::now();
size_t dt = t.deltaMS(m_TimeStamp);
if (dt < 5)
{
return;
}
m_TimeStamp = t;
m_count++;
update();
}