Sine Striker
2023-12-02 499afac952920595e6c3d4f94806427f894c7674
optimize code
18个文件已修改
102 ■■■■ 已修改文件
src/core/contexts/abstractwindowcontext.cpp 18 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/core/contexts/abstractwindowcontext_p.h 18 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/core/contexts/qtwindowcontext.cpp 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/core/contexts/qtwindowcontext_p.h 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/core/contexts/win32windowcontext.cpp 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/core/contexts/win32windowcontext_p.h 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/core/corewindowagent.cpp 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/core/corewindowagent.h 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/core/corewindowagent_p.h 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/core/windowitemdelegate.h 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/quick/quickitemdelegate_p.h 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/quick/quickwindowagent.cpp 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/quick/quickwindowagent.h 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/quick/quickwindowagent_p.h 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/widgets/widgetitemdelegate_p.h 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/widgets/widgetwindowagent.cpp 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/widgets/widgetwindowagent.h 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/widgets/widgetwindowagent_p.h 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/core/contexts/abstractwindowcontext.cpp
@@ -2,7 +2,9 @@
namespace QWK {
    AbstractWindowContext::~AbstractWindowContext() = default;
    AbstractWindowContext::~AbstractWindowContext() {
        delete m_delegate;
    }
    void AbstractWindowContext::setupWindow(QWindow *window) {
        Q_ASSERT(window);
@@ -37,11 +39,12 @@
        } else {
            m_hitTestVisibleRects.removeAll(rect);
        }
        hitTestVisibleShapeDirty = true;
        return true;
    }
    bool AbstractWindowContext::setSystemButton(CoreWindowAgent::SystemButton button,
                                                     QObject *obj) {
                                                QObject *obj) {
        Q_ASSERT(obj);
        Q_ASSERT(button != CoreWindowAgent::Unknown);
        if (!obj || (button == CoreWindowAgent::Unknown)) {
@@ -72,4 +75,15 @@
        // ?
    }
    QRegion AbstractWindowContext::hitTestShape() const {
        if (hitTestVisibleShapeDirty) {
            hitTestVisibleShape = {};
            for (const auto &rect : m_hitTestVisibleRects) {
                hitTestVisibleShape += rect;
            }
            hitTestVisibleShapeDirty = false;
        }
        return hitTestVisibleShape;
    }
}
src/core/contexts/abstractwindowcontext_p.h
@@ -1,6 +1,8 @@
#ifndef ABSTRACTWINDOWCONTEXT_P_H
#define ABSTRACTWINDOWCONTEXT_P_H
#include <array>
#include <QtCore/QSet>
#include <QtGui/QWindow>
#include <QtGui/QPolygon>
@@ -12,12 +14,9 @@
    class QWK_CORE_EXPORT AbstractWindowContext : public QObject {
        Q_OBJECT
        Q_DISABLE_COPY(AbstractWindowContext)
    public:
        inline AbstractWindowContext(QWindow *window, WindowItemDelegatePtr delegate)
            : m_windowHandle(window), m_delegate(std::move(delegate))
        {
        inline AbstractWindowContext(QWindow *window, WindowItemDelegate *delegate)
            : m_windowHandle(window), m_delegate(delegate) {
        }
        ~AbstractWindowContext() override;
@@ -39,9 +38,11 @@
        void showSystemMenu(const QPoint &pos);
        QRegion hitTestShape() const;
    protected:
        QWindow *m_windowHandle;
        WindowItemDelegatePtr m_delegate;
        WindowItemDelegate *m_delegate;
        QSet<QObject *> m_hitTestVisibleItems;
        QList<QRect> m_hitTestVisibleRects;
@@ -49,8 +50,9 @@
        QObject *m_titleBar{};
        std::array<QObject *, CoreWindowAgent::NumSystemButton> m_systemButtons{};
        // Cached shape
        mutable bool hitTestVisibleShapeDirty{};
        mutable QPolygon hitTestVisibleShape;
        mutable QRegion hitTestVisibleShape;
    };
    inline QWindow *AbstractWindowContext::window() const {
@@ -69,8 +71,6 @@
    inline QObject *AbstractWindowContext::titleBar() const {
        return m_titleBar;
    }
    using WindowContextPtr = std::shared_ptr<AbstractWindowContext>;
}
src/core/contexts/qtwindowcontext.cpp
@@ -40,7 +40,7 @@
#endif
    }
    QtWindowContext::QtWindowContext(QWindow *window, WindowItemDelegatePtr delegate)
    QtWindowContext::QtWindowContext(QWindow *window, WindowItemDelegate *delegate)
        : AbstractWindowContext(window, delegate) {
    }
src/core/contexts/qtwindowcontext_p.h
@@ -7,10 +7,8 @@
    class QWK_CORE_EXPORT QtWindowContext : public AbstractWindowContext {
        Q_OBJECT
        Q_DISABLE_COPY(QtWindowContext)
    public:
        QtWindowContext(QWindow *window, WindowItemDelegatePtr delegate);
        QtWindowContext(QWindow *window, WindowItemDelegate *delegate);
        ~QtWindowContext();
    public:
src/core/contexts/win32windowcontext.cpp
@@ -32,8 +32,8 @@
        return ::CallWindowProcW(g_qtWindowProc, hWnd, message, wParam, lParam);
    }
    Win32WindowContext::Win32WindowContext(QWindow *window, WindowItemDelegatePtr delegate)
        : AbstractWindowContext(window, std::move(delegate)), windowId(0) {
    Win32WindowContext::Win32WindowContext(QWindow *window, WindowItemDelegate *delegate)
        : AbstractWindowContext(window, delegate), windowId(0) {
    }
    Win32WindowContext::~Win32WindowContext() {
@@ -70,6 +70,8 @@
        // TODO: Implement
        // ...
        Q_UNUSED(windowId)
        return false; // Not handled
    }
src/core/contexts/win32windowcontext_p.h
@@ -8,10 +8,8 @@
    class QWK_CORE_EXPORT Win32WindowContext : public AbstractWindowContext {
        Q_OBJECT
        Q_DISABLE_COPY(Win32WindowContext)
    public:
        Win32WindowContext(QWindow *window, WindowItemDelegatePtr delegate);
        Win32WindowContext(QWindow *window, WindowItemDelegate *delegate);
        ~Win32WindowContext() override;
    public:
src/core/corewindowagent.cpp
@@ -11,28 +11,31 @@
namespace QWK {
    CoreWindowAgentPrivate::CoreWindowAgentPrivate() : q_ptr(nullptr), eventHandler(nullptr) {
    CoreWindowAgentPrivate::CoreWindowAgentPrivate() : eventHandler(nullptr) {
    }
    CoreWindowAgentPrivate::~CoreWindowAgentPrivate() = default;
    CoreWindowAgentPrivate::~CoreWindowAgentPrivate() {
        delete eventHandler;
    }
    void CoreWindowAgentPrivate::init() {
    }
    bool CoreWindowAgentPrivate::setup(QWindow *window, const WindowItemDelegatePtr &delegate) {
    bool CoreWindowAgentPrivate::setup(QWindow *window, WindowItemDelegate *delegate) {
        Q_ASSERT(window);
        if (!window) {
            return false;
        }
        auto handler =
#ifdef Q_OS_WINDOWS
            std::make_shared<Win32WindowContext>(window, delegate)
            new Win32WindowContext(window, delegate)
#else
            std::make_shared<QtWindowContext>(window, delegate)
            new QtWindowContext(window, delegate)
#endif
            ;
        if (!handler->setup()) {
            delete handler;
            return false;
        }
        eventHandler = handler;
src/core/corewindowagent.h
@@ -11,9 +11,7 @@
    class QWK_CORE_EXPORT CoreWindowAgent : public QObject {
        Q_OBJECT
        Q_DISABLE_COPY(CoreWindowAgent)
        Q_DECLARE_PRIVATE(CoreWindowAgent)
    public:
        ~CoreWindowAgent() override;
src/core/corewindowagent_p.h
@@ -7,9 +7,7 @@
namespace QWK {
    class QWK_CORE_EXPORT CoreWindowAgentPrivate {
        Q_DISABLE_COPY(CoreWindowAgentPrivate)
        Q_DECLARE_PUBLIC(CoreWindowAgent)
    public:
        CoreWindowAgentPrivate();
        virtual ~CoreWindowAgentPrivate();
@@ -18,9 +16,11 @@
        CoreWindowAgent *q_ptr; // no need to initialize
        bool setup(QWindow *window, const WindowItemDelegatePtr &delegate);
        bool setup(QWindow *window, WindowItemDelegate *delegate);
        WindowContextPtr eventHandler;
        AbstractWindowContext *eventHandler;
        Q_DISABLE_COPY_MOVE(CoreWindowAgentPrivate)
    };
}
src/core/windowitemdelegate.h
@@ -1,6 +1,8 @@
#ifndef WINDOWITEMDELEGATE_H
#define WINDOWITEMDELEGATE_H
#include <memory>
#include <QtCore/QObject>
#include <QtGui/QWindow>
@@ -9,8 +11,6 @@
namespace QWK {
    class WindowItemDelegate {
        Q_DISABLE_COPY(WindowItemDelegate)
    public:
        WindowItemDelegate() = default;
        virtual ~WindowItemDelegate() = default;
@@ -20,9 +20,10 @@
        virtual bool isEnabled(QObject *obj) const = 0;
        virtual bool isVisible(QObject *obj) const = 0;
    };
    using WindowItemDelegatePtr = std::shared_ptr<WindowItemDelegate>;
    private:
        Q_DISABLE_COPY_MOVE(WindowItemDelegate)
    };
}
src/quick/quickitemdelegate_p.h
@@ -10,8 +10,6 @@
namespace QWK {
    class QWK_QUICK_EXPORT QuickItemDelegate : public WindowItemDelegate {
        Q_DISABLE_COPY(QuickItemDelegate)
    public:
        QuickItemDelegate();
        ~QuickItemDelegate() override;
src/quick/quickwindowagent.cpp
@@ -34,7 +34,7 @@
            return false;
        }
        if (!d->setup(window, std::make_shared<QuickItemDelegate>())) {
        if (!d->setup(window, new QuickItemDelegate())) {
            return true;
        }
        d->host = window;
src/quick/quickwindowagent.h
@@ -13,9 +13,7 @@
    class QWK_QUICK_EXPORT QuickWindowAgent : public CoreWindowAgent {
        Q_OBJECT
        Q_DISABLE_COPY(QuickWindowAgent)
        Q_DECLARE_PRIVATE(QuickWindowAgent)
    public:
        explicit QuickWindowAgent(QObject *parent = nullptr);
        ~QuickWindowAgent() override;
src/quick/quickwindowagent_p.h
@@ -7,9 +7,7 @@
namespace QWK {
    class QuickWindowAgentPrivate : public CoreWindowAgentPrivate {
        Q_DISABLE_COPY(QuickWindowAgentPrivate)
        Q_DECLARE_PUBLIC(QuickWindowAgent)
    public:
        QuickWindowAgentPrivate();
        ~QuickWindowAgentPrivate() override;
src/widgets/widgetitemdelegate_p.h
@@ -10,8 +10,6 @@
namespace QWK {
    class QWK_WIDGETS_EXPORT WidgetItemDelegate : public WindowItemDelegate {
        Q_DISABLE_COPY(WidgetItemDelegate)
    public:
        WidgetItemDelegate();
        ~WidgetItemDelegate() override;
src/widgets/widgetwindowagent.cpp
@@ -33,7 +33,7 @@
        }
        std::ignore = w->winId(); // Make sure the window handle is created
        if (!d->setup(w->windowHandle(), std::make_shared<WidgetItemDelegate>())) {
        if (!d->setup(w->windowHandle(), new WidgetItemDelegate())) {
            return false;
        }
        d->host = w;
src/widgets/widgetwindowagent.h
@@ -12,9 +12,7 @@
    class QWK_WIDGETS_EXPORT WidgetWindowAgent : public CoreWindowAgent {
        Q_OBJECT
        Q_DISABLE_COPY(WidgetWindowAgent)
        Q_DECLARE_PRIVATE(WidgetWindowAgent)
    public:
        explicit WidgetWindowAgent(QObject *parent = nullptr);
        ~WidgetWindowAgent() override;
src/widgets/widgetwindowagent_p.h
@@ -7,9 +7,7 @@
namespace QWK {
    class WidgetWindowAgentPrivate : public CoreWindowAgentPrivate {
        Q_DISABLE_COPY(WidgetWindowAgentPrivate)
        Q_DECLARE_PUBLIC(WidgetWindowAgent)
    public:
        WidgetWindowAgentPrivate();
        ~WidgetWindowAgentPrivate();