2017-04-06 02:06:42 +03:00
|
|
|
#include "OverlayWidget.h"
|
|
|
|
#include <QEvent>
|
|
|
|
|
|
|
|
OverlayWidget::OverlayWidget(QWidget *parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
{
|
2017-04-26 02:23:12 +03:00
|
|
|
if (parent) {
|
2017-04-06 02:06:42 +03:00
|
|
|
parent->installEventFilter(this);
|
2017-04-26 02:23:12 +03:00
|
|
|
setGeometry(overlayGeometry());
|
|
|
|
raise();
|
|
|
|
}
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool OverlayWidget::event(QEvent *event)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OverlayWidget::eventFilter(QObject *obj, QEvent *event)
|
|
|
|
{
|
|
|
|
switch (event->type()) {
|
|
|
|
case QEvent::Move:
|
|
|
|
case QEvent::Resize:
|
|
|
|
setGeometry(overlayGeometry());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QWidget::eventFilter(obj, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
QRect OverlayWidget::overlayGeometry() const
|
|
|
|
{
|
|
|
|
QWidget *widget = parentWidget();
|
|
|
|
|
|
|
|
if (!widget)
|
|
|
|
return QRect();
|
|
|
|
|
|
|
|
return widget->rect();
|
|
|
|
}
|