From 9540909181e03e58cf608153187ca2b8308aa9c4 Mon Sep 17 00:00:00 2001 From: Aleksei Nikiforov Date: Mon, 6 Jul 2020 16:21:01 +0300 Subject: [PATCH] Okular: add indication for document loading process --- okular/core/document.cpp | 6 +++++ okular/core/observer.cpp | 16 ++++++++++++ okular/core/observer.h | 8 ++++++ okular/part.cpp | 4 +++ okular/part.h | 2 ++ okular/po/ru/okular.po | 5 ++++ okular/ui/minibar.cpp | 56 ++++++++++++++++++++++++++++++++++++++++ okular/ui/minibar.h | 25 ++++++++++++++++++ 8 files changed, 122 insertions(+) --- a/okular/core/document.cpp +++ b/okular/core/document.cpp @@ -1434,6 +1434,7 @@ void DocumentPrivate::sendGeneratorPixma // we can not really know if the generator can do async requests m_executingPixmapRequests.push_back(request); m_pixmapRequestsMutex.unlock(); + foreachObserverD( notifyPixmapGenerationStarted() ); m_generator->generatePixmap(request); } else { m_pixmapRequestsMutex.unlock(); @@ -3245,6 +3246,7 @@ void Document::requestTextPage(uint page // Memory management for TextPages + foreachObserver( notifyTextGenerationStarted() ); d->m_generator->generateTextPage(kp); } @@ -4971,6 +4973,8 @@ void DocumentPrivate::requestDone(Pixmap else qCWarning(OkularCoreDebug) << "Receiving a done request for the defunct observer" << observer; #endif + + foreachObserverD( notifyPixmapGenerationFinished() ); } // 3. delete request @@ -5044,6 +5048,8 @@ void DocumentPrivate::textGenerationDone // 2. Add the page to the fifo of generated text pages m_allocatedTextPagesFifo.append(page->number()); + + foreachObserverD( notifyTextGenerationFinished() ); } void Document::setRotation(int r) diff --git a/okular/core/observer.cpp b/okular/core/observer.cpp index caacfefef..6b9592160 100644 --- a/okular/core/observer.cpp +++ b/okular/core/observer.cpp @@ -52,3 +52,19 @@ bool DocumentObserver::canUnloadPixmap( int ) const void DocumentObserver::notifyCurrentPageChanged( int, int ) { } + +void DocumentObserver::notifyPixmapGenerationStarted() +{ +} + +void DocumentObserver::notifyPixmapGenerationFinished() +{ +} + +void DocumentObserver::notifyTextGenerationStarted() +{ +} + +void DocumentObserver::notifyTextGenerationFinished() +{ +} --- a/okular/core/observer.h +++ b/okular/core/observer.h @@ -118,6 +118,14 @@ public: */ virtual void notifyCurrentPageChanged(int previous, int current); + virtual void notifyPixmapGenerationStarted(); + + virtual void notifyPixmapGenerationFinished(); + + virtual void notifyTextGenerationStarted(); + + virtual void notifyTextGenerationFinished(); + private: class Private; const Private *d; --- a/okular/part/part.cpp +++ b/okular/part/part.cpp @@ -537,6 +537,8 @@ Part::Part(QWidget *parentWidget, QObjec bottomBarLayout->addWidget(m_miniBar); bottomBarLayout->addWidget(m_pageSizeLabel); rightLayout->addWidget(m_bottomBar); + m_loadingProgressBarWidget = new LoadingProgressBarWidget( rightContainer, m_document ); + rightLayout->addWidget( m_loadingProgressBarWidget ); m_pageNumberTool = new MiniBar(nullptr, m_miniBarLogic); @@ -555,6 +557,7 @@ Part::Part(QWidget *parentWidget, QObjec m_document->registerView(m_pageView); m_document->addObserver(m_toc); m_document->addObserver(m_miniBarLogic); + m_document->addObserver(m_loadingProgressBarWidget); #ifdef OKULAR_ENABLE_MINIBAR m_document->addObserver(m_progressWidget); #endif @@ -954,6 +957,7 @@ Part::~Part() delete m_pageNumberTool; delete m_miniBarLogic; delete m_bottomBar; + delete m_loadingProgressBarWidget; #ifdef OKULAR_ENABLE_MINIBAR delete m_progressWidget; #endif --- a/okular/part/part.h +++ b/okular/part/part.h @@ -63,6 +63,7 @@ class ThumbnailList; class PageSizeLabel; class PageView; class PresentationWidget; +class LoadingProgressBarWidget; class ProgressWidget; class SearchWidget; class Sidebar; @@ -325,6 +326,7 @@ private: QPointer m_miniBar; QPointer m_pageNumberTool; QPointer m_bottomBar; + QPointer m_loadingProgressBarWidget; QPointer m_presentationWidget; QPointer m_progressWidget; QPointer m_pageSizeLabel; --- a/okular/part/minibar.cpp +++ b/okular/part/minibar.cpp @@ -13,6 +13,7 @@ // qt / kde includes #include #include +#include #include #include #include @@ -556,6 +557,61 @@ HoverButton::HoverButton(QWidget *parent KAcceleratorManager::setNoAccel(this); } +LoadingProgressBarWidget::LoadingProgressBarWidget( QWidget * parent, Okular::Document * document ) + : QWidget(parent) + , m_document(document) + , m_pixmapGenerationInProgress(false) + , m_textGenerationInProgress(false) +{ + QHBoxLayout * horLayout = new QHBoxLayout( this ); + + QLabel * textLabel = new QLabel( i18n( "Loading document..." ), this ); + horLayout->addWidget( textLabel ); + + QProgressBar * progressBar = new QProgressBar( this ); + progressBar->setMaximum( 0 ); + horLayout->addWidget( progressBar ); + + hide(); +} + +LoadingProgressBarWidget::~LoadingProgressBarWidget() +{ + m_document->removeObserver( this ); +} + +void LoadingProgressBarWidget::notifyPixmapGenerationStarted() +{ + m_pixmapGenerationInProgress = true; + show(); +} + +void LoadingProgressBarWidget::notifyPixmapGenerationFinished() +{ + m_pixmapGenerationInProgress = false; + + if (!m_textGenerationInProgress) + { + hide(); + } +} + +void LoadingProgressBarWidget::notifyTextGenerationStarted() +{ + m_textGenerationInProgress = true; + show(); +} + +void LoadingProgressBarWidget::notifyTextGenerationFinished() +{ + m_textGenerationInProgress = false; + + if (!m_pixmapGenerationInProgress) + { + hide(); + } +} + #include "minibar.moc" /* kate: replace-tabs on; indent-width 4; */ diff --git a/okular/ui/minibar.h b/okular/ui/minibar.h index 0bf969ff0..17ceb1e53 100644 --- a/okular/part/minibar.h +++ b/okular/part/minibar.h @@ -179,4 +179,29 @@ class ProgressWidget : public QWidget, public Okular::DocumentObserver float m_progressPercentage; }; +class LoadingProgressBarWidget : public QWidget, public Okular::DocumentObserver +{ + Q_OBJECT + public: + LoadingProgressBarWidget( QWidget * parent, Okular::Document * document ); + ~LoadingProgressBarWidget(); + + // [INHERITED] from DocumentObserver + void notifyPixmapGenerationStarted() override; + + // [INHERITED] from DocumentObserver + void notifyPixmapGenerationFinished() override; + + // [INHERITED] from DocumentObserver + void notifyTextGenerationStarted() override; + + // [INHERITED] from DocumentObserver + void notifyTextGenerationFinished() override; + + private: + Okular::Document * m_document; + bool m_pixmapGenerationInProgress; + bool m_textGenerationInProgress; +}; + #endif -- 2.25.4