From 49b27d64a9778d53a3accd9bfbfbc3ee1a1a7178 Mon Sep 17 00:00:00 2001 From: Sine Striker <trueful@163.com> Date: 周三, 08 5月 2024 20:44:05 +0800 Subject: [PATCH] minor tweaks --- src/widgets/widgetwindowagent_mac.cpp | 34 +++++++++++++++++++++++++++++++--- 1 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/widgets/widgetwindowagent_mac.cpp b/src/widgets/widgetwindowagent_mac.cpp index 1d4f320..17156e4 100644 --- a/src/widgets/widgetwindowagent_mac.cpp +++ b/src/widgets/widgetwindowagent_mac.cpp @@ -1,3 +1,7 @@ +// Copyright (C) 2023-2024 Stdware Collections (https://www.github.com/stdware) +// Copyright (C) 2021-2023 wangwenx190 (Yuhang Zhao) +// SPDX-License-Identifier: Apache-2.0 + #include "widgetwindowagent_p.h" #include <QtGui/QtEvents> @@ -14,6 +18,9 @@ QObject *parent = nullptr) : QObject(parent), widget(widget), ctx(ctx) { widget->installEventFilter(this); + ctx->setSystemButtonAreaCallback([widget](const QSize &) { + return getWidgetSceneRect(widget); // + }); } ~SystemButtonAreaWidgetEventFilter() override = default; @@ -23,7 +30,7 @@ switch (event->type()) { case QEvent::Move: case QEvent::Resize: { - ctx->setSystemButtonArea(getWidgetSceneRect(widget)); + ctx->virtual_hook(AbstractWindowContext::SystemButtonAreaChangedHook, nullptr); break; } @@ -49,6 +56,8 @@ /*! Sets the widget that acts as the system button area. The system button will be centered in its area, it is recommended to place the widget in a layout and set a fixed size policy. + + The system button will be visible in the system title bar area. */ void WidgetWindowAgent::setSystemButtonArea(QWidget *widget) { Q_D(WidgetWindowAgent); @@ -58,13 +67,32 @@ auto ctx = d->context.get(); d->systemButtonAreaWidget = widget; if (!widget) { + d->context->setSystemButtonAreaCallback({}); d->systemButtonAreaWidgetEventFilter.reset(); - ctx->setSystemButtonArea({}); return; } d->systemButtonAreaWidgetEventFilter = std::make_unique<SystemButtonAreaWidgetEventFilter>(widget, ctx); - ctx->setSystemButtonArea(getWidgetSceneRect(widget)); + } + + /*! + Returns the the system button area callback. + */ + ScreenRectCallback WidgetWindowAgent::systemButtonAreaCallback() const { + Q_D(const WidgetWindowAgent); + return d->systemButtonAreaWidget ? nullptr : d->context->systemButtonAreaCallback(); + } + + /*! + Sets the the system button area callback, the \c size of the callback is the native title + bar size. + + The system button position will be updated when the window resizes. + */ + void WidgetWindowAgent::setSystemButtonAreaCallback(const ScreenRectCallback &callback) { + Q_D(WidgetWindowAgent); + setSystemButtonArea(nullptr); + d->context->setSystemButtonAreaCallback(callback); } } \ No newline at end of file -- Gitblit v1.9.1