Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
QmitkOverlayWidget.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "QmitkOverlayWidget.h"
14 #include <QPainter>
15 #include <QResizeEvent>
16 
18  : QWidget(parent)
19 {
20  this->installEventFilterOnParent();
22  this->setAttribute(Qt::WA_TranslucentBackground);
23 }
24 
26 {
27  this->removeEventFilterFromParent();
28 }
29 
31 {
32  return this->testAttribute(Qt::WA_TransparentForMouseEvents);
33 }
34 
36 {
37  this->setAttribute(Qt::WA_TransparentForMouseEvents, transparent);
38 }
39 
41 {
42  if (e->type() == QEvent::ParentAboutToChange)
43  {
44  this->removeEventFilterFromParent();
45  }
46  else if (e->type() == QEvent::ParentChange)
47  {
48  this->installEventFilterOnParent();
49  }
50 
51  return QWidget::event(e);
52 }
53 
54 bool QmitkOverlayWidget::eventFilter(QObject* watched, QEvent* event)
55 {
56  if (watched == this->parent())
57  {
58  if (event->type() == QEvent::Resize)
59  {
60  this->resize(static_cast<QResizeEvent*>(event)->size());
61  }
62  else if (event->type() == QEvent::ChildAdded)
63  {
64  this->raise();
65  }
66  }
67 
68  return QWidget::eventFilter(watched, event);
69 }
70 
72 {
73  QPainter painter(this);
74  painter.fillRect(this->rect(), QColor(0, 0, 0, 63));
75 }
76 
77 void QmitkOverlayWidget::installEventFilterOnParent()
78 {
79  if (this->parent() == nullptr)
80  return;
81 
82  this->parent()->installEventFilter(this);
83  this->raise();
84 }
85 
86 void QmitkOverlayWidget::removeEventFilterFromParent()
87 {
88  if (this->parent() == nullptr)
89  return;
90 
91  this->parent()->removeEventFilter(this);
92 }
void setTransparentForMouseEvents(bool transparent=true)
void paintEvent(QPaintEvent *event) override
bool isTransparentForMouseEvents() const
bool eventFilter(QObject *watched, QEvent *event) override
bool event(QEvent *e) override
QmitkOverlayWidget(QWidget *parent=nullptr)