refs #477, load indicator appears in wrong place.

A first improvement by re-centering it when view becomes visible.
This commit is contained in:
Klaus Basan
2015-10-02 14:57:12 +02:00
committed by Mathew Sutcliffe
parent 6fda875e8f
commit 42304f640b
4 changed files with 36 additions and 6 deletions

View File

@@ -103,10 +103,17 @@ namespace BlackGui
this->paint(p);
}
bool CLoadIndicator::isParentVisible() const
{
if (this->parentWidget()) { return parentWidget()->isVisible(); }
return false;
}
void CLoadIndicator::paint(QPainter &painter) const
{
if (!m_displayedWhenStopped && !isAnimated()) { return; }
if (!this->isVisible() || !this->isEnabled()) { return; }
if (!isParentVisible()) { return; }
int width = qMin(this->width(), this->height());
painter.setRenderHint(QPainter::Antialiasing);

View File

@@ -96,6 +96,9 @@ namespace BlackGui
//! \copydoc QWidget::paintEvent
virtual void paintEvent(QPaintEvent *event) override;
//! Is parent widget visible
bool isParentVisible() const;
private:
int m_angle = 0;
int m_timerId = -1;

View File

@@ -158,6 +158,16 @@ namespace BlackGui
// CStyleSheetUtility::useStyleSheetInDerivedWidget(this, QStyle::PE_Widget);
}
void CViewBaseNonTemplate::showEvent(QShowEvent *event)
{
if (this->isShowingLoadIndicator())
{
// re-center
this->centerLoadIndicator();
}
QTableView::showEvent(event);
}
void CViewBaseNonTemplate::allowDragDropValueObjects(bool allowDrag, bool allowDrop)
{
// see model for implementing logic of drag
@@ -246,17 +256,21 @@ namespace BlackGui
if (!this->m_loadIndicator)
{
this->m_loadIndicator = new CLoadIndicator(64, 64, this->viewport());
// connect(this->m_loadIndicator, &CLoadIndicator::updatedAnimation, this, &CViewBaseNonTemplate::ps_updatedIndicator);
this->m_loadIndicator = new CLoadIndicator(64, 64, this);
}
QPoint middle = this->geometry().center();
this->centerLoadIndicator();
this->m_loadIndicator->startAnimation();
}
void CViewBaseNonTemplate::centerLoadIndicator()
{
if (!m_loadIndicator) { return; }
QPoint middle = this->viewport()->geometry().center();
int w = m_loadIndicator->width();
int h = m_loadIndicator->height();
int x = middle.x() - w / 2;
int y = middle.y() - h / 2;
this->m_loadIndicator->setGeometry(x, y, w, h);
this->m_loadIndicator->startAnimation();
}
void CViewBaseNonTemplate::hideLoadIndicator()
@@ -379,7 +393,7 @@ namespace BlackGui
{
return model->sortContainerByColumn(container, sortColumn, sortOrder);
});
worker->thenWithResult<ContainerType>(this, [this, resize](const ContainerType &sortedContainer)
worker->thenWithResult<ContainerType>(this, [this, resize](const ContainerType & sortedContainer)
{
this->ps_updateContainer(CVariant::from(sortedContainer), false, resize);
});

View File

@@ -160,6 +160,9 @@ namespace BlackGui
//! \copydoc QTableView::paintEvent
virtual void paintEvent(QPaintEvent *event) override;
//! \copydoc QTableView::showEvent
virtual void showEvent(QShowEvent *event) override;
//! Perform resizing / non slot method for template
virtual void performModeBasedResizeToContent() = 0;
@@ -175,6 +178,9 @@ namespace BlackGui
//! Resize or skip resize?
virtual bool isResizeConditionMet(int containerSize = -1) const;
//! Center / re-center load indicator
void centerLoadIndicator();
//! Init default values
void init();