From 718590bf4dec0e8d9e7a75af98568f5eff5f8f9d Mon Sep 17 00:00:00 2001 From: Sine Striker <trueful@163.com> Date: 周二, 19 12月 2023 14:45:36 +0800 Subject: [PATCH] Remove stylesupport --- src/core/kernel/systemwindow_p.h | 145 ++++++++++++++++++++++++ src/quick/quickwindowagent.h | 2 src/core/contexts/abstractwindowcontext.cpp | 7 - src/core/contexts/cocoawindowcontext.mm | 10 CMakeLists.txt | 1 /dev/null | 18 --- src/core/CMakeLists.txt | 1 src/CMakeLists.txt | 4 src/core/contexts/qtwindowcontext.cpp | 128 -------------------- src/widgets/widgetwindowagent.h | 2 src/core/qwkglobal_p.h | 1 examples/mainwindow/mainwindow.cpp | 2 share/install.cmake | 4 13 files changed, 161 insertions(+), 164 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 01f9fad..ffbee08 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,6 @@ option(QWINDOWKIT_BUILD_STATIC "Build static libraries" OFF) option(QWINDOWKIT_BUILD_WIDGETS "Build widgets module" ON) option(QWINDOWKIT_BUILD_QUICK "Build quick module" ON) -option(QWINDOWKIT_BUILD_STYLE_SUPPORT "Build style support module" ON) option(QWINDOWKIT_BUILD_EXAMPLES "Build examples" OFF) option(QWINDOWKIT_BUILD_DOCUMENTATIONS "Build documentations" OFF) option(QWINDOWKIT_INSTALL "Install library" ON) diff --git a/examples/mainwindow/mainwindow.cpp b/examples/mainwindow/mainwindow.cpp index 79724d4..c2e518c 100644 --- a/examples/mainwindow/mainwindow.cpp +++ b/examples/mainwindow/mainwindow.cpp @@ -107,7 +107,7 @@ void MainWindow::installWindowAgent() { // 1. Setup window agent - QWK::WidgetWindowAgent *agent = QWK::QWK_Initialize(this); + QWK::WidgetWindowAgent *agent = QWK::setupWidgetWindow(this); // 2. Construct your title bar auto menuBar = []() { diff --git a/share/install.cmake b/share/install.cmake index cb4aec1..b8a6c5d 100644 --- a/share/install.cmake +++ b/share/install.cmake @@ -18,12 +18,10 @@ set(QMAKE_QWK_CORE_NAME_RELEASE QWKCore) set(QMAKE_QWK_WIDGETS_NAME_RELEASE QWKWidgets) set(QMAKE_QWK_QUICK_NAME_RELEASE QWKQuick) - set(QMAKE_QWK_STYLESUPPORT_NAME_RELEASE QWKStyleSupport) set(QMAKE_QWK_CORE_NAME_DEBUG QWKCore${CMAKE_DEBUG_POSTFIX}) set(QMAKE_QWK_WIDGETS_NAME_DEBUG QWKWidgets${CMAKE_DEBUG_POSTFIX}) set(QMAKE_QWK_QUICK_NAME_DEBUG QWKQuick${CMAKE_DEBUG_POSTFIX}) - set(QMAKE_QWK_STYLESUPPORT_NAME_DEBUG QWKStyleSupport${CMAKE_DEBUG_POSTFIX}) file(GLOB _qmake_components "${CMAKE_CURRENT_LIST_DIR}/qmake/*.pri.in") @@ -60,14 +58,12 @@ QWKCore${CMAKE_DEBUG_POSTFIX}.lib QWKWidgets${CMAKE_DEBUG_POSTFIX}.lib QWKQuick${CMAKE_DEBUG_POSTFIX}.lib - QWKStyleSupport${CMAKE_DEBUG_POSTFIX}.lib ) set(MSBUILD_QWK_LIBRARY_LIST_RELEASE QWKCore.lib QWKWidgets.lib QWKQuick.lib - QWKStyleSupport.lib ) to_dos_separator(MSBUILD_QWK_INSTALL_PREFIX) diff --git a/share/qmake/QWKStyleSupport.pri.in b/share/qmake/QWKStyleSupport.pri.in deleted file mode 100644 index 0e7be64..0000000 --- a/share/qmake/QWKStyleSupport.pri.in +++ /dev/null @@ -1,11 +0,0 @@ -!defined(QMAKE_QWK_STYLESUPPORT_INCLUDED, var) { - QMAKE_QWK_STYLESUPPORT_INCLUDED = 1 - - include($$PWD/QWKCore.pri) - - CONFIG(debug, debug|release) { - LIBS += -l@QMAKE_QWK_STYLESUPPORT_NAME_DEBUG@ - } else { - LIBS += -l@QMAKE_QWK_STYLESUPPORT_NAME_RELEASE@ - } -} \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 25d290a..739c9f8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -122,10 +122,6 @@ # ---------------------------------- add_subdirectory(core) -if(QWINDOWKIT_BUILD_STYLE_SUPPORT) - add_subdirectory(stylesupport) -endif() - if(QWINDOWKIT_BUILD_WIDGETS) add_subdirectory(widgets) endif() diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 88d350b..d76ca34 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -13,6 +13,7 @@ windowitemdelegate.cpp kernel/nativeeventfilter_p.h kernel/nativeeventfilter.cpp + kernel/systemwindow_p.h contexts/abstractwindowcontext_p.h contexts/abstractwindowcontext.cpp ) diff --git a/src/core/contexts/abstractwindowcontext.cpp b/src/core/contexts/abstractwindowcontext.cpp index ef1efbf..d34a1f9 100644 --- a/src/core/contexts/abstractwindowcontext.cpp +++ b/src/core/contexts/abstractwindowcontext.cpp @@ -39,9 +39,8 @@ bool AbstractWindowContext::setSystemButton(WindowAgentBase::SystemButton button, QObject *obj) { - Q_ASSERT(obj); Q_ASSERT(button != WindowAgentBase::Unknown); - if (!obj || (button == WindowAgentBase::Unknown)) { + if (button == WindowAgentBase::Unknown) { return false; } @@ -54,10 +53,6 @@ bool AbstractWindowContext::setTitleBar(QObject *item) { Q_ASSERT(item); - if (!item) { - return false; - } - if (m_titleBar == item) { return false; } diff --git a/src/core/contexts/cocoawindowcontext.mm b/src/core/contexts/cocoawindowcontext.mm index 76ff231..9add515 100644 --- a/src/core/contexts/cocoawindowcontext.mm +++ b/src/core/contexts/cocoawindowcontext.mm @@ -6,7 +6,7 @@ #include <QtGui/QGuiApplication> #include "qwkglobal_p.h" - +#include "systemwindow_p.h" namespace QWK { struct NSWindowProxy { @@ -259,9 +259,9 @@ if (type < QEvent::MouseButtonPress || type > QEvent::MouseMove) { return false; } - QObject *host = m_context->host(); - QWindow *window = m_context->window(); - WindowItemDelegate *delegate = m_context->delegate(); + auto host = m_context->host(); + auto window = m_context->window(); + auto delegate = m_context->delegate(); auto me = static_cast<const QMouseEvent *>(event); QPoint scenePos = getMouseEventScenePos(me); @@ -323,7 +323,7 @@ } case PreparingMove: { m_windowStatus = Moving; - window->startSystemMove(); + startSystemMove(window); event->accept(); return true; } diff --git a/src/core/contexts/qtwindowcontext.cpp b/src/core/contexts/qtwindowcontext.cpp index 58237c2..8a71c2b 100644 --- a/src/core/contexts/qtwindowcontext.cpp +++ b/src/core/contexts/qtwindowcontext.cpp @@ -3,6 +3,7 @@ #include <QtCore/QDebug> #include "qwkglobal_p.h" +#include "systemwindow_p.h" namespace QWK { @@ -76,125 +77,6 @@ #endif } -#ifdef Q_OS_LINUX - class WindowMoveManipulator : public QObject { - public: - explicit WindowMoveManipulator(QWindow *targetWindow) - : QObject(targetWindow), target(targetWindow), initialMousePosition(QCursor::pos()), - initialWindowPosition(targetWindow->position()) { - target->installEventFilter(this); - } - - protected: - bool eventFilter(QObject *obj, QEvent *event) override { - switch (event->type()) { - case QEvent::MouseMove: { - auto mouseEvent = static_cast<QMouseEvent *>(event); - QPoint delta = getMouseEventGlobalPos(mouseEvent) - initialMousePosition; - target->setPosition(initialWindowPosition + delta); - return true; - } - - case QEvent::MouseButtonRelease: { - if (target->y() < 0) { - target->setPosition(target->x(), 0); - } - target->removeEventFilter(this); - this->deleteLater(); - } - - default: - break; - } - return false; - } - - private: - QWindow *target; - QPoint initialMousePosition; - QPoint initialWindowPosition; - }; -#endif - -#if defined(Q_OS_MAC) || defined(Q_OS_LINUX) - class WindowResizeManipulator : public QObject { - public: - WindowResizeManipulator(QWindow *targetWindow, Qt::Edges edges) - : QObject(targetWindow), target(targetWindow), resizeEdges(edges), - initialMousePosition(QCursor::pos()), initialWindowRect(target->geometry()) { - target->installEventFilter(this); - } - - protected: - bool eventFilter(QObject *obj, QEvent *event) override { - switch (event->type()) { - case QEvent::MouseMove: { - auto mouseEvent = static_cast<QMouseEvent *>(event); - QPoint globalMousePos = getMouseEventGlobalPos(mouseEvent); - QRect windowRect = initialWindowRect; - - if (resizeEdges & Qt::LeftEdge) { - int delta = globalMousePos.x() - initialMousePosition.x(); - windowRect.setLeft(initialWindowRect.left() + delta); - } - if (resizeEdges & Qt::RightEdge) { - int delta = globalMousePos.x() - initialMousePosition.x(); - windowRect.setRight(initialWindowRect.right() + delta); - } - if (resizeEdges & Qt::TopEdge) { - int delta = globalMousePos.y() - initialMousePosition.y(); - windowRect.setTop(initialWindowRect.top() + delta); - } - if (resizeEdges & Qt::BottomEdge) { - int delta = globalMousePos.y() - initialMousePosition.y(); - windowRect.setBottom(initialWindowRect.bottom() + delta); - } - - target->setGeometry(windowRect); - return true; - } - - case QEvent::MouseButtonRelease: { - target->removeEventFilter(this); - this->deleteLater(); - } - - default: - break; - } - return false; - } - - private: - QWindow *target; - QPoint initialMousePosition; - QRect initialWindowRect; - Qt::Edges resizeEdges; - }; -#endif - - static inline void startSystemMove(QWindow *window) { -#ifdef Q_OS_LINUX - if (window->startSystemMove()) { - return; - } - std::ignore = new WindowMoveManipulator(window); -#else - window->startSystemMove(); -#endif - } - - static inline void startSystemResize(QWindow *window, Qt::Edges edges) { -#if defined(Q_OS_MAC) || defined(Q_OS_LINUX) - if (window->startSystemResize(edges)) { - return; - } - std::ignore = new WindowResizeManipulator(window, edges); -#else - window->startSystemResize(edges); -#endif - } - class QtWindowEventFilter : public QObject { public: explicit QtWindowEventFilter(AbstractWindowContext *context, QObject *parent = nullptr); @@ -230,11 +112,11 @@ if (type < QEvent::MouseButtonPress || type > QEvent::MouseMove) { return false; } - QObject *host = m_context->host(); - QWindow *window = m_context->window(); - WindowItemDelegate *delegate = m_context->delegate(); - bool fixedSize = delegate->isHostSizeFixed(host); + auto host = m_context->host(); + auto window = m_context->window(); + auto delegate = m_context->delegate(); auto me = static_cast<const QMouseEvent *>(event); + bool fixedSize = delegate->isHostSizeFixed(host); QPoint scenePos = getMouseEventScenePos(me); QPoint globalPos = getMouseEventGlobalPos(me); diff --git a/src/core/kernel/systemwindow_p.h b/src/core/kernel/systemwindow_p.h new file mode 100644 index 0000000..d6eb2c8 --- /dev/null +++ b/src/core/kernel/systemwindow_p.h @@ -0,0 +1,145 @@ +#ifndef SYSTEMWINDOW_P_H +#define SYSTEMWINDOW_P_H + +#include <QtGui/QWindow> +#include <QtGui/QMouseEvent> + +#include <QWKCore/private/qwkglobal_p.h> + +// Don't include this header in any header files. + +namespace QWK { + + // Anonymous namespace + namespace { + + class WindowMoveManipulator : public QObject { + public: + explicit WindowMoveManipulator(QWindow *targetWindow) + : QObject(targetWindow), target(targetWindow), initialMousePosition(QCursor::pos()), + initialWindowPosition(targetWindow->position()) { + target->installEventFilter(this); + } + + protected: + bool eventFilter(QObject *obj, QEvent *event) override { + switch (event->type()) { + case QEvent::MouseMove: { + auto mouseEvent = static_cast<QMouseEvent *>(event); + QPoint delta = getMouseEventGlobalPos(mouseEvent) - initialMousePosition; + target->setPosition(initialWindowPosition + delta); + return true; + } + + case QEvent::MouseButtonRelease: { + if (target->y() < 0) { + target->setPosition(target->x(), 0); + } + target->removeEventFilter(this); + this->deleteLater(); + } + + default: + break; + } + return false; + } + + private: + QWindow *target; + QPoint initialMousePosition; + QPoint initialWindowPosition; + }; + + class WindowResizeManipulator : public QObject { + public: + WindowResizeManipulator(QWindow *targetWindow, Qt::Edges edges) + : QObject(targetWindow), target(targetWindow), resizeEdges(edges), + initialMousePosition(QCursor::pos()), initialWindowRect(target->geometry()) { + target->installEventFilter(this); + } + + protected: + bool eventFilter(QObject *obj, QEvent *event) override { + switch (event->type()) { + case QEvent::MouseMove: { + auto mouseEvent = static_cast<QMouseEvent *>(event); + QPoint globalMousePos = getMouseEventGlobalPos(mouseEvent); + QRect windowRect = initialWindowRect; + + if (resizeEdges & Qt::LeftEdge) { + int delta = globalMousePos.x() - initialMousePosition.x(); + windowRect.setLeft(initialWindowRect.left() + delta); + } + if (resizeEdges & Qt::RightEdge) { + int delta = globalMousePos.x() - initialMousePosition.x(); + windowRect.setRight(initialWindowRect.right() + delta); + } + if (resizeEdges & Qt::TopEdge) { + int delta = globalMousePos.y() - initialMousePosition.y(); + windowRect.setTop(initialWindowRect.top() + delta); + } + if (resizeEdges & Qt::BottomEdge) { + int delta = globalMousePos.y() - initialMousePosition.y(); + windowRect.setBottom(initialWindowRect.bottom() + delta); + } + + target->setGeometry(windowRect); + return true; + } + + case QEvent::MouseButtonRelease: { + target->removeEventFilter(this); + this->deleteLater(); + } + + default: + break; + } + return false; + } + + private: + QWindow *target; + QPoint initialMousePosition; + QRect initialWindowRect; + Qt::Edges resizeEdges; + }; + + } + + // QWindow::startSystemMove() and QWindow::startSystemResize() is first supported at Qt 5.15 + // QWindow::startSystemResize() returns false on macOS + // QWindow::startSystemMove() and QWindow::startSystemResize() returns false on Linux Unity DE + + // When the new API fails, we emulate the window actions using the classical API. + + static inline void startSystemMove(QWindow *window) { +#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0)) + std::ignore = new WindowMoveManipulator(window); +#elif defined(Q_OS_LINUX) + if (window->startSystemMove()) { + return; + } + std::ignore = new WindowMoveManipulator(window); +#else + window->startSystemMove(); +#endif + } + + static inline void startSystemResize(QWindow *window, Qt::Edges edges) { +#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0)) + std::ignore = new WindowResizeManipulator(window, edges); +#elif defined(Q_OS_MAC) || defined(Q_OS_LINUX) + if (window->startSystemResize(edges)) { + return; + } + std::ignore = new WindowResizeManipulator(window, edges); +#else + window->startSystemResize(edges); +#endif + } + +} + +#endif // SYSTEMWINDOW_P_H diff --git a/src/core/qwkglobal_p.h b/src/core/qwkglobal_p.h index 6df96cd..d780c53 100644 --- a/src/core/qwkglobal_p.h +++ b/src/core/qwkglobal_p.h @@ -40,6 +40,7 @@ return event->windowPos().toPoint(); #endif } + inline QPoint getMouseEventGlobalPos(const QMouseEvent *event) { #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) return event->globalPosition().toPoint(); diff --git a/src/quick/quickwindowagent.h b/src/quick/quickwindowagent.h index 23b6521..95220c0 100644 --- a/src/quick/quickwindowagent.h +++ b/src/quick/quickwindowagent.h @@ -38,7 +38,7 @@ QuickWindowAgent(QuickWindowAgentPrivate &d, QObject *parent = nullptr); }; - inline QuickWindowAgent *QWK_Initialize(QQuickWindow *window) { + inline QuickWindowAgent *setupQuickWindow(QQuickWindow *window) { auto agent = new QuickWindowAgent(window); agent->setup(window); return agent; diff --git a/src/stylesupport/CMakeLists.txt b/src/stylesupport/CMakeLists.txt deleted file mode 100644 index eea48a5..0000000 --- a/src/stylesupport/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -project(QWKStyleSupport - VERSION ${QWINDOWKIT_VERSION} - LANGUAGES CXX -) - -set(_src - qwkstylesupportglobal.h -) - -qwk_add_library(${PROJECT_NAME} AUTOGEN - SOURCES ${_src} - LINKS QWKCore - QT_LINKS Core Gui - QT_INCLUDE_PRIVATE Core Gui - PREFIX QWK_STYLESUPPORT -) - -set_target_properties(${PROJECT_NAME} PROPERTIES - CXX_STANDARD 17 - CXX_STANDARD_REQUIRED TRUE -) - -set(QWINDOWKIT_ENABLED_TARGETS ${QWINDOWKIT_ENABLED_TARGETS} ${PROJECT_NAME} PARENT_SCOPE) -set(QWINDOWKIT_ENABLED_SUBDIRECTORIES ${QWINDOWKIT_ENABLED_SUBDIRECTORIES} stylesupport PARENT_SCOPE) \ No newline at end of file diff --git a/src/stylesupport/qwkstylesupportglobal.h b/src/stylesupport/qwkstylesupportglobal.h deleted file mode 100644 index 27f8e31..0000000 --- a/src/stylesupport/qwkstylesupportglobal.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef QWKSTYLESUPPORTGLOBAL_H -#define QWKSTYLESUPPORTGLOBAL_H - -#include <QtCore/QtGlobal> - -#ifndef QWK_STYLESUPPORT_EXPORT -# ifdef QWK_STYLESUPPORT_STATIC -# define QWK_STYLESUPPORT_EXPORT -# else -# ifdef QWK_STYLESUPPORT_LIBRARY -# define QWK_STYLESUPPORT_EXPORT Q_DECL_EXPORT -# else -# define QWK_STYLESUPPORT_EXPORT Q_DECL_IMPORT -# endif -# endif -#endif - -#endif // QWKSTYLESUPPORTGLOBAL_H diff --git a/src/widgets/widgetwindowagent.h b/src/widgets/widgetwindowagent.h index 94af904..9938b1a 100644 --- a/src/widgets/widgetwindowagent.h +++ b/src/widgets/widgetwindowagent.h @@ -42,7 +42,7 @@ WidgetWindowAgent(WidgetWindowAgentPrivate &d, QObject *parent = nullptr); }; - inline WidgetWindowAgent *QWK_Initialize(QWidget *w) { + inline WidgetWindowAgent *setupWidgetWindow(QWidget *w) { auto agent = new WidgetWindowAgent(w); agent->setup(w); return agent; -- Gitblit v1.9.1