mirror of
https://github.com/rizinorg/cutter.git
synced 2025-01-19 10:58:51 +00:00
Add ProgressIndicator for Tasks
This commit is contained in:
parent
c0397fdcb5
commit
baf7abce60
@ -168,7 +168,8 @@ SOURCES += \
|
|||||||
widgets/BacktraceWidget.cpp \
|
widgets/BacktraceWidget.cpp \
|
||||||
dialogs/OpenFileDialog.cpp \
|
dialogs/OpenFileDialog.cpp \
|
||||||
utils/StringsTask.cpp \
|
utils/StringsTask.cpp \
|
||||||
utils/CommandTask.cpp
|
utils/CommandTask.cpp \
|
||||||
|
utils/ProgressIndicator.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
Cutter.h \
|
Cutter.h \
|
||||||
@ -251,7 +252,8 @@ HEADERS += \
|
|||||||
widgets/BacktraceWidget.h \
|
widgets/BacktraceWidget.h \
|
||||||
dialogs/OpenFileDialog.h \
|
dialogs/OpenFileDialog.h \
|
||||||
utils/StringsTask.h \
|
utils/StringsTask.h \
|
||||||
utils/CommandTask.h
|
utils/CommandTask.h \
|
||||||
|
utils/ProgressIndicator.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
dialogs/AboutDialog.ui \
|
dialogs/AboutDialog.ui \
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#include "utils/HexAsciiHighlighter.h"
|
#include "utils/HexAsciiHighlighter.h"
|
||||||
#include "utils/Helpers.h"
|
#include "utils/Helpers.h"
|
||||||
#include "utils/SvgIconEngine.h"
|
#include "utils/SvgIconEngine.h"
|
||||||
|
#include "utils/ProgressIndicator.h"
|
||||||
|
|
||||||
#include "dialogs/NewFileDialog.h"
|
#include "dialogs/NewFileDialog.h"
|
||||||
#include "dialogs/OptionsDialog.h"
|
#include "dialogs/OptionsDialog.h"
|
||||||
@ -143,8 +144,14 @@ void MainWindow::initUI()
|
|||||||
spacer->setMinimumSize(20, 20);
|
spacer->setMinimumSize(20, 20);
|
||||||
ui->mainToolBar->addWidget(spacer);
|
ui->mainToolBar->addWidget(spacer);
|
||||||
|
|
||||||
tasksIndicator = new QLabel(this);
|
tasksProgressIndicator = new ProgressIndicator();
|
||||||
ui->mainToolBar->addWidget(tasksIndicator);
|
ui->mainToolBar->addWidget(tasksProgressIndicator);
|
||||||
|
|
||||||
|
QWidget *spacerEnd = new QWidget();
|
||||||
|
spacerEnd->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
||||||
|
spacerEnd->setMinimumSize(4, 0);
|
||||||
|
spacerEnd->setMaximumWidth(4);
|
||||||
|
ui->mainToolBar->addWidget(spacerEnd);
|
||||||
|
|
||||||
// Visual navigation tool bar
|
// Visual navigation tool bar
|
||||||
this->visualNavbar = new VisualNavbar(this);
|
this->visualNavbar = new VisualNavbar(this);
|
||||||
@ -237,9 +244,7 @@ void MainWindow::initUI()
|
|||||||
void MainWindow::updateTasksIndicator()
|
void MainWindow::updateTasksIndicator()
|
||||||
{
|
{
|
||||||
bool running = Core()->getAsyncTaskManager()->getTasksRunning();
|
bool running = Core()->getAsyncTaskManager()->getTasksRunning();
|
||||||
QLabel *l = static_cast<QLabel *>(tasksIndicator);
|
tasksProgressIndicator->setProgressIndicatorVisible(running);
|
||||||
l->setText(running ? "running" : "");
|
|
||||||
//tasksIndicator->setVisible(running);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionExtraGraph_triggered()
|
void MainWindow::on_actionExtraGraph_triggered()
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
class CutterCore;
|
class CutterCore;
|
||||||
class Omnibar;
|
class Omnibar;
|
||||||
|
class ProgressIndicator;
|
||||||
class PreviewWidget;
|
class PreviewWidget;
|
||||||
class Highlighter;
|
class Highlighter;
|
||||||
class AsciiHighlighter;
|
class AsciiHighlighter;
|
||||||
@ -183,7 +184,7 @@ private:
|
|||||||
AsciiHighlighter *hex_highlighter;
|
AsciiHighlighter *hex_highlighter;
|
||||||
VisualNavbar *visualNavbar;
|
VisualNavbar *visualNavbar;
|
||||||
Omnibar *omnibar;
|
Omnibar *omnibar;
|
||||||
QWidget *tasksIndicator;
|
ProgressIndicator *tasksProgressIndicator;
|
||||||
|
|
||||||
Configuration *configuration;
|
Configuration *configuration;
|
||||||
|
|
||||||
|
89
src/utils/ProgressIndicator.cpp
Normal file
89
src/utils/ProgressIndicator.cpp
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
|
||||||
|
#include "ProgressIndicator.h"
|
||||||
|
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
|
static const int lineWidth = 3;
|
||||||
|
static const int paddingOuter = lineWidth + 2;
|
||||||
|
static const int paddingInner = 8;
|
||||||
|
static const int arms = 12;
|
||||||
|
static const int timerInterval = 50;
|
||||||
|
|
||||||
|
ProgressIndicator::ProgressIndicator(QWidget *parent)
|
||||||
|
: QWidget(parent)
|
||||||
|
{
|
||||||
|
updateAnimationTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
ProgressIndicator::~ProgressIndicator()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProgressIndicator::setProgressIndicatorVisible(bool visible)
|
||||||
|
{
|
||||||
|
bool change = progressIndicatorVisible != visible;
|
||||||
|
progressIndicatorVisible = visible;
|
||||||
|
if (change) {
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
updateAnimationTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProgressIndicator::setAnimating(bool animating)
|
||||||
|
{
|
||||||
|
this->animating = animating;
|
||||||
|
updateAnimationTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProgressIndicator::updateAnimationTimer()
|
||||||
|
{
|
||||||
|
bool shouldBeAnimating = animating && progressIndicatorVisible;
|
||||||
|
if (shouldBeAnimating && !animationTimerId) {
|
||||||
|
animationTimerId = startTimer(timerInterval);
|
||||||
|
} else {
|
||||||
|
killTimer(animationTimerId);
|
||||||
|
animationTimerId = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QSize ProgressIndicator::minimumSizeHint() const
|
||||||
|
{
|
||||||
|
return QSize(16, 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
QSize ProgressIndicator::sizeHint() const
|
||||||
|
{
|
||||||
|
return QSize(32, 32);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProgressIndicator::timerEvent(QTimerEvent *)
|
||||||
|
{
|
||||||
|
animationState = (animationState + 1) % arms;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
void ProgressIndicator::paintEvent(QPaintEvent *)
|
||||||
|
{
|
||||||
|
if (!getProgressIndicatorVisible()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPainter painter(this);
|
||||||
|
painter.setRenderHint(QPainter::Antialiasing, true);
|
||||||
|
|
||||||
|
QPen pen(palette().windowText(), lineWidth, Qt::SolidLine, Qt::RoundCap);
|
||||||
|
painter.setPen(pen);
|
||||||
|
|
||||||
|
QPointF origin(width() * 0.5, height() * 0.5);
|
||||||
|
QLineF line(paddingInner, 0.0, width() * 0.5 - paddingOuter, 0.0);
|
||||||
|
|
||||||
|
qreal angle = 360.0 / arms;
|
||||||
|
for (int i=0; i<arms; i++) {
|
||||||
|
int state = (i + (arms - animationState)) % arms;
|
||||||
|
painter.setOpacity((float)state / arms);
|
||||||
|
painter.drawLine(line * QTransform()
|
||||||
|
.translate(origin.x(), origin.y())
|
||||||
|
.rotate(angle * i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
37
src/utils/ProgressIndicator.h
Normal file
37
src/utils/ProgressIndicator.h
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
|
||||||
|
#ifndef PROGRESSINDICATOR_H
|
||||||
|
#define PROGRESSINDICATOR_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
class ProgressIndicator: public QWidget
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ProgressIndicator(QWidget *parent = nullptr);
|
||||||
|
virtual ~ProgressIndicator();
|
||||||
|
|
||||||
|
QSize minimumSizeHint() const override;
|
||||||
|
QSize sizeHint() const override;
|
||||||
|
|
||||||
|
bool getProgressIndicatorVisible() const { return progressIndicatorVisible; }
|
||||||
|
void setProgressIndicatorVisible(bool visible);
|
||||||
|
|
||||||
|
bool getAnimating() const { return animating; }
|
||||||
|
void setAnimating(bool animating);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void timerEvent(QTimerEvent *event) override;
|
||||||
|
void paintEvent(QPaintEvent *event) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool animating = true;
|
||||||
|
bool progressIndicatorVisible = true;
|
||||||
|
|
||||||
|
int animationTimerId = 0;
|
||||||
|
int animationState = 0;
|
||||||
|
|
||||||
|
void updateAnimationTimer();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //PROGRESSINDICATOR_H
|
Loading…
Reference in New Issue
Block a user