From 286811c9dfa6fdb85fd82f0f35c0e7f00cdeb707 Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Sat, 7 May 2022 18:02:44 +0800 Subject: [PATCH] expose private headers, someone may need Signed-off-by: Yuhang Zhao <2546789017@qq.com> --- .../Core/private/framelesswindowsmanager_p.h | 66 +++++++++++++ .../Quick/FramelessQuickWindow | 1 - .../Quick/private/framelessquickhelper_p.h | 81 +++++++++++++++ .../framelessquickwindow_p.h} | 5 +- .../Quick/private/framelessquickwindow_p_p.h | 85 ++++++++++++++++ .../private/quickstandardclosebutton_p.h | 69 +++++++++++++ .../private/quickstandardmaximizebutton_p.h | 77 +++++++++++++++ .../private/quickstandardminimizebutton_p.h | 69 +++++++++++++ .../Quick/private/quickstandardtitlebar_p.h | 98 ++++++++++++++++++ .../Widgets/private/framelessmainwindow_p.h | 63 ++++++++++++ .../Widgets/private/framelesswidget_p.h | 63 ++++++++++++ .../private/framelesswidgetshelper_p.h | 78 +++++++++++++++ .../Widgets/private/standardsystembutton_p.h | 93 +++++++++++++++++ .../Widgets/private/standardtitlebar_p.h | 72 ++++++++++++++ .../Widgets/private/widgetssharedhelper_p.h | 40 +++++++- src/core/CMakeLists.txt | 3 +- src/core/framelesshelper_qt.h | 24 ----- src/core/framelesshelper_win.h | 24 ----- src/core/framelesshelper_windows.h | 24 ----- src/core/framelesshelpercore_global.h | 24 ----- src/core/framelesswindowsmanager.h | 24 ----- src/core/framelesswindowsmanager_p.h | 67 +------------ src/core/utils.cpp | 26 +++-- src/core/utils.h | 24 ----- src/quick/CMakeLists.txt | 15 +-- src/quick/framelesshelperquick_global.h | 24 ----- src/quick/framelessquickhelper.cpp | 5 +- src/quick/framelessquickhelper.h | 24 ----- src/quick/framelessquickhelper_p.h | 82 +-------------- src/quick/framelessquickmodule.cpp | 2 +- src/quick/framelessquickmodule.h | 24 ----- src/quick/framelessquickutils.h | 24 ----- src/quick/framelessquickwindow.cpp | 23 +++-- src/quick/framelessquickwindow_p.h | 85 +--------------- src/quick/framelessquickwindow_p_p.h | 1 + src/quick/quickstandardclosebutton_p.h | 70 +------------ src/quick/quickstandardmaximizebutton_p.h | 78 +-------------- src/quick/quickstandardminimizebutton_p.h | 70 +------------ src/quick/quickstandardtitlebar_p.h | 99 +------------------ src/widgets/CMakeLists.txt | 13 +-- src/widgets/framelesshelperwidgets_global.h | 24 ----- src/widgets/framelessmainwindow.h | 24 ----- src/widgets/framelessmainwindow_p.h | 64 +----------- src/widgets/framelesswidget.h | 24 ----- src/widgets/framelesswidget_p.h | 64 +----------- src/widgets/framelesswidgetshelper.cpp | 2 +- src/widgets/framelesswidgetshelper.h | 24 ----- src/widgets/framelesswidgetshelper_p.h | 79 +-------------- src/widgets/standardsystembutton.cpp | 1 + src/widgets/standardsystembutton.h | 24 ----- src/widgets/standardsystembutton_p.h | 94 +----------------- src/widgets/standardtitlebar.cpp | 25 ++--- src/widgets/standardtitlebar.h | 24 ----- src/widgets/standardtitlebar_p.h | 73 +------------- src/widgets/widgetssharedhelper_p.h | 64 +----------- 55 files changed, 1040 insertions(+), 1409 deletions(-) create mode 100644 include/FramelessHelper/Core/private/framelesswindowsmanager_p.h delete mode 100644 include/FramelessHelper/Quick/FramelessQuickWindow create mode 100644 include/FramelessHelper/Quick/private/framelessquickhelper_p.h rename include/FramelessHelper/Quick/{framelessquickwindow.h => private/framelessquickwindow_p.h} (93%) create mode 100644 include/FramelessHelper/Quick/private/framelessquickwindow_p_p.h create mode 100644 include/FramelessHelper/Quick/private/quickstandardclosebutton_p.h create mode 100644 include/FramelessHelper/Quick/private/quickstandardmaximizebutton_p.h create mode 100644 include/FramelessHelper/Quick/private/quickstandardminimizebutton_p.h create mode 100644 include/FramelessHelper/Quick/private/quickstandardtitlebar_p.h create mode 100644 include/FramelessHelper/Widgets/private/framelessmainwindow_p.h create mode 100644 include/FramelessHelper/Widgets/private/framelesswidget_p.h create mode 100644 include/FramelessHelper/Widgets/private/framelesswidgetshelper_p.h create mode 100644 include/FramelessHelper/Widgets/private/standardsystembutton_p.h create mode 100644 include/FramelessHelper/Widgets/private/standardtitlebar_p.h rename src/quick/framelessquickwindow.h => include/FramelessHelper/Widgets/private/widgetssharedhelper_p.h (57%) create mode 100644 src/quick/framelessquickwindow_p_p.h diff --git a/include/FramelessHelper/Core/private/framelesswindowsmanager_p.h b/include/FramelessHelper/Core/private/framelesswindowsmanager_p.h new file mode 100644 index 0000000..93a4e7b --- /dev/null +++ b/include/FramelessHelper/Core/private/framelesswindowsmanager_p.h @@ -0,0 +1,66 @@ +/* + * MIT License + * + * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +#include "framelesshelpercore_global.h" +#include + +FRAMELESSHELPER_BEGIN_NAMESPACE + +class FramelessWindowsManager; + +class FRAMELESSHELPER_CORE_API FramelessWindowsManagerPrivate : public QObject +{ + Q_OBJECT + Q_DECLARE_PUBLIC(FramelessWindowsManager) + Q_DISABLE_COPY_MOVE(FramelessWindowsManagerPrivate) + +public: + explicit FramelessWindowsManagerPrivate(FramelessWindowsManager *q); + ~FramelessWindowsManagerPrivate() override; + + Q_NODISCARD static FramelessWindowsManagerPrivate *get(FramelessWindowsManager *pub); + Q_NODISCARD static const FramelessWindowsManagerPrivate *get(const FramelessWindowsManager *pub); + + Q_NODISCARD static bool usePureQtImplementation(); + Q_NODISCARD Global::SystemTheme systemTheme() const; + Q_NODISCARD QColor systemAccentColor() const; + + static void addWindow(const Global::SystemParameters ¶ms); + Q_INVOKABLE void notifySystemThemeHasChangedOrNot(); + +private: + void initialize(); + +private: + FramelessWindowsManager *q_ptr = nullptr; + Global::SystemTheme m_systemTheme = Global::SystemTheme::Unknown; + QColor m_accentColor = {}; +#ifdef Q_OS_WINDOWS + Global::DwmColorizationArea m_colorizationArea = Global::DwmColorizationArea::None_; +#endif +}; + +FRAMELESSHELPER_END_NAMESPACE diff --git a/include/FramelessHelper/Quick/FramelessQuickWindow b/include/FramelessHelper/Quick/FramelessQuickWindow deleted file mode 100644 index 06e08be..0000000 --- a/include/FramelessHelper/Quick/FramelessQuickWindow +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/include/FramelessHelper/Quick/private/framelessquickhelper_p.h b/include/FramelessHelper/Quick/private/framelessquickhelper_p.h new file mode 100644 index 0000000..83a2d2f --- /dev/null +++ b/include/FramelessHelper/Quick/private/framelessquickhelper_p.h @@ -0,0 +1,81 @@ +/* + * MIT License + * + * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +#include "framelesshelperquick_global.h" +#include + +QT_BEGIN_NAMESPACE +class QQuickItem; +QT_END_NAMESPACE + +FRAMELESSHELPER_BEGIN_NAMESPACE + +struct QuickHelperData; +class FramelessQuickHelper; + +class FRAMELESSHELPER_QUICK_API FramelessQuickHelperPrivate : public QObject +{ + Q_OBJECT + Q_DECLARE_PUBLIC(FramelessQuickHelper) + Q_DISABLE_COPY_MOVE(FramelessQuickHelperPrivate) + +public: + explicit FramelessQuickHelperPrivate(FramelessQuickHelper *q); + ~FramelessQuickHelperPrivate() override; + + Q_NODISCARD static FramelessQuickHelperPrivate *get(FramelessQuickHelper *pub); + Q_NODISCARD static const FramelessQuickHelperPrivate *get(const FramelessQuickHelper *pub); + + Q_NODISCARD QQuickItem *getTitleBarItem() const; + void setTitleBarItem(QQuickItem *value); + + void attachToWindow(); + void setSystemButton(QQuickItem *item, const QuickGlobal::SystemButtonType buttonType); + void setHitTestVisible(QQuickItem *item); + void showSystemMenu(const QPoint &pos); + void windowStartSystemMove2(const QPoint &pos); + void windowStartSystemResize2(const Qt::Edges edges, const QPoint &pos); + + void moveWindowToDesktopCenter(); + void bringWindowToFront(); + + Q_NODISCARD bool isWindowFixedSize() const; + void setWindowFixedSize(const bool value); + +private: + Q_NODISCARD QRect mapItemGeometryToScene(const QQuickItem * const item) const; + Q_NODISCARD bool isInSystemButtons(const QPoint &pos, QuickGlobal::SystemButtonType *button) const; + Q_NODISCARD bool isInTitleBarDraggableArea(const QPoint &pos) const; + Q_NODISCARD bool shouldIgnoreMouseEvents(const QPoint &pos) const; + void setSystemButtonState(const QuickGlobal::SystemButtonType button, const QuickGlobal::ButtonState state); + Q_NODISCARD QuickHelperData getWindowData() const; + Q_NODISCARD QuickHelperData *getWindowDataMutable() const; + +private: + FramelessQuickHelper *q_ptr = nullptr; +}; + +FRAMELESSHELPER_END_NAMESPACE diff --git a/include/FramelessHelper/Quick/framelessquickwindow.h b/include/FramelessHelper/Quick/private/framelessquickwindow_p.h similarity index 93% rename from include/FramelessHelper/Quick/framelessquickwindow.h rename to include/FramelessHelper/Quick/private/framelessquickwindow_p.h index d3a383b..028b47e 100644 --- a/include/FramelessHelper/Quick/framelessquickwindow.h +++ b/include/FramelessHelper/Quick/private/framelessquickwindow_p.h @@ -28,7 +28,7 @@ #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) #include -Q_MOC_INCLUDE("framelessquickwindow_p.h") +Q_MOC_INCLUDE("framelessquickwindow_p_p.h") FRAMELESSHELPER_BEGIN_NAMESPACE @@ -45,6 +45,7 @@ class FRAMELESSHELPER_QUICK_API FramelessQuickWindow : public QQuickWindow Q_PROPERTY(bool hidden READ isHidden NOTIFY hiddenChanged FINAL) Q_PROPERTY(bool normal READ isNormal NOTIFY normalChanged FINAL) Q_PROPERTY(bool minimized READ isMinimized NOTIFY minimizedChanged FINAL) + Q_PROPERTY(bool maximized READ isMaximized NOTIFY maximizedChanged FINAL) Q_PROPERTY(bool zoomed READ isZoomed NOTIFY zoomedChanged FINAL) Q_PROPERTY(bool fullScreen READ isFullScreen NOTIFY fullScreenChanged FINAL) Q_PRIVATE_PROPERTY(FramelessQuickWindow::d_func(), QQuickAnchorLine topBorderBottom READ getTopBorderBottom CONSTANT FINAL) @@ -56,6 +57,7 @@ public: Q_NODISCARD bool isHidden() const; Q_NODISCARD bool isNormal() const; Q_NODISCARD bool isMinimized() const; + Q_NODISCARD bool isMaximized() const; Q_NODISCARD bool isZoomed() const; Q_NODISCARD bool isFullScreen() const; @@ -68,6 +70,7 @@ Q_SIGNALS: void hiddenChanged(); void normalChanged(); void minimizedChanged(); + void maximizedChanged(); void zoomedChanged(); void fullScreenChanged(); diff --git a/include/FramelessHelper/Quick/private/framelessquickwindow_p_p.h b/include/FramelessHelper/Quick/private/framelessquickwindow_p_p.h new file mode 100644 index 0000000..7b54cb2 --- /dev/null +++ b/include/FramelessHelper/Quick/private/framelessquickwindow_p_p.h @@ -0,0 +1,85 @@ +/* + * MIT License + * + * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +#include "framelesshelperquick_global.h" +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) +#include +#include +#include + +QT_BEGIN_NAMESPACE +class QQuickRectangle; +QT_END_NAMESPACE + +FRAMELESSHELPER_BEGIN_NAMESPACE + +class FramelessQuickWindow; + +class FRAMELESSHELPER_QUICK_API FramelessQuickWindowPrivate : public QObject +{ + Q_OBJECT + Q_DECLARE_PUBLIC(FramelessQuickWindow) + Q_DISABLE_COPY_MOVE(FramelessQuickWindowPrivate) + +public: + explicit FramelessQuickWindowPrivate(FramelessQuickWindow *q); + ~FramelessQuickWindowPrivate() override; + + Q_NODISCARD static FramelessQuickWindowPrivate *get(FramelessQuickWindow *pub); + Q_NODISCARD static const FramelessQuickWindowPrivate *get(const FramelessQuickWindow *pub); + + Q_INVOKABLE Q_NODISCARD bool isHidden() const; + Q_INVOKABLE Q_NODISCARD bool isNormal() const; + Q_INVOKABLE Q_NODISCARD bool isMinimized() const; + Q_INVOKABLE Q_NODISCARD bool isMaximized() const; + Q_INVOKABLE Q_NODISCARD bool isZoomed() const; + Q_INVOKABLE Q_NODISCARD bool isFullScreen() const; + + Q_INVOKABLE Q_NODISCARD QColor getFrameBorderColor() const; + Q_INVOKABLE Q_NODISCARD QQuickAnchorLine getTopBorderBottom() const; + +public Q_SLOTS: + void showMinimized2(); + void toggleMaximized(); + void toggleFullScreen(); + +private: + void initialize(); + Q_NODISCARD bool shouldDrawFrameBorder() const; + +private Q_SLOTS: + void updateTopBorderColor(); + void updateTopBorderHeight(); + +private: + FramelessQuickWindow *q_ptr = nullptr; + QScopedPointer m_topBorderRectangle; + QScopedPointer m_topBorderAnchors; + QQuickWindow::Visibility m_savedVisibility = QQuickWindow::Windowed; +}; + +FRAMELESSHELPER_END_NAMESPACE +#endif diff --git a/include/FramelessHelper/Quick/private/quickstandardclosebutton_p.h b/include/FramelessHelper/Quick/private/quickstandardclosebutton_p.h new file mode 100644 index 0000000..f315578 --- /dev/null +++ b/include/FramelessHelper/Quick/private/quickstandardclosebutton_p.h @@ -0,0 +1,69 @@ +/* + * MIT License + * + * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +#include "framelesshelperquick_global.h" +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) +#include +#include + +QT_BEGIN_NAMESPACE +class QQuickImage; +class QQuickRectangle; +QT_END_NAMESPACE + +FRAMELESSHELPER_BEGIN_NAMESPACE + +class FRAMELESSHELPER_QUICK_API QuickStandardCloseButton : public QQuickButton +{ + Q_OBJECT +#ifdef QML_NAMED_ELEMENT + QML_NAMED_ELEMENT(StandardCloseButton) +#endif + Q_DISABLE_COPY_MOVE(QuickStandardCloseButton) + +public: + explicit QuickStandardCloseButton(QQuickItem *parent = nullptr); + ~QuickStandardCloseButton() override; + +private Q_SLOTS: + void updateForeground(); + void updateBackground(); + void updateToolTip(); + +private: + void initialize(); + +private: + QScopedPointer m_contentItem; + QScopedPointer m_image; + QScopedPointer m_backgroundItem; + QPointer m_tooltip = nullptr; +}; + +FRAMELESSHELPER_END_NAMESPACE + +QML_DECLARE_TYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickStandardCloseButton)) +#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) diff --git a/include/FramelessHelper/Quick/private/quickstandardmaximizebutton_p.h b/include/FramelessHelper/Quick/private/quickstandardmaximizebutton_p.h new file mode 100644 index 0000000..aee2abb --- /dev/null +++ b/include/FramelessHelper/Quick/private/quickstandardmaximizebutton_p.h @@ -0,0 +1,77 @@ +/* + * MIT License + * + * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +#include "framelesshelperquick_global.h" +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) +#include +#include + +QT_BEGIN_NAMESPACE +class QQuickImage; +class QQuickRectangle; +QT_END_NAMESPACE + +FRAMELESSHELPER_BEGIN_NAMESPACE + +class FRAMELESSHELPER_QUICK_API QuickStandardMaximizeButton : public QQuickButton +{ + Q_OBJECT +#ifdef QML_NAMED_ELEMENT + QML_NAMED_ELEMENT(StandardMaximizeButton) +#endif + Q_DISABLE_COPY_MOVE(QuickStandardMaximizeButton) + Q_PROPERTY(bool maximized READ isMaximized WRITE setMaximized NOTIFY maximizedChanged FINAL) + +public: + explicit QuickStandardMaximizeButton(QQuickItem *parent = nullptr); + ~QuickStandardMaximizeButton() override; + + Q_NODISCARD bool isMaximized() const; + void setMaximized(const bool max); + +private Q_SLOTS: + void updateForeground(); + void updateBackground(); + void updateToolTip(); + +Q_SIGNALS: + void maximizedChanged(); + +private: + void initialize(); + +private: + bool m_max = false; + QScopedPointer m_contentItem; + QScopedPointer m_image; + QScopedPointer m_backgroundItem; + QPointer m_tooltip = nullptr; +}; + +FRAMELESSHELPER_END_NAMESPACE + +QML_DECLARE_TYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickStandardMaximizeButton)) +#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) diff --git a/include/FramelessHelper/Quick/private/quickstandardminimizebutton_p.h b/include/FramelessHelper/Quick/private/quickstandardminimizebutton_p.h new file mode 100644 index 0000000..49ea059 --- /dev/null +++ b/include/FramelessHelper/Quick/private/quickstandardminimizebutton_p.h @@ -0,0 +1,69 @@ +/* + * MIT License + * + * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +#include "framelesshelperquick_global.h" +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) +#include +#include + +QT_BEGIN_NAMESPACE +class QQuickImage; +class QQuickRectangle; +QT_END_NAMESPACE + +FRAMELESSHELPER_BEGIN_NAMESPACE + +class FRAMELESSHELPER_QUICK_API QuickStandardMinimizeButton : public QQuickButton +{ + Q_OBJECT +#ifdef QML_NAMED_ELEMENT + QML_NAMED_ELEMENT(StandardMinimizeButton) +#endif + Q_DISABLE_COPY_MOVE(QuickStandardMinimizeButton) + +public: + explicit QuickStandardMinimizeButton(QQuickItem *parent = nullptr); + ~QuickStandardMinimizeButton() override; + +private Q_SLOTS: + void updateForeground(); + void updateBackground(); + void updateToolTip(); + +private: + void initialize(); + +private: + QScopedPointer m_contentItem; + QScopedPointer m_image; + QScopedPointer m_backgroundItem; + QPointer m_tooltip = nullptr; +}; + +FRAMELESSHELPER_END_NAMESPACE + +QML_DECLARE_TYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickStandardMinimizeButton)) +#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) diff --git a/include/FramelessHelper/Quick/private/quickstandardtitlebar_p.h b/include/FramelessHelper/Quick/private/quickstandardtitlebar_p.h new file mode 100644 index 0000000..a038785 --- /dev/null +++ b/include/FramelessHelper/Quick/private/quickstandardtitlebar_p.h @@ -0,0 +1,98 @@ +/* + * MIT License + * + * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +#include "framelesshelperquick_global.h" +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) +#include + +QT_BEGIN_NAMESPACE +class QQuickLabel; +class QQuickRow; +QT_END_NAMESPACE + +FRAMELESSHELPER_BEGIN_NAMESPACE + +class QuickStandardMinimizeButton; +class QuickStandardMaximizeButton; +class QuickStandardCloseButton; + +class FRAMELESSHELPER_QUICK_API QuickStandardTitleBar : public QQuickRectangle +{ + Q_OBJECT +#ifdef QML_NAMED_ELEMENT + QML_NAMED_ELEMENT(StandardTitleBar) +#endif + Q_DISABLE_COPY_MOVE(QuickStandardTitleBar) + Q_PROPERTY(Qt::Alignment titleLabelAlignment READ titleLabelAlignment WRITE setTitleLabelAlignment NOTIFY titleLabelAlignmentChanged FINAL) + Q_PROPERTY(QuickStandardMinimizeButton* minimizeButton READ minimizeButton CONSTANT FINAL) + Q_PROPERTY(QuickStandardMaximizeButton* maximizeButton READ maximizeButton CONSTANT FINAL) + Q_PROPERTY(QuickStandardCloseButton* closeButton READ closeButton CONSTANT FINAL) + +public: + explicit QuickStandardTitleBar(QQuickItem *parent = nullptr); + ~QuickStandardTitleBar() override; + + Q_NODISCARD Qt::Alignment titleLabelAlignment() const; + void setTitleLabelAlignment(const Qt::Alignment value); + + Q_NODISCARD QuickStandardMinimizeButton *minimizeButton() const; + Q_NODISCARD QuickStandardMaximizeButton *maximizeButton() const; + Q_NODISCARD QuickStandardCloseButton *closeButton() const; + +protected: + void itemChange(const ItemChange change, const ItemChangeData &value) override; + +private Q_SLOTS: + void updateMaximizeButton(); + void updateTitleLabelText(); + void updateTitleBarColor(); + void clickMinimizeButton(); + void clickMaximizeButton(); + void clickCloseButton(); + +Q_SIGNALS: + void titleLabelAlignmentChanged(); + +private: + void initialize(); + void updateAll(); + +private: + Qt::Alignment m_labelAlignment = {}; + QScopedPointer m_label; + QScopedPointer m_row; + QScopedPointer m_minBtn; + QScopedPointer m_maxBtn; + QScopedPointer m_closeBtn; + QMetaObject::Connection m_windowStateChangeConnection = {}; + QMetaObject::Connection m_windowActiveChangeConnection = {}; + QMetaObject::Connection m_windowTitleChangeConnection = {}; +}; + +FRAMELESSHELPER_END_NAMESPACE + +QML_DECLARE_TYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickStandardTitleBar)) +#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) diff --git a/include/FramelessHelper/Widgets/private/framelessmainwindow_p.h b/include/FramelessHelper/Widgets/private/framelessmainwindow_p.h new file mode 100644 index 0000000..55b3284 --- /dev/null +++ b/include/FramelessHelper/Widgets/private/framelessmainwindow_p.h @@ -0,0 +1,63 @@ +/* + * MIT License + * + * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +#include "framelesshelperwidgets_global.h" +#include + +FRAMELESSHELPER_BEGIN_NAMESPACE + +class FramelessMainWindow; +class WidgetsSharedHelper; + +class FRAMELESSHELPER_WIDGETS_API FramelessMainWindowPrivate : public QObject +{ + Q_OBJECT + Q_DECLARE_PUBLIC(FramelessMainWindow) + Q_DISABLE_COPY_MOVE(FramelessMainWindowPrivate) + +public: + explicit FramelessMainWindowPrivate(FramelessMainWindow *q); + ~FramelessMainWindowPrivate() override; + + Q_NODISCARD static FramelessMainWindowPrivate *get(FramelessMainWindow *pub); + Q_NODISCARD static const FramelessMainWindowPrivate *get(const FramelessMainWindow *pub); + + Q_NODISCARD bool isNormal() const; + Q_NODISCARD bool isZoomed() const; + + void toggleMaximized(); + void toggleFullScreen(); + +private: + void initialize(); + +private: + FramelessMainWindow *q_ptr = nullptr; + Qt::WindowState m_savedWindowState = Qt::WindowNoState; + QScopedPointer m_helper; +}; + +FRAMELESSHELPER_END_NAMESPACE diff --git a/include/FramelessHelper/Widgets/private/framelesswidget_p.h b/include/FramelessHelper/Widgets/private/framelesswidget_p.h new file mode 100644 index 0000000..eea7791 --- /dev/null +++ b/include/FramelessHelper/Widgets/private/framelesswidget_p.h @@ -0,0 +1,63 @@ +/* + * MIT License + * + * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +#include "framelesshelperwidgets_global.h" +#include + +FRAMELESSHELPER_BEGIN_NAMESPACE + +class FramelessWidget; +class WidgetsSharedHelper; + +class FRAMELESSHELPER_WIDGETS_API FramelessWidgetPrivate : public QObject +{ + Q_OBJECT + Q_DECLARE_PUBLIC(FramelessWidget) + Q_DISABLE_COPY_MOVE(FramelessWidgetPrivate) + +public: + explicit FramelessWidgetPrivate(FramelessWidget *q); + ~FramelessWidgetPrivate() override; + + Q_NODISCARD static FramelessWidgetPrivate *get(FramelessWidget *pub); + Q_NODISCARD static const FramelessWidgetPrivate *get(const FramelessWidget *pub); + + Q_NODISCARD bool isNormal() const; + Q_NODISCARD bool isZoomed() const; + + void toggleMaximized(); + void toggleFullScreen(); + +private: + void initialize(); + +private: + FramelessWidget *q_ptr = nullptr; + Qt::WindowState m_savedWindowState = Qt::WindowNoState; + QScopedPointer m_helper; +}; + +FRAMELESSHELPER_END_NAMESPACE diff --git a/include/FramelessHelper/Widgets/private/framelesswidgetshelper_p.h b/include/FramelessHelper/Widgets/private/framelesswidgetshelper_p.h new file mode 100644 index 0000000..b811f28 --- /dev/null +++ b/include/FramelessHelper/Widgets/private/framelesswidgetshelper_p.h @@ -0,0 +1,78 @@ +/* + * MIT License + * + * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +#include "framelesshelperwidgets_global.h" +#include + +FRAMELESSHELPER_BEGIN_NAMESPACE + +struct WidgetsHelperData; +class FramelessWidgetsHelper; + +class FRAMELESSHELPER_WIDGETS_API FramelessWidgetsHelperPrivate : public QObject +{ + Q_OBJECT + Q_DECLARE_PUBLIC(FramelessWidgetsHelper) + Q_DISABLE_COPY_MOVE(FramelessWidgetsHelperPrivate) + +public: + explicit FramelessWidgetsHelperPrivate(FramelessWidgetsHelper *q); + ~FramelessWidgetsHelperPrivate() override; + + Q_NODISCARD static FramelessWidgetsHelperPrivate *get(FramelessWidgetsHelper *pub); + Q_NODISCARD static const FramelessWidgetsHelperPrivate *get(const FramelessWidgetsHelper *pub); + + Q_NODISCARD QWidget *getTitleBarWidget() const; + void setTitleBarWidget(QWidget *widget); + + void attachToWindow(); + void setSystemButton(QWidget *widget, const Global::SystemButtonType buttonType); + void setHitTestVisible(QWidget *widget); + void showSystemMenu(const QPoint &pos); + void windowStartSystemMove2(const QPoint &pos); + void windowStartSystemResize2(const Qt::Edges edges, const QPoint &pos); + + void moveWindowToDesktopCenter(); + void bringWindowToFront(); + + Q_NODISCARD bool isWindowFixedSize() const; + void setWindowFixedSize(const bool value); + +private: + Q_NODISCARD QRect mapWidgetGeometryToScene(const QWidget * const widget) const; + Q_NODISCARD bool isInSystemButtons(const QPoint &pos, Global::SystemButtonType *button) const; + Q_NODISCARD bool isInTitleBarDraggableArea(const QPoint &pos) const; + Q_NODISCARD bool shouldIgnoreMouseEvents(const QPoint &pos) const; + void setSystemButtonState(const Global::SystemButtonType button, const Global::ButtonState state); + Q_NODISCARD QWidget *getWindow() const; + Q_NODISCARD WidgetsHelperData getWindowData() const; + Q_NODISCARD WidgetsHelperData *getWindowDataMutable() const; + +private: + FramelessWidgetsHelper *q_ptr = nullptr; +}; + +FRAMELESSHELPER_END_NAMESPACE diff --git a/include/FramelessHelper/Widgets/private/standardsystembutton_p.h b/include/FramelessHelper/Widgets/private/standardsystembutton_p.h new file mode 100644 index 0000000..971c187 --- /dev/null +++ b/include/FramelessHelper/Widgets/private/standardsystembutton_p.h @@ -0,0 +1,93 @@ +/* + * MIT License + * + * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +#include +#include +#include "framelesshelperwidgets_global.h" + +QT_BEGIN_NAMESPACE +class QEnterEvent; +class QPaintEvent; +QT_END_NAMESPACE + +FRAMELESSHELPER_BEGIN_NAMESPACE + +class StandardSystemButton; + +class FRAMELESSHELPER_WIDGETS_API StandardSystemButtonPrivate : public QObject +{ + Q_OBJECT + Q_DECLARE_PUBLIC(StandardSystemButton) + Q_DISABLE_COPY_MOVE(StandardSystemButtonPrivate) + +public: + explicit StandardSystemButtonPrivate(StandardSystemButton *q); + ~StandardSystemButtonPrivate() override; + + Q_NODISCARD static StandardSystemButtonPrivate *get(StandardSystemButton *pub); + Q_NODISCARD static const StandardSystemButtonPrivate *get(const StandardSystemButton *pub); + + void refreshButtonTheme(const bool force); + + Q_NODISCARD Global::SystemButtonType getButtonType() const; + void setButtonType(const Global::SystemButtonType type); + + void setIcon(const QIcon &value, const bool reverse); + void setPixmap(const QPixmap &value, const bool reverse); + void setImage(const QImage &value, const bool reverse); + + Q_NODISCARD QSize getRecommendedButtonSize() const; + + Q_NODISCARD bool isHovered() const; + Q_NODISCARD bool isPressed() const; + Q_NODISCARD QColor getHoverColor() const; + Q_NODISCARD QColor getPressColor() const; + + void setHovered(const bool value); + void setPressed(const bool value); + void setHoverColor(const QColor &value); + void setPressColor(const QColor &value); + + void enterEventHandler(QT_ENTER_EVENT_TYPE *event); + void leaveEventHandler(QEvent *event); + void paintEventHandler(QPaintEvent *event); + +private: + void initialize(); + +private: + StandardSystemButton *q_ptr = nullptr; + Global::SystemTheme m_buttonTheme = Global::SystemTheme::Unknown; + Global::SystemButtonType m_buttonType = Global::SystemButtonType::Unknown; + QPixmap m_icon = {}; + QPixmap m_reversedIcon = {}; + QColor m_hoverColor = {}; + QColor m_pressColor = {}; + bool m_hovered = false; + bool m_pressed = false; +}; + +FRAMELESSHELPER_END_NAMESPACE diff --git a/include/FramelessHelper/Widgets/private/standardtitlebar_p.h b/include/FramelessHelper/Widgets/private/standardtitlebar_p.h new file mode 100644 index 0000000..7088947 --- /dev/null +++ b/include/FramelessHelper/Widgets/private/standardtitlebar_p.h @@ -0,0 +1,72 @@ +/* + * MIT License + * + * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +#include "framelesshelperwidgets_global.h" +#include +#include + +QT_BEGIN_NAMESPACE +class QLabel; +QT_END_NAMESPACE + +FRAMELESSHELPER_BEGIN_NAMESPACE + +class StandardTitleBar; +class StandardSystemButton; + +class FRAMELESSHELPER_WIDGETS_API StandardTitleBarPrivate : public QObject +{ + Q_OBJECT + Q_DECLARE_PUBLIC(StandardTitleBar) + Q_DISABLE_COPY_MOVE(StandardTitleBarPrivate) + +public: + explicit StandardTitleBarPrivate(StandardTitleBar *q); + ~StandardTitleBarPrivate() override; + + Q_NODISCARD static StandardTitleBarPrivate *get(StandardTitleBar *pub); + Q_NODISCARD static const StandardTitleBarPrivate *get(const StandardTitleBar *pub); + +public Q_SLOTS: + void updateMaximizeButton(); + void updateTitleBarStyleSheet(); + +protected: + Q_NODISCARD bool eventFilter(QObject *object, QEvent *event) override; + +private: + void initialize(); + +private: + StandardTitleBar *q_ptr = nullptr; + QScopedPointer m_windowTitleLabel; + QScopedPointer m_minimizeButton; + QScopedPointer m_maximizeButton; + QScopedPointer m_closeButton; + QPointer m_window = nullptr; +}; + +FRAMELESSHELPER_END_NAMESPACE diff --git a/src/quick/framelessquickwindow.h b/include/FramelessHelper/Widgets/private/widgetssharedhelper_p.h similarity index 57% rename from src/quick/framelessquickwindow.h rename to include/FramelessHelper/Widgets/private/widgetssharedhelper_p.h index ecd96bd..7f24955 100644 --- a/src/quick/framelessquickwindow.h +++ b/include/FramelessHelper/Widgets/private/widgetssharedhelper_p.h @@ -22,4 +22,42 @@ * SOFTWARE. */ -#include "../../include/FramelessHelper/Quick/framelessquickwindow.h" +#pragma once + +#include "framelesshelperwidgets_global.h" +#include +#include + +QT_BEGIN_NAMESPACE +class QPaintEvent; +QT_END_NAMESPACE + +FRAMELESSHELPER_BEGIN_NAMESPACE + +class FRAMELESSHELPER_WIDGETS_API WidgetsSharedHelper : public QObject +{ + Q_OBJECT + Q_DISABLE_COPY_MOVE(WidgetsSharedHelper) + +public: + explicit WidgetsSharedHelper(QObject *parent = nullptr); + ~WidgetsSharedHelper() override; + + void setup(QWidget *widget); + +protected: + Q_NODISCARD bool eventFilter(QObject *object, QEvent *event) override; + +private Q_SLOTS: + void updateContentsMargins(); + +private: + void changeEventHandler(QEvent *event); + void paintEventHandler(QPaintEvent *event); + Q_NODISCARD bool shouldDrawFrameBorder() const; + +private: + QPointer m_targetWidget = nullptr; +}; + +FRAMELESSHELPER_END_NAMESPACE diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 14e84b2..9348ad7 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -37,10 +37,10 @@ set(SOURCES ${INCLUDE_PREFIX}/framelesshelper_qt.h ${INCLUDE_PREFIX}/framelesswindowsmanager.h ${INCLUDE_PREFIX}/utils.h + ${INCLUDE_PREFIX}/private/framelesswindowsmanager_p.h framelesshelpercore.qrc utils.cpp framelesshelper_qt.cpp - framelesswindowsmanager_p.h framelesswindowsmanager.cpp ) @@ -127,4 +127,5 @@ target_link_libraries(${SUB_PROJ_NAME} PRIVATE target_include_directories(${SUB_PROJ_NAME} PUBLIC "$/${INCLUDE_PREFIX}" + "$/${INCLUDE_PREFIX}/private" ) diff --git a/src/core/framelesshelper_qt.h b/src/core/framelesshelper_qt.h index 6c34347..8f36da7 100644 --- a/src/core/framelesshelper_qt.h +++ b/src/core/framelesshelper_qt.h @@ -1,25 +1 @@ -/* - * MIT License - * - * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - #include "../../include/FramelessHelper/Core/framelesshelper_qt.h" diff --git a/src/core/framelesshelper_win.h b/src/core/framelesshelper_win.h index 3dc9078..419c1c4 100644 --- a/src/core/framelesshelper_win.h +++ b/src/core/framelesshelper_win.h @@ -1,25 +1 @@ -/* - * MIT License - * - * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - #include "../../include/FramelessHelper/Core/framelesshelper_win.h" diff --git a/src/core/framelesshelper_windows.h b/src/core/framelesshelper_windows.h index ce71f6c..6825491 100644 --- a/src/core/framelesshelper_windows.h +++ b/src/core/framelesshelper_windows.h @@ -1,25 +1 @@ -/* - * MIT License - * - * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - #include "../../include/FramelessHelper/Core/framelesshelper_windows.h" diff --git a/src/core/framelesshelpercore_global.h b/src/core/framelesshelpercore_global.h index 13d1be4..5975bc2 100644 --- a/src/core/framelesshelpercore_global.h +++ b/src/core/framelesshelpercore_global.h @@ -1,25 +1 @@ -/* - * MIT License - * - * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - #include "../../include/FramelessHelper/Core/framelesshelpercore_global.h" diff --git a/src/core/framelesswindowsmanager.h b/src/core/framelesswindowsmanager.h index e682e5d..4370a26 100644 --- a/src/core/framelesswindowsmanager.h +++ b/src/core/framelesswindowsmanager.h @@ -1,25 +1 @@ -/* - * MIT License - * - * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - #include "../../include/FramelessHelper/Core/framelesswindowsmanager.h" diff --git a/src/core/framelesswindowsmanager_p.h b/src/core/framelesswindowsmanager_p.h index 93a4e7b..35dd801 100644 --- a/src/core/framelesswindowsmanager_p.h +++ b/src/core/framelesswindowsmanager_p.h @@ -1,66 +1 @@ -/* - * MIT License - * - * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#pragma once - -#include "framelesshelpercore_global.h" -#include - -FRAMELESSHELPER_BEGIN_NAMESPACE - -class FramelessWindowsManager; - -class FRAMELESSHELPER_CORE_API FramelessWindowsManagerPrivate : public QObject -{ - Q_OBJECT - Q_DECLARE_PUBLIC(FramelessWindowsManager) - Q_DISABLE_COPY_MOVE(FramelessWindowsManagerPrivate) - -public: - explicit FramelessWindowsManagerPrivate(FramelessWindowsManager *q); - ~FramelessWindowsManagerPrivate() override; - - Q_NODISCARD static FramelessWindowsManagerPrivate *get(FramelessWindowsManager *pub); - Q_NODISCARD static const FramelessWindowsManagerPrivate *get(const FramelessWindowsManager *pub); - - Q_NODISCARD static bool usePureQtImplementation(); - Q_NODISCARD Global::SystemTheme systemTheme() const; - Q_NODISCARD QColor systemAccentColor() const; - - static void addWindow(const Global::SystemParameters ¶ms); - Q_INVOKABLE void notifySystemThemeHasChangedOrNot(); - -private: - void initialize(); - -private: - FramelessWindowsManager *q_ptr = nullptr; - Global::SystemTheme m_systemTheme = Global::SystemTheme::Unknown; - QColor m_accentColor = {}; -#ifdef Q_OS_WINDOWS - Global::DwmColorizationArea m_colorizationArea = Global::DwmColorizationArea::None_; -#endif -}; - -FRAMELESSHELPER_END_NAMESPACE +#include "../../include/FramelessHelper/Core/private/framelesswindowsmanager_p.h" diff --git a/src/core/utils.cpp b/src/core/utils.cpp index ad55536..28ab5f2 100644 --- a/src/core/utils.cpp +++ b/src/core/utils.cpp @@ -71,18 +71,22 @@ Qt::CursorShape Utils::calculateCursorShape(const QWindow *window, const QPoint if (window->visibility() != QWindow::Windowed) { return Qt::ArrowCursor; } - if (((pos.x() < kDefaultResizeBorderThickness) && (pos.y() < kDefaultResizeBorderThickness)) - || ((pos.x() >= (window->width() - kDefaultResizeBorderThickness)) && (pos.y() >= (window->height() - kDefaultResizeBorderThickness)))) { + const int x = pos.x(); + const int y = pos.y(); + const int w = window->width(); + const int h = window->height(); + if (((x < kDefaultResizeBorderThickness) && (y < kDefaultResizeBorderThickness)) + || ((x >= (w - kDefaultResizeBorderThickness)) && (y >= (h - kDefaultResizeBorderThickness)))) { return Qt::SizeFDiagCursor; } - if (((pos.x() >= (window->width() - kDefaultResizeBorderThickness)) && (pos.y() < kDefaultResizeBorderThickness)) - || ((pos.x() < kDefaultResizeBorderThickness) && (pos.y() >= (window->height() - kDefaultResizeBorderThickness)))) { + if (((x >= (w - kDefaultResizeBorderThickness)) && (y < kDefaultResizeBorderThickness)) + || ((x < kDefaultResizeBorderThickness) && (y >= (h - kDefaultResizeBorderThickness)))) { return Qt::SizeBDiagCursor; } - if ((pos.x() < kDefaultResizeBorderThickness) || (pos.x() >= (window->width() - kDefaultResizeBorderThickness))) { + if ((x < kDefaultResizeBorderThickness) || (x >= (w - kDefaultResizeBorderThickness))) { return Qt::SizeHorCursor; } - if ((pos.y() < kDefaultResizeBorderThickness) || (pos.y() >= (window->height() - kDefaultResizeBorderThickness))) { + if ((y < kDefaultResizeBorderThickness) || (y >= (h - kDefaultResizeBorderThickness))) { return Qt::SizeVerCursor; } return Qt::ArrowCursor; @@ -104,16 +108,18 @@ Qt::Edges Utils::calculateWindowEdges(const QWindow *window, const QPoint &pos) return {}; } Qt::Edges edges = {}; - if (pos.x() < kDefaultResizeBorderThickness) { + const int x = pos.x(); + const int y = pos.y(); + if (x < kDefaultResizeBorderThickness) { edges |= Qt::LeftEdge; } - if (pos.x() >= (window->width() - kDefaultResizeBorderThickness)) { + if (x >= (window->width() - kDefaultResizeBorderThickness)) { edges |= Qt::RightEdge; } - if (pos.y() < kDefaultResizeBorderThickness) { + if (y < kDefaultResizeBorderThickness) { edges |= Qt::TopEdge; } - if (pos.y() >= (window->height() - kDefaultResizeBorderThickness)) { + if (y >= (window->height() - kDefaultResizeBorderThickness)) { edges |= Qt::BottomEdge; } return edges; diff --git a/src/core/utils.h b/src/core/utils.h index 684e708..072a20e 100644 --- a/src/core/utils.h +++ b/src/core/utils.h @@ -1,25 +1 @@ -/* - * MIT License - * - * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - #include "../../include/FramelessHelper/Core/utils.h" diff --git a/src/quick/CMakeLists.txt b/src/quick/CMakeLists.txt index b4c3b21..569255e 100644 --- a/src/quick/CMakeLists.txt +++ b/src/quick/CMakeLists.txt @@ -33,19 +33,19 @@ set(SOURCES framelesshelperquick.qrc ${INCLUDE_PREFIX}/framelesshelperquick_global.h ${INCLUDE_PREFIX}/framelessquickmodule.h - ${INCLUDE_PREFIX}/framelessquickwindow.h ${INCLUDE_PREFIX}/framelessquickhelper.h ${INCLUDE_PREFIX}/framelessquickutils.h - quickstandardminimizebutton_p.h + ${INCLUDE_PREFIX}/private/quickstandardminimizebutton_p.h + ${INCLUDE_PREFIX}/private/quickstandardmaximizebutton_p.h + ${INCLUDE_PREFIX}/private/quickstandardclosebutton_p.h + ${INCLUDE_PREFIX}/private/quickstandardtitlebar_p.h + ${INCLUDE_PREFIX}/private/framelessquickhelper_p.h + ${INCLUDE_PREFIX}/private/framelessquickwindow_p.h + ${INCLUDE_PREFIX}/private/framelessquickwindow_p_p.h quickstandardminimizebutton.cpp - quickstandardmaximizebutton_p.h quickstandardmaximizebutton.cpp - quickstandardclosebutton_p.h quickstandardclosebutton.cpp - quickstandardtitlebar_p.h quickstandardtitlebar.cpp - framelessquickhelper_p.h - framelessquickwindow_p.h framelessquickutils.cpp framelessquickmodule.cpp framelessquickwindow.cpp @@ -114,4 +114,5 @@ target_link_libraries(${SUB_PROJ_NAME} PUBLIC target_include_directories(${SUB_PROJ_NAME} PUBLIC "$/${INCLUDE_PREFIX}" + "$/${INCLUDE_PREFIX}/private" ) diff --git a/src/quick/framelesshelperquick_global.h b/src/quick/framelesshelperquick_global.h index b32b26c..9485ee0 100644 --- a/src/quick/framelesshelperquick_global.h +++ b/src/quick/framelesshelperquick_global.h @@ -1,25 +1 @@ -/* - * MIT License - * - * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - #include "../../include/FramelessHelper/Quick/framelesshelperquick_global.h" diff --git a/src/quick/framelessquickhelper.cpp b/src/quick/framelessquickhelper.cpp index 8cb9541..6e18fd3 100644 --- a/src/quick/framelessquickhelper.cpp +++ b/src/quick/framelessquickhelper.cpp @@ -325,11 +325,10 @@ void FramelessQuickHelperPrivate::bringWindowToFront() if (!window) { return; } - const QQuickWindow::Visibility visibility = window->visibility(); - if (visibility == QQuickWindow::Hidden) { + if (window->visibility() == QQuickWindow::Hidden) { window->show(); } - if (visibility == QQuickWindow::Minimized) { + if (window->visibility() == QQuickWindow::Minimized) { window->showNormal(); // ### FIXME } window->raise(); diff --git a/src/quick/framelessquickhelper.h b/src/quick/framelessquickhelper.h index 4f4e9b3..d77b668 100644 --- a/src/quick/framelessquickhelper.h +++ b/src/quick/framelessquickhelper.h @@ -1,25 +1 @@ -/* - * MIT License - * - * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - #include "../../include/FramelessHelper/Quick/framelessquickhelper.h" diff --git a/src/quick/framelessquickhelper_p.h b/src/quick/framelessquickhelper_p.h index 83a2d2f..4b0ffc5 100644 --- a/src/quick/framelessquickhelper_p.h +++ b/src/quick/framelessquickhelper_p.h @@ -1,81 +1 @@ -/* - * MIT License - * - * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#pragma once - -#include "framelesshelperquick_global.h" -#include - -QT_BEGIN_NAMESPACE -class QQuickItem; -QT_END_NAMESPACE - -FRAMELESSHELPER_BEGIN_NAMESPACE - -struct QuickHelperData; -class FramelessQuickHelper; - -class FRAMELESSHELPER_QUICK_API FramelessQuickHelperPrivate : public QObject -{ - Q_OBJECT - Q_DECLARE_PUBLIC(FramelessQuickHelper) - Q_DISABLE_COPY_MOVE(FramelessQuickHelperPrivate) - -public: - explicit FramelessQuickHelperPrivate(FramelessQuickHelper *q); - ~FramelessQuickHelperPrivate() override; - - Q_NODISCARD static FramelessQuickHelperPrivate *get(FramelessQuickHelper *pub); - Q_NODISCARD static const FramelessQuickHelperPrivate *get(const FramelessQuickHelper *pub); - - Q_NODISCARD QQuickItem *getTitleBarItem() const; - void setTitleBarItem(QQuickItem *value); - - void attachToWindow(); - void setSystemButton(QQuickItem *item, const QuickGlobal::SystemButtonType buttonType); - void setHitTestVisible(QQuickItem *item); - void showSystemMenu(const QPoint &pos); - void windowStartSystemMove2(const QPoint &pos); - void windowStartSystemResize2(const Qt::Edges edges, const QPoint &pos); - - void moveWindowToDesktopCenter(); - void bringWindowToFront(); - - Q_NODISCARD bool isWindowFixedSize() const; - void setWindowFixedSize(const bool value); - -private: - Q_NODISCARD QRect mapItemGeometryToScene(const QQuickItem * const item) const; - Q_NODISCARD bool isInSystemButtons(const QPoint &pos, QuickGlobal::SystemButtonType *button) const; - Q_NODISCARD bool isInTitleBarDraggableArea(const QPoint &pos) const; - Q_NODISCARD bool shouldIgnoreMouseEvents(const QPoint &pos) const; - void setSystemButtonState(const QuickGlobal::SystemButtonType button, const QuickGlobal::ButtonState state); - Q_NODISCARD QuickHelperData getWindowData() const; - Q_NODISCARD QuickHelperData *getWindowDataMutable() const; - -private: - FramelessQuickHelper *q_ptr = nullptr; -}; - -FRAMELESSHELPER_END_NAMESPACE +#include "../../include/FramelessHelper/Quick/private/framelessquickhelper_p.h" diff --git a/src/quick/framelessquickmodule.cpp b/src/quick/framelessquickmodule.cpp index 0f87e51..146e634 100644 --- a/src/quick/framelessquickmodule.cpp +++ b/src/quick/framelessquickmodule.cpp @@ -30,7 +30,7 @@ # include "quickstandardmaximizebutton_p.h" # include "quickstandardclosebutton_p.h" # include "quickstandardtitlebar_p.h" -# include "framelessquickwindow.h" +# include "framelessquickwindow_p.h" #else // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) # include #endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) diff --git a/src/quick/framelessquickmodule.h b/src/quick/framelessquickmodule.h index f2e4126..4ff3622 100644 --- a/src/quick/framelessquickmodule.h +++ b/src/quick/framelessquickmodule.h @@ -1,25 +1 @@ -/* - * MIT License - * - * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - #include "../../include/FramelessHelper/Quick/framelessquickmodule.h" diff --git a/src/quick/framelessquickutils.h b/src/quick/framelessquickutils.h index e7c774d..d765638 100644 --- a/src/quick/framelessquickutils.h +++ b/src/quick/framelessquickutils.h @@ -1,25 +1 @@ -/* - * MIT License - * - * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - #include "../../include/FramelessHelper/Quick/framelessquickutils.h" diff --git a/src/quick/framelessquickwindow.cpp b/src/quick/framelessquickwindow.cpp index 7f6e01b..9c88311 100644 --- a/src/quick/framelessquickwindow.cpp +++ b/src/quick/framelessquickwindow.cpp @@ -22,9 +22,9 @@ * SOFTWARE. */ -#include "framelessquickwindow.h" -#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) #include "framelessquickwindow_p.h" +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) +#include "framelessquickwindow_p_p.h" #include "framelessquickhelper.h" #include #include @@ -84,12 +84,16 @@ bool FramelessQuickWindowPrivate::isMinimized() const return (q->visibility() == FramelessQuickWindow::Minimized); } +bool FramelessQuickWindowPrivate::isMaximized() const +{ + Q_Q(const FramelessQuickWindow); + return (q->visibility() == FramelessQuickWindow::Maximized); +} + bool FramelessQuickWindowPrivate::isZoomed() const { Q_Q(const FramelessQuickWindow); - const FramelessQuickWindow::Visibility visibility = q->visibility(); - return ((visibility == FramelessQuickWindow::Maximized) || - (visibility == FramelessQuickWindow::FullScreen)); + return (isMaximized() || (q->visibility() == FramelessQuickWindow::FullScreen)); } bool FramelessQuickWindowPrivate::isFullScreen() const @@ -130,7 +134,7 @@ void FramelessQuickWindowPrivate::showMinimized2() void FramelessQuickWindowPrivate::toggleMaximized() { Q_Q(FramelessQuickWindow); - if (isZoomed()) { + if (isMaximized()) { q->showNormal(); } else { q->showMaximized(); @@ -171,6 +175,7 @@ void FramelessQuickWindowPrivate::initialize() Q_EMIT q->hiddenChanged(); Q_EMIT q->normalChanged(); Q_EMIT q->minimizedChanged(); + Q_EMIT q->maximizedChanged(); Q_EMIT q->zoomedChanged(); Q_EMIT q->fullScreenChanged(); }); @@ -233,6 +238,12 @@ bool FramelessQuickWindow::isMinimized() const return d->isMinimized(); } +bool FramelessQuickWindow::isMaximized() const +{ + Q_D(const FramelessQuickWindow); + return d->isMaximized(); +} + bool FramelessQuickWindow::isZoomed() const { Q_D(const FramelessQuickWindow); diff --git a/src/quick/framelessquickwindow_p.h b/src/quick/framelessquickwindow_p.h index c911973..dfe7fbf 100644 --- a/src/quick/framelessquickwindow_p.h +++ b/src/quick/framelessquickwindow_p.h @@ -1,84 +1 @@ -/* - * MIT License - * - * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#pragma once - -#include "framelesshelperquick_global.h" -#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) -#include -#include -#include - -QT_BEGIN_NAMESPACE -class QQuickRectangle; -QT_END_NAMESPACE - -FRAMELESSHELPER_BEGIN_NAMESPACE - -class FramelessQuickWindow; - -class FRAMELESSHELPER_QUICK_API FramelessQuickWindowPrivate : public QObject -{ - Q_OBJECT - Q_DECLARE_PUBLIC(FramelessQuickWindow) - Q_DISABLE_COPY_MOVE(FramelessQuickWindowPrivate) - -public: - explicit FramelessQuickWindowPrivate(FramelessQuickWindow *q); - ~FramelessQuickWindowPrivate() override; - - Q_NODISCARD static FramelessQuickWindowPrivate *get(FramelessQuickWindow *pub); - Q_NODISCARD static const FramelessQuickWindowPrivate *get(const FramelessQuickWindow *pub); - - Q_INVOKABLE Q_NODISCARD bool isHidden() const; - Q_INVOKABLE Q_NODISCARD bool isNormal() const; - Q_INVOKABLE Q_NODISCARD bool isMinimized() const; - Q_INVOKABLE Q_NODISCARD bool isZoomed() const; - Q_INVOKABLE Q_NODISCARD bool isFullScreen() const; - - Q_INVOKABLE Q_NODISCARD QColor getFrameBorderColor() const; - Q_INVOKABLE Q_NODISCARD QQuickAnchorLine getTopBorderBottom() const; - -public Q_SLOTS: - void showMinimized2(); - void toggleMaximized(); - void toggleFullScreen(); - -private: - void initialize(); - Q_NODISCARD bool shouldDrawFrameBorder() const; - -private Q_SLOTS: - void updateTopBorderColor(); - void updateTopBorderHeight(); - -private: - FramelessQuickWindow *q_ptr = nullptr; - QScopedPointer m_topBorderRectangle; - QScopedPointer m_topBorderAnchors; - QQuickWindow::Visibility m_savedVisibility = QQuickWindow::Windowed; -}; - -FRAMELESSHELPER_END_NAMESPACE -#endif +#include "../../include/FramelessHelper/Quick/private/framelessquickwindow_p.h" diff --git a/src/quick/framelessquickwindow_p_p.h b/src/quick/framelessquickwindow_p_p.h new file mode 100644 index 0000000..51f24e0 --- /dev/null +++ b/src/quick/framelessquickwindow_p_p.h @@ -0,0 +1 @@ +#include "../../include/FramelessHelper/Quick/private/framelessquickwindow_p_p.h" diff --git a/src/quick/quickstandardclosebutton_p.h b/src/quick/quickstandardclosebutton_p.h index f315578..dc4adcb 100644 --- a/src/quick/quickstandardclosebutton_p.h +++ b/src/quick/quickstandardclosebutton_p.h @@ -1,69 +1 @@ -/* - * MIT License - * - * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#pragma once - -#include "framelesshelperquick_global.h" -#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) -#include -#include - -QT_BEGIN_NAMESPACE -class QQuickImage; -class QQuickRectangle; -QT_END_NAMESPACE - -FRAMELESSHELPER_BEGIN_NAMESPACE - -class FRAMELESSHELPER_QUICK_API QuickStandardCloseButton : public QQuickButton -{ - Q_OBJECT -#ifdef QML_NAMED_ELEMENT - QML_NAMED_ELEMENT(StandardCloseButton) -#endif - Q_DISABLE_COPY_MOVE(QuickStandardCloseButton) - -public: - explicit QuickStandardCloseButton(QQuickItem *parent = nullptr); - ~QuickStandardCloseButton() override; - -private Q_SLOTS: - void updateForeground(); - void updateBackground(); - void updateToolTip(); - -private: - void initialize(); - -private: - QScopedPointer m_contentItem; - QScopedPointer m_image; - QScopedPointer m_backgroundItem; - QPointer m_tooltip = nullptr; -}; - -FRAMELESSHELPER_END_NAMESPACE - -QML_DECLARE_TYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickStandardCloseButton)) -#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) +#include "../../include/FramelessHelper/Quick/private/quickstandardclosebutton_p.h" diff --git a/src/quick/quickstandardmaximizebutton_p.h b/src/quick/quickstandardmaximizebutton_p.h index aee2abb..40a6d00 100644 --- a/src/quick/quickstandardmaximizebutton_p.h +++ b/src/quick/quickstandardmaximizebutton_p.h @@ -1,77 +1 @@ -/* - * MIT License - * - * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#pragma once - -#include "framelesshelperquick_global.h" -#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) -#include -#include - -QT_BEGIN_NAMESPACE -class QQuickImage; -class QQuickRectangle; -QT_END_NAMESPACE - -FRAMELESSHELPER_BEGIN_NAMESPACE - -class FRAMELESSHELPER_QUICK_API QuickStandardMaximizeButton : public QQuickButton -{ - Q_OBJECT -#ifdef QML_NAMED_ELEMENT - QML_NAMED_ELEMENT(StandardMaximizeButton) -#endif - Q_DISABLE_COPY_MOVE(QuickStandardMaximizeButton) - Q_PROPERTY(bool maximized READ isMaximized WRITE setMaximized NOTIFY maximizedChanged FINAL) - -public: - explicit QuickStandardMaximizeButton(QQuickItem *parent = nullptr); - ~QuickStandardMaximizeButton() override; - - Q_NODISCARD bool isMaximized() const; - void setMaximized(const bool max); - -private Q_SLOTS: - void updateForeground(); - void updateBackground(); - void updateToolTip(); - -Q_SIGNALS: - void maximizedChanged(); - -private: - void initialize(); - -private: - bool m_max = false; - QScopedPointer m_contentItem; - QScopedPointer m_image; - QScopedPointer m_backgroundItem; - QPointer m_tooltip = nullptr; -}; - -FRAMELESSHELPER_END_NAMESPACE - -QML_DECLARE_TYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickStandardMaximizeButton)) -#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) +#include "../../include/FramelessHelper/Quick/private/quickstandardmaximizebutton_p.h" diff --git a/src/quick/quickstandardminimizebutton_p.h b/src/quick/quickstandardminimizebutton_p.h index 49ea059..818986e 100644 --- a/src/quick/quickstandardminimizebutton_p.h +++ b/src/quick/quickstandardminimizebutton_p.h @@ -1,69 +1 @@ -/* - * MIT License - * - * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#pragma once - -#include "framelesshelperquick_global.h" -#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) -#include -#include - -QT_BEGIN_NAMESPACE -class QQuickImage; -class QQuickRectangle; -QT_END_NAMESPACE - -FRAMELESSHELPER_BEGIN_NAMESPACE - -class FRAMELESSHELPER_QUICK_API QuickStandardMinimizeButton : public QQuickButton -{ - Q_OBJECT -#ifdef QML_NAMED_ELEMENT - QML_NAMED_ELEMENT(StandardMinimizeButton) -#endif - Q_DISABLE_COPY_MOVE(QuickStandardMinimizeButton) - -public: - explicit QuickStandardMinimizeButton(QQuickItem *parent = nullptr); - ~QuickStandardMinimizeButton() override; - -private Q_SLOTS: - void updateForeground(); - void updateBackground(); - void updateToolTip(); - -private: - void initialize(); - -private: - QScopedPointer m_contentItem; - QScopedPointer m_image; - QScopedPointer m_backgroundItem; - QPointer m_tooltip = nullptr; -}; - -FRAMELESSHELPER_END_NAMESPACE - -QML_DECLARE_TYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickStandardMinimizeButton)) -#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) +#include "../../include/FramelessHelper/Quick/private/quickstandardminimizebutton_p.h" diff --git a/src/quick/quickstandardtitlebar_p.h b/src/quick/quickstandardtitlebar_p.h index a038785..4b85072 100644 --- a/src/quick/quickstandardtitlebar_p.h +++ b/src/quick/quickstandardtitlebar_p.h @@ -1,98 +1 @@ -/* - * MIT License - * - * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#pragma once - -#include "framelesshelperquick_global.h" -#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) -#include - -QT_BEGIN_NAMESPACE -class QQuickLabel; -class QQuickRow; -QT_END_NAMESPACE - -FRAMELESSHELPER_BEGIN_NAMESPACE - -class QuickStandardMinimizeButton; -class QuickStandardMaximizeButton; -class QuickStandardCloseButton; - -class FRAMELESSHELPER_QUICK_API QuickStandardTitleBar : public QQuickRectangle -{ - Q_OBJECT -#ifdef QML_NAMED_ELEMENT - QML_NAMED_ELEMENT(StandardTitleBar) -#endif - Q_DISABLE_COPY_MOVE(QuickStandardTitleBar) - Q_PROPERTY(Qt::Alignment titleLabelAlignment READ titleLabelAlignment WRITE setTitleLabelAlignment NOTIFY titleLabelAlignmentChanged FINAL) - Q_PROPERTY(QuickStandardMinimizeButton* minimizeButton READ minimizeButton CONSTANT FINAL) - Q_PROPERTY(QuickStandardMaximizeButton* maximizeButton READ maximizeButton CONSTANT FINAL) - Q_PROPERTY(QuickStandardCloseButton* closeButton READ closeButton CONSTANT FINAL) - -public: - explicit QuickStandardTitleBar(QQuickItem *parent = nullptr); - ~QuickStandardTitleBar() override; - - Q_NODISCARD Qt::Alignment titleLabelAlignment() const; - void setTitleLabelAlignment(const Qt::Alignment value); - - Q_NODISCARD QuickStandardMinimizeButton *minimizeButton() const; - Q_NODISCARD QuickStandardMaximizeButton *maximizeButton() const; - Q_NODISCARD QuickStandardCloseButton *closeButton() const; - -protected: - void itemChange(const ItemChange change, const ItemChangeData &value) override; - -private Q_SLOTS: - void updateMaximizeButton(); - void updateTitleLabelText(); - void updateTitleBarColor(); - void clickMinimizeButton(); - void clickMaximizeButton(); - void clickCloseButton(); - -Q_SIGNALS: - void titleLabelAlignmentChanged(); - -private: - void initialize(); - void updateAll(); - -private: - Qt::Alignment m_labelAlignment = {}; - QScopedPointer m_label; - QScopedPointer m_row; - QScopedPointer m_minBtn; - QScopedPointer m_maxBtn; - QScopedPointer m_closeBtn; - QMetaObject::Connection m_windowStateChangeConnection = {}; - QMetaObject::Connection m_windowActiveChangeConnection = {}; - QMetaObject::Connection m_windowTitleChangeConnection = {}; -}; - -FRAMELESSHELPER_END_NAMESPACE - -QML_DECLARE_TYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickStandardTitleBar)) -#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) +#include "../../include/FramelessHelper/Quick/private/quickstandardtitlebar_p.h" diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt index 0c5080c..e78a08a 100644 --- a/src/widgets/CMakeLists.txt +++ b/src/widgets/CMakeLists.txt @@ -33,17 +33,17 @@ set(SOURCES ${INCLUDE_PREFIX}/standardsystembutton.h ${INCLUDE_PREFIX}/framelesswidgetshelper.h ${INCLUDE_PREFIX}/standardtitlebar.h - framelesswidgetshelper_p.h - standardsystembutton_p.h - standardtitlebar_p.h - framelesswidget_p.h - framelessmainwindow_p.h + ${INCLUDE_PREFIX}/private/framelesswidgetshelper_p.h + ${INCLUDE_PREFIX}/private/standardsystembutton_p.h + ${INCLUDE_PREFIX}/private/standardtitlebar_p.h + ${INCLUDE_PREFIX}/private/framelesswidget_p.h + ${INCLUDE_PREFIX}/private/framelessmainwindow_p.h + ${INCLUDE_PREFIX}/private/widgetssharedhelper_p.h framelessmainwindow.cpp framelesswidgetshelper.cpp framelesswidget.cpp standardsystembutton.cpp standardtitlebar.cpp - widgetssharedhelper_p.h widgetssharedhelper.cpp ) @@ -98,4 +98,5 @@ target_link_libraries(${SUB_PROJ_NAME} PUBLIC target_include_directories(${SUB_PROJ_NAME} PUBLIC "$/${INCLUDE_PREFIX}" + "$/${INCLUDE_PREFIX}/private" ) diff --git a/src/widgets/framelesshelperwidgets_global.h b/src/widgets/framelesshelperwidgets_global.h index 2cd1de3..bd9e331 100644 --- a/src/widgets/framelesshelperwidgets_global.h +++ b/src/widgets/framelesshelperwidgets_global.h @@ -1,25 +1 @@ -/* - * MIT License - * - * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - #include "../../include/FramelessHelper/Widgets/framelesshelperwidgets_global.h" diff --git a/src/widgets/framelessmainwindow.h b/src/widgets/framelessmainwindow.h index 2f5d9c6..150fc77 100644 --- a/src/widgets/framelessmainwindow.h +++ b/src/widgets/framelessmainwindow.h @@ -1,25 +1 @@ -/* - * MIT License - * - * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - #include "../../include/FramelessHelper/Widgets/framelessmainwindow.h" diff --git a/src/widgets/framelessmainwindow_p.h b/src/widgets/framelessmainwindow_p.h index 55b3284..4ba45e9 100644 --- a/src/widgets/framelessmainwindow_p.h +++ b/src/widgets/framelessmainwindow_p.h @@ -1,63 +1 @@ -/* - * MIT License - * - * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#pragma once - -#include "framelesshelperwidgets_global.h" -#include - -FRAMELESSHELPER_BEGIN_NAMESPACE - -class FramelessMainWindow; -class WidgetsSharedHelper; - -class FRAMELESSHELPER_WIDGETS_API FramelessMainWindowPrivate : public QObject -{ - Q_OBJECT - Q_DECLARE_PUBLIC(FramelessMainWindow) - Q_DISABLE_COPY_MOVE(FramelessMainWindowPrivate) - -public: - explicit FramelessMainWindowPrivate(FramelessMainWindow *q); - ~FramelessMainWindowPrivate() override; - - Q_NODISCARD static FramelessMainWindowPrivate *get(FramelessMainWindow *pub); - Q_NODISCARD static const FramelessMainWindowPrivate *get(const FramelessMainWindow *pub); - - Q_NODISCARD bool isNormal() const; - Q_NODISCARD bool isZoomed() const; - - void toggleMaximized(); - void toggleFullScreen(); - -private: - void initialize(); - -private: - FramelessMainWindow *q_ptr = nullptr; - Qt::WindowState m_savedWindowState = Qt::WindowNoState; - QScopedPointer m_helper; -}; - -FRAMELESSHELPER_END_NAMESPACE +#include "../../include/FramelessHelper/Widgets/private/framelessmainwindow_p.h" diff --git a/src/widgets/framelesswidget.h b/src/widgets/framelesswidget.h index 478372e..a256d8e 100644 --- a/src/widgets/framelesswidget.h +++ b/src/widgets/framelesswidget.h @@ -1,25 +1 @@ -/* - * MIT License - * - * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - #include "../../include/FramelessHelper/Widgets/framelesswidget.h" diff --git a/src/widgets/framelesswidget_p.h b/src/widgets/framelesswidget_p.h index eea7791..041c187 100644 --- a/src/widgets/framelesswidget_p.h +++ b/src/widgets/framelesswidget_p.h @@ -1,63 +1 @@ -/* - * MIT License - * - * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#pragma once - -#include "framelesshelperwidgets_global.h" -#include - -FRAMELESSHELPER_BEGIN_NAMESPACE - -class FramelessWidget; -class WidgetsSharedHelper; - -class FRAMELESSHELPER_WIDGETS_API FramelessWidgetPrivate : public QObject -{ - Q_OBJECT - Q_DECLARE_PUBLIC(FramelessWidget) - Q_DISABLE_COPY_MOVE(FramelessWidgetPrivate) - -public: - explicit FramelessWidgetPrivate(FramelessWidget *q); - ~FramelessWidgetPrivate() override; - - Q_NODISCARD static FramelessWidgetPrivate *get(FramelessWidget *pub); - Q_NODISCARD static const FramelessWidgetPrivate *get(const FramelessWidget *pub); - - Q_NODISCARD bool isNormal() const; - Q_NODISCARD bool isZoomed() const; - - void toggleMaximized(); - void toggleFullScreen(); - -private: - void initialize(); - -private: - FramelessWidget *q_ptr = nullptr; - Qt::WindowState m_savedWindowState = Qt::WindowNoState; - QScopedPointer m_helper; -}; - -FRAMELESSHELPER_END_NAMESPACE +#include "../../include/FramelessHelper/Widgets/private/framelesswidget_p.h" diff --git a/src/widgets/framelesswidgetshelper.cpp b/src/widgets/framelesswidgetshelper.cpp index 74eb026..e19ed1d 100644 --- a/src/widgets/framelesswidgetshelper.cpp +++ b/src/widgets/framelesswidgetshelper.cpp @@ -455,7 +455,7 @@ void FramelessWidgetsHelperPrivate::setSystemButtonState(const SystemButtonType const int pressedIndex = mo->indexOfSlot(QMetaObject::normalizedSignature("setPressed(bool)").constData()); const int hoveredIndex = mo->indexOfSlot(QMetaObject::normalizedSignature("setHovered(bool)").constData()); const int clickedIndex = mo->indexOfSignal(QMetaObject::normalizedSignature("clicked()").constData()); - if ((pressedIndex != -1) && (hoveredIndex != -1) && (clickedIndex != -1)) { + if ((pressedIndex >= 0) && (hoveredIndex >= 0) && (clickedIndex >= 0)) { updateButtonState(widgetButton); } } diff --git a/src/widgets/framelesswidgetshelper.h b/src/widgets/framelesswidgetshelper.h index bc4d8fa..5417ab4 100644 --- a/src/widgets/framelesswidgetshelper.h +++ b/src/widgets/framelesswidgetshelper.h @@ -1,25 +1 @@ -/* - * MIT License - * - * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - #include "../../include/FramelessHelper/Widgets/framelesswidgetshelper.h" diff --git a/src/widgets/framelesswidgetshelper_p.h b/src/widgets/framelesswidgetshelper_p.h index b811f28..e5cbbe4 100644 --- a/src/widgets/framelesswidgetshelper_p.h +++ b/src/widgets/framelesswidgetshelper_p.h @@ -1,78 +1 @@ -/* - * MIT License - * - * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#pragma once - -#include "framelesshelperwidgets_global.h" -#include - -FRAMELESSHELPER_BEGIN_NAMESPACE - -struct WidgetsHelperData; -class FramelessWidgetsHelper; - -class FRAMELESSHELPER_WIDGETS_API FramelessWidgetsHelperPrivate : public QObject -{ - Q_OBJECT - Q_DECLARE_PUBLIC(FramelessWidgetsHelper) - Q_DISABLE_COPY_MOVE(FramelessWidgetsHelperPrivate) - -public: - explicit FramelessWidgetsHelperPrivate(FramelessWidgetsHelper *q); - ~FramelessWidgetsHelperPrivate() override; - - Q_NODISCARD static FramelessWidgetsHelperPrivate *get(FramelessWidgetsHelper *pub); - Q_NODISCARD static const FramelessWidgetsHelperPrivate *get(const FramelessWidgetsHelper *pub); - - Q_NODISCARD QWidget *getTitleBarWidget() const; - void setTitleBarWidget(QWidget *widget); - - void attachToWindow(); - void setSystemButton(QWidget *widget, const Global::SystemButtonType buttonType); - void setHitTestVisible(QWidget *widget); - void showSystemMenu(const QPoint &pos); - void windowStartSystemMove2(const QPoint &pos); - void windowStartSystemResize2(const Qt::Edges edges, const QPoint &pos); - - void moveWindowToDesktopCenter(); - void bringWindowToFront(); - - Q_NODISCARD bool isWindowFixedSize() const; - void setWindowFixedSize(const bool value); - -private: - Q_NODISCARD QRect mapWidgetGeometryToScene(const QWidget * const widget) const; - Q_NODISCARD bool isInSystemButtons(const QPoint &pos, Global::SystemButtonType *button) const; - Q_NODISCARD bool isInTitleBarDraggableArea(const QPoint &pos) const; - Q_NODISCARD bool shouldIgnoreMouseEvents(const QPoint &pos) const; - void setSystemButtonState(const Global::SystemButtonType button, const Global::ButtonState state); - Q_NODISCARD QWidget *getWindow() const; - Q_NODISCARD WidgetsHelperData getWindowData() const; - Q_NODISCARD WidgetsHelperData *getWindowDataMutable() const; - -private: - FramelessWidgetsHelper *q_ptr = nullptr; -}; - -FRAMELESSHELPER_END_NAMESPACE +#include "../../include/FramelessHelper/Widgets/private/framelesswidgetshelper_p.h" diff --git a/src/widgets/standardsystembutton.cpp b/src/widgets/standardsystembutton.cpp index 1fd7d18..20ef9d2 100644 --- a/src/widgets/standardsystembutton.cpp +++ b/src/widgets/standardsystembutton.cpp @@ -302,6 +302,7 @@ void StandardSystemButtonPrivate::paintEventHandler(QPaintEvent *event) void StandardSystemButtonPrivate::initialize() { Q_Q(StandardSystemButton); + q->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); q->setFixedSize(kDefaultSystemButtonSize); q->setIconSize(kDefaultSystemButtonIconSize); connect(q, &StandardSystemButton::pressed, this, [this](){ setPressed(true); }); diff --git a/src/widgets/standardsystembutton.h b/src/widgets/standardsystembutton.h index 66699b6..e7263f5 100644 --- a/src/widgets/standardsystembutton.h +++ b/src/widgets/standardsystembutton.h @@ -1,25 +1 @@ -/* - * MIT License - * - * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - #include "../../include/FramelessHelper/Widgets/standardsystembutton.h" diff --git a/src/widgets/standardsystembutton_p.h b/src/widgets/standardsystembutton_p.h index 971c187..c4433ae 100644 --- a/src/widgets/standardsystembutton_p.h +++ b/src/widgets/standardsystembutton_p.h @@ -1,93 +1 @@ -/* - * MIT License - * - * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#pragma once - -#include -#include -#include "framelesshelperwidgets_global.h" - -QT_BEGIN_NAMESPACE -class QEnterEvent; -class QPaintEvent; -QT_END_NAMESPACE - -FRAMELESSHELPER_BEGIN_NAMESPACE - -class StandardSystemButton; - -class FRAMELESSHELPER_WIDGETS_API StandardSystemButtonPrivate : public QObject -{ - Q_OBJECT - Q_DECLARE_PUBLIC(StandardSystemButton) - Q_DISABLE_COPY_MOVE(StandardSystemButtonPrivate) - -public: - explicit StandardSystemButtonPrivate(StandardSystemButton *q); - ~StandardSystemButtonPrivate() override; - - Q_NODISCARD static StandardSystemButtonPrivate *get(StandardSystemButton *pub); - Q_NODISCARD static const StandardSystemButtonPrivate *get(const StandardSystemButton *pub); - - void refreshButtonTheme(const bool force); - - Q_NODISCARD Global::SystemButtonType getButtonType() const; - void setButtonType(const Global::SystemButtonType type); - - void setIcon(const QIcon &value, const bool reverse); - void setPixmap(const QPixmap &value, const bool reverse); - void setImage(const QImage &value, const bool reverse); - - Q_NODISCARD QSize getRecommendedButtonSize() const; - - Q_NODISCARD bool isHovered() const; - Q_NODISCARD bool isPressed() const; - Q_NODISCARD QColor getHoverColor() const; - Q_NODISCARD QColor getPressColor() const; - - void setHovered(const bool value); - void setPressed(const bool value); - void setHoverColor(const QColor &value); - void setPressColor(const QColor &value); - - void enterEventHandler(QT_ENTER_EVENT_TYPE *event); - void leaveEventHandler(QEvent *event); - void paintEventHandler(QPaintEvent *event); - -private: - void initialize(); - -private: - StandardSystemButton *q_ptr = nullptr; - Global::SystemTheme m_buttonTheme = Global::SystemTheme::Unknown; - Global::SystemButtonType m_buttonType = Global::SystemButtonType::Unknown; - QPixmap m_icon = {}; - QPixmap m_reversedIcon = {}; - QColor m_hoverColor = {}; - QColor m_pressColor = {}; - bool m_hovered = false; - bool m_pressed = false; -}; - -FRAMELESSHELPER_END_NAMESPACE +#include "../../include/FramelessHelper/Widgets/private/standardsystembutton_p.h" diff --git a/src/widgets/standardtitlebar.cpp b/src/widgets/standardtitlebar.cpp index 3a36055..f792d18 100644 --- a/src/widgets/standardtitlebar.cpp +++ b/src/widgets/standardtitlebar.cpp @@ -147,7 +147,7 @@ bool StandardTitleBarPrivate::eventFilter(QObject *object, QEvent *event) void StandardTitleBarPrivate::initialize() { Q_Q(StandardTitleBar); - m_window = q->window(); + m_window = (q->nativeParentWidget() ? q->nativeParentWidget() : q->window()); q->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); q->setFixedHeight(kDefaultTitleBarHeight); m_windowTitleLabel.reset(new QLabel(q)); @@ -158,35 +158,38 @@ void StandardTitleBarPrivate::initialize() m_windowTitleLabel->setText(m_window->windowTitle()); connect(m_window, &QWidget::windowTitleChanged, m_windowTitleLabel.data(), &QLabel::setText); m_minimizeButton.reset(new StandardSystemButton(SystemButtonType::Minimize, q)); - m_minimizeButton->setFixedSize(kDefaultSystemButtonSize); - m_minimizeButton->setIconSize(kDefaultSystemButtonIconSize); m_minimizeButton->setToolTip(tr("Minimize")); connect(m_minimizeButton.data(), &StandardSystemButton::clicked, m_window, &QWidget::showMinimized); m_maximizeButton.reset(new StandardSystemButton(SystemButtonType::Maximize, q)); - m_maximizeButton->setFixedSize(kDefaultSystemButtonSize); - m_maximizeButton->setIconSize(kDefaultSystemButtonIconSize); updateMaximizeButton(); connect(m_maximizeButton.data(), &StandardSystemButton::clicked, this, [this](){ - if (m_window->isMaximized() || m_window->isFullScreen()) { + if (m_window->isMaximized()) { m_window->showNormal(); } else { m_window->showMaximized(); } }); m_closeButton.reset(new StandardSystemButton(SystemButtonType::Close, q)); - m_closeButton->setFixedSize(kDefaultSystemButtonSize); - m_closeButton->setIconSize(kDefaultSystemButtonIconSize); m_closeButton->setToolTip(tr("Close")); connect(m_closeButton.data(), &StandardSystemButton::clicked, m_window, &QWidget::close); + const auto systemButtonsInnerLayout = new QHBoxLayout; + systemButtonsInnerLayout->setSpacing(0); + systemButtonsInnerLayout->setContentsMargins(0, 0, 0, 0); + systemButtonsInnerLayout->addWidget(m_minimizeButton.data()); + systemButtonsInnerLayout->addWidget(m_maximizeButton.data()); + systemButtonsInnerLayout->addWidget(m_closeButton.data()); + const auto systemButtonsOuterLayout = new QVBoxLayout; + systemButtonsOuterLayout->setSpacing(0); + systemButtonsOuterLayout->setContentsMargins(0, 0, 0, 0); + systemButtonsOuterLayout->addLayout(systemButtonsInnerLayout); + systemButtonsOuterLayout->addStretch(); const auto titleBarLayout = new QHBoxLayout(q); titleBarLayout->setContentsMargins(0, 0, 0, 0); titleBarLayout->setSpacing(0); titleBarLayout->addSpacerItem(new QSpacerItem(kDefaultTitleBarContentsMargin, kDefaultTitleBarContentsMargin)); titleBarLayout->addWidget(m_windowTitleLabel.data()); titleBarLayout->addStretch(); - titleBarLayout->addWidget(m_minimizeButton.data()); - titleBarLayout->addWidget(m_maximizeButton.data()); - titleBarLayout->addWidget(m_closeButton.data()); + titleBarLayout->addLayout(systemButtonsOuterLayout); q->setLayout(titleBarLayout); updateTitleBarStyleSheet(); connect(FramelessWindowsManager::instance(), &FramelessWindowsManager::systemThemeChanged, diff --git a/src/widgets/standardtitlebar.h b/src/widgets/standardtitlebar.h index 944eac3..8379a49 100644 --- a/src/widgets/standardtitlebar.h +++ b/src/widgets/standardtitlebar.h @@ -1,25 +1 @@ -/* - * MIT License - * - * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - #include "../../include/FramelessHelper/Widgets/standardtitlebar.h" diff --git a/src/widgets/standardtitlebar_p.h b/src/widgets/standardtitlebar_p.h index 7088947..797d31d 100644 --- a/src/widgets/standardtitlebar_p.h +++ b/src/widgets/standardtitlebar_p.h @@ -1,72 +1 @@ -/* - * MIT License - * - * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#pragma once - -#include "framelesshelperwidgets_global.h" -#include -#include - -QT_BEGIN_NAMESPACE -class QLabel; -QT_END_NAMESPACE - -FRAMELESSHELPER_BEGIN_NAMESPACE - -class StandardTitleBar; -class StandardSystemButton; - -class FRAMELESSHELPER_WIDGETS_API StandardTitleBarPrivate : public QObject -{ - Q_OBJECT - Q_DECLARE_PUBLIC(StandardTitleBar) - Q_DISABLE_COPY_MOVE(StandardTitleBarPrivate) - -public: - explicit StandardTitleBarPrivate(StandardTitleBar *q); - ~StandardTitleBarPrivate() override; - - Q_NODISCARD static StandardTitleBarPrivate *get(StandardTitleBar *pub); - Q_NODISCARD static const StandardTitleBarPrivate *get(const StandardTitleBar *pub); - -public Q_SLOTS: - void updateMaximizeButton(); - void updateTitleBarStyleSheet(); - -protected: - Q_NODISCARD bool eventFilter(QObject *object, QEvent *event) override; - -private: - void initialize(); - -private: - StandardTitleBar *q_ptr = nullptr; - QScopedPointer m_windowTitleLabel; - QScopedPointer m_minimizeButton; - QScopedPointer m_maximizeButton; - QScopedPointer m_closeButton; - QPointer m_window = nullptr; -}; - -FRAMELESSHELPER_END_NAMESPACE +#include "../../include/FramelessHelper/Widgets/private/standardtitlebar_p.h" diff --git a/src/widgets/widgetssharedhelper_p.h b/src/widgets/widgetssharedhelper_p.h index 7f24955..8b5fbc5 100644 --- a/src/widgets/widgetssharedhelper_p.h +++ b/src/widgets/widgetssharedhelper_p.h @@ -1,63 +1 @@ -/* - * MIT License - * - * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#pragma once - -#include "framelesshelperwidgets_global.h" -#include -#include - -QT_BEGIN_NAMESPACE -class QPaintEvent; -QT_END_NAMESPACE - -FRAMELESSHELPER_BEGIN_NAMESPACE - -class FRAMELESSHELPER_WIDGETS_API WidgetsSharedHelper : public QObject -{ - Q_OBJECT - Q_DISABLE_COPY_MOVE(WidgetsSharedHelper) - -public: - explicit WidgetsSharedHelper(QObject *parent = nullptr); - ~WidgetsSharedHelper() override; - - void setup(QWidget *widget); - -protected: - Q_NODISCARD bool eventFilter(QObject *object, QEvent *event) override; - -private Q_SLOTS: - void updateContentsMargins(); - -private: - void changeEventHandler(QEvent *event); - void paintEventHandler(QPaintEvent *event); - Q_NODISCARD bool shouldDrawFrameBorder() const; - -private: - QPointer m_targetWidget = nullptr; -}; - -FRAMELESSHELPER_END_NAMESPACE +#include "../../include/FramelessHelper/Widgets/private/widgetssharedhelper_p.h"