summary refs log tree commit diff
path: root/src/ui/OverlayWidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/OverlayWidget.cpp')
-rw-r--r--src/ui/OverlayWidget.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/ui/OverlayWidget.cpp b/src/ui/OverlayWidget.cpp
new file mode 100644
index 00000000..ccac0116
--- /dev/null
+++ b/src/ui/OverlayWidget.cpp
@@ -0,0 +1,72 @@
+#include "OverlayWidget.h"
+#include <QEvent>
+
+OverlayWidget::OverlayWidget(QWidget *parent)
+  : QWidget(parent)
+{
+        if (parent) {
+                parent->installEventFilter(this);
+                setGeometry(overlayGeometry());
+                raise();
+        }
+}
+
+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();
+}
+
+void
+OverlayWidget::paintEvent(QPaintEvent *event)
+{
+        Q_UNUSED(event);
+
+        QStyleOption opt;
+        opt.init(this);
+        QPainter p(this);
+        style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
+}