forked from github_mirror/framelesshelper
parent
f700b07e5c
commit
ebc20e23b6
|
@ -36,7 +36,6 @@ if(NOT DEFINED CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||||
#set(CMAKE_C_VISIBILITY_PRESET hidden)
|
|
||||||
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
|
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
|
||||||
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
|
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
#include <QtCore/qglobal.h>
|
#include <QtCore/qglobal.h>
|
||||||
#include <QtCore/qobject.h>
|
#include <QtCore/qobject.h>
|
||||||
|
#include <QtCore/qsize.h>
|
||||||
#include <QtGui/qcolor.h>
|
#include <QtGui/qcolor.h>
|
||||||
|
|
||||||
#ifndef FRAMELESSHELPER_CORE_API
|
#ifndef FRAMELESSHELPER_CORE_API
|
||||||
|
@ -104,4 +105,14 @@ Q_NAMESPACE_EXPORT(FRAMELESSHELPER_CORE_API)
|
||||||
[[maybe_unused]] static const QColor kDefaultSystemLightColor = QStringLiteral("#f0f0f0");
|
[[maybe_unused]] static const QColor kDefaultSystemLightColor = QStringLiteral("#f0f0f0");
|
||||||
[[maybe_unused]] static const QColor kDefaultSystemDarkColor = QStringLiteral("#202020");
|
[[maybe_unused]] static const QColor kDefaultSystemDarkColor = QStringLiteral("#202020");
|
||||||
|
|
||||||
|
[[maybe_unused]] static constexpr const QSize kDefaultSystemButtonSize = {int(qRound(qreal(kDefaultTitleBarHeight) * 1.5)), kDefaultTitleBarHeight};
|
||||||
|
[[maybe_unused]] static constexpr const QSize kDefaultSystemButtonIconSize = {16, 16};
|
||||||
|
|
||||||
|
enum class WindowLayout : int
|
||||||
|
{
|
||||||
|
Standard = 0,
|
||||||
|
Custom = 1
|
||||||
|
};
|
||||||
|
Q_ENUM_NS(WindowLayout)
|
||||||
|
|
||||||
FRAMELESSHELPER_END_NAMESPACE
|
FRAMELESSHELPER_END_NAMESPACE
|
||||||
|
|
|
@ -27,8 +27,6 @@
|
||||||
|
|
||||||
FRAMELESSHELPER_BEGIN_NAMESPACE
|
FRAMELESSHELPER_BEGIN_NAMESPACE
|
||||||
|
|
||||||
static constexpr const QSize kDefaultSystemButtonIconSize = {16, 16};
|
|
||||||
|
|
||||||
[[nodiscard]] static inline SystemTheme strToTheme(const QString &str)
|
[[nodiscard]] static inline SystemTheme strToTheme(const QString &str)
|
||||||
{
|
{
|
||||||
Q_ASSERT(!str.isEmpty());
|
Q_ASSERT(!str.isEmpty());
|
||||||
|
|
|
@ -38,7 +38,8 @@ class FRAMELESSHELPER_WIDGETS_API FramelessMainWindow : public QMainWindow
|
||||||
Q_PROPERTY(QWidget* titleBarWidget READ titleBarWidget WRITE setTitleBarWidget NOTIFY titleBarWidgetChanged FINAL)
|
Q_PROPERTY(QWidget* titleBarWidget READ titleBarWidget WRITE setTitleBarWidget NOTIFY titleBarWidgetChanged FINAL)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit FramelessMainWindow(QWidget *parent = nullptr, Qt::WindowFlags flags = {});
|
explicit FramelessMainWindow(QWidget *parent = nullptr, Qt::WindowFlags flags = {},
|
||||||
|
const WindowLayout wl = WindowLayout::Standard);
|
||||||
~FramelessMainWindow() override;
|
~FramelessMainWindow() override;
|
||||||
|
|
||||||
Q_NODISCARD bool isNormal() const;
|
Q_NODISCARD bool isNormal() const;
|
||||||
|
|
|
@ -39,7 +39,7 @@ class FRAMELESSHELPER_WIDGETS_API FramelessWidget : public QWidget
|
||||||
Q_PROPERTY(QWidget* contentWidget READ contentWidget WRITE setContentWidget NOTIFY contentWidgetChanged FINAL)
|
Q_PROPERTY(QWidget* contentWidget READ contentWidget WRITE setContentWidget NOTIFY contentWidgetChanged FINAL)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit FramelessWidget(QWidget *parent = nullptr);
|
explicit FramelessWidget(QWidget *parent = nullptr, const WindowLayout wl = WindowLayout::Standard);
|
||||||
~FramelessWidget() override;
|
~FramelessWidget() override;
|
||||||
|
|
||||||
Q_NODISCARD bool isNormal() const;
|
Q_NODISCARD bool isNormal() const;
|
||||||
|
|
|
@ -51,23 +51,18 @@ QPushButton:pressed {
|
||||||
}
|
}
|
||||||
)");
|
)");
|
||||||
|
|
||||||
FramelessWidgetsHelper::FramelessWidgetsHelper(QWidget *q, QObject *parent) : QObject(parent)
|
FramelessWidgetsHelper::FramelessWidgetsHelper(QWidget *q, const WindowLayout wl) : QObject(q)
|
||||||
{
|
{
|
||||||
Q_ASSERT(q);
|
Q_ASSERT(q);
|
||||||
if (q) {
|
if (q) {
|
||||||
this->q = q;
|
this->q = q;
|
||||||
|
m_windowLayout = wl;
|
||||||
|
initialize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FramelessWidgetsHelper::~FramelessWidgetsHelper() = default;
|
FramelessWidgetsHelper::~FramelessWidgetsHelper() = default;
|
||||||
|
|
||||||
void FramelessWidgetsHelper::initialize()
|
|
||||||
{
|
|
||||||
q->setAttribute(Qt::WA_DontCreateNativeAncestors);
|
|
||||||
q->createWinId();
|
|
||||||
setupInitialUi();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FramelessWidgetsHelper::isNormal() const
|
bool FramelessWidgetsHelper::isNormal() const
|
||||||
{
|
{
|
||||||
return (q->windowState() == Qt::WindowNoState);
|
return (q->windowState() == Qt::WindowNoState);
|
||||||
|
@ -227,6 +222,13 @@ void FramelessWidgetsHelper::mouseDoubleClickEventHandler(QMouseEvent *event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FramelessWidgetsHelper::initialize()
|
||||||
|
{
|
||||||
|
q->setAttribute(Qt::WA_DontCreateNativeAncestors);
|
||||||
|
q->createWinId();
|
||||||
|
setupInitialUi();
|
||||||
|
}
|
||||||
|
|
||||||
void FramelessWidgetsHelper::setupFramelessHelperOnce()
|
void FramelessWidgetsHelper::setupFramelessHelperOnce()
|
||||||
{
|
{
|
||||||
if (m_framelessHelperInited) {
|
if (m_framelessHelperInited) {
|
||||||
|
@ -247,11 +249,9 @@ void FramelessWidgetsHelper::setupFramelessHelperOnce()
|
||||||
|
|
||||||
void FramelessWidgetsHelper::createSystemTitleBar()
|
void FramelessWidgetsHelper::createSystemTitleBar()
|
||||||
{
|
{
|
||||||
if (m_systemTitleBarWidget) {
|
if (isCustomWindow()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
static constexpr const QSize systemButtonSize = {int(qRound(qreal(kDefaultTitleBarHeight) * 1.5)), kDefaultTitleBarHeight};
|
|
||||||
static constexpr const QSize systemButtonIconSize = {16, 16};
|
|
||||||
m_systemTitleBarWidget = new QWidget(q);
|
m_systemTitleBarWidget = new QWidget(q);
|
||||||
m_systemTitleBarWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
m_systemTitleBarWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||||
m_systemTitleBarWidget->setFixedHeight(kDefaultTitleBarHeight);
|
m_systemTitleBarWidget->setFixedHeight(kDefaultTitleBarHeight);
|
||||||
|
@ -263,13 +263,13 @@ void FramelessWidgetsHelper::createSystemTitleBar()
|
||||||
m_systemWindowTitleLabel->setText(q->windowTitle());
|
m_systemWindowTitleLabel->setText(q->windowTitle());
|
||||||
connect(q, &FramelessWidget::windowTitleChanged, m_systemWindowTitleLabel, &QLabel::setText);
|
connect(q, &FramelessWidget::windowTitleChanged, m_systemWindowTitleLabel, &QLabel::setText);
|
||||||
m_systemMinimizeButton = new QPushButton(m_systemTitleBarWidget);
|
m_systemMinimizeButton = new QPushButton(m_systemTitleBarWidget);
|
||||||
m_systemMinimizeButton->setFixedSize(systemButtonSize);
|
m_systemMinimizeButton->setFixedSize(kDefaultSystemButtonSize);
|
||||||
m_systemMinimizeButton->setIconSize(systemButtonIconSize);
|
m_systemMinimizeButton->setIconSize(kDefaultSystemButtonIconSize);
|
||||||
m_systemMinimizeButton->setToolTip(tr("Minimize"));
|
m_systemMinimizeButton->setToolTip(tr("Minimize"));
|
||||||
connect(m_systemMinimizeButton, &QPushButton::clicked, q, &FramelessWidget::showMinimized);
|
connect(m_systemMinimizeButton, &QPushButton::clicked, q, &FramelessWidget::showMinimized);
|
||||||
m_systemMaximizeButton = new QPushButton(m_systemTitleBarWidget);
|
m_systemMaximizeButton = new QPushButton(m_systemTitleBarWidget);
|
||||||
m_systemMaximizeButton->setFixedSize(systemButtonSize);
|
m_systemMaximizeButton->setFixedSize(kDefaultSystemButtonSize);
|
||||||
m_systemMaximizeButton->setIconSize(systemButtonIconSize);
|
m_systemMaximizeButton->setIconSize(kDefaultSystemButtonIconSize);
|
||||||
m_systemMaximizeButton->setToolTip(tr("Maximize"));
|
m_systemMaximizeButton->setToolTip(tr("Maximize"));
|
||||||
connect(m_systemMaximizeButton, &QPushButton::clicked, this, [this](){
|
connect(m_systemMaximizeButton, &QPushButton::clicked, this, [this](){
|
||||||
if (isZoomed()) {
|
if (isZoomed()) {
|
||||||
|
@ -280,8 +280,8 @@ void FramelessWidgetsHelper::createSystemTitleBar()
|
||||||
updateSystemButtonsIcon();
|
updateSystemButtonsIcon();
|
||||||
});
|
});
|
||||||
m_systemCloseButton = new QPushButton(m_systemTitleBarWidget);
|
m_systemCloseButton = new QPushButton(m_systemTitleBarWidget);
|
||||||
m_systemCloseButton->setFixedSize(systemButtonSize);
|
m_systemCloseButton->setFixedSize(kDefaultSystemButtonSize);
|
||||||
m_systemCloseButton->setIconSize(systemButtonIconSize);
|
m_systemCloseButton->setIconSize(kDefaultSystemButtonIconSize);
|
||||||
m_systemCloseButton->setToolTip(tr("Close"));
|
m_systemCloseButton->setToolTip(tr("Close"));
|
||||||
connect(m_systemCloseButton, &QPushButton::clicked, q, &FramelessWidget::close);
|
connect(m_systemCloseButton, &QPushButton::clicked, q, &FramelessWidget::close);
|
||||||
updateSystemButtonsIcon();
|
updateSystemButtonsIcon();
|
||||||
|
@ -299,7 +299,7 @@ void FramelessWidgetsHelper::createSystemTitleBar()
|
||||||
|
|
||||||
void FramelessWidgetsHelper::createUserContentContainer()
|
void FramelessWidgetsHelper::createUserContentContainer()
|
||||||
{
|
{
|
||||||
if (isMainWindow()) {
|
if (isCustomWindow() || isMainWindow()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_userContentContainerWidget = new QWidget(q);
|
m_userContentContainerWidget = new QWidget(q);
|
||||||
|
@ -312,8 +312,10 @@ void FramelessWidgetsHelper::createUserContentContainer()
|
||||||
|
|
||||||
void FramelessWidgetsHelper::setupInitialUi()
|
void FramelessWidgetsHelper::setupInitialUi()
|
||||||
{
|
{
|
||||||
|
if (isStandardWindow()) {
|
||||||
createSystemTitleBar();
|
createSystemTitleBar();
|
||||||
if (isMainWindow()) {
|
if (isMainWindow()) {
|
||||||
|
// ### TODO
|
||||||
} else {
|
} else {
|
||||||
createUserContentContainer();
|
createUserContentContainer();
|
||||||
m_mainLayout = new QVBoxLayout(q);
|
m_mainLayout = new QVBoxLayout(q);
|
||||||
|
@ -324,6 +326,7 @@ void FramelessWidgetsHelper::setupInitialUi()
|
||||||
q->setLayout(m_mainLayout);
|
q->setLayout(m_mainLayout);
|
||||||
}
|
}
|
||||||
updateSystemTitleBarStyleSheet();
|
updateSystemTitleBarStyleSheet();
|
||||||
|
}
|
||||||
updateContentsMargins();
|
updateContentsMargins();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,13 +344,15 @@ bool FramelessWidgetsHelper::isInTitleBarDraggableArea(const QPoint &pos) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return region;
|
return region;
|
||||||
} else {
|
}
|
||||||
|
if (isStandardWindow()) {
|
||||||
QRegion region = {QRect(QPoint(0, 0), m_systemTitleBarWidget->size())};
|
QRegion region = {QRect(QPoint(0, 0), m_systemTitleBarWidget->size())};
|
||||||
region -= m_systemMinimizeButton->geometry();
|
region -= m_systemMinimizeButton->geometry();
|
||||||
region -= m_systemMaximizeButton->geometry();
|
region -= m_systemMaximizeButton->geometry();
|
||||||
region -= m_systemCloseButton->geometry();
|
region -= m_systemCloseButton->geometry();
|
||||||
return region;
|
return region;
|
||||||
}
|
}
|
||||||
|
return {};
|
||||||
}();
|
}();
|
||||||
return draggableRegion.contains(pos);
|
return draggableRegion.contains(pos);
|
||||||
}
|
}
|
||||||
|
@ -369,6 +374,16 @@ bool FramelessWidgetsHelper::isMainWindow() const
|
||||||
return q->inherits(QT_MAINWINDOW_CLASS_NAME);
|
return q->inherits(QT_MAINWINDOW_CLASS_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FramelessWidgetsHelper::isStandardWindow() const
|
||||||
|
{
|
||||||
|
return (m_windowLayout == WindowLayout::Standard);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FramelessWidgetsHelper::isCustomWindow()
|
||||||
|
{
|
||||||
|
return (m_windowLayout == WindowLayout::Custom);
|
||||||
|
}
|
||||||
|
|
||||||
void FramelessWidgetsHelper::updateContentsMargins()
|
void FramelessWidgetsHelper::updateContentsMargins()
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_WINDOWS
|
#ifdef Q_OS_WINDOWS
|
||||||
|
@ -378,6 +393,9 @@ void FramelessWidgetsHelper::updateContentsMargins()
|
||||||
|
|
||||||
void FramelessWidgetsHelper::updateSystemTitleBarStyleSheet()
|
void FramelessWidgetsHelper::updateSystemTitleBarStyleSheet()
|
||||||
{
|
{
|
||||||
|
if (isCustomWindow()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const bool active = q->isActiveWindow();
|
const bool active = q->isActiveWindow();
|
||||||
const bool dark = Utils::shouldAppsUseDarkMode();
|
const bool dark = Utils::shouldAppsUseDarkMode();
|
||||||
const bool colorizedTitleBar = Utils::isTitleBarColorized();
|
const bool colorizedTitleBar = Utils::isTitleBarColorized();
|
||||||
|
@ -411,6 +429,9 @@ void FramelessWidgetsHelper::updateSystemTitleBarStyleSheet()
|
||||||
|
|
||||||
void FramelessWidgetsHelper::updateSystemButtonsIcon()
|
void FramelessWidgetsHelper::updateSystemButtonsIcon()
|
||||||
{
|
{
|
||||||
|
if (isCustomWindow()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const SystemTheme theme = ((Utils::shouldAppsUseDarkMode() || Utils::isTitleBarColorized()) ? SystemTheme::Dark : SystemTheme::Light);
|
const SystemTheme theme = ((Utils::shouldAppsUseDarkMode() || Utils::isTitleBarColorized()) ? SystemTheme::Dark : SystemTheme::Light);
|
||||||
m_systemMinimizeButton->setIcon(qvariant_cast<QIcon>(Utils::getSystemButtonIconResource(SystemButtonType::Minimize, theme, ResourceType::Icon)));
|
m_systemMinimizeButton->setIcon(qvariant_cast<QIcon>(Utils::getSystemButtonIconResource(SystemButtonType::Minimize, theme, ResourceType::Icon)));
|
||||||
if (isZoomed()) {
|
if (isZoomed()) {
|
||||||
|
|
|
@ -45,11 +45,9 @@ class FRAMELESSHELPER_WIDGETS_API FramelessWidgetsHelper : public QObject
|
||||||
Q_DISABLE_COPY_MOVE(FramelessWidgetsHelper)
|
Q_DISABLE_COPY_MOVE(FramelessWidgetsHelper)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit FramelessWidgetsHelper(QWidget *q, QObject *parent = nullptr);
|
explicit FramelessWidgetsHelper(QWidget *q, const WindowLayout wl);
|
||||||
~FramelessWidgetsHelper() override;
|
~FramelessWidgetsHelper() override;
|
||||||
|
|
||||||
Q_INVOKABLE void initialize();
|
|
||||||
|
|
||||||
Q_NODISCARD Q_INVOKABLE bool isNormal() const;
|
Q_NODISCARD Q_INVOKABLE bool isNormal() const;
|
||||||
Q_NODISCARD Q_INVOKABLE bool isZoomed() const;
|
Q_NODISCARD Q_INVOKABLE bool isZoomed() const;
|
||||||
|
|
||||||
|
@ -68,6 +66,7 @@ public:
|
||||||
void mouseDoubleClickEventHandler(QMouseEvent *event);
|
void mouseDoubleClickEventHandler(QMouseEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void initialize();
|
||||||
void setupFramelessHelperOnce();
|
void setupFramelessHelperOnce();
|
||||||
void createSystemTitleBar();
|
void createSystemTitleBar();
|
||||||
void createUserContentContainer();
|
void createUserContentContainer();
|
||||||
|
@ -75,6 +74,8 @@ private:
|
||||||
Q_NODISCARD bool isInTitleBarDraggableArea(const QPoint &pos) const;
|
Q_NODISCARD bool isInTitleBarDraggableArea(const QPoint &pos) const;
|
||||||
Q_NODISCARD bool shouldDrawFrameBorder() const;
|
Q_NODISCARD bool shouldDrawFrameBorder() const;
|
||||||
Q_NODISCARD bool isMainWindow() const;
|
Q_NODISCARD bool isMainWindow() const;
|
||||||
|
Q_NODISCARD bool isStandardWindow() const;
|
||||||
|
Q_NODISCARD bool isCustomWindow();
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void updateContentsMargins();
|
void updateContentsMargins();
|
||||||
|
@ -84,6 +85,7 @@ private Q_SLOTS:
|
||||||
private:
|
private:
|
||||||
QWidget *q = nullptr;
|
QWidget *q = nullptr;
|
||||||
bool m_framelessHelperInited = false;
|
bool m_framelessHelperInited = false;
|
||||||
|
WindowLayout m_windowLayout = WindowLayout::Standard;
|
||||||
QWidget *m_systemTitleBarWidget = nullptr;
|
QWidget *m_systemTitleBarWidget = nullptr;
|
||||||
QLabel *m_systemWindowTitleLabel = nullptr;
|
QLabel *m_systemWindowTitleLabel = nullptr;
|
||||||
QPushButton *m_systemMinimizeButton = nullptr;
|
QPushButton *m_systemMinimizeButton = nullptr;
|
||||||
|
|
Loading…
Reference in New Issue