Zhao Yuhang
2023-12-28 96833537013e55ee42ef86ea75afca373bdced29
add quick mac button API
3个文件已修改
1个文件已添加
61 ■■■■■ 已修改文件
src/quick/CMakeLists.txt 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/quick/quickwindowagent.h 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/quick/quickwindowagent_mac.cpp 46 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/quick/quickwindowagent_p.h 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/quick/CMakeLists.txt
@@ -15,6 +15,8 @@
if(WIN32)
    list(APPEND _src quickwindowagent_win.cpp)
elseif(APPLE)
    list(APPEND _src quickwindowagent_mac.cpp)
endif()
qwk_add_library(${PROJECT_NAME} AUTOGEN
src/quick/quickwindowagent.h
@@ -30,6 +30,11 @@
        Q_INVOKABLE bool isHitTestVisible(const QQuickItem *item) const;
        Q_INVOKABLE void setHitTestVisible(const QQuickItem *item, bool visible = true);
#ifdef Q_OS_MAC
        QQuickItem *systemButtonArea() const;
        void setSystemButtonArea(QQuickItem *item);
#endif
    Q_SIGNALS:
        void titleBarWidgetChanged(const QQuickItem *item);
        void systemButtonChanged(SystemButton button, const QQuickItem *item);
src/quick/quickwindowagent_mac.cpp
New file
@@ -0,0 +1,46 @@
#include "quickwindowagent_p.h"
namespace QWK {
    /*!
        Returns the item that acts as the system button area.
    */
    QQuickItem *QuickWindowAgent::systemButtonArea() const {
        Q_D(const QuickWindowAgent);
        return d->systemButtonAreaItem;
    }
    /*!
        Sets the item that acts as the system button area. The system button will be centered in
        its area, it is recommended to place the item in a layout and set a fixed size policy.
    */
    void QuickWindowAgent::setSystemButtonArea(QQuickItem *item) {
        Q_D(QuickWindowAgent);
        if (d->systemButtonAreaItem == item)
            return;
        auto ctx = d->context.get();
        d->systemButtonAreaItem = item;
        if (!item) {
            disconnect(systemButtonAreaItemXChangedConnection);
            disconnect(systemButtonAreaItemYChangedConnection);
            disconnect(systemButtonAreaItemWidthChangedConnection);
            disconnect(systemButtonAreaItemHeightChangedConnection);
            systemButtonAreaItemXChangedConnection = {};
            systemButtonAreaItemYChangedConnection = {};
            systemButtonAreaItemWidthChangedConnection = {};
            systemButtonAreaItemHeightChangedConnection = {};
            ctx->setSystemButtonArea({});
            return;
        }
        const auto updateSystemButtonArea = [ctx, item]() -> void {
            ctx->setSystemButtonArea(QRectF(item->mapToScene(QPointF(0, 0)), item->size()).toRect());
        };
        systemButtonAreaItemXChangedConnection = connect(item, &QQuickItem::xChanged, this, updateSystemButtonArea);
        systemButtonAreaItemYChangedConnection = connect(item, &QQuickItem::yChanged, this, updateSystemButtonArea);
        systemButtonAreaItemWidthChangedConnection = connect(item, &QQuickItem::widthChanged, this, updateSystemButtonArea);
        systemButtonAreaItemHeightChangedConnection = connect(item, &QQuickItem::heightChanged, this, updateSystemButtonArea);
        updateSystemButtonArea();
    }
}
src/quick/quickwindowagent_p.h
@@ -27,6 +27,14 @@
        // Host
        QQuickWindow *hostWindow{};
#ifdef Q_OS_MAC
        QQuickItem *systemButtonAreaItem{};
        QMetaObject::Connection systemButtonAreaItemXChangedConnection{};
        QMetaObject::Connection systemButtonAreaItemYChangedConnection{};
        QMetaObject::Connection systemButtonAreaItemWidthChangedConnection{};
        QMetaObject::Connection systemButtonAreaItemHeightChangedConnection{};
#endif
#if defined(Q_OS_WINDOWS) && QWINDOWKIT_CONFIG(ENABLE_WINDOWS_SYSTEM_BORDERS)
        void setupWindows10BorderWorkaround();
#endif