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>
This commit is contained in:
Yuhang Zhao 2022-04-24 11:33:05 +08:00
parent a0a9b8d108
commit 2915d1f33a
12 changed files with 66 additions and 89 deletions

View File

@ -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

View File

@ -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"));
}

View File

@ -49,10 +49,10 @@ private:
void setupUi();
private:
QScopedPointer<QLabel> m_titleLabel;
QScopedPointer<QPushButton> m_minBtn;
QScopedPointer<QPushButton> m_maxBtn;
QScopedPointer<QPushButton> m_closeBtn;
QScopedPointer<QWidget> m_titleBarWidget;
QScopedPointer<GLWidget> 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;
};

View File

@ -1 +0,0 @@
#include <framelesswidgetshelper.h>

View File

@ -74,7 +74,7 @@ Q_SIGNALS:
void systemButtonStateChanged(const Global::SystemButtonType, const Global::ButtonState);
private:
QScopedPointer<FramelessWidgetsHelper> m_helper;
QScopedPointer<FramelessWidgetsHelper> d_ptr;
};
FRAMELESSHELPER_END_NAMESPACE

View File

@ -79,7 +79,7 @@ Q_SIGNALS:
void systemButtonStateChanged(const Global::SystemButtonType, const Global::ButtonState);
private:
QScopedPointer<FramelessWidgetsHelper> m_helper;
QScopedPointer<FramelessWidgetsHelper> d_ptr;
};
FRAMELESSHELPER_END_NAMESPACE

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -22,7 +22,7 @@
* SOFTWARE.
*/
#include "framelesswidgetshelper.h"
#include "framelesswidgetshelper_p.h"
#include "standardsystembutton.h"
#include <QtCore/qdebug.h>
#include <QtCore/qvariant.h>

View File

@ -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"