From a01d640c27f232a1a52a65e869d8a17ae779c3cd Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Mon, 13 Jul 2026 15:59:39 +0800 Subject: [PATCH] refactor: remove frameless window remove frameless window and merge it into mainwindow. because we do not need frameless and transparent window, so most of its functions are removed in previous commits. --- CMakeLists.txt | 2 -- app/framelesswindow.cpp | 36 ------------------------------------ app/framelesswindow.h | 27 --------------------------- app/mainwindow.cpp | 21 ++++++++++++++------- app/mainwindow.h | 6 +++--- 5 files changed, 17 insertions(+), 75 deletions(-) delete mode 100644 app/framelesswindow.cpp delete mode 100644 app/framelesswindow.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c831ba..0b4d3d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,7 +39,6 @@ endif () set (PPIC_CPP_FILES app/main.cpp - app/framelesswindow.cpp app/mainwindow.cpp app/actionmanager.cpp app/graphicsview.cpp @@ -57,7 +56,6 @@ set (PPIC_CPP_FILES ) set (PPIC_HEADER_FILES - app/framelesswindow.h app/mainwindow.h app/actionmanager.h app/graphicsview.h diff --git a/app/framelesswindow.cpp b/app/framelesswindow.cpp deleted file mode 100644 index 70aa5cd..0000000 --- a/app/framelesswindow.cpp +++ /dev/null @@ -1,36 +0,0 @@ -// SPDX-FileCopyrightText: 2022 Gary Wang -// SPDX-FileCopyrightText: 2023 Tad Young -// -// SPDX-License-Identifier: MIT - -#include "framelesswindow.h" - -#include -#include -#include -#include -#include - -FramelessWindow::FramelessWindow(QWidget *parent) - : QWidget(parent) - , m_centralLayout(new QVBoxLayout(this)) -{ - this->setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint); - - // YYC MARK: - // 72 px is the height of Windows Photo Viewer's bottom line. - - // TODO: This value may be declared as a constant. - m_centralLayout->setContentsMargins(QMargins(0, 0, 0, 72)); -} - -void FramelessWindow::setCentralWidget(QWidget *widget) -{ - if (m_centralWidget) { - m_centralLayout->removeWidget(m_centralWidget); - m_centralWidget->deleteLater(); - } - - m_centralLayout->addWidget(widget); - m_centralWidget = widget; -} diff --git a/app/framelesswindow.h b/app/framelesswindow.h deleted file mode 100644 index e0e7624..0000000 --- a/app/framelesswindow.h +++ /dev/null @@ -1,27 +0,0 @@ -// SPDX-FileCopyrightText: 2022 Gary Wang -// -// SPDX-License-Identifier: MIT - -#ifndef FRAMELESSWINDOW_H -#define FRAMELESSWINDOW_H - -#include - -QT_BEGIN_NAMESPACE -class QVBoxLayout; -QT_END_NAMESPACE - -class FramelessWindow : public QWidget -{ - Q_OBJECT -public: - explicit FramelessWindow(QWidget *parent = nullptr); - - void setCentralWidget(QWidget * widget); - -private: - QVBoxLayout * m_centralLayout = nullptr; - QWidget * m_centralWidget = nullptr; // just a pointer, doesn't take the ownership. -}; - -#endif // FRAMELESSWINDOW_H diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp index edcdf87..fdc0d22 100644 --- a/app/mainwindow.cpp +++ b/app/mainwindow.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #ifdef HAVE_QTDBUS #include @@ -46,11 +47,17 @@ using namespace Qt::Literals::StringLiterals; MainWindow::MainWindow(QWidget *parent) - : FramelessWindow(parent) + : QWidget(parent) , m_am(new ActionManager) , m_pm(new PlaylistManager(this)) , m_fileSystemWatcher(new QFileSystemWatcher(this)) { + this->setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint); + m_centralLayout = new QVBoxLayout(this); + // YYC MARK: + // 72 px is the height of Windows Photo Viewer's bottom line. + m_centralLayout->setContentsMargins(QMargins(0, 0, 0, 72)); // TODO: This value may be declared as a constant. + // YYC MARK: // Blumis set original value is 350 x 330. // It is too small for modern device, @@ -65,7 +72,7 @@ MainWindow::MainWindow(QWidget *parent) m_gv = new GraphicsView(this); m_gv->setScene(scene); - this->setCentralWidget(m_gv); + m_centralLayout->addWidget(m_gv); m_nav = new NavigatorView(this); // YYC MARK: @@ -299,7 +306,7 @@ void MainWindow::showEvent(QShowEvent *event) { updateWidgetsPosition(); - return FramelessWindow::showEvent(event); + return QWidget::showEvent(event); } void MainWindow::mouseDoubleClickEvent(QMouseEvent *event) @@ -364,7 +371,7 @@ void MainWindow::wheelEvent(QWheelEvent *event) } event->accept(); } else { - FramelessWindow::wheelEvent(event); + QWidget::wheelEvent(event); } } @@ -372,14 +379,14 @@ void MainWindow::resizeEvent(QResizeEvent *event) { updateWidgetsPosition(); - return FramelessWindow::resizeEvent(event); + return QWidget::resizeEvent(event); } void MainWindow::contextMenuEvent(QContextMenuEvent *event) { m_menu->exec(mapToGlobal(event->pos())); - return FramelessWindow::contextMenuEvent(event); + return QWidget::contextMenuEvent(event); } void MainWindow::dragEnterEvent(QDragEnterEvent *event) @@ -390,7 +397,7 @@ void MainWindow::dragEnterEvent(QDragEnterEvent *event) event->ignore(); } - return FramelessWindow::dragEnterEvent(event); + return QWidget::dragEnterEvent(event); } void MainWindow::dragMoveEvent(QDragMoveEvent *event) diff --git a/app/mainwindow.h b/app/mainwindow.h index 711cfae..1efc72c 100644 --- a/app/mainwindow.h +++ b/app/mainwindow.h @@ -5,14 +5,13 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H -#include "framelesswindow.h" - #include #include #include QT_BEGIN_NAMESPACE class QMenu; +class QVBoxLayout; class QGraphicsView; class QFileSystemWatcher; QT_END_NAMESPACE @@ -22,7 +21,7 @@ class PlaylistManager; class GraphicsView; class NavigatorView; class BottomButtonGroup; -class MainWindow : public FramelessWindow +class MainWindow : public QWidget { Q_OBJECT @@ -104,6 +103,7 @@ private: NavigatorView *m_nav; QMenu *m_menu; + QVBoxLayout * m_centralLayout = nullptr; QFileSystemWatcher *m_fileSystemWatcher; BottomButtonGroup *m_bottomButtonGroup; };