Timeline preview render: put small progress bar inside start button

Ref: T1949
parent 4e4870bb
......@@ -1611,3 +1611,8 @@ void KdenliveDoc::invalidatePreviews(QList <int> chunks)
}
setModified(true);
}
void KdenliveDoc::previewProgress(int p)
{
pCore->window()->setPreviewProgress(p);
}
......@@ -158,6 +158,7 @@ public:
bool profileChanged(const QString &profile) const;
void doAddAction(const QString &name, QAction *a);
void invalidatePreviews(QList <int> chunks);
void previewProgress(int p);
private:
QUrl m_url;
......
......@@ -108,6 +108,41 @@
#include <QVBoxLayout>
#include <QtGlobal>
MyToolButton::MyToolButton(QWidget *parent) : QToolButton(parent)
{
m_progress = width() - 6;
}
void MyToolButton::setProgress(int progress)
{
int prog = (width() - 6) * (double) progress / 100;
if (prog == m_progress)
return;
m_progress = progress < 0 ? -1 : prog;
update();
}
int MyToolButton::progress() const
{
return m_progress;
}
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
painter.fillRect(3, height() - 5, m_progress, 3, palette().highlight().color());
painter.setPen(palette().shadow().color());
painter.drawRoundedRect(2, height() - 6, width() - 4, 5, 2, 2);
}
}
static const char version[] = KDENLIVE_VERSION;
namespace Mlt
{
......@@ -543,16 +578,27 @@ MainWindow::MainWindow(const QString &MltPath, const QUrl &Url, const QString &
timelineTb->addAction(actionCollection()->action(QStringLiteral("remove_extract")));
timelineTb->addAction(actionCollection()->action(QStringLiteral("remove_lift")));
QToolButton *timelinePreview = new QToolButton(this);
MyToolButton *timelinePreview = new MyToolButton(this);
QMenu *tlMenu = new QMenu(this);
timelinePreview->setMenu(tlMenu);
connect(this, &MainWindow::setPreviewProgress, timelinePreview, &MyToolButton::setProgress);
QAction *prevRender = actionCollection()->action(QStringLiteral("prerender_timeline_zone"));
tlMenu->addAction(prevRender);
tlMenu->addAction(actionCollection()->action(QStringLiteral("set_render_timeline_zone")));
tlMenu->addAction(actionCollection()->action(QStringLiteral("unset_render_timeline_zone")));
timelinePreview->setDefaultAction(prevRender);
timelinePreview->setPopupMode(QToolButton::MenuButtonPopup);
timelinePreview->setAutoRaise(true);
timelineTb->addWidget(timelinePreview);
/*QPropertyAnimation *animation = new QPropertyAnimation(timelinePreview, "progress");
animation->setDuration(1000);
animation->setLoopCount(-1);
animation->setStartValue(1);
animation->setEndValue(100);
animation->start();*/
timelineTb->addAction(toolButtonAction);
QWidget *sep = new QWidget(this);
sep->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
......
......@@ -60,6 +60,23 @@ class KIconLoader;
#define EXIT_RESTART (42)
class MyToolButton: public QToolButton
{
Q_PROPERTY(int progress READ progress WRITE setProgress)
Q_OBJECT
public:
explicit MyToolButton(QWidget *parent = 0);
int progress() const;
void setProgress(int);
protected:
virtual void paintEvent(QPaintEvent *event);
private:
int m_progress;
};
class /*KDENLIVECORE_EXPORT*/ MainWindow : public KXmlGuiWindow
{
Q_OBJECT
......@@ -450,6 +467,7 @@ signals:
void configurationChanged();
void GUISetupDone();
void reloadTheme();
void setPreviewProgress(int);
};
......
......@@ -1673,8 +1673,11 @@ void Render::doPreviewRender(QList <int> frames, QDir folder, QString id, QStrin
args << "-consumer" << "avformat:" + folder.absoluteFilePath(fileName);
args << consumerParams;
int result = QProcess::execute(KdenliveSettings::rendererpath(), args);
if (result < 0) {
if (result != 0) {
// Something is wrong, abort
qDebug()<<"+++++++++\n++ ERROR ++\n++++++";
emit previewRender(i, QString(), -1);
QFile::remove(folder.absoluteFilePath(fileName));
break;
}
emit previewRender(i, folder.absoluteFilePath(fileName), progress);
......
......@@ -1745,6 +1745,10 @@ void Timeline::gotPreviewRender(int frame, const QString &file, int progress)
m_tractor->unlock();
m_hasOverlayTrack = true;
}
if (file.isEmpty()) {
m_doc->previewProgress(progress);
return;
}
Mlt::Producer *overlayTrack = m_tractor->track(tracksCount());
m_tractor->lock();
Mlt::Playlist trackPlaylist((mlt_playlist) overlayTrack->get_service());
......@@ -1758,7 +1762,7 @@ void Timeline::gotPreviewRender(int frame, const QString &file, int progress)
}
}
m_tractor->unlock();
m_doc->progressInfo(i18n("Rendering preview"), progress);
m_doc->previewProgress(progress);
m_doc->setModified(true);
//m_doc->updatePreview(progress);
}
......
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