Show remaining time in timeline preview button

parent 1dcbe3fb
......@@ -242,8 +242,6 @@ signals:
void reloadEffects();
/** @brief Fps was changed, update timeline */
void updateFps(bool changed);
/** @brief A timeline preview render is available */
void previewRender(int frame, const QString &file, int progress);
};
#endif
......
......@@ -110,15 +110,51 @@
MyToolButton::MyToolButton(QWidget *parent) : QToolButton(parent)
{
setPopupMode(MenuButtonPopup);
m_progress = width() - 6;
m_pix = new QPixmap(1,1);
m_pix->fill(Qt::transparent);
m_blankIcon = QIcon(*m_pix);
}
MyToolButton::~MyToolButton()
{
delete m_pix;
}
void MyToolButton::setProgress(int progress)
{
int prog = (width() - 6) * (double) progress / 100;
int prog = (width() - 6) * (double) progress / 1000;
if (m_timer.isValid()) {
// calculate remaining time
qint64 ms = m_timer.elapsed() * (1000.0 / progress - 1);
if (ms < 60000)
m_remainingTime = i18nc("s as seconds", "%1s", ms / 1000);
else if (ms < 3600000)
m_remainingTime = i18nc("m as minutes", "%1m", ms / 60000);
else {
m_remainingTime = i18nc("h as hours", "%1h", qMax(99, (int) (ms / 3600000)));
}
}
if (prog == m_progress)
return;
m_progress = progress < 0 ? -1 : prog;
if (progress < 0) {
m_remainingTime.clear();
m_timer.invalidate();
m_progress = -1;
} else {
if (!m_timer.isValid()) {
m_icon = QIcon(icon());
setIcon(m_blankIcon);
m_timer.start();
}
if (progress == 1000) {
m_remainingTime.clear();
m_timer.invalidate();
setIcon(m_icon);
}
m_progress = prog;
}
update();
}
......@@ -131,18 +167,22 @@ void MyToolButton::paintEvent(QPaintEvent *event)
{
QToolButton::paintEvent(event);
if (m_progress < width() - 6) {
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
if (m_progress < 0)
painter.fillRect(3, height() - 5, (width() - 6), 3, Qt::red);
else {
QColor w(Qt::white);
w.setAlpha(40);
painter.fillRect(3, height() - 5, m_progress, 3, palette().highlight().color());
painter.fillRect(3 + m_progress, height() - 5, width() - 6 - m_progress, 3, w);
}
painter.setPen(palette().shadow().color());
painter.drawRoundedRect(2, height() - 6, width() - 4, 5, 2, 2);
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
if (m_progress < 0)
painter.fillRect(3, height() - 5, (width() - 6), 3, Qt::red);
else {
if (m_progress > 0) {
// draw remaining time
painter.drawText(rect(), Qt::AlignLeft, m_remainingTime);
}
QColor w(Qt::white);
w.setAlpha(40);
painter.fillRect(3, height() - 5, m_progress, 3, palette().highlight().color());
painter.fillRect(3 + m_progress, height() - 5, width() - 6 - m_progress, 3, w);
}
painter.setPen(palette().shadow().color());
painter.drawRoundedRect(2, height() - 6, width() - 4, 5, 2, 2);
}
}
......
......@@ -67,6 +67,7 @@ class MyToolButton: public QToolButton
Q_OBJECT
public:
explicit MyToolButton(QWidget *parent = 0);
~MyToolButton();
int progress() const;
void setProgress(int);
......@@ -75,6 +76,11 @@ protected:
private:
int m_progress;
QIcon m_icon;
QIcon m_blankIcon;
QPixmap *m_pix;
QElapsedTimer m_timer;
QString m_remainingTime;
};
class /*KDENLIVECORE_EXPORT*/ MainWindow : public KXmlGuiWindow
......
......@@ -1656,9 +1656,9 @@ void Render::doPreviewRender(QList <int> frames, QDir folder, QString id, QStrin
break;
QString fileName = id + QString("-%1.%2").arg(i).arg(KdenliveSettings::tl_extension());
if (frames.count() > 1) {
progress = (double) (ct) / (frames.count() - 1) * 100;
progress = (double) (ct) / (frames.count() - 1) * 1000;
} else {
progress = 100;
progress = 1000;
}
ct++;
if (folder.exists(fileName)) {
......
......@@ -479,13 +479,13 @@ void CustomRuler::paintEvent(QPaintEvent *e)
QColor preview(Qt::green);
preview.setAlpha(120);
foreach(int frame, m_renderingPreviews) {
QRect rec(frame * m_factor - m_offset, MAX_HEIGHT - 3, KdenliveSettings::timelinechunks() * m_factor, 3);
QRectF rec(frame * m_factor - m_offset, MAX_HEIGHT - 3, KdenliveSettings::timelinechunks() * m_factor, 3);
p.fillRect(rec, preview);
}
preview = Qt::darkRed;
preview.setAlpha(120);
foreach(int frame, m_dirtyRenderingPreviews) {
QRect rec(frame * m_factor - m_offset, MAX_HEIGHT - 3, KdenliveSettings::timelinechunks() * m_factor, 3);
QRectF rec(frame * m_factor - m_offset, MAX_HEIGHT - 3, KdenliveSettings::timelinechunks() * m_factor, 3);
p.fillRect(rec, preview);
}
......@@ -519,7 +519,7 @@ void CustomRuler::updatePreview(int frame, bool rendered)
m_renderingPreviews.removeAll(frame);
m_dirtyRenderingPreviews << frame;
}
update(frame * m_factor - offset(), MAX_HEIGHT - 3, KdenliveSettings::timelinechunks() * m_factor, 3);
update(frame * m_factor - offset(), MAX_HEIGHT - 3, KdenliveSettings::timelinechunks() * m_factor + 1, 3);
}
const QStringList CustomRuler::previewChunks() const
......@@ -562,6 +562,6 @@ void CustomRuler::addChunks(QList <int> chunks, bool add)
m_dirtyRenderingPreviews.removeAll(frame);
}
}
update(chunks.first() * m_factor - offset(), MAX_HEIGHT - 3, (chunks.last() - chunks.first()) * KdenliveSettings::timelinechunks() * m_factor, 3);
update(chunks.first() * m_factor - offset(), MAX_HEIGHT - 3, (chunks.last() - chunks.first()) * KdenliveSettings::timelinechunks() * m_factor + 1, 3);
}
......@@ -143,7 +143,6 @@ Timeline::Timeline(KdenliveDoc *doc, const QList<QAction *> &actions, const QLis
connect(m_trackview->horizontalScrollBar(), SIGNAL(rangeChanged(int,int)), this, SLOT(slotUpdateVerticalScroll(int,int)));
connect(m_trackview, SIGNAL(mousePosition(int)), this, SIGNAL(mousePosition(int)));
connect(m_doc->renderer(), &Render::previewRender, this, &Timeline::gotPreviewRender);
connect(m_doc, &KdenliveDoc::previewRender, this, &Timeline::gotPreviewRender);
}
Timeline::~Timeline()
......@@ -1764,7 +1763,6 @@ void Timeline::gotPreviewRender(int frame, const QString &file, int progress)
m_tractor->unlock();
m_doc->previewProgress(progress);
m_doc->setModified(true);
//m_doc->updatePreview(progress);
}
void Timeline::addPreviewRange(bool add)
......@@ -1848,7 +1846,7 @@ void Timeline::loadPreviewRender()
int pos = frame.toInt();
const QString fileName = dir.absoluteFilePath(documentId + QString("-%1.%2").arg(pos).arg(KdenliveSettings::tl_extension()));
if (QFile::exists(fileName)) {
gotPreviewRender(pos, fileName, 100);
gotPreviewRender(pos, fileName, 1000);
} else dirtyChunks << frame;
}
if (!dirtyChunks.isEmpty()) {
......
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