From dddf96c011723a12b11acc2980c10eb370961021 Mon Sep 17 00:00:00 2001 From: Zhao Yuhang <2546789017@qq.com> Date: 周五, 15 12月 2023 21:35:17 +0800 Subject: [PATCH] add qt impl --- src/quick/quickwindowagent.cpp | 81 ++-------------------------------------- 1 files changed, 5 insertions(+), 76 deletions(-) diff --git a/src/quick/quickwindowagent.cpp b/src/quick/quickwindowagent.cpp index 747daf0..2e69f76 100644 --- a/src/quick/quickwindowagent.cpp +++ b/src/quick/quickwindowagent.cpp @@ -2,75 +2,15 @@ #include "quickwindowagent_p.h" #include <QtQuick/QQuickWindow> -#include <QtQuick/QQuickPaintedItem> -#include <QtQuick/private/qquickitem_p.h> #include <QtQuick/private/qquickanchors_p.h> - -#ifdef Q_OS_WINDOWS -# include <QWKCore/private/win10borderhandler_p.h> -#endif #include "quickitemdelegate_p.h" namespace QWK { - class BorderItem : public QQuickPaintedItem, public Win10BorderHandler { - Q_OBJECT - public: - explicit BorderItem(QQuickItem *parent = nullptr); - ~BorderItem() override; + QuickWindowAgentPrivate::QuickWindowAgentPrivate() = default; - void updateGeometry() override; - void requestUpdate() override; - - bool isActive() const override; - - public: - void paint(QPainter *painter) override; - }; - - BorderItem::BorderItem(QQuickItem *parent) - : Win10BorderHandler(parent->window()), QQuickPaintedItem(parent) { - setAntialiasing(true); // ### FIXME: do we need to enable or disable this? - setMipmap(true); // ### FIXME: do we need to enable or disable this? - setFillColor({}); // Will improve the performance a little bit. - setOpaquePainting(true); // Will also improve the performance, we don't draw - // semi-transparent borders of course. - - auto parentPri = QQuickItemPrivate::get(parent); - auto anchors = QQuickItemPrivate::get(this)->anchors(); - anchors->setTop(parentPri->top()); - anchors->setLeft(parentPri->left()); - anchors->setRight(parentPri->right()); - - setZ(10); - } - - BorderItem::~BorderItem() = default; - - void BorderItem::updateGeometry() { - setHeight(m_borderThickness); - } - - void BorderItem::requestUpdate() { - update(); - } - - bool BorderItem::isActive() const { - return static_cast<QQuickWindow *>(m_window)->isActive(); - } - - void BorderItem::paint(QPainter *painter) { - QRect rect(QPoint(0, 0), size().toSize()); - QRegion region(rect); - Win10BorderHandler::paintBorder(*painter, rect, region); - } - - QuickWindowAgentPrivate::QuickWindowAgentPrivate() { - } - - QuickWindowAgentPrivate::~QuickWindowAgentPrivate() { - } + QuickWindowAgentPrivate::~QuickWindowAgentPrivate() = default; void QuickWindowAgentPrivate::init() { } @@ -79,8 +19,7 @@ : QuickWindowAgent(*new QuickWindowAgentPrivate(), parent) { } - QuickWindowAgent::~QuickWindowAgent() { - } + QuickWindowAgent::~QuickWindowAgent() = default; bool QuickWindowAgent::setup(QQuickWindow *window) { Q_ASSERT(window); @@ -99,15 +38,7 @@ d->hostWindow = window; #ifdef Q_OS_WINDOWS - // Install painting hook - if (bool needPaintBorder; - QMetaObject::invokeMethod(d->context.get(), "needWin10BorderHandler", - Qt::DirectConnection, Q_RETURN_ARG(bool, needPaintBorder)), - needPaintBorder) { - QMetaObject::invokeMethod( - d->context.get(), "setWin10BorderHandler", Qt::DirectConnection, - Q_ARG(Win10BorderHandler *, new BorderItem(window->contentItem()))); - } + d->setupWindows10BorderWorkaround(); #endif return true; } @@ -158,6 +89,4 @@ d.init(); } -} - -#include "quickwindowagent.moc" \ No newline at end of file +} \ No newline at end of file -- Gitblit v1.9.1