From 2915d1f33ad8084eca25edd964455040bbb57734 Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Sun, 24 Apr 2022 11:33:05 +0800 Subject: [PATCH] Widgets: move FramelessWidgetsHelper to source directory It's pure implementation detail, so should not be publicly visible Also fixed the crash of the QOpenGLWidget demo application. Signed-off-by: Yuhang Zhao <2546789017@qq.com> --- README.md | 5 ++- examples/openglwidget/mainwindow.cpp | 36 +++++++++---------- examples/openglwidget/mainwindow.h | 12 +++---- .../Widgets/FramelessWidgetsHelper | 1 - .../Widgets/framelessmainwindow.h | 2 +- .../FramelessHelper/Widgets/framelesswidget.h | 2 +- src/widgets/CMakeLists.txt | 2 +- src/widgets/framelessmainwindow.cpp | 32 ++++++++--------- src/widgets/framelesswidget.cpp | 36 +++++++++---------- src/widgets/framelesswidgetshelper.cpp | 2 +- src/widgets/framelesswidgetshelper.h | 25 ------------- .../widgets/framelesswidgetshelper_p.h | 0 12 files changed, 66 insertions(+), 89 deletions(-) delete mode 100644 include/FramelessHelper/Widgets/FramelessWidgetsHelper delete mode 100644 src/widgets/framelesswidgetshelper.h rename include/FramelessHelper/Widgets/framelesswidgetshelper.h => src/widgets/framelesswidgetshelper_p.h (100%) diff --git a/README.md b/README.md index 4472f66..9a95f9b 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,9 @@ - [ ] All: Add QtWebEngine demo applications for both Qt Widgets and Qt Quick. - [ ] All: Make more settings and options configurable through environment variables and configuration files. - Future versions - - [ ] Windows: Maximize button docking feature introduced in Windows 11 + - [ ] Windows: Maximize button docking feature introduced in Windows 11. + - [ ] Linux: Support runtime theme switching. + - [ ] Linux: Move window resize area outside of the client area. - [ ] More feature requests are welcome! ## Build @@ -73,6 +75,7 @@ Please refer to the demo applications to see more detailed usages: [examples](./ ### Linux - FramelessHelper will force your application to use the _XCB_ platform plugin when running on Wayland. +- Currently lacks runtime theme switching support ### macOS diff --git a/examples/openglwidget/mainwindow.cpp b/examples/openglwidget/mainwindow.cpp index abee208..b32d863 100644 --- a/examples/openglwidget/mainwindow.cpp +++ b/examples/openglwidget/mainwindow.cpp @@ -46,42 +46,42 @@ void MainWindow::updateMaximizeButton() void MainWindow::setupUi() { - m_titleLabel.reset(new QLabel(this)); + m_titleLabel = new QLabel(this); QFont f = font(); f.setPointSize(kDefaultTitleBarFontPointSize); m_titleLabel->setFont(f); - connect(this, &MainWindow::windowTitleChanged, m_titleLabel.data(), &QLabel::setText); - m_minBtn.reset(new QPushButton(this)); + connect(this, &MainWindow::windowTitleChanged, m_titleLabel, &QLabel::setText); + m_minBtn = new QPushButton(this); m_minBtn->setText(tr("MINIMIZE")); - connect(m_minBtn.data(), &QPushButton::clicked, this, &MainWindow::showMinimized); - m_maxBtn.reset(new QPushButton(this)); + connect(m_minBtn, &QPushButton::clicked, this, &MainWindow::showMinimized); + m_maxBtn = new QPushButton(this); updateMaximizeButton(); - connect(m_maxBtn.data(), &QPushButton::clicked, this, &MainWindow::toggleMaximized); + connect(m_maxBtn, &QPushButton::clicked, this, &MainWindow::toggleMaximized); connect(this, &MainWindow::zoomedChanged, this, &MainWindow::updateMaximizeButton); - m_closeBtn.reset(new QPushButton(this)); + m_closeBtn = new QPushButton(this); m_closeBtn->setText(tr("CLOSE")); - connect(m_closeBtn.data(), &QPushButton::clicked, this, &MainWindow::close); - m_titleBarWidget.reset(new QWidget(this)); + connect(m_closeBtn, &QPushButton::clicked, this, &MainWindow::close); + m_titleBarWidget = new QWidget(this); m_titleBarWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); m_titleBarWidget->setFixedHeight(kDefaultTitleBarHeight); - const auto titleBarLayout = new QHBoxLayout(m_titleBarWidget.data()); + const auto titleBarLayout = new QHBoxLayout(m_titleBarWidget); titleBarLayout->setSpacing(0); titleBarLayout->setContentsMargins(0, 0, 0, 0); titleBarLayout->addSpacerItem(new QSpacerItem(kDefaultTitleBarTitleLabelMargin, kDefaultTitleBarTitleLabelMargin)); - titleBarLayout->addWidget(m_titleLabel.data()); + titleBarLayout->addWidget(m_titleLabel); titleBarLayout->addStretch(); - titleBarLayout->addWidget(m_minBtn.data()); - titleBarLayout->addWidget(m_maxBtn.data()); - titleBarLayout->addWidget(m_closeBtn.data()); + titleBarLayout->addWidget(m_minBtn); + titleBarLayout->addWidget(m_maxBtn); + titleBarLayout->addWidget(m_closeBtn); m_titleBarWidget->setLayout(titleBarLayout); - m_glWidget.reset(new GLWidget(this)); + m_glWidget = new GLWidget(this); const auto mainLayout = new QVBoxLayout(this); mainLayout->setSpacing(0); mainLayout->setContentsMargins(0, 0, 0, 0); - mainLayout->addWidget(m_titleBarWidget.data()); - mainLayout->addWidget(m_glWidget.data()); + mainLayout->addWidget(m_titleBarWidget); + mainLayout->addWidget(m_glWidget); setLayout(mainLayout); - setTitleBarWidget(m_titleBarWidget.data()); + setTitleBarWidget(m_titleBarWidget); resize(800, 600); setWindowTitle(tr("QOpenGLWidget demo")); } diff --git a/examples/openglwidget/mainwindow.h b/examples/openglwidget/mainwindow.h index e726c4b..5277dea 100644 --- a/examples/openglwidget/mainwindow.h +++ b/examples/openglwidget/mainwindow.h @@ -49,10 +49,10 @@ private: void setupUi(); private: - QScopedPointer m_titleLabel; - QScopedPointer m_minBtn; - QScopedPointer m_maxBtn; - QScopedPointer m_closeBtn; - QScopedPointer m_titleBarWidget; - QScopedPointer m_glWidget; + QLabel *m_titleLabel = nullptr; + QPushButton *m_minBtn = nullptr; + QPushButton *m_maxBtn = nullptr; + QPushButton *m_closeBtn = nullptr; + QWidget *m_titleBarWidget = nullptr; + GLWidget *m_glWidget = nullptr; }; diff --git a/include/FramelessHelper/Widgets/FramelessWidgetsHelper b/include/FramelessHelper/Widgets/FramelessWidgetsHelper deleted file mode 100644 index 51467e8..0000000 --- a/include/FramelessHelper/Widgets/FramelessWidgetsHelper +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/include/FramelessHelper/Widgets/framelessmainwindow.h b/include/FramelessHelper/Widgets/framelessmainwindow.h index a3be465..2ccef08 100644 --- a/include/FramelessHelper/Widgets/framelessmainwindow.h +++ b/include/FramelessHelper/Widgets/framelessmainwindow.h @@ -74,7 +74,7 @@ Q_SIGNALS: void systemButtonStateChanged(const Global::SystemButtonType, const Global::ButtonState); private: - QScopedPointer m_helper; + QScopedPointer d_ptr; }; FRAMELESSHELPER_END_NAMESPACE diff --git a/include/FramelessHelper/Widgets/framelesswidget.h b/include/FramelessHelper/Widgets/framelesswidget.h index 4a4f6a8..6be876a 100644 --- a/include/FramelessHelper/Widgets/framelesswidget.h +++ b/include/FramelessHelper/Widgets/framelesswidget.h @@ -79,7 +79,7 @@ Q_SIGNALS: void systemButtonStateChanged(const Global::SystemButtonType, const Global::ButtonState); private: - QScopedPointer m_helper; + QScopedPointer d_ptr; }; FRAMELESSHELPER_END_NAMESPACE diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt index a97b1db..009b140 100644 --- a/src/widgets/CMakeLists.txt +++ b/src/widgets/CMakeLists.txt @@ -28,10 +28,10 @@ set(INCLUDE_PREFIX ../../include/FramelessHelper/Widgets) set(SOURCES ${INCLUDE_PREFIX}/framelesshelperwidgets_global.h - ${INCLUDE_PREFIX}/framelesswidgetshelper.h ${INCLUDE_PREFIX}/framelesswidget.h ${INCLUDE_PREFIX}/framelessmainwindow.h ${INCLUDE_PREFIX}/standardsystembutton.h + framelesswidgetshelper_p.h standardsystembutton_p.h framelessmainwindow.cpp framelesswidgetshelper.cpp diff --git a/src/widgets/framelessmainwindow.cpp b/src/widgets/framelessmainwindow.cpp index ea8c0e9..95c7380 100644 --- a/src/widgets/framelessmainwindow.cpp +++ b/src/widgets/framelessmainwindow.cpp @@ -23,7 +23,7 @@ */ #include "framelessmainwindow.h" -#include "framelesswidgetshelper.h" +#include "framelesswidgetshelper_p.h" FRAMELESSHELPER_BEGIN_NAMESPACE @@ -31,79 +31,79 @@ using namespace Global; FramelessMainWindow::FramelessMainWindow(QWidget *parent, const Qt::WindowFlags flags, const UserSettings &settings) : QMainWindow(parent, flags) { - m_helper.reset(new FramelessWidgetsHelper(this, settings)); + d_ptr.reset(new FramelessWidgetsHelper(this, settings)); } FramelessMainWindow::~FramelessMainWindow() = default; bool FramelessMainWindow::isNormal() const { - return m_helper->isNormal(); + return d_ptr->isNormal(); } bool FramelessMainWindow::isZoomed() const { - return m_helper->isZoomed(); + return d_ptr->isZoomed(); } bool FramelessMainWindow::isFixedSize() const { - return m_helper->isFixedSize(); + return d_ptr->isFixedSize(); } void FramelessMainWindow::setFixedSize(const bool value) { - m_helper->setFixedSize(value); + d_ptr->setFixedSize(value); } void FramelessMainWindow::setTitleBarWidget(QWidget *widget) { - m_helper->setTitleBarWidget(widget); + d_ptr->setTitleBarWidget(widget); } QWidget *FramelessMainWindow::titleBarWidget() const { - return m_helper->getTitleBarWidget(); + return d_ptr->getTitleBarWidget(); } void FramelessMainWindow::setHitTestVisible(QWidget *widget) { - m_helper->setHitTestVisible(widget); + d_ptr->setHitTestVisible(widget); } void FramelessMainWindow::toggleMaximized() { - m_helper->toggleMaximized(); + d_ptr->toggleMaximized(); } void FramelessMainWindow::toggleFullScreen() { - m_helper->toggleFullScreen(); + d_ptr->toggleFullScreen(); } void FramelessMainWindow::moveToDesktopCenter() { - m_helper->moveToDesktopCenter(); + d_ptr->moveToDesktopCenter(); } void FramelessMainWindow::bringToFront() { - m_helper->bringToFront(); + d_ptr->bringToFront(); } void FramelessMainWindow::showSystemMenu(const QPoint &pos) { - m_helper->showSystemMenu(pos); + d_ptr->showSystemMenu(pos); } void FramelessMainWindow::startSystemMove2(const QPoint &pos) { - m_helper->startSystemMove2(pos); + d_ptr->startSystemMove2(pos); } void FramelessMainWindow::startSystemResize2(const Qt::Edges edges, const QPoint &pos) { - m_helper->startSystemResize2(edges, pos); + d_ptr->startSystemResize2(edges, pos); } FRAMELESSHELPER_END_NAMESPACE diff --git a/src/widgets/framelesswidget.cpp b/src/widgets/framelesswidget.cpp index a3ee705..6210b7d 100644 --- a/src/widgets/framelesswidget.cpp +++ b/src/widgets/framelesswidget.cpp @@ -23,7 +23,7 @@ */ #include "framelesswidget.h" -#include "framelesswidgetshelper.h" +#include "framelesswidgetshelper_p.h" FRAMELESSHELPER_BEGIN_NAMESPACE @@ -31,89 +31,89 @@ using namespace Global; FramelessWidget::FramelessWidget(QWidget *parent, const UserSettings &settings) : QWidget(parent) { - m_helper.reset(new FramelessWidgetsHelper(this, settings)); + d_ptr.reset(new FramelessWidgetsHelper(this, settings)); } FramelessWidget::~FramelessWidget() = default; bool FramelessWidget::isNormal() const { - return m_helper->isNormal(); + return d_ptr->isNormal(); } bool FramelessWidget::isZoomed() const { - return m_helper->isZoomed(); + return d_ptr->isZoomed(); } bool FramelessWidget::isFixedSize() const { - return m_helper->isFixedSize(); + return d_ptr->isFixedSize(); } void FramelessWidget::setFixedSize(const bool value) { - m_helper->setFixedSize(value); + d_ptr->setFixedSize(value); } void FramelessWidget::setTitleBarWidget(QWidget *widget) { - m_helper->setTitleBarWidget(widget); + d_ptr->setTitleBarWidget(widget); } QWidget *FramelessWidget::titleBarWidget() const { - return m_helper->getTitleBarWidget(); + return d_ptr->getTitleBarWidget(); } void FramelessWidget::setContentWidget(QWidget *widget) { - m_helper->setContentWidget(widget); + d_ptr->setContentWidget(widget); } QWidget *FramelessWidget::contentWidget() const { - return m_helper->getContentWidget(); + return d_ptr->getContentWidget(); } void FramelessWidget::setHitTestVisible(QWidget *widget) { - m_helper->setHitTestVisible(widget); + d_ptr->setHitTestVisible(widget); } void FramelessWidget::toggleMaximized() { - m_helper->toggleMaximized(); + d_ptr->toggleMaximized(); } void FramelessWidget::toggleFullScreen() { - m_helper->toggleFullScreen(); + d_ptr->toggleFullScreen(); } void FramelessWidget::moveToDesktopCenter() { - m_helper->moveToDesktopCenter(); + d_ptr->moveToDesktopCenter(); } void FramelessWidget::bringToFront() { - m_helper->bringToFront(); + d_ptr->bringToFront(); } void FramelessWidget::showSystemMenu(const QPoint &pos) { - m_helper->showSystemMenu(pos); + d_ptr->showSystemMenu(pos); } void FramelessWidget::startSystemMove2(const QPoint &pos) { - m_helper->startSystemMove2(pos); + d_ptr->startSystemMove2(pos); } void FramelessWidget::startSystemResize2(const Qt::Edges edges, const QPoint &pos) { - m_helper->startSystemResize2(edges, pos); + d_ptr->startSystemResize2(edges, pos); } FRAMELESSHELPER_END_NAMESPACE diff --git a/src/widgets/framelesswidgetshelper.cpp b/src/widgets/framelesswidgetshelper.cpp index 5ac5568..b4fc2ee 100644 --- a/src/widgets/framelesswidgetshelper.cpp +++ b/src/widgets/framelesswidgetshelper.cpp @@ -22,7 +22,7 @@ * SOFTWARE. */ -#include "framelesswidgetshelper.h" +#include "framelesswidgetshelper_p.h" #include "standardsystembutton.h" #include #include diff --git a/src/widgets/framelesswidgetshelper.h b/src/widgets/framelesswidgetshelper.h deleted file mode 100644 index bc4d8fa..0000000 --- a/src/widgets/framelesswidgetshelper.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/include/FramelessHelper/Widgets/framelesswidgetshelper.h b/src/widgets/framelesswidgetshelper_p.h similarity index 100% rename from include/FramelessHelper/Widgets/framelesswidgetshelper.h rename to src/widgets/framelesswidgetshelper_p.h