2017-04-06 02:06:42 +03:00
|
|
|
#include "OverlayWidget.h"
|
|
|
|
#include <QEvent>
|
|
|
|
|
|
|
|
OverlayWidget::OverlayWidget(QWidget *parent)
|
2017-08-20 13:47:22 +03:00
|
|
|
: QWidget(parent)
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
2017-09-10 12:59:21 +03:00
|
|
|
if (parent) {
|
|
|
|
parent->installEventFilter(this);
|
|
|
|
setGeometry(overlayGeometry());
|
|
|
|
raise();
|
|
|
|
}
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
bool
|
|
|
|
OverlayWidget::event(QEvent *event)
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
2017-09-10 12:59:21 +03:00
|
|
|
if (!parent())
|
|
|
|
return QWidget::event(event);
|
|
|
|
|
|
|
|
switch (event->type()) {
|
|
|
|
case QEvent::ParentChange: {
|
|
|
|
parent()->installEventFilter(this);
|
|
|
|
setGeometry(overlayGeometry());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case QEvent::ParentAboutToChange: {
|
|
|
|
parent()->removeEventFilter(this);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QWidget::event(event);
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
bool
|
|
|
|
OverlayWidget::eventFilter(QObject *obj, QEvent *event)
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
2017-09-10 12:59:21 +03:00
|
|
|
switch (event->type()) {
|
|
|
|
case QEvent::Move:
|
|
|
|
case QEvent::Resize:
|
|
|
|
setGeometry(overlayGeometry());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QWidget::eventFilter(obj, event);
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
QRect
|
|
|
|
OverlayWidget::overlayGeometry() const
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
2017-09-10 12:59:21 +03:00
|
|
|
QWidget *widget = parentWidget();
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
if (!widget)
|
|
|
|
return QRect();
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
return widget->rect();
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|