matrixion/src/ui/OverlayWidget.cpp

75 lines
1.5 KiB
C++
Raw Normal View History

2017-04-06 02:06:42 +03:00
#include "OverlayWidget.h"
2020-01-31 08:12:02 +03:00
#include <QPainter>
#include <QStyleOption>
2017-04-06 02:06:42 +03:00
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
}
void
OverlayWidget::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
QStyleOption opt;
opt.init(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}