diff options
author | Eike Ziller <eike.ziller@theqtcompany.com> | 2015-01-16 11:59:54 +0100 |
---|---|---|
committer | Eike Ziller <eike.ziller@theqtcompany.com> | 2015-01-16 16:45:02 +0100 |
commit | bafdf36f805d1d63f7c03afb61d941846d0461c1 (patch) | |
tree | 8fd1edd543de6aab3c1aa32953aeb8e131a62c5f /src/libs/utils/progressindicator.cpp | |
parent | 7fec1199f30d5d71a0bc6a9db873a93d6ba6248f (diff) |
Add easy way to add progress indicator overlay to a widget
Adds a way to 'attach' a progress indicator to a parent, so it
automatically keeps itself centered on the parent.
Also adds shortcut methods to BaseTreeView.
Change-Id: I962a9300d89ef5d1e03298d670e0cee781d3a4e5
Reviewed-by: hjk <hjk@theqtcompany.com>
Diffstat (limited to 'src/libs/utils/progressindicator.cpp')
-rw-r--r-- | src/libs/utils/progressindicator.cpp | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/src/libs/utils/progressindicator.cpp b/src/libs/utils/progressindicator.cpp index 10e0f9a5d13..f1a6f3e905c 100644 --- a/src/libs/utils/progressindicator.cpp +++ b/src/libs/utils/progressindicator.cpp @@ -29,26 +29,40 @@ ****************************************************************************/ #include "progressindicator.h" + +#include "qtcassert.h" #include "stylehelper.h" +#include <QEvent> #include <QPainter> #include <QPixmap> using namespace Utils; -ProgressIndicator::ProgressIndicator(Size size, QWidget *parent) +ProgressIndicator::ProgressIndicator(IndicatorSize size, QWidget *parent) : QWidget(parent), m_rotation(0) { setAttribute(Qt::WA_TransparentForMouseEvents); + m_timer.setSingleShot(false); + connect(&m_timer, &QTimer::timeout, this, &ProgressIndicator::step); + setIndicatorSize(size); +} + +void ProgressIndicator::setIndicatorSize(ProgressIndicator::IndicatorSize size) +{ m_size = size; m_rotationStep = size == Small ? 45 : 30; + m_timer.setInterval(size == Small ? 100 : 80); m_pixmap.load(StyleHelper::dpiSpecificImageFile( size == Small ? QLatin1String(":/utils/images/progressindicator_small.png") : QLatin1String(":/utils/images/progressindicator_big.png"))); - m_timer.setInterval(size == Small ? 100 : 80); - m_timer.setSingleShot(false); - connect(&m_timer, &QTimer::timeout, this, &ProgressIndicator::step); + updateGeometry(); +} + +ProgressIndicator::IndicatorSize ProgressIndicator::indicatorSize() const +{ + return m_size; } QSize ProgressIndicator::sizeHint() const @@ -56,6 +70,16 @@ QSize ProgressIndicator::sizeHint() const return m_pixmap.size() / m_pixmap.devicePixelRatio(); } +void ProgressIndicator::attachToWidget(QWidget *parent) +{ + if (parentWidget()) + parentWidget()->removeEventFilter(this); + setParent(parent); + parent->installEventFilter(this); + resizeToParent(); + raise(); +} + void ProgressIndicator::paintEvent(QPaintEvent *) { QPainter p(this); @@ -82,9 +106,23 @@ void ProgressIndicator::hideEvent(QHideEvent *) m_timer.stop(); } +bool ProgressIndicator::eventFilter(QObject *obj, QEvent *ev) +{ + if (obj == parent() && ev->type() == QEvent::Resize) { + resizeToParent(); + } + return QWidget::eventFilter(obj, ev); +} + void ProgressIndicator::step() { m_rotation = (m_rotation + m_rotationStep + 360) % 360; update(); } +void ProgressIndicator::resizeToParent() +{ + QTC_ASSERT(parentWidget(), return); + setGeometry(QRect(QPoint(0, 0), parentWidget()->size())); +} + |