From fd8aca4a20f52f696aa239ead1baa20cea5879f6 Mon Sep 17 00:00:00 2001 From: SineStriker <55847490+SineStriker@users.noreply.github.com> Date: 周一, 11 12月 2023 14:58:25 +0800 Subject: [PATCH] Merge pull request #2 from stdware/refactor --- src/widgets/widgetwindowagent.cpp | 64 ++++++++++++++++--------------- 1 files changed, 33 insertions(+), 31 deletions(-) diff --git a/src/widgets/widgetwindowagent.cpp b/src/widgets/widgetwindowagent.cpp index 252213e..f7d016e 100644 --- a/src/widgets/widgetwindowagent.cpp +++ b/src/widgets/widgetwindowagent.cpp @@ -32,20 +32,48 @@ return false; } - std::ignore = w->winId(); // Make sure the window handle is created - if (!d->setup(w->windowHandle(), new WidgetItemDelegate())) { + w->setAttribute(Qt::WA_DontCreateNativeAncestors); + w->setAttribute(Qt::WA_NativeWindow); + + if (!d->setup(w, new WidgetItemDelegate())) { return false; } d->hostWidget = w; return true; } - bool WidgetWindowAgent::isHitTestVisible(QWidget *w) const { + const QWidget *WidgetWindowAgent::titleBar() const { + Q_D(const WidgetWindowAgent); + return static_cast<const QWidget *>(d->context->titleBar()); + } + + void WidgetWindowAgent::setTitleBar(const QWidget *w) { + Q_D(WidgetWindowAgent); + if (!d->context->setTitleBar(w)) { + return; + } + Q_EMIT titleBarWidgetChanged(w); + } + + const QWidget *WidgetWindowAgent::systemButton(SystemButton button) const { + Q_D(const WidgetWindowAgent); + return static_cast<const QWidget *>(d->context->systemButton(button)); + } + + void WidgetWindowAgent::setSystemButton(SystemButton button, const QWidget *w) { + Q_D(WidgetWindowAgent); + if (!d->context->setSystemButton(button, w)) { + return; + } + Q_EMIT systemButtonChanged(button, w); + } + + bool WidgetWindowAgent::isHitTestVisible(const QWidget *w) const { Q_D(const WidgetWindowAgent); return d->context->isHitTestVisible(w); } - void WidgetWindowAgent::setHitTestVisible(QWidget *w, bool visible) { + void WidgetWindowAgent::setHitTestVisible(const QWidget *w, bool visible) { Q_D(WidgetWindowAgent); d->context->setHitTestVisible(w, visible); } @@ -55,34 +83,8 @@ d->context->setHitTestVisible(rect, visible); } - QWidget *WidgetWindowAgent::systemButton(CoreWindowAgent::SystemButton button) const { - Q_D(const WidgetWindowAgent); - return static_cast<QWidget *>(d->context->systemButton(button)); - } - - void WidgetWindowAgent::setSystemButton(CoreWindowAgent::SystemButton button, QWidget *w) { - Q_D(WidgetWindowAgent); - if (!d->context->setSystemButton(button, w)) { - return; - } - Q_EMIT systemButtonChanged(button, w); - } - - QWidget *WidgetWindowAgent::titleBar() const { - Q_D(const WidgetWindowAgent); - return static_cast<QWidget *>(d->context->titleBar()); - } - - void WidgetWindowAgent::setTitleBar(QWidget *w) { - Q_D(WidgetWindowAgent); - if (!d->context->setTitleBar(w)) { - return; - } - Q_EMIT titleBarWidgetChanged(w); - } - WidgetWindowAgent::WidgetWindowAgent(WidgetWindowAgentPrivate &d, QObject *parent) - : CoreWindowAgent(d, parent) { + : WindowAgentBase(d, parent) { d.init(); } } -- Gitblit v1.9.1