From d536e8c6118966d1af2d906f8457aa0d53958f3d Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Fri, 3 Jul 2026 14:56:54 +0800 Subject: [PATCH] refactor: move prev/next picture button to bottom toolbar. --- app/actionmanager.cpp | 10 ++++++++-- app/actionmanager.h | 1 + app/mainwindow.cpp | 34 +++++----------------------------- app/mainwindow.h | 2 -- 4 files changed, 14 insertions(+), 33 deletions(-) diff --git a/app/actionmanager.cpp b/app/actionmanager.cpp index dc2319a..3de0d7f 100644 --- a/app/actionmanager.cpp +++ b/app/actionmanager.cpp @@ -43,13 +43,13 @@ void ActionManager::setupAction(MainWindow *mainWindow) CREATE_NEW_ICON_ACTION(mainWindow, actionZoomOut, zoom-out); CREATE_NEW_ICON_ACTION(mainWindow, actionToggleCheckerboard, view-background-checkerboard); CREATE_NEW_ICON_ACTION(mainWindow, actionRotateClockwise, object-rotate-right); + CREATE_NEW_ICON_ACTION(mainWindow, actionPrevPicture, go-previous); + CREATE_NEW_ICON_ACTION(mainWindow, actionNextPicture, go-next); #undef CREATE_NEW_ICON_ACTION #define CREATE_NEW_ACTION(w, a) create_action(w, &a, QString(), ACTION_NAME(a)) #define CREATE_NEW_THEMEICON_ACTION(w, a, i) create_action(w, &a, QLatin1String(STRIFY(i)), ACTION_NAME(a), true) CREATE_NEW_ACTION(mainWindow, actionRotateCounterClockwise); - CREATE_NEW_ACTION(mainWindow, actionPrevPicture); - CREATE_NEW_ACTION(mainWindow, actionNextPicture); CREATE_NEW_ACTION(mainWindow, actionTogglePauseAnimation); CREATE_NEW_ACTION(mainWindow, actionAnimationNextFrame); @@ -147,3 +147,9 @@ void ActionManager::setupShortcuts() }); } +void ActionManager::enablePrevNextPictureAction(bool enablePrevPictureAction, bool enableNextPictureAction) +{ + actionPrevPicture->setEnabled(enablePrevPictureAction); + actionNextPicture->setEnabled(enableNextPictureAction); +} + diff --git a/app/actionmanager.h b/app/actionmanager.h index 0497d60..edf0740 100644 --- a/app/actionmanager.h +++ b/app/actionmanager.h @@ -18,6 +18,7 @@ public: void setupAction(MainWindow * mainWindow); void retranslateUi(MainWindow *MainWindow); void setupShortcuts(); + void enablePrevNextPictureAction(bool enablePrevPictureAction, bool enableNextPictureAction); static QIcon loadHidpiIcon(const QString &resp, QSize sz = QSize(32, 32)); diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp index 46db372..3084c85 100644 --- a/app/mainwindow.cpp +++ b/app/mainwindow.cpp @@ -83,22 +83,6 @@ MainWindow::MainWindow(QWidget *parent) connect(m_graphicsView, &GraphicsView::viewportRectChanged, m_gv, &NavigatorView::updateMainViewportRegion); - m_prevButton = new ToolButton(false, m_graphicsView); - m_prevButton->setIconSize(QSize(75, 75)); - m_prevButton->setIconResourcePath(":/icons/go-previous.svg"); - m_prevButton->setVisible(false); - m_prevButton->setOpacity(0, false); - m_nextButton = new ToolButton(false, m_graphicsView); - m_nextButton->setIconSize(QSize(75, 75)); - m_nextButton->setIconResourcePath(":/icons/go-next.svg"); - m_nextButton->setVisible(false); - m_nextButton->setOpacity(0, false); - - connect(m_prevButton, &QAbstractButton::clicked, - this, &MainWindow::galleryPrev); - connect(m_nextButton, &QAbstractButton::clicked, - this, &MainWindow::galleryNext); - m_am->setupAction(this); m_bottomButtonGroup = new BottomButtonGroup({ @@ -106,6 +90,8 @@ MainWindow::MainWindow(QWidget *parent) m_am->actionToggleMaximize, m_am->actionZoomIn, m_am->actionZoomOut, + m_am->actionPrevPicture, + m_am->actionNextPicture, m_am->actionToggleCheckerboard, m_am->actionRotateClockwise }, this); @@ -291,9 +277,6 @@ void MainWindow::enterEvent(QEnterEvent *event) m_bottomButtonGroup->setOpacity(1); m_gv->setOpacity(1); - m_prevButton->setOpacity(1); - m_nextButton->setOpacity(1); - return FramelessWindow::enterEvent(event); } @@ -302,9 +285,6 @@ void MainWindow::leaveEvent(QEvent *event) m_bottomButtonGroup->setOpacity(0); m_gv->setOpacity(0); - m_prevButton->setOpacity(0); - m_nextButton->setOpacity(0); - return FramelessWindow::leaveEvent(event); } @@ -552,9 +532,6 @@ void MainWindow::closeWindow() void MainWindow::updateWidgetsPosition() { - m_prevButton->move(25, (height() - m_prevButton->sizeHint().height()) / 2); - m_nextButton->move(width() - m_nextButton->sizeHint().width() - 25, - (height() - m_prevButton->sizeHint().height()) / 2); m_bottomButtonGroup->move((width() - m_bottomButtonGroup->width()) / 2, height() - m_bottomButtonGroup->height()); m_gv->move(width() - m_gv->width(), height() - m_gv->height()); @@ -851,8 +828,7 @@ void MainWindow::updateGalleryButtonsVisibility() { const int galleryFileCount = m_pm->totalCount(); const bool loopGallery = Settings::instance()->loopGallery(); - m_prevButton->setVisible(galleryFileCount > 1); - m_nextButton->setVisible(galleryFileCount > 1); - m_prevButton->setEnabled(loopGallery || !m_pm->isFirstIndex()); - m_nextButton->setEnabled(loopGallery || !m_pm->isLastIndex()); + m_am->enablePrevNextPictureAction( + galleryFileCount > 1 && (loopGallery || !m_pm->isFirstIndex()), + galleryFileCount > 1 && (loopGallery || !m_pm->isLastIndex())); } diff --git a/app/mainwindow.h b/app/mainwindow.h index 5735b2f..a610255 100644 --- a/app/mainwindow.h +++ b/app/mainwindow.h @@ -111,8 +111,6 @@ private: QPoint m_oldMousePos; QFileSystemWatcher *m_fileSystemWatcher; - ToolButton *m_prevButton; - ToolButton *m_nextButton; GraphicsView *m_graphicsView; NavigatorView *m_gv; BottomButtonGroup *m_bottomButtonGroup;