src/quick/CMakeLists.txt | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/quick/quickwindowagent.h | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/quick/quickwindowagent_mac.cpp | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/quick/quickwindowagent_p.h | ●●●●● 补丁 | 查看 | 原始文档 | 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 @@ -32,4 +34,4 @@ ) set(QWINDOWKIT_ENABLED_TARGETS ${QWINDOWKIT_ENABLED_TARGETS} ${PROJECT_NAME} PARENT_SCOPE) set(QWINDOWKIT_ENABLED_SUBDIRECTORIES ${QWINDOWKIT_ENABLED_SUBDIRECTORIES} quick PARENT_SCOPE) set(QWINDOWKIT_ENABLED_SUBDIRECTORIES ${QWINDOWKIT_ENABLED_SUBDIRECTORIES} quick PARENT_SCOPE) 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 @@ -34,4 +42,4 @@ } #endif // QUICKWINDOWAGENTPRIVATE_H #endif // QUICKWINDOWAGENTPRIVATE_H