More reliable progress bar in splash screen

parent 49ba7fc6
Pipeline #21990 passed with stage
in 26 minutes and 27 seconds
......@@ -1001,7 +1001,7 @@ void ProjectItemModel::loadBinPlaylist(Mlt::Tractor *documentTractor, Mlt::Tract
if (progressDialog) {
progressDialog->setValue(i);
} else {
pCore->loadingMessageUpdated(QString(), 100 * i / max);
pCore->loadingMessageUpdated(QString(), 1);
}
QScopedPointer<Mlt::Producer> prod(playlist.get_clip(i));
if (prod->is_blank() || !prod->is_valid()) {
......
......@@ -272,7 +272,9 @@ signals:
void finalizeRecording(const QString &captureFile);
void autoScrollChanged();
/** @brief Send a message to splash screen if still displayed */
void loadingMessageUpdated(const QString &, int progress = 0);
void loadingMessageUpdated(const QString &, int progress = 0, int max = -1);
/** @brief Opening finished, close splash screen */
void closeSplash();
};
#endif
......@@ -21,18 +21,31 @@
#include "splash.hpp"
#include <QStyle>
#include <QStyleOptionProgressBar>
Splash::Splash(const QPixmap &pixmap)
: QSplashScreen(pixmap)
, m_progress(0)
{
// Set style for progressbar...
m_pbStyle.initFrom(this);
m_pbStyle.state = QStyle::State_Enabled;
m_pbStyle.textVisible = false;
m_pbStyle.minimum = 0;
m_pbStyle.maximum = 100;
m_pbStyle.progress = 0;
m_pbStyle.invertedAppearance = false;
m_pbStyle.rect = QRect(4, pixmap.height() - 24, pixmap.width() / 2, 20); // Where is it.
}
void Splash::showProgressMessage(const QString &message, int progress)
void Splash::showProgressMessage(const QString &message, int progress, int max)
{
m_progress = qBound(0, progress, 100);
if (max > -1) {
m_pbStyle.maximum = max;
}
if (progress > 0) {
m_progress++;
}
if (!message.isEmpty()) {
showMessage(message, Qt::AlignRight | Qt::AlignBottom, Qt::white);
}
......@@ -44,17 +57,10 @@ void Splash::drawContents(QPainter *painter)
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.
m_pbStyle.progress = m_progress;
//m_pbStyle.rect = QRect(4, height() - 24, width() / 2, 20); // Where is it.
// Draw it...
style()->drawControl(QStyle::CE_ProgressBar, &pbstyle, painter, this);
style()->drawControl(QStyle::CE_ProgressBar, &m_pbStyle, painter, this);
}
......@@ -23,7 +23,7 @@
#define SPLASH_H
#include <QSplashScreen>
#include <QStyleOptionProgressBar>
class Splash : public QSplashScreen
{
......@@ -34,10 +34,11 @@ public:
//~Splash();
public slots:
void showProgressMessage(const QString &message, int progress = 0);
void showProgressMessage(const QString &message, int progress = 0, int max = -1);
private:
int m_progress;
QStyleOptionProgressBar m_pbStyle;
protected:
void drawContents(QPainter *painter);
......
......@@ -253,10 +253,11 @@ int main(int argc, char *argv[])
}
qApp->processEvents(QEventLoop::AllEvents);
Core::build(!parser.value(QStringLiteral("config")).isEmpty(), parser.value(QStringLiteral("mlt-path")));
QMetaObject::Connection connection = QObject::connect(pCore.get(), &Core::loadingMessageUpdated, &splash, &Splash::showProgressMessage, Qt::DirectConnection);
QObject::connect(pCore.get(), &Core::loadingMessageUpdated, &splash, &Splash::showProgressMessage, Qt::DirectConnection);
QObject::connect(pCore.get(), &Core::closeSplash, [&] () {
splash.finish(pCore->window());
});
pCore->initGUI(url, clipsToLoad);
QObject::disconnect( connection );
splash.finish(pCore->window());
int result = app.exec();
Core::clean();
......
......@@ -64,6 +64,7 @@ static QString getProjectNameFilters(bool ark=true) {
ProjectManager::ProjectManager(QObject *parent)
: QObject(parent)
, m_mainTimelineModel(nullptr)
, m_loading(false)
{
m_fileRevert = KStandardAction::revert(this, SLOT(slotRevert()), pCore->window()->actionCollection());
......@@ -101,6 +102,7 @@ ProjectManager::~ProjectManager() = default;
void ProjectManager::slotLoadOnOpen()
{
m_loading = true;
if (m_startUrl.isValid()) {
openFile();
} else if (KdenliveSettings::openlastproject()) {
......@@ -120,6 +122,8 @@ void ProjectManager::slotLoadOnOpen()
pCore->bin()->droppedUrls(urls);
}
m_loadClipsOnOpen.clear();
m_loading = false;
pCore->closeSplash();
}
void ProjectManager::init(const QUrl &projectUrl, const QString &clipList)
......@@ -522,11 +526,11 @@ void ProjectManager::doOpenFile(const QUrl &url, KAutoSaveFile *stale)
m_fileRevert->setEnabled(true);
delete m_progressDialog;
m_progressDialog == nullptr;
m_progressDialog = nullptr;
ThumbnailCache::get()->clearCache();
pCore->monitorManager()->resetDisplay();
pCore->monitorManager()->activateMonitor(Kdenlive::ProjectMonitor);
if (pCore->window()->isVisible()) {
if (!m_loading) {
m_progressDialog = new QProgressDialog(pCore->window());
m_progressDialog->setWindowTitle(i18n("Loading project"));
m_progressDialog->setCancelButton(nullptr);
......@@ -569,6 +573,8 @@ void ProjectManager::doOpenFile(const QUrl &url, KAutoSaveFile *stale)
if (m_progressDialog) {
m_progressDialog->setLabelText(i18n("Loading clips"));
m_progressDialog->setMaximum(doc->clipsCount());
} else {
pCore->loadingMessageUpdated(QString(), 0, doc->clipsCount());
}
// TODO refac delete this
......
......@@ -201,6 +201,8 @@ private:
KRecentFilesAction *m_recentFilesAction;
NotesPlugin *m_notesPlugin;
QProgressDialog *m_progressDialog{nullptr};
/** @brief If true, means we are still opening Kdenlive, send messages to splash screen */
bool m_loading;
void saveRecentFiles();
};
......
......@@ -281,14 +281,15 @@ PlaylistState::ClipState inferState(const std::shared_ptr<Mlt::Producer> &prod,
bool constructTrackFromMelt(const std::shared_ptr<TimelineItemModel> &timeline, int tid, Mlt::Playlist &track,
const std::unordered_map<QString, QString> &binIdCorresp, Fun &undo, Fun &redo, bool audioTrack, QProgressDialog *progressDialog)
{
for (int i = 0; i < track.count(); i++) {
int max = track.count();
for (int i = 0; i < max; i++) {
if (track.is_blank(i)) {
continue;
}
if (progressDialog) {
progressDialog->setValue(progressDialog->value() + 1);
} else {
pCore->loadingMessageUpdated(QString(), 100 * i / track.count());
pCore->loadingMessageUpdated(QString(), 1);
}
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