Add progress bar to splash screen (wip)

parent 4087ed12
Pipeline #21964 passed with stage
in 22 minutes
......@@ -1000,6 +1000,8 @@ void ProjectItemModel::loadBinPlaylist(Mlt::Tractor *documentTractor, Mlt::Tract
for (int i = 0; i < max; i++) {
if (progressDialog) {
progressDialog->setValue(i);
} else {
pCore->loadingMessageUpdated(QString(), 100 * i / max);
}
QScopedPointer<Mlt::Producer> prod(playlist.get_clip(i));
if (prod->is_blank() || !prod->is_valid()) {
......
......@@ -272,7 +272,7 @@ signals:
void finalizeRecording(const QString &captureFile);
void autoScrollChanged();
/** @brief Send a message to splash screen if still displayed */
void loadingMessageUpdated(const QString &, int align = Qt::AlignRight | Qt::AlignBottom, const QColor col = QColor(Qt::white));
void loadingMessageUpdated(const QString &, int progress = 0);
};
#endif
......@@ -8,5 +8,6 @@ set(kdenlive_SRCS
dialogs/renderwidget.cpp
dialogs/titletemplatedialog.cpp
dialogs/wizard.cpp
dialogs/splash.cpp
PARENT_SCOPE)
......@@ -20,55 +20,41 @@
***************************************************************************/
#include "splash.hpp"
#include <QStyle>
#include <QStyleOptionProgressBar>
#include <KDeclarative/KDeclarative>
#include <QQmlContext>
#include <QQuickItem>
#include <QQuickWindow>
#include <QStandardPaths>
#include <kdeclarative_version.h>
Splash::Splash(QObject *parent)
: QObject(parent)
, m_engine(new QQmlEngine())
, childItem(nullptr)
Splash::Splash(const QPixmap &pixmap)
: QSplashScreen(pixmap)
, m_progress(0)
{
KDeclarative::KDeclarative kdeclarative;
kdeclarative.setDeclarativeEngine(m_engine);
kdeclarative.setupEngine(m_engine);
kdeclarative.setupContext();
component = new QQmlComponent(m_engine);
QQuickWindow::setDefaultAlphaBuffer(true);
component->loadUrl(QUrl(QStringLiteral("qrc:/qml/splash.qml")));
if (component->isLoading())
QObject::connect(component, SIGNAL(statusChanged(QQmlComponent::Status)),
this, SLOT(continueLoading()));
else {
continueLoading();
}
}
void Splash::continueLoading()
void Splash::showProgressMessage(const QString &message, int progress)
{
if (component->isReady()) {
childItem = qobject_cast<QQuickWindow*>(component->create());
} else {
qWarning() << component->errorString();
m_progress = qBound(0, progress, 100);
if (!message.isEmpty()) {
showMessage(message, Qt::AlignRight | Qt::AlignBottom, Qt::white);
}
}
Splash::~Splash()
{
delete childItem;
delete component;
delete m_engine;
repaint();
}
void Splash::endSplash()
void Splash::drawContents(QPainter *painter)
{
if (childItem) {
QMetaObject::invokeMethod(childItem, "endSplash");
} else {
qDebug()<<"** ERROR NO SPLASH COMPO";
}
emit sigEndSplash();
QSplashScreen::drawContents(painter);
// Set style for progressbar...
QStyleOptionProgressBar pbstyle;
pbstyle.initFrom(this);
pbstyle.state = QStyle::State_Enabled;
pbstyle.textVisible = false;
pbstyle.minimum = 0;
pbstyle.maximum = 100;
pbstyle.progress = m_progress;
pbstyle.invertedAppearance = false;
pbstyle.rect = QRect(4, height() - 24, width() / 2, 20); // Where is it.
// Draw it...
style()->drawControl(QStyle::CE_ProgressBar, &pbstyle, painter, this);
}
......@@ -22,33 +22,25 @@
#ifndef SPLASH_H
#define SPLASH_H
#include <QObject>
#include <memory>
#include <QSplashScreen>
class QQmlEngine;
class QQmlComponent;
class QQuickWindow;
class Splash : public QObject
class Splash : public QSplashScreen
{
Q_OBJECT
public:
Splash(QObject *parent);
~Splash();
explicit Splash(const QPixmap &pixmap);
//~Splash();
void endSplash();
signals:
void sigEndSplash();
private slots:
void continueLoading();
public slots:
void showProgressMessage(const QString &message, int progress = 0);
private:
int m_progress;
protected:
QQmlEngine *m_engine;
QQmlComponent* component;
QQuickWindow *childItem;
void drawContents(QPainter *painter);
};
#endif
......@@ -20,6 +20,7 @@
#include "core.h"
#include "logger.hpp"
#include "dialogs/splash.hpp"
#include <config-kdenlive.h>
#include <mlt++/Mlt.h>
......@@ -100,7 +101,7 @@ int main(int argc, char *argv[])
QPixmap pixmap(":/pics/splash-background.png");
qApp->processEvents(QEventLoop::AllEvents);
QSplashScreen splash(pixmap);
Splash splash(pixmap);
qApp->processEvents(QEventLoop::AllEvents);
splash.showMessage(i18n("Version %1", QString(KDENLIVE_VERSION)), Qt::AlignRight | Qt::AlignBottom, Qt::white);
splash.show();
......@@ -252,8 +253,9 @@ int main(int argc, char *argv[])
}
qApp->processEvents(QEventLoop::AllEvents);
Core::build(!parser.value(QStringLiteral("config")).isEmpty(), parser.value(QStringLiteral("mlt-path")));
QObject::connect(pCore.get(), &Core::loadingMessageUpdated, &splash, &QSplashScreen::showMessage);
QMetaObject::Connection connection = QObject::connect(pCore.get(), &Core::loadingMessageUpdated, &splash, &Splash::showProgressMessage, Qt::DirectConnection);
pCore->initGUI(url, clipsToLoad);
QObject::disconnect( connection );
splash.finish(pCore->window());
int result = app.exec();
Core::clean();
......
......@@ -287,6 +287,8 @@ bool constructTrackFromMelt(const std::shared_ptr<TimelineItemModel> &timeline,
}
if (progressDialog) {
progressDialog->setValue(progressDialog->value() + 1);
} else {
pCore->loadingMessageUpdated(QString(), 100 * i / track.count());
}
std::shared_ptr<Mlt::Producer> clip(track.get_clip(i));
int position = track.clip_start(i);
......
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