tasks: added elapsed/remaining time displays for all tasks
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
set(OLIVE_SOURCES
|
||||
${OLIVE_SOURCES}
|
||||
widget/taskview/elapsedcounterwidget.h
|
||||
widget/taskview/elapsedcounterwidget.cpp
|
||||
widget/taskview/taskview.h
|
||||
widget/taskview/taskview.cpp
|
||||
widget/taskview/taskviewitem.h
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2019 Olive Team
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#include "elapsedcounterwidget.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QHBoxLayout>
|
||||
|
||||
#include "common/timecodefunctions.h"
|
||||
|
||||
OLIVE_NAMESPACE_ENTER
|
||||
|
||||
ElapsedCounterWidget::ElapsedCounterWidget(QWidget* parent) :
|
||||
QWidget(parent),
|
||||
last_progress_(0),
|
||||
start_time_(0)
|
||||
{
|
||||
QHBoxLayout* layout = new QHBoxLayout(this);
|
||||
layout->setSpacing(0);
|
||||
layout->setMargin(0);
|
||||
|
||||
elapsed_lbl_ = new QLabel();
|
||||
layout->addWidget(elapsed_lbl_);
|
||||
|
||||
remaining_lbl_ = new QLabel();
|
||||
layout->addWidget(remaining_lbl_);
|
||||
|
||||
elapsed_timer_.setInterval(500);
|
||||
connect(&elapsed_timer_, &QTimer::timeout, this, &ElapsedCounterWidget::UpdateTimers);
|
||||
UpdateTimers();
|
||||
}
|
||||
|
||||
void ElapsedCounterWidget::SetProgress(double d)
|
||||
{
|
||||
last_progress_ = d;
|
||||
UpdateTimers();
|
||||
}
|
||||
|
||||
void ElapsedCounterWidget::Start()
|
||||
{
|
||||
Start(QDateTime::currentMSecsSinceEpoch());
|
||||
}
|
||||
|
||||
void ElapsedCounterWidget::Start(qint64 start_time)
|
||||
{
|
||||
start_time_ = start_time;
|
||||
elapsed_timer_.start();
|
||||
UpdateTimers();
|
||||
}
|
||||
|
||||
void ElapsedCounterWidget::UpdateTimers()
|
||||
{
|
||||
int64_t elapsed_ms, remaining_ms;
|
||||
|
||||
if (last_progress_ > 0) {
|
||||
elapsed_ms = QDateTime::currentMSecsSinceEpoch() - start_time_;
|
||||
|
||||
double ms_per_progress_unit = elapsed_ms / last_progress_;
|
||||
double remaining_progress = 1.0 - last_progress_;
|
||||
|
||||
remaining_ms = qRound64(ms_per_progress_unit * remaining_progress);
|
||||
} else {
|
||||
elapsed_ms = 0;
|
||||
remaining_ms = 0;
|
||||
}
|
||||
|
||||
elapsed_lbl_->setText(tr("Elapsed: %1").arg(Timecode::TimeToString(elapsed_ms)));
|
||||
remaining_lbl_->setText(tr("Remaining: %1").arg(Timecode::TimeToString(remaining_ms)));
|
||||
}
|
||||
|
||||
OLIVE_NAMESPACE_EXIT
|
||||
@@ -0,0 +1,61 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2019 Olive Team
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#ifndef ELAPSEDCOUNTERWIDGET_H
|
||||
#define ELAPSEDCOUNTERWIDGET_H
|
||||
|
||||
#include <QLabel>
|
||||
#include <QTimer>
|
||||
#include <QWidget>
|
||||
|
||||
#include "common/define.h"
|
||||
|
||||
OLIVE_NAMESPACE_ENTER
|
||||
|
||||
class ElapsedCounterWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ElapsedCounterWidget(QWidget* parent = nullptr);
|
||||
|
||||
void SetProgress(double d);
|
||||
|
||||
void Start();
|
||||
void Start(qint64 start_time);
|
||||
|
||||
private:
|
||||
QLabel* elapsed_lbl_;
|
||||
|
||||
QLabel* remaining_lbl_;
|
||||
|
||||
double last_progress_;
|
||||
|
||||
QTimer elapsed_timer_;
|
||||
|
||||
qint64 start_time_;
|
||||
|
||||
private slots:
|
||||
void UpdateTimers();
|
||||
|
||||
};
|
||||
|
||||
OLIVE_NAMESPACE_EXIT
|
||||
|
||||
#endif // ELAPSEDCOUNTERWIDGET_H
|
||||
@@ -20,8 +20,10 @@
|
||||
|
||||
#include "taskviewitem.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "common/timecodefunctions.h"
|
||||
#include "ui/icons/icons.h"
|
||||
|
||||
OLIVE_NAMESPACE_ENTER
|
||||
@@ -55,9 +57,22 @@ TaskViewItem::TaskViewItem(Task* task, QWidget *parent) :
|
||||
cancel_btn_->setIcon(icon::Error);
|
||||
middle_layout->addWidget(cancel_btn_);
|
||||
|
||||
// Create status label
|
||||
task_status_lbl_ = new QLabel(this);
|
||||
layout->addWidget(task_status_lbl_);
|
||||
// Create stack with error label and elapsed/remaining time
|
||||
status_stack_ = new QStackedWidget();
|
||||
status_stack_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
|
||||
layout->addWidget(status_stack_);
|
||||
|
||||
// Create elapsed timer
|
||||
elapsed_timer_lbl_ = new ElapsedCounterWidget();
|
||||
status_stack_->addWidget(elapsed_timer_lbl_);
|
||||
|
||||
// Create error label
|
||||
task_error_lbl_ = new QLabel(this);
|
||||
status_stack_->addWidget(task_error_lbl_);
|
||||
|
||||
// Set up elapsed timer
|
||||
status_stack_->setCurrentWidget(elapsed_timer_lbl_);
|
||||
elapsed_timer_lbl_->Start(task_->GetStartTime());
|
||||
|
||||
// Connect to the task
|
||||
connect(task_, &Task::ProgressChanged, this, &TaskViewItem::UpdateProgress);
|
||||
@@ -66,13 +81,15 @@ TaskViewItem::TaskViewItem(Task* task, QWidget *parent) :
|
||||
|
||||
void TaskViewItem::Failed()
|
||||
{
|
||||
task_status_lbl_->setStyleSheet("color: red");
|
||||
task_status_lbl_->setText(tr("Error: %1").arg(task_->GetError()));
|
||||
status_stack_->setCurrentWidget(task_error_lbl_);
|
||||
task_error_lbl_->setStyleSheet("color: red");
|
||||
task_error_lbl_->setText(tr("Error: %1").arg(task_->GetError()));
|
||||
}
|
||||
|
||||
void TaskViewItem::UpdateProgress(double d)
|
||||
{
|
||||
progress_bar_->setValue(qRound(100.0 * d));
|
||||
elapsed_timer_lbl_->SetProgress(d);
|
||||
}
|
||||
|
||||
OLIVE_NAMESPACE_EXIT
|
||||
|
||||
@@ -24,8 +24,10 @@
|
||||
#include <QLabel>
|
||||
#include <QProgressBar>
|
||||
#include <QPushButton>
|
||||
#include <QStackedWidget>
|
||||
#include <QWidget>
|
||||
|
||||
#include "elapsedcounterwidget.h"
|
||||
#include "task/task.h"
|
||||
|
||||
OLIVE_NAMESPACE_ENTER
|
||||
@@ -54,7 +56,10 @@ private:
|
||||
QLabel* task_name_lbl_;
|
||||
QProgressBar* progress_bar_;
|
||||
QPushButton* cancel_btn_;
|
||||
QLabel* task_status_lbl_;
|
||||
|
||||
QStackedWidget* status_stack_;
|
||||
ElapsedCounterWidget* elapsed_timer_lbl_;
|
||||
QLabel* task_error_lbl_;
|
||||
|
||||
Task* task_;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user