refs #911, utility class to easily enable class for load indicator

and used it with CDbLoadOverviewComponent
This commit is contained in:
Klaus Basan
2017-03-22 18:31:31 +01:00
committed by Mathew Sutcliffe
parent cc1fd0e868
commit 24af0f044f
4 changed files with 93 additions and 44 deletions

View File

@@ -24,7 +24,7 @@ namespace BlackGui
namespace Components
{
CDbLoadOverviewComponent::CDbLoadOverviewComponent(QWidget *parent) :
QFrame(parent),
QFrame(parent), CLoadIndicatorEnabled(this),
ui(new Ui::CDbLoadOverviewComponent)
{
Q_ASSERT_X(sGui, Q_FUNC_INFO, "missing sGui");
@@ -105,16 +105,6 @@ namespace BlackGui
QFrame::resizeEvent(event);
}
bool CDbLoadOverviewComponent::isShowingLoadIndicator() const
{
return m_loadIndicator && this->isVisible() && m_loadIndicator->isAnimated();
}
bool CDbLoadOverviewComponent::isLoadInProgress() const
{
return m_loadInProgress;
}
void CDbLoadOverviewComponent::showVisibleLoadAllButtons(bool shared, bool db)
{
const bool widget = shared || db;
@@ -133,13 +123,6 @@ namespace BlackGui
this->triggerLoadingFromSharedFiles(CEntityFlags::AllDbEntitiesNoInfoObjects);
}
void CDbLoadOverviewComponent::centerLoadIndicator()
{
if (!m_loadIndicator) { return; }
const QPoint middle = this->visibleRegion().boundingRect().center();
this->m_loadIndicator->centerLoadIndicator(middle);
}
void CDbLoadOverviewComponent::ps_setValues()
{
if (!sGui) { return; }
@@ -212,18 +195,7 @@ namespace BlackGui
ui->lbl_SharedUrls->setMinimumHeight(10 + (18 * sharedUrls.size()));
// Indicator
if (this->m_loadIndicator) { this->m_loadIndicator->stopAnimation(); }
}
void CDbLoadOverviewComponent::showLoading()
{
if (!this->m_loadIndicator)
{
this->m_loadIndicator = new CLoadIndicator(64, 64, this);
}
this->centerLoadIndicator();
this->m_loadIndicator->startAnimation(true);
this->hideLoading();
}
bool CDbLoadOverviewComponent::isInitialized() const

View File

@@ -27,7 +27,8 @@ namespace BlackGui
/*!
* Overview about load state of DB data
*/
class BLACKGUI_EXPORT CDbLoadOverviewComponent : public QFrame
class BLACKGUI_EXPORT CDbLoadOverviewComponent :
public QFrame, public BlackGui::CLoadIndicatorEnabled
{
Q_OBJECT
@@ -50,12 +51,6 @@ namespace BlackGui
//! Show load all buttons
void showVisibleLoadAllButtons(bool shared, bool db);
//! Showing load indicator?
bool isShowingLoadIndicator() const;
//! Loading in progress?
bool isLoadInProgress() const;
//! Load all from DB
void loadAllFromDb();
@@ -71,12 +66,8 @@ namespace BlackGui
//! \copydoc QWidget::resizeEvent
virtual void resizeEvent(QResizeEvent *event) override;
//! Center load indicator
void centerLoadIndicator();
private:
QScopedPointer<Ui::CDbLoadOverviewComponent> ui;
BlackGui::CLoadIndicator *m_loadIndicator = nullptr; //!< load indicator if needed
BlackMisc::CDigestSignal m_dsTriggerGuiUpdate { this, &CDbLoadOverviewComponent::ps_triggerDigestGuiUpdate, &CDbLoadOverviewComponent::ps_setValues, 750, 4 };
bool m_loadInProgress = false; //!< data loading in progress
@@ -86,9 +77,6 @@ namespace BlackGui
//! Trigger loading from shared files
void triggerLoadingFromSharedFiles(BlackMisc::Network::CEntityFlags::Entity entities);
//! Show loading
void showLoading();
//! Values at least set once
bool isInitialized() const;

View File

@@ -64,6 +64,7 @@ namespace BlackGui
{
// only timeout myself id
this->stopAnimation(stopId);
emit this->timedOut();
});
}
this->m_pendingIds.push_back(stopId);
@@ -170,4 +171,53 @@ namespace BlackGui
const int y = middle.y() - h / 2;
this->setGeometry(x, y, w, h);
}
CLoadIndicatorEnabled::CLoadIndicatorEnabled(QWidget *usingWidget) :
m_usingWidget(usingWidget)
{
Q_ASSERT_X(usingWidget, Q_FUNC_INFO, "need widget");
}
bool CLoadIndicatorEnabled::isShowingLoadIndicator() const
{
return m_loadIndicator && m_usingWidget->isVisible() && m_loadIndicator->isAnimated();
}
bool CLoadIndicatorEnabled::isLoadInProgress() const
{
return m_loadInProgress;
}
void CLoadIndicatorEnabled::showLoading(int timeoutMs, bool processEvents)
{
if (!this->m_loadIndicator)
{
this->m_loadIndicator = new CLoadIndicator(64, 64, m_usingWidget);
QObject::connect(this->m_loadIndicator, &CLoadIndicator::timedOut,
[this] { this->indicatorTimedOut(); });
}
this->centerLoadIndicator();
m_indicatorId = this->m_loadIndicator->startAnimation(timeoutMs, processEvents);
}
void CLoadIndicatorEnabled::hideLoading()
{
if (m_loadIndicator)
{
m_loadIndicator->stopAnimation();
}
}
void CLoadIndicatorEnabled::centerLoadIndicator()
{
if (!m_loadIndicator) { return; }
const QPoint middle = this->m_usingWidget->visibleRegion().boundingRect().center();
this->m_loadIndicator->centerLoadIndicator(middle);
}
void CLoadIndicatorEnabled::indicatorTimedOut()
{
// to be overridden
}
} // ns

View File

@@ -73,6 +73,10 @@ namespace BlackGui
//! Center this load indicator
void centerLoadIndicator(const QPoint &middle);
signals:
//! Timed out
void timedOut();
public slots:
//! Starts the spin animation.
//! \sa stopAnimation isAnimated
@@ -116,6 +120,41 @@ namespace BlackGui
bool m_displayedWhenStopped = false;
QColor m_color = Qt::blue;
};
/**
* Enable widgte class for load indicator
*/
class BLACKGUI_EXPORT CLoadIndicatorEnabled
{
public:
//! Ctor
CLoadIndicatorEnabled(QWidget *usingWidget);
//! Showing load indicator?
bool isShowingLoadIndicator() const;
//! Show load indicator
void showLoading(int timeoutMs = -1, bool processEvents = true);
//! Hide load indicator
void hideLoading();
//! Loading in progress?
bool isLoadInProgress() const;
protected:
//! Center load indicator
void centerLoadIndicator();
//! Indicator timed out
//! \remark override for usage
void virtual indicatorTimedOut();
QWidget *m_usingWidget = nullptr; //!< widget which uses load indicator
CLoadIndicator *m_loadIndicator = nullptr; //!< indicator itself
bool m_loadInProgress = false; //!< flag indicating loading
int m_indicatorId = -1; //!< last indicator id returned
};
} // ns
#endif