forked from qt-creator/qt-creator
Factor an overlay widget out of progress indicator
The principle of having a widget on top of all other children of the same parent, for the purpose of painting an overlay, is generic. Change-Id: I6d3ee89cc51354988fedcc40340bb45a065db607 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -220,9 +220,11 @@ void ProgressIndicatorPainter::nextAnimationStep()
|
||||
\sa setIndicatorSize
|
||||
*/
|
||||
ProgressIndicator::ProgressIndicator(ProgressIndicatorSize size, QWidget *parent)
|
||||
: QWidget(parent), m_paint(size)
|
||||
: OverlayWidget(parent)
|
||||
, m_paint(size)
|
||||
{
|
||||
setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
setPaintFunction(
|
||||
[this](QWidget *w, QPainter &p, QPaintEvent *) { m_paint.paint(p, w->rect()); });
|
||||
m_paint.setUpdateCallback([this]() { update(); });
|
||||
updateGeometry();
|
||||
}
|
||||
@@ -248,29 +250,6 @@ QSize ProgressIndicator::sizeHint() const
|
||||
return m_paint.size();
|
||||
}
|
||||
|
||||
/*!
|
||||
Makes the indicator a child of \a parent, automatically centering on it,
|
||||
and adapting to size changes.
|
||||
*/
|
||||
void ProgressIndicator::attachToWidget(QWidget *parent)
|
||||
{
|
||||
if (parentWidget())
|
||||
parentWidget()->removeEventFilter(this);
|
||||
setParent(parent);
|
||||
parent->installEventFilter(this);
|
||||
resizeToParent();
|
||||
raise();
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
*/
|
||||
void ProgressIndicator::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter p(this);
|
||||
m_paint.paint(p, rect());
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
*/
|
||||
@@ -287,24 +266,4 @@ void ProgressIndicator::hideEvent(QHideEvent *)
|
||||
m_paint.stopAnimation();
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
*/
|
||||
bool ProgressIndicator::eventFilter(QObject *obj, QEvent *ev)
|
||||
{
|
||||
if (obj == parent() && ev->type() == QEvent::Resize) {
|
||||
resizeToParent();
|
||||
}
|
||||
return QWidget::eventFilter(obj, ev);
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
*/
|
||||
void ProgressIndicator::resizeToParent()
|
||||
{
|
||||
QTC_ASSERT(parentWidget(), return);
|
||||
setGeometry(QRect(QPoint(0, 0), parentWidget()->size()));
|
||||
}
|
||||
|
||||
} // namespace Utils
|
||||
|
||||
Reference in New Issue
Block a user