forked from github_mirror/framelesshelper
Minor tweaks
Amends commit 0759f7f010
Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
parent
0759f7f010
commit
18d883b96a
|
@ -56,6 +56,8 @@ if(TARGET Qt${QT_VERSION_MAJOR}::Widgets)
|
||||||
list(APPEND SOURCES
|
list(APPEND SOURCES
|
||||||
qtacrylicwidget.h
|
qtacrylicwidget.h
|
||||||
qtacrylicwidget.cpp
|
qtacrylicwidget.cpp
|
||||||
|
qtacrylicmainwindow.h
|
||||||
|
qtacrylicmainwindow.cpp
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
if(TARGET Qt${QT_VERSION_MAJOR}::Widgets)
|
if(TARGET Qt${QT_VERSION_MAJOR}::Widgets)
|
||||||
add_subdirectory(widget)
|
add_subdirectory(widget)
|
||||||
|
add_subdirectory(mainwindow)
|
||||||
endif()
|
endif()
|
||||||
if(TARGET Qt${QT_VERSION_MAJOR}::Quick)
|
if(TARGET Qt${QT_VERSION_MAJOR}::Quick)
|
||||||
add_subdirectory(quick)
|
add_subdirectory(quick)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
TEMPLATE = subdirs
|
TEMPLATE = subdirs
|
||||||
CONFIG -= ordered
|
CONFIG -= ordered
|
||||||
qtHaveModule(widgets): SUBDIRS += widget qmainwindow
|
qtHaveModule(widgets): SUBDIRS += widget mainwindow
|
||||||
qtHaveModule(quick): SUBDIRS += quick
|
qtHaveModule(quick): SUBDIRS += quick
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||||
|
|
||||||
|
set(CMAKE_AUTOUIC ON)
|
||||||
|
set(CMAKE_AUTOMOC ON)
|
||||||
|
set(CMAKE_AUTORCC ON)
|
||||||
|
|
||||||
|
find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED)
|
||||||
|
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)
|
||||||
|
|
||||||
|
set(SOURCES
|
||||||
|
../images.qrc
|
||||||
|
TitleBar.ui
|
||||||
|
MainWindow.ui
|
||||||
|
main.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
if(WIN32)
|
||||||
|
enable_language(RC)
|
||||||
|
list(APPEND SOURCES ../windows.rc ../windows.manifest)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_executable(MainWindow WIN32 ${SOURCES})
|
||||||
|
|
||||||
|
target_link_libraries(MainWindow PRIVATE
|
||||||
|
Qt${QT_VERSION_MAJOR}::Widgets
|
||||||
|
wangwenx190::FramelessHelper
|
||||||
|
)
|
||||||
|
|
||||||
|
target_compile_definitions(MainWindow PRIVATE
|
||||||
|
QT_NO_CAST_FROM_ASCII
|
||||||
|
QT_NO_CAST_TO_ASCII
|
||||||
|
QT_NO_KEYWORDS
|
||||||
|
QT_DEPRECATED_WARNINGS
|
||||||
|
QT_DISABLE_DEPRECATED_BEFORE=0x060000
|
||||||
|
)
|
||||||
|
|
||||||
|
if(MSVC)
|
||||||
|
target_compile_options(MainWindow PRIVATE /utf-8)
|
||||||
|
if(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug"))
|
||||||
|
target_compile_options(MainWindow PRIVATE /guard:cf)
|
||||||
|
target_link_options(MainWindow PRIVATE /GUARD:CF)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(WIN32)
|
||||||
|
target_link_libraries(MainWindow PRIVATE user32 shell32 gdi32 dwmapi)
|
||||||
|
endif()
|
|
@ -26,13 +26,10 @@
|
||||||
#include "../../qtacrylicmainwindow.h"
|
#include "../../qtacrylicmainwindow.h"
|
||||||
#include "ui_MainWindow.h"
|
#include "ui_MainWindow.h"
|
||||||
#include "ui_TitleBar.h"
|
#include "ui_TitleBar.h"
|
||||||
#include <QApplication>
|
#include <QtWidgets/qapplication.h>
|
||||||
#include <QStyleOption>
|
#include <QtWidgets/qstyleoption.h>
|
||||||
#include <QWidget>
|
#include <QtWidgets/qwidget.h>
|
||||||
#include <QWindow>
|
#include <QtGui/qwindow.h>
|
||||||
#ifdef WIN32
|
|
||||||
#include <Windows.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
@ -59,7 +56,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
QApplication application(argc, argv);
|
QApplication application(argc, argv);
|
||||||
|
|
||||||
QtAcrylicMainWindow *mainWindow = new QtAcrylicMainWindow(NULL, Qt::WindowFlags());
|
QtAcrylicMainWindow *mainWindow = new QtAcrylicMainWindow;
|
||||||
mainWindow->setAcrylicEnabled(true);
|
mainWindow->setAcrylicEnabled(true);
|
||||||
|
|
||||||
Ui::MainWindow appMainWindow;
|
Ui::MainWindow appMainWindow;
|
||||||
|
@ -74,31 +71,22 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
mainWindow->setMenuWidget(widget);
|
mainWindow->setMenuWidget(widget);
|
||||||
|
|
||||||
QObject::connect(mainWindow,
|
QObject::connect(mainWindow, &QMainWindow::windowIconChanged, titleBarWidget.iconButton, &QPushButton::setIcon);
|
||||||
&QMainWindow::windowIconChanged,
|
QObject::connect(mainWindow, &QMainWindow::windowTitleChanged, titleBarWidget.titleLabel, &QLabel::setText);
|
||||||
titleBarWidget.iconButton,
|
QObject::connect(titleBarWidget.closeButton, &QPushButton::clicked, mainWindow, &QMainWindow::close);
|
||||||
&QPushButton::setIcon);
|
QObject::connect(titleBarWidget.minimizeButton, &QPushButton::clicked, mainWindow, &QMainWindow::showMinimized);
|
||||||
QObject::connect(mainWindow,
|
QObject::connect(titleBarWidget.maximizeButton, &QPushButton::clicked, [mainWindow](){
|
||||||
&QMainWindow::windowTitleChanged,
|
if (mainWindow->isMaximized() || mainWindow->isFullScreen()) {
|
||||||
titleBarWidget.titleLabel,
|
mainWindow->showNormal();
|
||||||
&QLabel::setText);
|
} else {
|
||||||
QObject::connect(titleBarWidget.closeButton,
|
mainWindow->showMaximized();
|
||||||
&QPushButton::clicked,
|
}
|
||||||
mainWindow,
|
});
|
||||||
&QMainWindow::close);
|
QObject::connect(mainWindow, &QtAcrylicMainWindow::windowStateChanged, [mainWindow, titleBarWidget](){
|
||||||
QObject::connect(titleBarWidget.minimizeButton,
|
titleBarWidget.maximizeButton->setChecked(mainWindow->isMaximized());
|
||||||
&QPushButton::clicked,
|
titleBarWidget.maximizeButton->setToolTip(mainWindow->isMaximized() ? QObject::tr("Restore") : QObject::tr("Maximize"));
|
||||||
mainWindow,
|
});
|
||||||
&QMainWindow::showMinimized);
|
QObject::connect(titleBarWidget.iconButton, &QPushButton::clicked, mainWindow, &QtAcrylicMainWindow::displaySystemMenu);
|
||||||
QObject::connect(titleBarWidget.maximizeButton,
|
|
||||||
&QPushButton::clicked,
|
|
||||||
[mainWindow, titleBarWidget]() {
|
|
||||||
if (mainWindow->isMaximized()) {
|
|
||||||
mainWindow->showNormal();
|
|
||||||
} else {
|
|
||||||
mainWindow->showMaximized();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
QStyleOption option;
|
QStyleOption option;
|
||||||
option.initFrom(mainWindow);
|
option.initFrom(mainWindow);
|
||||||
|
@ -108,19 +96,8 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
mainWindow->createWinId(); // Qt's internal function, make sure it's a top level window.
|
mainWindow->createWinId(); // Qt's internal function, make sure it's a top level window.
|
||||||
const QWindow *win = mainWindow->windowHandle();
|
const QWindow *win = mainWindow->windowHandle();
|
||||||
|
|
||||||
QObject::connect(mainWindow,
|
|
||||||
&QtAcrylicMainWindow::windowStateChanged,
|
|
||||||
[mainWindow, titleBarWidget]() {
|
|
||||||
titleBarWidget.maximizeButton->setChecked(mainWindow->isMaximized());
|
|
||||||
titleBarWidget.maximizeButton->setToolTip(mainWindow->isMaximized() ? QObject::tr("Restore") : QObject::tr("Maximize"));
|
|
||||||
});
|
|
||||||
|
|
||||||
QObject::connect(titleBarWidget.iconButton,
|
|
||||||
&QPushButton::clicked,
|
|
||||||
mainWindow,
|
|
||||||
&QtAcrylicMainWindow::displaySystemMenu);
|
|
||||||
|
|
||||||
|
FramelessWindowsManager::addWindow(win);
|
||||||
FramelessWindowsManager::addIgnoreObject(win, titleBarWidget.iconButton);
|
FramelessWindowsManager::addIgnoreObject(win, titleBarWidget.iconButton);
|
||||||
FramelessWindowsManager::addIgnoreObject(win, titleBarWidget.minimizeButton);
|
FramelessWindowsManager::addIgnoreObject(win, titleBarWidget.minimizeButton);
|
||||||
FramelessWindowsManager::addIgnoreObject(win, titleBarWidget.maximizeButton);
|
FramelessWindowsManager::addIgnoreObject(win, titleBarWidget.maximizeButton);
|
|
@ -1,4 +1,4 @@
|
||||||
TARGET = QMainWindow
|
TARGET = MainWindow
|
||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
QT += widgets
|
QT += widgets
|
||||||
SOURCES += main.cpp
|
SOURCES += main.cpp
|
10
lib.pro
10
lib.pro
|
@ -24,10 +24,12 @@ SOURCES += \
|
||||||
qtacryliceffecthelper.cpp
|
qtacryliceffecthelper.cpp
|
||||||
qtHaveModule(widgets) {
|
qtHaveModule(widgets) {
|
||||||
QT += widgets
|
QT += widgets
|
||||||
HEADERS += qtacrylicwidget.h \
|
HEADERS += \
|
||||||
qtacrylicmainwindow.h
|
qtacrylicwidget.h \
|
||||||
SOURCES += qtacrylicwidget.cpp \
|
qtacrylicmainwindow.h
|
||||||
qtacrylicmainwindow.cpp
|
SOURCES += \
|
||||||
|
qtacrylicwidget.cpp \
|
||||||
|
qtacrylicmainwindow.cpp
|
||||||
}
|
}
|
||||||
qtHaveModule(quick) {
|
qtHaveModule(quick) {
|
||||||
QT += quick
|
QT += quick
|
||||||
|
|
|
@ -24,12 +24,13 @@
|
||||||
|
|
||||||
#include "qtacrylicmainwindow.h"
|
#include "qtacrylicmainwindow.h"
|
||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
#include "framelesswindowsmanager.h"
|
|
||||||
#include <QtCore/qdebug.h>
|
#include <QtCore/qdebug.h>
|
||||||
#include <QtGui/qevent.h>
|
#include <QtGui/qevent.h>
|
||||||
#include <QtGui/qpainter.h>
|
#include <QtGui/qpainter.h>
|
||||||
|
|
||||||
QtAcrylicMainWindow::QtAcrylicMainWindow(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(parent, flags) {}
|
QtAcrylicMainWindow::QtAcrylicMainWindow(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(parent, flags)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
QtAcrylicMainWindow::~QtAcrylicMainWindow() = default;
|
QtAcrylicMainWindow::~QtAcrylicMainWindow() = default;
|
||||||
|
|
||||||
|
@ -150,6 +151,9 @@ void QtAcrylicMainWindow::setAcrylicEnabled(const bool value)
|
||||||
setBackgroundRole(m_acrylicEnabled ? QPalette::Base : QPalette::Window);
|
setBackgroundRole(m_acrylicEnabled ? QPalette::Base : QPalette::Window);
|
||||||
update();
|
update();
|
||||||
Q_EMIT acrylicEnabledChanged();
|
Q_EMIT acrylicEnabledChanged();
|
||||||
|
if (m_acrylicEnabled) {
|
||||||
|
m_acrylicHelper.showWarning();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,7 +162,6 @@ void QtAcrylicMainWindow::showEvent(QShowEvent *event)
|
||||||
QMainWindow::showEvent(event);
|
QMainWindow::showEvent(event);
|
||||||
updateContentMargin();
|
updateContentMargin();
|
||||||
if (!m_inited) {
|
if (!m_inited) {
|
||||||
FramelessWindowsManager::addWindow(windowHandle());
|
|
||||||
m_acrylicHelper.install(windowHandle());
|
m_acrylicHelper.install(windowHandle());
|
||||||
m_acrylicHelper.updateAcrylicBrush(tintColor());
|
m_acrylicHelper.updateAcrylicBrush(tintColor());
|
||||||
connect(&m_acrylicHelper, &QtAcrylicEffectHelper::needsRepaint, this, qOverload<>(&QtAcrylicMainWindow::update));
|
connect(&m_acrylicHelper, &QtAcrylicEffectHelper::needsRepaint, this, qOverload<>(&QtAcrylicMainWindow::update));
|
||||||
|
@ -168,7 +171,8 @@ void QtAcrylicMainWindow::showEvent(QShowEvent *event)
|
||||||
|
|
||||||
void QtAcrylicMainWindow::updateContentMargin()
|
void QtAcrylicMainWindow::updateContentMargin()
|
||||||
{
|
{
|
||||||
const qreal m = isMaximized() ? 0.0 : 1.0 / devicePixelRatioF();
|
const qreal margin = (isMaximized() || isFullScreen()) ? 0.0 : (1.0 / devicePixelRatioF());
|
||||||
|
const int m = qRound(margin);
|
||||||
setContentsMargins(m, m, m, m);
|
setContentsMargins(m, m, m, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,16 +191,16 @@ void QtAcrylicMainWindow::paintEvent(QPaintEvent *event)
|
||||||
|
|
||||||
void QtAcrylicMainWindow::changeEvent(QEvent *event)
|
void QtAcrylicMainWindow::changeEvent(QEvent *event)
|
||||||
{
|
{
|
||||||
if( event->type()==QEvent::WindowStateChange ) {
|
QMainWindow::changeEvent(event);
|
||||||
|
if (event->type() == QEvent::WindowStateChange) {
|
||||||
updateContentMargin();
|
updateContentMargin();
|
||||||
Q_EMIT windowStateChanged();
|
Q_EMIT windowStateChanged();
|
||||||
}
|
}
|
||||||
QMainWindow::changeEvent(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtAcrylicMainWindow::displaySystemMenu()
|
void QtAcrylicMainWindow::displaySystemMenu()
|
||||||
{
|
{
|
||||||
#ifdef WIN32
|
#ifdef Q_OS_WINDOWS
|
||||||
Utilities::displaySystemMenu(windowHandle());
|
Utilities::displaySystemMenu(windowHandle());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ class FRAMELESSHELPER_EXPORT QtAcrylicMainWindow : public QMainWindow
|
||||||
Q_PROPERTY(bool acrylicEnabled READ acrylicEnabled WRITE setAcrylicEnabled NOTIFY acrylicEnabledChanged)
|
Q_PROPERTY(bool acrylicEnabled READ acrylicEnabled WRITE setAcrylicEnabled NOTIFY acrylicEnabledChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit QtAcrylicMainWindow(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags());
|
explicit QtAcrylicMainWindow(QWidget *parent = nullptr, Qt::WindowFlags flags = {});
|
||||||
~QtAcrylicMainWindow() override;
|
~QtAcrylicMainWindow() override;
|
||||||
|
|
||||||
QColor tintColor() const;
|
QColor tintColor() const;
|
||||||
|
@ -61,10 +61,13 @@ public:
|
||||||
|
|
||||||
qreal frameThickness() const;
|
qreal frameThickness() const;
|
||||||
void setFrameThickness(const qreal value);
|
void setFrameThickness(const qreal value);
|
||||||
|
|
||||||
bool acrylicEnabled() const;
|
bool acrylicEnabled() const;
|
||||||
void setAcrylicEnabled(const bool value);
|
void setAcrylicEnabled(const bool value);
|
||||||
|
|
||||||
|
public Q_SLOTS:
|
||||||
|
void displaySystemMenu();
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void tintColorChanged();
|
void tintColorChanged();
|
||||||
void tintOpacityChanged();
|
void tintOpacityChanged();
|
||||||
|
@ -75,18 +78,17 @@ Q_SIGNALS:
|
||||||
void acrylicEnabledChanged();
|
void acrylicEnabledChanged();
|
||||||
void windowStateChanged();
|
void windowStateChanged();
|
||||||
|
|
||||||
public Q_SLOTS:
|
|
||||||
void displaySystemMenu();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void showEvent(QShowEvent *event) override;
|
void showEvent(QShowEvent *event) override;
|
||||||
void paintEvent(QPaintEvent *event) override;
|
void paintEvent(QPaintEvent *event) override;
|
||||||
void changeEvent(QEvent *event) override;
|
void changeEvent(QEvent *event) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void updateContentMargin();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QtAcrylicEffectHelper m_acrylicHelper;
|
QtAcrylicEffectHelper m_acrylicHelper;
|
||||||
bool m_frameVisible = true;
|
bool m_frameVisible = true;
|
||||||
bool m_acrylicEnabled = false;
|
bool m_acrylicEnabled = false;
|
||||||
bool m_inited = false;
|
bool m_inited = false;
|
||||||
void updateContentMargin();
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -73,7 +73,6 @@ Q_SIGNALS:
|
||||||
void frameColorChanged();
|
void frameColorChanged();
|
||||||
void frameThicknessChanged();
|
void frameThicknessChanged();
|
||||||
void acrylicEnabledChanged();
|
void acrylicEnabledChanged();
|
||||||
void windowStateChanged();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void showEvent(QShowEvent *event) override;
|
void showEvent(QShowEvent *event) override;
|
||||||
|
|
Loading…
Reference in New Issue