| | |
| | | |
| | | #include <QtGui/QtEvents> |
| | | #include <QtGui/QPainter> |
| | | #include <QtCore/QDebug> |
| | | |
| | | #ifdef Q_OS_WINDOWS |
| | | # include <QWKCore/private/win10borderhandler_p.h> |
| | | #endif |
| | | |
| | | #include "widgetitemdelegate_p.h" |
| | | |
| | | namespace QWK { |
| | | |
| | | class WidgetPaintFilter : public QObject { |
| | | #ifdef Q_OS_WINDOWS |
| | | class WidgetBorderHandler : public QObject, public Win10BorderHandler { |
| | | public: |
| | | WidgetPaintFilter(QWidget *widget, AbstractWindowContext *ctx) : widget(widget), ctx(ctx) { |
| | | explicit WidgetBorderHandler(QWidget *widget) |
| | | : Win10BorderHandler(widget->windowHandle()), widget(widget) { |
| | | widget->installEventFilter(this); |
| | | } |
| | | |
| | | void updateGeometry() override { |
| | | if (widget->windowState() & (Qt::WindowMaximized | Qt::WindowFullScreen)) { |
| | | widget->setContentsMargins({}); |
| | | } else { |
| | | widget->setContentsMargins({0, int(m_borderThickness), 0, 0}); |
| | | } |
| | | } |
| | | |
| | | void requestUpdate() override { |
| | | widget->update(); |
| | | } |
| | | |
| | | bool isActive() const override { |
| | | return widget->isActiveWindow(); |
| | | } |
| | | |
| | | protected: |
| | | bool eventFilter(QObject *obj, QEvent *event) override { |
| | | switch (event->type()) { |
| | | case QEvent::Paint: { |
| | | auto pe = static_cast<QPaintEvent *>(event); |
| | | if (widget->windowState() & (Qt::WindowMaximized | Qt::WindowFullScreen)) |
| | | break; |
| | | auto paintEvent = static_cast<QPaintEvent *>(event); |
| | | QPainter painter(widget); |
| | | QRect rect = pe->rect(); |
| | | QRegion region = pe->region(); |
| | | void *args[] = { |
| | | &painter, |
| | | &rect, |
| | | ®ion, |
| | | }; |
| | | ctx->virtual_hook(AbstractWindowContext::DrawBordersHook, args); |
| | | paintBorder(painter, paintEvent->rect(), paintEvent->region()); |
| | | return true; |
| | | } |
| | | default: |
| | |
| | | } |
| | | |
| | | QWidget *widget; |
| | | AbstractWindowContext *ctx; |
| | | }; |
| | | #endif |
| | | |
| | | WidgetWindowAgentPrivate::WidgetWindowAgentPrivate() { |
| | | } |
| | |
| | | } |
| | | d->hostWidget = w; |
| | | |
| | | #ifdef Q_OS_WINDOWS |
| | | // Install painting hook |
| | | if (bool needPaintBorder = false; |
| | | d->context->virtual_hook(AbstractWindowContext::NeedsDrawBordersHook, &needPaintBorder), |
| | | if (bool needPaintBorder; |
| | | QMetaObject::invokeMethod(d->context.get(), "needWin10BorderHandler", |
| | | Qt::DirectConnection, Q_RETURN_ARG(bool, needPaintBorder)), |
| | | needPaintBorder) { |
| | | d->paintFilter = std::make_unique<WidgetPaintFilter>(w, d->context.get()); |
| | | QMetaObject::invokeMethod(d->context.get(), "setWin10BorderHandler", |
| | | Qt::DirectConnection, |
| | | Q_ARG(Win10BorderHandler *, new WidgetBorderHandler(w))); |
| | | } |
| | | |
| | | if (d->context->key() == "win32") { |
| | | w->setContentsMargins(0, 1, 0, 0); |
| | | } |
| | | |
| | | #endif |
| | | return true; |
| | | } |
| | | |