From 88e0f5513a9a87b3964d5ac89920d2db83f9e857 Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Sat, 30 Jan 2021 20:35:36 +0200 Subject: [PATCH 01/15] Reader: make 3 keyboard shortcuts work with non-Latin layouts MainWindowViewer::keyPressEvent()'s custom matching of these shortcuts does not leverage all the features of standard Qt shortcut matching. As a result, the corresponding actions cannot be triggered when their assigned shortcuts consist of a single Latin letter without modifiers and e.g. Ukrainian keyboard layout is active. Furthermore, some key presses (e.g. Scroll Lock in my customized keyboard layout) set QKeyEvent::key() to 0, which the custom matching considers equal to an unassigned shortcut. So an action without shortcut is triggered by such a key press. Adding these 3 actions to MainWindowViewer and connecting the corresponding slots to their triggered() signals allows to remove the custom matching code and thus eliminates both of its issues. --- YACReader/main_window_viewer.cpp | 38 +++++--------------------------- YACReader/main_window_viewer.h | 2 -- 2 files changed, 6 insertions(+), 34 deletions(-) diff --git a/YACReader/main_window_viewer.cpp b/YACReader/main_window_viewer.cpp index afd6b100..27177daf 100644 --- a/YACReader/main_window_viewer.cpp +++ b/YACReader/main_window_viewer.cpp @@ -1046,36 +1046,6 @@ void MainWindowViewer::disableActions() showFlowAction->setDisabled(true); } -void MainWindowViewer::keyPressEvent(QKeyEvent *event) -{ - // TODO remove unused keys - int _key = event->key(); - Qt::KeyboardModifiers modifiers = event->modifiers(); - - if (modifiers & Qt::ShiftModifier) - _key |= Qt::SHIFT; - if (modifiers & Qt::ControlModifier) - _key |= Qt::CTRL; - if (modifiers & Qt::MetaModifier) - _key |= Qt::META; - if (modifiers & Qt::AltModifier) - _key |= Qt::ALT; - - QKeySequence key(_key); - - if (key == ShortcutsManager::getShortcutsManager().getShortcut(TOGGLE_FULL_SCREEN_ACTION_Y)) { - toggleFullScreen(); - event->accept(); - } else if (key == ShortcutsManager::getShortcutsManager().getShortcut(TOGGLE_TOOL_BARS_ACTION_Y)) { - toggleToolBars(); - event->accept(); - } else if (key == ShortcutsManager::getShortcutsManager().getShortcut(CHANGE_FIT_ACTION_Y)) { - toggleWidthHeight(); - event->accept(); - } else - QWidget::keyPressEvent(event); -} - void MainWindowViewer::mouseDoubleClickEvent(QMouseEvent *event) { if (event->button() == Qt::LeftButton) { @@ -1269,14 +1239,17 @@ void MainWindowViewer::setUpShortcutsManagement() allActions << tmpList; - // keys without actions (General) QAction *toggleFullScreenAction = new QAction(tr("Toggle fullscreen mode"), orphanActions); toggleFullScreenAction->setData(TOGGLE_FULL_SCREEN_ACTION_Y); toggleFullScreenAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(TOGGLE_FULL_SCREEN_ACTION_Y)); + addAction(toggleFullScreenAction); + connect(toggleFullScreenAction, &QAction::triggered, this, &MainWindowViewer::toggleFullScreen); QAction *toggleToolbarsAction = new QAction(tr("Hide/show toolbar"), orphanActions); toggleToolbarsAction->setData(TOGGLE_TOOL_BARS_ACTION_Y); toggleToolbarsAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(TOGGLE_TOOL_BARS_ACTION_Y)); + addAction(toggleToolbarsAction); + connect(toggleToolbarsAction, &QAction::triggered, this, &MainWindowViewer::toggleToolBars); editShortcutsDialog->addActionsGroup(tr("General"), QIcon(":/images/shortcuts_group_general.png"), tmpList = QList() @@ -1324,10 +1297,11 @@ void MainWindowViewer::setUpShortcutsManagement() allActions << tmpList; - // keys without actions auto toggleFitToScreenAction = new QAction(tr("Toggle between fit to width and fit to height"), orphanActions); toggleFitToScreenAction->setData(CHANGE_FIT_ACTION_Y); toggleFitToScreenAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(CHANGE_FIT_ACTION_Y)); + addAction(toggleFitToScreenAction); + connect(toggleFitToScreenAction, &QAction::triggered, this, &MainWindowViewer::toggleWidthHeight); editShortcutsDialog->addActionsGroup(tr("Page adjustement"), QIcon(":/images/shortcuts_group_page.png"), tmpList = QList() diff --git a/YACReader/main_window_viewer.h b/YACReader/main_window_viewer.h index 2c83c054..2608080b 100644 --- a/YACReader/main_window_viewer.h +++ b/YACReader/main_window_viewer.h @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include @@ -165,7 +164,6 @@ private: void getSiblingComics(QString path, QString currentComic); //! Manejadores de evento: - void keyPressEvent(QKeyEvent *event) override; // void resizeEvent(QResizeEvent * event); void mouseDoubleClickEvent(QMouseEvent *event) override; void dropEvent(QDropEvent *event) override; From 133b547e7aa7d62bdd0a1c58ad3324acab7a0e2d Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Sat, 6 Mar 2021 18:13:13 +0200 Subject: [PATCH 02/15] Remove unused *Step* data members from Viewer --- YACReader/viewer.cpp | 3 --- YACReader/viewer.h | 2 -- 2 files changed, 5 deletions(-) diff --git a/YACReader/viewer.cpp b/YACReader/viewer.cpp index 9db26b13..db37a8fb 100644 --- a/YACReader/viewer.cpp +++ b/YACReader/viewer.cpp @@ -34,7 +34,6 @@ Viewer::Viewer(QWidget *parent) wheelStop(false), direction(1), drag(false), - numScrollSteps(22), shouldOpenNext(false), shouldOpenPrevious(false), magnifyingGlassShowed(false), @@ -597,13 +596,11 @@ void Viewer::keyPressEvent(QKeyEvent *event) else*/ if (key == ShortcutsManager::getShortcutsManager().getShortcut(AUTO_SCROLL_FORWARD_ACTION_Y)) { - posByStep = height() / numScrollSteps; nextPos = verticalScrollBar()->sliderPosition() + static_cast((height() * 0.80)); scrollDown(); } else if (key == ShortcutsManager::getShortcutsManager().getShortcut(AUTO_SCROLL_BACKWARD_ACTION_Y)) { - posByStep = height() / numScrollSteps; nextPos = verticalScrollBar()->sliderPosition() - static_cast((height() * 0.80)); scrollUp(); } diff --git a/YACReader/viewer.h b/YACReader/viewer.h index 393815d9..c58439df 100644 --- a/YACReader/viewer.h +++ b/YACReader/viewer.h @@ -119,7 +119,6 @@ private: QPropertyAnimation *verticalScroller; QPropertyAnimation *horizontalScroller; QParallelAnimationGroup *groupScroller; - int posByStep; int nextPos; GoToFlowWidget *goToFlow; QPropertyAnimation *showGoToFlowAnimation; @@ -135,7 +134,6 @@ private: QTimer *hideCursorTimer; int direction; bool drag; - int numScrollSteps; //! Widgets QLabel *content; From feaee915bc11a82e578f773a7de6c424294ffae1 Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Sat, 6 Mar 2021 18:39:01 +0200 Subject: [PATCH 03/15] Extract Viewer::(vertical|horizontal)ScrollStep() --- YACReader/viewer.cpp | 32 ++++++++++++++++++++++---------- YACReader/viewer.h | 3 +++ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/YACReader/viewer.cpp b/YACReader/viewer.cpp index db37a8fb..d024945b 100644 --- a/YACReader/viewer.cpp +++ b/YACReader/viewer.cpp @@ -492,6 +492,18 @@ void Viewer::scrollBackwardVerticalFirst() } } +static constexpr auto relativeScrollStep = 0.80; + +int Viewer::verticalScrollStep() const +{ + return static_cast(height() * relativeScrollStep); +} + +int Viewer::horizontalScrollStep() const +{ + return static_cast(width() * relativeScrollStep); +} + bool Viewer::isEdge(scrollDirection d) { if (d == UP) @@ -509,15 +521,15 @@ void Viewer::scrollZigzag(scrollDirection d1, scrollDirection d2, bool forward) if (!isEdge(d1)) { if (d1 == UP) scrollTo(horizontalScrollBar()->sliderPosition(), - verticalScrollBar()->sliderPosition() - static_cast((height() * 0.80))); + verticalScrollBar()->sliderPosition() - verticalScrollStep()); else if (d1 == DOWN) scrollTo(horizontalScrollBar()->sliderPosition(), - verticalScrollBar()->sliderPosition() + static_cast((height() * 0.80))); + verticalScrollBar()->sliderPosition() + verticalScrollStep()); else if (d1 == LEFT) - scrollTo(horizontalScrollBar()->sliderPosition() - static_cast((width() * 0.80)), + scrollTo(horizontalScrollBar()->sliderPosition() - horizontalScrollStep(), verticalScrollBar()->sliderPosition()); else // d1 == RIGHT - scrollTo(horizontalScrollBar()->sliderPosition() + static_cast((width() * 0.80)), + scrollTo(horizontalScrollBar()->sliderPosition() + horizontalScrollStep(), verticalScrollBar()->sliderPosition()); } else if (!isEdge(d2)) { int x = 0; @@ -533,13 +545,13 @@ void Viewer::scrollZigzag(scrollDirection d1, scrollDirection d2, bool forward) x = horizontalScrollBar()->minimum(); if (d2 == UP) - y = std::max(verticalScrollBar()->sliderPosition() - static_cast((height() * 0.80)), verticalScrollBar()->minimum()); + y = std::max(verticalScrollBar()->sliderPosition() - verticalScrollStep(), verticalScrollBar()->minimum()); else if (d2 == DOWN) - y = std::min(verticalScrollBar()->sliderPosition() + static_cast((height() * 0.80)), verticalScrollBar()->maximum()); + y = std::min(verticalScrollBar()->sliderPosition() + verticalScrollStep(), verticalScrollBar()->maximum()); else if (d2 == LEFT) - x = std::max(horizontalScrollBar()->sliderPosition() - static_cast((width() * 0.80)), horizontalScrollBar()->minimum()); + x = std::max(horizontalScrollBar()->sliderPosition() - horizontalScrollStep(), horizontalScrollBar()->minimum()); else // d2 == RIGHT - x = std::min(horizontalScrollBar()->sliderPosition() + static_cast((width() * 0.80)), horizontalScrollBar()->maximum()); + x = std::min(horizontalScrollBar()->sliderPosition() + horizontalScrollStep(), horizontalScrollBar()->maximum()); scrollTo(x, y); } else { @@ -596,12 +608,12 @@ void Viewer::keyPressEvent(QKeyEvent *event) else*/ if (key == ShortcutsManager::getShortcutsManager().getShortcut(AUTO_SCROLL_FORWARD_ACTION_Y)) { - nextPos = verticalScrollBar()->sliderPosition() + static_cast((height() * 0.80)); + nextPos = verticalScrollBar()->sliderPosition() + verticalScrollStep(); scrollDown(); } else if (key == ShortcutsManager::getShortcutsManager().getShortcut(AUTO_SCROLL_BACKWARD_ACTION_Y)) { - nextPos = verticalScrollBar()->sliderPosition() - static_cast((height() * 0.80)); + nextPos = verticalScrollBar()->sliderPosition() - verticalScrollStep(); scrollUp(); } diff --git a/YACReader/viewer.h b/YACReader/viewer.h index c58439df..7e959511 100644 --- a/YACReader/viewer.h +++ b/YACReader/viewer.h @@ -164,6 +164,9 @@ private: void moveAction(const QKeySequence &key); + int verticalScrollStep() const; + int horizontalScrollStep() const; + //! ZigzagScroll enum scrollDirection { UP, DOWN, From 3bb475b47a98d21ced16c253e92d2a4e93032ae3 Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Sun, 7 Mar 2021 19:01:35 +0200 Subject: [PATCH 04/15] MainWindowViewer: deduplicate enabling/disabling actions --- YACReader/main_window_viewer.cpp | 84 +++++++++++++------------------- YACReader/main_window_viewer.h | 1 + 2 files changed, 35 insertions(+), 50 deletions(-) diff --git a/YACReader/main_window_viewer.cpp b/YACReader/main_window_viewer.cpp index 27177daf..c3b94d60 100644 --- a/YACReader/main_window_viewer.cpp +++ b/YACReader/main_window_viewer.cpp @@ -987,31 +987,7 @@ void MainWindowViewer::saveImage() void MainWindowViewer::enableActions() { - saveImageAction->setDisabled(false); - goToPageOnTheLeftAction->setDisabled(false); - goToPageOnTheRightAction->setDisabled(false); - adjustHeightAction->setDisabled(false); - adjustWidthAction->setDisabled(false); - goToPageAction->setDisabled(false); - // alwaysOnTopAction->setDisabled(false); - leftRotationAction->setDisabled(false); - rightRotationAction->setDisabled(false); - showMagnifyingGlassAction->setDisabled(false); - doublePageAction->setDisabled(false); - doubleMangaPageAction->setDisabled(false); - adjustToFullSizeAction->setDisabled(false); - adjustToFullSizeAction->setDisabled(false); - fitToPageAction->setDisabled(false); - showZoomSliderlAction->setDisabled(false); - increasePageZoomAction->setDisabled(false); - decreasePageZoomAction->setDisabled(false); - resetZoomAction->setDisabled(false); - // setBookmark->setDisabled(false); - showBookmarksAction->setDisabled(false); - showInfoAction->setDisabled(false); // TODO enable goTo and showInfo (or update) when numPages emited - showDictionaryAction->setDisabled(false); - showFlowAction->setDisabled(false); - + setActionsEnabled(true); #ifdef Q_OS_MAC activateWindow(); raise(); @@ -1019,31 +995,11 @@ void MainWindowViewer::enableActions() } void MainWindowViewer::disableActions() { - saveImageAction->setDisabled(true); - goToPageOnTheLeftAction->setDisabled(true); - goToPageOnTheRightAction->setDisabled(true); - adjustHeightAction->setDisabled(true); - adjustWidthAction->setDisabled(true); - goToPageAction->setDisabled(true); - // alwaysOnTopAction->setDisabled(true); - leftRotationAction->setDisabled(true); - rightRotationAction->setDisabled(true); - showMagnifyingGlassAction->setDisabled(true); - doublePageAction->setDisabled(true); - doubleMangaPageAction->setDisabled(true); - adjustToFullSizeAction->setDisabled(true); - fitToPageAction->setDisabled(true); - showZoomSliderlAction->setDisabled(true); - increasePageZoomAction->setDisabled(true); - decreasePageZoomAction->setDisabled(true); - resetZoomAction->setDisabled(true); - setBookmarkAction->setDisabled(true); - showBookmarksAction->setDisabled(true); - showInfoAction->setDisabled(true); // TODO enable goTo and showInfo (or update) when numPages emited - openComicOnTheLeftAction->setDisabled(true); - openComicOnTheRightAction->setDisabled(true); - showDictionaryAction->setDisabled(true); - showFlowAction->setDisabled(true); + setActionsEnabled(false); + for (auto *a : { setBookmarkAction, + openComicOnTheLeftAction, + openComicOnTheRightAction }) + a->setEnabled(false); } void MainWindowViewer::mouseDoubleClickEvent(QMouseEvent *event) @@ -1582,6 +1538,34 @@ void MainWindowViewer::getSiblingComics(QString path, QString currentComic) updatePrevNextActions(index > 0, index + 1 < list.count()); } +void MainWindowViewer::setActionsEnabled(bool enabled) +{ + // TODO enable goTo and showInfo (or update) when numPages emited + const auto actions = { saveImageAction, + goToPageOnTheLeftAction, + goToPageOnTheRightAction, + adjustHeightAction, + adjustWidthAction, + goToPageAction, + leftRotationAction, + rightRotationAction, + showMagnifyingGlassAction, + doublePageAction, + doubleMangaPageAction, + adjustToFullSizeAction, + fitToPageAction, + showZoomSliderlAction, + increasePageZoomAction, + decreasePageZoomAction, + resetZoomAction, + showBookmarksAction, + showInfoAction, + showDictionaryAction, + showFlowAction }; + for (auto *a : actions) + a->setEnabled(enabled); +} + void MainWindowViewer::dropEvent(QDropEvent *event) { QList urlList; diff --git a/YACReader/main_window_viewer.h b/YACReader/main_window_viewer.h index 2608080b..01830a10 100644 --- a/YACReader/main_window_viewer.h +++ b/YACReader/main_window_viewer.h @@ -162,6 +162,7 @@ private: void refreshRecentFilesActionList(); void clearRecentFiles(); void getSiblingComics(QString path, QString currentComic); + void setActionsEnabled(bool enabled); //! Manejadores de evento: // void resizeEvent(QResizeEvent * event); From b3c99823ebb07be89199407bf6d688308d34e9bd Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Sun, 7 Mar 2021 19:24:59 +0200 Subject: [PATCH 05/15] MainWindowViewer::createActions(): deduplicate setDisabled --- YACReader/main_window_viewer.cpp | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/YACReader/main_window_viewer.cpp b/YACReader/main_window_viewer.cpp index c3b94d60..9d2fe02b 100644 --- a/YACReader/main_window_viewer.cpp +++ b/YACReader/main_window_viewer.cpp @@ -179,6 +179,7 @@ void MainWindowViewer::setupUI() createActions(); setUpShortcutsManagement(); + disableActions(); createToolBars(); @@ -268,7 +269,6 @@ void MainWindowViewer::createActions() saveImageAction = new QAction(tr("Save"), this); saveImageAction->setIcon(QIcon(":/images/viewer_toolbar/save.png")); saveImageAction->setToolTip(tr("Save current page")); - saveImageAction->setDisabled(true); saveImageAction->setData(SAVE_IMAGE_ACTION_Y); saveImageAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SAVE_IMAGE_ACTION_Y)); connect(saveImageAction, &QAction::triggered, this, &MainWindowViewer::saveImage); @@ -276,7 +276,6 @@ void MainWindowViewer::createActions() openComicOnTheLeftAction = new QAction(tr("Previous Comic"), this); openComicOnTheLeftAction->setIcon(QIcon(":/images/viewer_toolbar/openPrevious.png")); openComicOnTheLeftAction->setToolTip(tr("Open previous comic")); - openComicOnTheLeftAction->setDisabled(true); openComicOnTheLeftAction->setData(OPEN_PREVIOUS_COMIC_ACTION_Y); openComicOnTheLeftAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(OPEN_PREVIOUS_COMIC_ACTION_Y)); connect(openComicOnTheLeftAction, &QAction::triggered, this, &MainWindowViewer::openLeftComic); @@ -284,7 +283,6 @@ void MainWindowViewer::createActions() openComicOnTheRightAction = new QAction(tr("Next Comic"), this); openComicOnTheRightAction->setIcon(QIcon(":/images/viewer_toolbar/openNext.png")); openComicOnTheRightAction->setToolTip(tr("Open next comic")); - openComicOnTheRightAction->setDisabled(true); openComicOnTheRightAction->setData(OPEN_NEXT_COMIC_ACTION_Y); openComicOnTheRightAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(OPEN_NEXT_COMIC_ACTION_Y)); connect(openComicOnTheRightAction, &QAction::triggered, this, &MainWindowViewer::openRightComic); @@ -293,7 +291,6 @@ void MainWindowViewer::createActions() goToPageOnTheLeftAction->setIcon(QIcon(":/images/viewer_toolbar/previous.png")); goToPageOnTheLeftAction->setShortcutContext(Qt::WidgetShortcut); goToPageOnTheLeftAction->setToolTip(tr("Go to previous page")); - goToPageOnTheLeftAction->setDisabled(true); goToPageOnTheLeftAction->setData(PREV_ACTION_Y); goToPageOnTheLeftAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(PREV_ACTION_Y)); connect(goToPageOnTheLeftAction, &QAction::triggered, viewer, &Viewer::left); @@ -302,7 +299,6 @@ void MainWindowViewer::createActions() goToPageOnTheRightAction->setIcon(QIcon(":/images/viewer_toolbar/next.png")); goToPageOnTheRightAction->setShortcutContext(Qt::WidgetShortcut); goToPageOnTheRightAction->setToolTip(tr("Go to next page")); - goToPageOnTheRightAction->setDisabled(true); goToPageOnTheRightAction->setData(NEXT_ACTION_Y); goToPageOnTheRightAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(NEXT_ACTION_Y)); connect(goToPageOnTheRightAction, &QAction::triggered, viewer, &Viewer::right); @@ -310,7 +306,6 @@ void MainWindowViewer::createActions() adjustHeightAction = new QAction(tr("Fit Height"), this); adjustHeightAction->setIcon(QIcon(":/images/viewer_toolbar/toHeight.png")); // adjustWidth->setCheckable(true); - adjustHeightAction->setDisabled(true); adjustHeightAction->setToolTip(tr("Fit image to height")); // adjustWidth->setIcon(QIcon(":/images/fitWidth.png")); adjustHeightAction->setData(ADJUST_HEIGHT_ACTION_Y); @@ -321,7 +316,6 @@ void MainWindowViewer::createActions() adjustWidthAction = new QAction(tr("Fit Width"), this); adjustWidthAction->setIcon(QIcon(":/images/viewer_toolbar/toWidth.png")); // adjustWidth->setCheckable(true); - adjustWidthAction->setDisabled(true); adjustWidthAction->setToolTip(tr("Fit image to width")); // adjustWidth->setIcon(QIcon(":/images/fitWidth.png")); adjustWidthAction->setData(ADJUST_WIDTH_ACTION_Y); @@ -332,7 +326,6 @@ void MainWindowViewer::createActions() adjustToFullSizeAction = new QAction(tr("Show full size"), this); adjustToFullSizeAction->setIcon(QIcon(":/images/viewer_toolbar/full.png")); adjustToFullSizeAction->setCheckable(false); - adjustToFullSizeAction->setDisabled(true); adjustToFullSizeAction->setData(ADJUST_TO_FULL_SIZE_ACTION_Y); adjustToFullSizeAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(ADJUST_TO_FULL_SIZE_ACTION_Y)); adjustToFullSizeAction->setCheckable(true); @@ -340,7 +333,6 @@ void MainWindowViewer::createActions() fitToPageAction = new QAction(tr("Fit to page"), this); fitToPageAction->setIcon(QIcon(":/images/viewer_toolbar/fitToPage.png")); - fitToPageAction->setDisabled(true); fitToPageAction->setData(FIT_TO_PAGE_ACTION_Y); fitToPageAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(FIT_TO_PAGE_ACTION_Y)); fitToPageAction->setCheckable(true); @@ -371,37 +363,31 @@ void MainWindowViewer::createActions() } resetZoomAction = new QAction(tr("Reset zoom"), this); - resetZoomAction->setDisabled(true); resetZoomAction->setData(RESET_ZOOM_ACTION_Y); resetZoomAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(RESET_ZOOM_ACTION_Y)); connect(resetZoomAction, &QAction::triggered, this, &MainWindowViewer::resetZoomLevel); showZoomSliderlAction = new QAction(tr("Show zoom slider"), this); showZoomSliderlAction->setIcon(QIcon(":/images/viewer_toolbar/zoom.png")); - showZoomSliderlAction->setDisabled(true); increasePageZoomAction = new QAction(tr("Zoom+"), this); - increasePageZoomAction->setDisabled(true); increasePageZoomAction->setData(ZOOM_PLUS_ACTION_Y); increasePageZoomAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(ZOOM_PLUS_ACTION_Y)); connect(increasePageZoomAction, &QAction::triggered, this, &MainWindowViewer::increasePageZoomLevel); decreasePageZoomAction = new QAction(tr("Zoom-"), this); - decreasePageZoomAction->setDisabled(true); decreasePageZoomAction->setData(ZOOM_MINUS_ACTION_Y); decreasePageZoomAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(ZOOM_MINUS_ACTION_Y)); connect(decreasePageZoomAction, &QAction::triggered, this, &MainWindowViewer::decreasePageZoomLevel); leftRotationAction = new QAction(tr("Rotate image to the left"), this); leftRotationAction->setIcon(QIcon(":/images/viewer_toolbar/rotateL.png")); - leftRotationAction->setDisabled(true); leftRotationAction->setData(LEFT_ROTATION_ACTION_Y); leftRotationAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(LEFT_ROTATION_ACTION_Y)); connect(leftRotationAction, &QAction::triggered, viewer, &Viewer::rotateLeft); rightRotationAction = new QAction(tr("Rotate image to the right"), this); rightRotationAction->setIcon(QIcon(":/images/viewer_toolbar/rotateR.png")); - rightRotationAction->setDisabled(true); rightRotationAction->setData(RIGHT_ROTATION_ACTION_Y); rightRotationAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(RIGHT_ROTATION_ACTION_Y)); connect(rightRotationAction, &QAction::triggered, viewer, &Viewer::rotateRight); @@ -409,7 +395,6 @@ void MainWindowViewer::createActions() doublePageAction = new QAction(tr("Double page mode"), this); doublePageAction->setToolTip(tr("Switch to double page mode")); doublePageAction->setIcon(QIcon(":/images/viewer_toolbar/doublePage.png")); - doublePageAction->setDisabled(true); doublePageAction->setCheckable(true); doublePageAction->setChecked(Configuration::getConfiguration().getDoublePage()); doublePageAction->setData(DOUBLE_PAGE_ACTION_Y); @@ -420,7 +405,6 @@ void MainWindowViewer::createActions() doubleMangaPageAction = new QAction(tr("Double page manga mode"), this); doubleMangaPageAction->setToolTip(tr("Reverse reading order in double page mode")); doubleMangaPageAction->setIcon(QIcon(":/images/viewer_toolbar/doubleMangaPage.png")); - doubleMangaPageAction->setDisabled(true); doubleMangaPageAction->setCheckable(true); doubleMangaPageAction->setChecked(Configuration::getConfiguration().getDoubleMangaPage()); doubleMangaPageAction->setData(DOUBLE_MANGA_PAGE_ACTION_Y); @@ -430,7 +414,6 @@ void MainWindowViewer::createActions() goToPageAction = new QAction(tr("Go To"), this); goToPageAction->setIcon(QIcon(":/images/viewer_toolbar/goto.png")); - goToPageAction->setDisabled(true); goToPageAction->setToolTip(tr("Go to page ...")); goToPageAction->setData(GO_TO_PAGE_ACTION_Y); goToPageAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(GO_TO_PAGE_ACTION_Y)); @@ -454,7 +437,6 @@ void MainWindowViewer::createActions() showMagnifyingGlassAction = new QAction(tr("Magnifying glass"), this); showMagnifyingGlassAction->setToolTip(tr("Switch Magnifying glass")); showMagnifyingGlassAction->setIcon(QIcon(":/images/viewer_toolbar/magnifyingGlass.png")); - showMagnifyingGlassAction->setDisabled(true); showMagnifyingGlassAction->setCheckable(true); showMagnifyingGlassAction->setData(SHOW_MAGNIFYING_GLASS_ACTION_Y); showMagnifyingGlassAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SHOW_MAGNIFYING_GLASS_ACTION_Y)); @@ -463,7 +445,6 @@ void MainWindowViewer::createActions() setBookmarkAction = new QAction(tr("Set bookmark"), this); setBookmarkAction->setToolTip(tr("Set a bookmark on the current page")); setBookmarkAction->setIcon(QIcon(":/images/viewer_toolbar/bookmark.png")); - setBookmarkAction->setDisabled(true); setBookmarkAction->setCheckable(true); setBookmarkAction->setData(SET_BOOKMARK_ACTION_Y); setBookmarkAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SET_BOOKMARK_ACTION_Y)); @@ -474,7 +455,6 @@ void MainWindowViewer::createActions() showBookmarksAction = new QAction(tr("Show bookmarks"), this); showBookmarksAction->setToolTip(tr("Show the bookmarks of the current comic")); showBookmarksAction->setIcon(QIcon(":/images/viewer_toolbar/showBookmarks.png")); - showBookmarksAction->setDisabled(true); showBookmarksAction->setData(SHOW_BOOKMARKS_ACTION_Y); showBookmarksAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SHOW_BOOKMARKS_ACTION_Y)); connect(showBookmarksAction, &QAction::triggered, viewer->getBookmarksDialog(), &QWidget::show); @@ -488,7 +468,6 @@ void MainWindowViewer::createActions() showInfoAction = new QAction(tr("Show Info"), this); showInfoAction->setIcon(QIcon(":/images/viewer_toolbar/info.png")); - showInfoAction->setDisabled(true); showInfoAction->setData(SHOW_INFO_ACTION_Y); showInfoAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SHOW_INFO_ACTION_Y)); connect(showInfoAction, &QAction::triggered, viewer, &Viewer::informationSwitch); @@ -502,7 +481,6 @@ void MainWindowViewer::createActions() showDictionaryAction = new QAction(tr("Show Dictionary"), this); showDictionaryAction->setIcon(QIcon(":/images/viewer_toolbar/translator.png")); // showDictionaryAction->setCheckable(true); - showDictionaryAction->setDisabled(true); showDictionaryAction->setData(SHOW_DICTIONARY_ACTION_Y); showDictionaryAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SHOW_DICTIONARY_ACTION_Y)); connect(showDictionaryAction, &QAction::triggered, viewer, &Viewer::translatorSwitch); @@ -519,7 +497,6 @@ void MainWindowViewer::createActions() showFlowAction = new QAction(tr("Show go to flow"), this); showFlowAction->setIcon(QIcon(":/images/viewer_toolbar/flow.png")); - showFlowAction->setDisabled(true); showFlowAction->setData(SHOW_FLOW_ACTION_Y); showFlowAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SHOW_FLOW_ACTION_Y)); connect(showFlowAction, &QAction::triggered, viewer, &Viewer::goToFlowSwitch); From f030a7fb0c4740471665c9fdb6eab960ae47a5c1 Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Sun, 7 Mar 2021 20:08:43 +0200 Subject: [PATCH 06/15] Remove deprecated and always disabled alwaysOnTopAction --- YACReader/configuration.cpp | 2 -- YACReader/configuration.h | 2 -- YACReader/main_window_viewer.cpp | 30 +--------------------- YACReader/main_window_viewer.h | 3 --- common/yacreader_global_gui.h | 1 - shortcuts_management/shortcuts_manager.cpp | 1 - shortcuts_management/shortcuts_manager.h | 1 - 7 files changed, 1 insertion(+), 39 deletions(-) diff --git a/YACReader/configuration.cpp b/YACReader/configuration.cpp index d45e945b..68a9d173 100644 --- a/YACReader/configuration.cpp +++ b/YACReader/configuration.cpp @@ -41,8 +41,6 @@ void Configuration::load(QSettings *settings) settings->setValue(DOUBLE_PAGE, false); if (!settings->contains(BACKGROUND_COLOR)) settings->setValue(BACKGROUND_COLOR, QColor(40, 40, 40)); - if (!settings->contains(ALWAYS_ON_TOP)) - settings->setValue(ALWAYS_ON_TOP, false); if (!settings->contains(SHOW_TOOLBARS)) settings->setValue(SHOW_TOOLBARS, true); if (!settings->contains(QUICK_NAVI_MODE)) diff --git a/YACReader/configuration.h b/YACReader/configuration.h index 513f129d..3c4649ea 100644 --- a/YACReader/configuration.h +++ b/YACReader/configuration.h @@ -69,8 +69,6 @@ public: QColor getBackgroundColor() { return settings->value(BACKGROUND_COLOR).value(); } void setBackgroundColor(const QColor &color) { settings->value(BACKGROUND_COLOR, color); } - bool getAlwaysOnTop() { return settings->value(ALWAYS_ON_TOP).toBool(); } - void setAlwaysOnTop(bool b) { settings->setValue(ALWAYS_ON_TOP, b); } bool getShowToolbars() { return settings->value(SHOW_TOOLBARS).toBool(); } void setShowToolbars(bool b) { settings->setValue(SHOW_TOOLBARS, b); } bool getShowInformation() { return settings->value(SHOW_INFO, false).toBool(); } diff --git a/YACReader/main_window_viewer.cpp b/YACReader/main_window_viewer.cpp index 9d2fe02b..bc6d5e23 100644 --- a/YACReader/main_window_viewer.cpp +++ b/YACReader/main_window_viewer.cpp @@ -70,7 +70,7 @@ public: #endif*/ MainWindowViewer::MainWindowViewer() - : QMainWindow(), fullscreen(false), toolbars(true), alwaysOnTop(false), currentDirectory("."), currentDirectoryImgDest("."), isClient(false) + : QMainWindow(), fullscreen(false), toolbars(true), currentDirectory("."), currentDirectoryImgDest("."), isClient(false) { loadConfiguration(); setupUI(); @@ -118,7 +118,6 @@ MainWindowViewer::~MainWindowViewer() delete showInfoAction; delete closeAction; delete showDictionaryAction; - delete alwaysOnTopAction; delete adjustToFullSizeAction; delete fitToPageAction; delete showFlowAction; @@ -189,11 +188,6 @@ void MainWindowViewer::setupUI() viewer->setFocusPolicy(Qt::StrongFocus); - // if(Configuration::getConfiguration().getAlwaysOnTop()) - //{ - // setWindowFlags(this->windowFlags() | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint); - // } - previousWindowFlags = windowFlags(); previousPos = pos(); previousSize = size(); @@ -485,16 +479,6 @@ void MainWindowViewer::createActions() showDictionaryAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SHOW_DICTIONARY_ACTION_Y)); connect(showDictionaryAction, &QAction::triggered, viewer, &Viewer::translatorSwitch); - // deprecated - alwaysOnTopAction = new QAction(tr("Always on top"), this); - alwaysOnTopAction->setIcon(QIcon(":/images/alwaysOnTop.png")); - alwaysOnTopAction->setCheckable(true); - alwaysOnTopAction->setDisabled(true); - alwaysOnTopAction->setChecked(Configuration::getConfiguration().getAlwaysOnTop()); - alwaysOnTopAction->setData(ALWAYS_ON_TOP_ACTION_Y); - alwaysOnTopAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(ALWAYS_ON_TOP_ACTION_Y)); - connect(alwaysOnTopAction, &QAction::triggered, this, &MainWindowViewer::alwaysOnTopSwitch); - showFlowAction = new QAction(tr("Show go to flow"), this); showFlowAction->setIcon(QIcon(":/images/viewer_toolbar/flow.png")); showFlowAction->setData(SHOW_FLOW_ACTION_Y); @@ -1579,18 +1563,6 @@ void MainWindowViewer::dragEnterEvent(QDragEnterEvent *event) } } -void MainWindowViewer::alwaysOnTopSwitch() -{ - if (!Configuration::getConfiguration().getAlwaysOnTop()) { - setWindowFlags(this->windowFlags() | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint); // always on top - show(); - } else { - setWindowFlags(this->windowFlags() ^ (Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint)); - show(); - } - Configuration::getConfiguration().setAlwaysOnTop(!Configuration::getConfiguration().getAlwaysOnTop()); -} - void MainWindowViewer::adjustToFullSizeSwitch() { Configuration::getConfiguration().setFitMode(YACReader::FitMode::FullRes); diff --git a/YACReader/main_window_viewer.h b/YACReader/main_window_viewer.h index 01830a10..4bfc76c7 100644 --- a/YACReader/main_window_viewer.h +++ b/YACReader/main_window_viewer.h @@ -59,7 +59,6 @@ public slots: void openComic(QString pathFile); void openFolderFromPath(QString pathDir); void openFolderFromPath(QString pathFile, QString atFileName); - void alwaysOnTopSwitch(); void adjustToFullSizeSwitch(); void fitToPageSwitch(); void resetZoomLevel(); @@ -85,7 +84,6 @@ private: //! State bool fullscreen; bool toolbars; - bool alwaysOnTop; bool fromMaximized; // QTBUG-41883 @@ -139,7 +137,6 @@ private: QAction *doubleMangaPageAction; QAction *showShorcutsAction; QAction *showDictionaryAction; - QAction *alwaysOnTopAction; QAction *adjustToFullSizeAction; QAction *fitToPageAction; QAction *resetZoomAction; diff --git a/common/yacreader_global_gui.h b/common/yacreader_global_gui.h index 3c951396..330ff3ac 100644 --- a/common/yacreader_global_gui.h +++ b/common/yacreader_global_gui.h @@ -24,7 +24,6 @@ #define DOUBLE_MANGA_PAGE "DOUBLE_MANGA_PAGE" #define COVER_IS_SP "COVER_IS_SP" #define BACKGROUND_COLOR "BACKGROUND_COLOR" -#define ALWAYS_ON_TOP "ALWAYS_ON_TOP" #define SHOW_TOOLBARS "SHOW_TOOLBARS" #define BRIGHTNESS "BRIGHTNESS" #define CONTRAST "CONTRAST" diff --git a/shortcuts_management/shortcuts_manager.cpp b/shortcuts_management/shortcuts_manager.cpp index b1593611..deb7df9b 100644 --- a/shortcuts_management/shortcuts_manager.cpp +++ b/shortcuts_management/shortcuts_manager.cpp @@ -52,7 +52,6 @@ void ShortcutsManager::initDefaultShorcuts() defaultShorcuts.insert(SHOW_INFO_ACTION_Y, Qt::Key_I); defaultShorcuts.insert(CLOSE_ACTION_Y, Qt::Key_Escape); defaultShorcuts.insert(SHOW_DICTIONARY_ACTION_Y, Qt::Key_T); - defaultShorcuts.insert(ALWAYS_ON_TOP_ACTION_Y, Qt::Key_Q); // deprecated defaultShorcuts.insert(ADJUST_TO_FULL_SIZE_ACTION_Y, Qt::Key_W); defaultShorcuts.insert(SHOW_FLOW_ACTION_Y, Qt::Key_S); defaultShorcuts.insert(ZOOM_PLUS_ACTION_Y, Qt::Key_Plus); diff --git a/shortcuts_management/shortcuts_manager.h b/shortcuts_management/shortcuts_manager.h index 26f751a0..2201296d 100644 --- a/shortcuts_management/shortcuts_manager.h +++ b/shortcuts_management/shortcuts_manager.h @@ -116,7 +116,6 @@ public: #define SHOW_INFO_ACTION_Y "SHOW_INFO_ACTION_Y" #define CLOSE_ACTION_Y "CLOSE_ACTION_Y" #define SHOW_DICTIONARY_ACTION_Y "SHOW_DICTIONARY_ACTION_Y" -#define ALWAYS_ON_TOP_ACTION_Y "ALWAYS_ON_TOP_ACTION_Y" #define ADJUST_TO_FULL_SIZE_ACTION_Y "ADJUST_TO_FULL_SIZE_ACTION_Y" #define FIT_TO_PAGE_ACTION_Y "FIT_TO_PAGE_ACTION_Y" #define SHOW_FLOW_ACTION_Y "SHOW_FLOW_ACTION_Y" From 0fad89dc030a5306191d35b6015f594b01cb37c7 Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Mon, 8 Mar 2021 11:25:01 +0200 Subject: [PATCH 07/15] Simplify code that disables previous/next comic actions --- YACReader/main_window_viewer.cpp | 24 ++++++++++-------------- YACReader/main_window_viewer.h | 1 + 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/YACReader/main_window_viewer.cpp b/YACReader/main_window_viewer.cpp index bc6d5e23..7f0140ce 100644 --- a/YACReader/main_window_viewer.cpp +++ b/YACReader/main_window_viewer.cpp @@ -179,6 +179,7 @@ void MainWindowViewer::setupUI() createActions(); setUpShortcutsManagement(); disableActions(); + disablePreviousNextComicActions(); createToolBars(); @@ -957,9 +958,12 @@ void MainWindowViewer::enableActions() void MainWindowViewer::disableActions() { setActionsEnabled(false); - for (auto *a : { setBookmarkAction, - openComicOnTheLeftAction, - openComicOnTheRightAction }) + setBookmarkAction->setEnabled(false); +} + +void MainWindowViewer::disablePreviousNextComicActions() +{ + for (auto *a : { openComicOnTheLeftAction, openComicOnTheRightAction }) a->setEnabled(false); } @@ -1125,17 +1129,9 @@ void MainWindowViewer::checkNewVersion() void MainWindowViewer::processReset() { - if (isClient) { - if (siblingComics.count() > 1) { - bool openNextB = openComicOnTheRightAction->isEnabled(); - bool openPrevB = openComicOnTheLeftAction->isEnabled(); - disableActions(); - openComicOnTheRightAction->setEnabled(openNextB); - openComicOnTheLeftAction->setEnabled(openPrevB); - } else - disableActions(); - } else - disableActions(); + disableActions(); + if (!isClient || siblingComics.size() <= 1) + disablePreviousNextComicActions(); } void MainWindowViewer::setUpShortcutsManagement() diff --git a/YACReader/main_window_viewer.h b/YACReader/main_window_viewer.h index 4bfc76c7..23c26683 100644 --- a/YACReader/main_window_viewer.h +++ b/YACReader/main_window_viewer.h @@ -45,6 +45,7 @@ public slots: void showToolBars(); void enableActions(); void disableActions(); + void disablePreviousNextComicActions(); void toggleFullScreen(); void toFullScreen(); void toNormal(); From a1bb7735d262c573f7b677d3dedba84ecec8cada Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Sat, 6 Mar 2021 18:48:25 +0200 Subject: [PATCH 08/15] Reader: make 12 keyboard shortcuts work with non-Latin layouts Viewer::keyPressEvent()'s custom matching of these shortcuts is the same as MainWindowViewer::keyPressEvent()'s before the recent commit "Reader: make 3 keyboard shortcuts work with non-Latin layouts". That commit's message details the issues with the custom code. render->hasLoadedComic() condition in Viewer::keyPressEvent() becomes true when Comic::_loaded is set to true. This always happens right after Comic emits its numPages() signal. That is why the 12 fixed actions are now enabled when Viewer emits its comicLoaded() signal, which is connected to Render::numPages, which in turn is connected to Comic::numPages signal. The 12 fixed actions are now disabled when most other actions are disabled: before a comic is opened and on comic opening error. --- YACReader/main_window_viewer.cpp | 49 ++++++++++++----- YACReader/main_window_viewer.h | 3 ++ YACReader/viewer.cpp | 90 +++++++++----------------------- YACReader/viewer.h | 9 +++- 4 files changed, 73 insertions(+), 78 deletions(-) diff --git a/YACReader/main_window_viewer.cpp b/YACReader/main_window_viewer.cpp index 7f0140ce..3cb01319 100644 --- a/YACReader/main_window_viewer.cpp +++ b/YACReader/main_window_viewer.cpp @@ -24,6 +24,8 @@ #include #include +#include + #include #include #include @@ -137,6 +139,7 @@ void MainWindowViewer::setupUI() // setUnifiedTitleAndToolBarOnMac(true); viewer = new Viewer(this); + connect(viewer, &Viewer::comicLoaded, this, [this] { setLoadedComicActionsEnabled(true); }); connect(viewer, &Viewer::reset, this, &MainWindowViewer::processReset); // detected end of comic connect(viewer, &Viewer::openNextComic, this, &MainWindowViewer::openNextComic); @@ -958,6 +961,7 @@ void MainWindowViewer::enableActions() void MainWindowViewer::disableActions() { setActionsEnabled(false); + setLoadedComicActionsEnabled(false); setBookmarkAction->setEnabled(false); } @@ -1236,50 +1240,76 @@ void MainWindowViewer::setUpShortcutsManagement() auto autoScrollForwardAction = new QAction(tr("Autoscroll down"), orphanActions); autoScrollForwardAction->setData(AUTO_SCROLL_FORWARD_ACTION_Y); autoScrollForwardAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(AUTO_SCROLL_FORWARD_ACTION_Y)); + connect(autoScrollForwardAction, &QAction::triggered, viewer, &Viewer::scrollForward); auto autoScrollBackwardAction = new QAction(tr("Autoscroll up"), orphanActions); autoScrollBackwardAction->setData(AUTO_SCROLL_BACKWARD_ACTION_Y); autoScrollBackwardAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(AUTO_SCROLL_BACKWARD_ACTION_Y)); + connect(autoScrollBackwardAction, &QAction::triggered, viewer, &Viewer::scrollBackward); auto autoScrollForwardHorizontalFirstAction = new QAction(tr("Autoscroll forward, horizontal first"), orphanActions); autoScrollForwardHorizontalFirstAction->setData(AUTO_SCROLL_FORWARD_HORIZONTAL_FIRST_ACTION_Y); autoScrollForwardHorizontalFirstAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(AUTO_SCROLL_FORWARD_HORIZONTAL_FIRST_ACTION_Y)); + connect(autoScrollForwardHorizontalFirstAction, &QAction::triggered, viewer, &Viewer::scrollForwardHorizontalFirst); auto autoScrollBackwardHorizontalFirstAction = new QAction(tr("Autoscroll backward, horizontal first"), orphanActions); autoScrollBackwardHorizontalFirstAction->setData(AUTO_SCROLL_BACKWARD_HORIZONTAL_FIRST_ACTION_Y); autoScrollBackwardHorizontalFirstAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(AUTO_SCROLL_BACKWARD_HORIZONTAL_FIRST_ACTION_Y)); + connect(autoScrollBackwardHorizontalFirstAction, &QAction::triggered, viewer, &Viewer::scrollBackwardHorizontalFirst); auto autoScrollForwardVerticalFirstAction = new QAction(tr("Autoscroll forward, vertical first"), orphanActions); autoScrollForwardVerticalFirstAction->setData(AUTO_SCROLL_FORWARD_VERTICAL_FIRST_ACTION_Y); autoScrollForwardVerticalFirstAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(AUTO_SCROLL_FORWARD_VERTICAL_FIRST_ACTION_Y)); + connect(autoScrollForwardVerticalFirstAction, &QAction::triggered, viewer, &Viewer::scrollForwardVerticalFirst); auto autoScrollBackwardVerticalFirstAction = new QAction(tr("Autoscroll backward, vertical first"), orphanActions); autoScrollBackwardVerticalFirstAction->setData(AUTO_SCROLL_BACKWARD_VERTICAL_FIRST_ACTION_Y); autoScrollBackwardVerticalFirstAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(AUTO_SCROLL_BACKWARD_VERTICAL_FIRST_ACTION_Y)); + connect(autoScrollBackwardVerticalFirstAction, &QAction::triggered, viewer, &Viewer::scrollBackwardVerticalFirst); auto moveDownAction = new QAction(tr("Move down"), orphanActions); moveDownAction->setData(MOVE_DOWN_ACTION_Y); moveDownAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(MOVE_DOWN_ACTION_Y)); + connect(moveDownAction, &QAction::triggered, viewer, [this] { viewer->moveView(Qt::Key_Down); }); auto moveUpAction = new QAction(tr("Move up"), orphanActions); moveUpAction->setData(MOVE_UP_ACTION_Y); moveUpAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(MOVE_UP_ACTION_Y)); + connect(moveUpAction, &QAction::triggered, viewer, [this] { viewer->moveView(Qt::Key_Up); }); auto moveLeftAction = new QAction(tr("Move left"), orphanActions); moveLeftAction->setData(MOVE_LEFT_ACTION_Y); moveLeftAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(MOVE_LEFT_ACTION_Y)); + connect(moveLeftAction, &QAction::triggered, viewer, [this] { viewer->moveView(Qt::Key_Left); }); auto moveRightAction = new QAction(tr("Move right"), orphanActions); moveRightAction->setData(MOVE_RIGHT_ACTION_Y); moveRightAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(MOVE_RIGHT_ACTION_Y)); + connect(moveRightAction, &QAction::triggered, viewer, [this] { viewer->moveView(Qt::Key_Right); }); auto goToFirstPageAction = new QAction(tr("Go to the first page"), orphanActions); goToFirstPageAction->setData(GO_TO_FIRST_PAGE_ACTION_Y); goToFirstPageAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(GO_TO_FIRST_PAGE_ACTION_Y)); + connect(goToFirstPageAction, &QAction::triggered, viewer, &Viewer::goToFirstPage); auto goToLastPageAction = new QAction(tr("Go to the last page"), orphanActions); goToLastPageAction->setData(GO_TO_LAST_PAGE_ACTION_Y); goToLastPageAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(GO_TO_LAST_PAGE_ACTION_Y)); + connect(goToLastPageAction, &QAction::triggered, viewer, &Viewer::goToLastPage); + + loadedComicActions = { autoScrollForwardAction, + autoScrollBackwardAction, + autoScrollForwardHorizontalFirstAction, + autoScrollBackwardHorizontalFirstAction, + autoScrollForwardVerticalFirstAction, + autoScrollBackwardVerticalFirstAction, + moveDownAction, + moveUpAction, + moveLeftAction, + moveRightAction, + goToFirstPageAction, + goToLastPageAction }; + addActions(loadedComicActions); editShortcutsDialog->addActionsGroup(tr("Reading"), QIcon(":/images/shortcuts_group_reading.png"), tmpList = QList() @@ -1287,18 +1317,7 @@ void MainWindowViewer::setUpShortcutsManagement() << goToPageOnTheLeftAction << setBookmarkAction << showBookmarksAction - << autoScrollForwardAction - << autoScrollBackwardAction - << autoScrollForwardHorizontalFirstAction - << autoScrollBackwardHorizontalFirstAction - << autoScrollForwardVerticalFirstAction - << autoScrollBackwardVerticalFirstAction - << moveDownAction - << moveUpAction - << moveLeftAction - << moveRightAction - << goToFirstPageAction - << goToLastPageAction + << loadedComicActions << goToPageAction); allActions << tmpList; @@ -1523,6 +1542,12 @@ void MainWindowViewer::setActionsEnabled(bool enabled) a->setEnabled(enabled); } +void MainWindowViewer::setLoadedComicActionsEnabled(bool enabled) +{ + for (auto *a : std::as_const(loadedComicActions)) + a->setEnabled(enabled); +} + void MainWindowViewer::dropEvent(QDropEvent *event) { QList urlList; diff --git a/YACReader/main_window_viewer.h b/YACReader/main_window_viewer.h index 23c26683..54746725 100644 --- a/YACReader/main_window_viewer.h +++ b/YACReader/main_window_viewer.h @@ -148,6 +148,8 @@ private: QAction *showEditShortcutsAction; + QList loadedComicActions; + YACReaderSlider *zoomSliderAction; HttpVersionChecker *versionChecker; @@ -161,6 +163,7 @@ private: void clearRecentFiles(); void getSiblingComics(QString path, QString currentComic); void setActionsEnabled(bool enabled); + void setLoadedComicActionsEnabled(bool enabled); //! Manejadores de evento: // void resizeEvent(QResizeEvent * event); diff --git a/YACReader/viewer.cpp b/YACReader/viewer.cpp index d024945b..edda73de 100644 --- a/YACReader/viewer.cpp +++ b/YACReader/viewer.cpp @@ -178,6 +178,7 @@ void Viewer::createConnections() connect(render, &Render::crcError, this, &Viewer::processCRCError); connect(render, QOverload::of(&Render::numPages), goToFlow, &GoToFlowWidget::setNumSlides); connect(render, QOverload::of(&Render::numPages), goToDialog, &GoToDialog::setNumPages); + connect(render, qOverload(&Render::numPages), this, &Viewer::comicLoaded); connect(render, QOverload::of(&Render::imageLoaded), goToFlow, &GoToFlowWidget::setImageReady); connect(render, &Render::currentPageReady, this, &Viewer::updatePage); connect(render, &Render::processingPage, this, &Viewer::setLoadingMessage); @@ -284,6 +285,14 @@ void Viewer::showGoToDialog() { goToDialog->open(); } +void Viewer::goToFirstPage() +{ + goTo(0); +} +void Viewer::goToLastPage() +{ + goTo(this->render->numPages() - 1); +} void Viewer::goTo(unsigned int page) { direction = 1; // in "go to" direction is always fordward @@ -456,6 +465,18 @@ void Viewer::scrollUp() } } +void Viewer::scrollForward() +{ + nextPos = verticalScrollBar()->sliderPosition() + verticalScrollStep(); + scrollDown(); +} + +void Viewer::scrollBackward() +{ + nextPos = verticalScrollBar()->sliderPosition() - verticalScrollStep(); + scrollUp(); +} + void Viewer::scrollForwardHorizontalFirst() { if (!doubleMangaPage) { @@ -603,54 +624,8 @@ void Viewer::keyPressEvent(QKeyEvent *event) _key |= Qt::ALT; QKeySequence key(_key); - /*if(goToFlow->isVisible() && event->key()!=Qt::Key_S) - QCoreApplication::sendEvent(goToFlow,event); - else*/ - if (key == ShortcutsManager::getShortcutsManager().getShortcut(AUTO_SCROLL_FORWARD_ACTION_Y)) { - nextPos = verticalScrollBar()->sliderPosition() + verticalScrollStep(); - scrollDown(); - } - - else if (key == ShortcutsManager::getShortcutsManager().getShortcut(AUTO_SCROLL_BACKWARD_ACTION_Y)) { - nextPos = verticalScrollBar()->sliderPosition() - verticalScrollStep(); - scrollUp(); - } - - else if (key == ShortcutsManager::getShortcutsManager().getShortcut(AUTO_SCROLL_FORWARD_HORIZONTAL_FIRST_ACTION_Y)) { - scrollForwardHorizontalFirst(); - } - - else if (key == ShortcutsManager::getShortcutsManager().getShortcut(AUTO_SCROLL_BACKWARD_HORIZONTAL_FIRST_ACTION_Y)) { - scrollBackwardHorizontalFirst(); - } - - else if (key == ShortcutsManager::getShortcutsManager().getShortcut(AUTO_SCROLL_FORWARD_VERTICAL_FIRST_ACTION_Y)) { - scrollForwardVerticalFirst(); - } - - else if (key == ShortcutsManager::getShortcutsManager().getShortcut(AUTO_SCROLL_BACKWARD_VERTICAL_FIRST_ACTION_Y)) { - scrollBackwardVerticalFirst(); - } - - else if (key == ShortcutsManager::getShortcutsManager().getShortcut(MOVE_DOWN_ACTION_Y) || - key == ShortcutsManager::getShortcutsManager().getShortcut(MOVE_UP_ACTION_Y) || - key == ShortcutsManager::getShortcutsManager().getShortcut(MOVE_LEFT_ACTION_Y) || - key == ShortcutsManager::getShortcutsManager().getShortcut(MOVE_RIGHT_ACTION_Y)) { - moveAction(key); - emit backgroundChanges(); - } - - else if (key == ShortcutsManager::getShortcutsManager().getShortcut(GO_TO_FIRST_PAGE_ACTION_Y)) { - goTo(0); - } - - else if (key == ShortcutsManager::getShortcutsManager().getShortcut(GO_TO_LAST_PAGE_ACTION_Y)) { - goTo(this->render->numPages() - 1); - } - - else - QAbstractScrollArea::keyPressEvent(event); + QAbstractScrollArea::keyPressEvent(event); if (mglass->isVisible() && (key == ShortcutsManager::getShortcutsManager().getShortcut(SIZE_UP_MGLASS_ACTION_Y) || key == ShortcutsManager::getShortcutsManager().getShortcut(SIZE_DOWN_MGLASS_ACTION_Y) || key == ShortcutsManager::getShortcutsManager().getShortcut(ZOOM_IN_MGLASS_ACTION_Y) || key == ShortcutsManager::getShortcutsManager().getShortcut(ZOOM_OUT_MGLASS_ACTION_Y))) { QCoreApplication::sendEvent(mglass, event); @@ -660,24 +635,11 @@ void Viewer::keyPressEvent(QKeyEvent *event) QAbstractScrollArea::keyPressEvent(event); } -void Viewer::moveAction(const QKeySequence &key) +void Viewer::moveView(Qt::Key directionKey) { - int _key = 0; - - if (key == ShortcutsManager::getShortcutsManager().getShortcut(MOVE_DOWN_ACTION_Y)) - _key = Qt::Key_Down; - - else if (key == ShortcutsManager::getShortcutsManager().getShortcut(MOVE_UP_ACTION_Y)) - _key = Qt::Key_Up; - - else if (key == ShortcutsManager::getShortcutsManager().getShortcut(MOVE_LEFT_ACTION_Y)) - _key = Qt::Key_Left; - - else if (key == ShortcutsManager::getShortcutsManager().getShortcut(MOVE_RIGHT_ACTION_Y)) - _key = Qt::Key_Right; - - QKeyEvent _event = QKeyEvent(QEvent::KeyPress, _key, Qt::NoModifier); - QAbstractScrollArea::keyPressEvent(&_event); + QKeyEvent event(QEvent::KeyPress, directionKey, Qt::NoModifier); + QAbstractScrollArea::keyPressEvent(&event); + emit backgroundChanges(); } static void animateScroll(QPropertyAnimation &scroller, const QScrollBar &scrollBar, int delta) diff --git a/YACReader/viewer.h b/YACReader/viewer.h index 7e959511..ee5bbda9 100644 --- a/YACReader/viewer.h +++ b/YACReader/viewer.h @@ -51,6 +51,8 @@ public slots: void left(); void right(); void showGoToDialog(); + void goToFirstPage(); + void goToLastPage(); void goTo(unsigned int page); void updatePage(); void updateContentSize(); @@ -58,6 +60,8 @@ public slots: void updateOptions(); void scrollDown(); void scrollUp(); + void scrollForward(); + void scrollBackward(); void scrollForwardHorizontalFirst(); void scrollBackwardHorizontalFirst(); void scrollForwardVerticalFirst(); @@ -162,8 +166,6 @@ private: void wheelEvent(QWheelEvent *event) override; void mouseMoveEvent(QMouseEvent *event) override; - void moveAction(const QKeySequence &key); - int verticalScrollStep() const; int horizontalScrollStep() const; @@ -185,10 +187,13 @@ public: // returns the current index starting in 1 [1,nPages] unsigned int getIndex(); void updateComic(ComicDB &comic); + void moveView(Qt::Key directionKey); + signals: void backgroundChanges(); void pageAvailable(bool); void pageIsBookmark(bool); + void comicLoaded(); void reset(); void openNextComic(); void openPreviousComic(); From fdba938fe83ec312c38dd0ac404f40fa4e8c127f Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Mon, 8 Mar 2021 16:28:31 +0200 Subject: [PATCH 09/15] MagnifyingGlass: don't updateImage() needlessly Not all possible keyboard modifiers of a wheel event change MagnifyingGlass's pixmap. So in case of e.g. MetaModifier or more than one modifier, MagnifyingGlass::wheelEvent() calls updateImage() to no avail. Move the updateImage() call into the public slots to make them self-sufficient. This also allows not to call updateImage() when the pixmap is not changed in case the adjusted parameter has reached its minimum or maximum value already. --- YACReader/magnifying_glass.cpp | 30 ++++++++++++++++++++---------- YACReader/magnifying_glass.h | 1 + 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/YACReader/magnifying_glass.cpp b/YACReader/magnifying_glass.cpp index 594a550e..d2b8f458 100644 --- a/YACReader/magnifying_glass.cpp +++ b/YACReader/magnifying_glass.cpp @@ -170,59 +170,70 @@ void MagnifyingGlass::wheelEvent(QWheelEvent *event) else zoomOut(); break; + default: + break; // Never propagate a wheel event to the parent widget, even if we ignore it. } - updateImage(); event->setAccepted(true); } void MagnifyingGlass::zoomIn() { - if (zoomLevel > 0.2f) + if (zoomLevel > 0.2f) { zoomLevel -= 0.025f; + updateImage(); + } } void MagnifyingGlass::zoomOut() { - if (zoomLevel < 0.9f) + if (zoomLevel < 0.9f) { zoomLevel += 0.025f; + updateImage(); + } } void MagnifyingGlass::sizeUp() { auto p = (Viewer *)parent(); if (width() < (p->width() * 0.90f)) - resize(width() + 30, height() + 15); + resizeAndUpdate(width() + 30, height() + 15); } void MagnifyingGlass::sizeDown() { if (width() > 175) - resize(width() - 30, height() - 15); + resizeAndUpdate(width() - 30, height() - 15); } void MagnifyingGlass::heightUp() { auto p = (Viewer *)parent(); if (height() < (p->height() * 0.90f)) - resize(width(), height() + 15); + resizeAndUpdate(width(), height() + 15); } void MagnifyingGlass::heightDown() { if (height() > 80) - resize(width(), height() - 15); + resizeAndUpdate(width(), height() - 15); } void MagnifyingGlass::widthUp() { auto p = (Viewer *)parent(); if (width() < (p->width() * 0.90f)) - resize(width() + 30, height()); + resizeAndUpdate(width() + 30, height()); } void MagnifyingGlass::widthDown() { if (width() > 175) - resize(width() - 30, height()); + resizeAndUpdate(width() - 30, height()); +} + +void MagnifyingGlass::resizeAndUpdate(int w, int h) +{ + resize(w, h); + updateImage(); } void MagnifyingGlass::keyPressEvent(QKeyEvent *event) @@ -264,7 +275,6 @@ void MagnifyingGlass::keyPressEvent(QKeyEvent *event) } if (validKey) { - updateImage(); event->setAccepted(true); } } diff --git a/YACReader/magnifying_glass.h b/YACReader/magnifying_glass.h index c1ca71e3..a0933e3c 100644 --- a/YACReader/magnifying_glass.h +++ b/YACReader/magnifying_glass.h @@ -12,6 +12,7 @@ class MagnifyingGlass : public QLabel private: float zoomLevel; void setup(const QSize &size); + void resizeAndUpdate(int w, int h); void keyPressEvent(QKeyEvent *event) override; public: From efe9a1b99507d742b8c685495480d4934196a59e Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Wed, 10 Mar 2021 14:59:36 +0200 Subject: [PATCH 10/15] MagnifyingGlass: get rid of C-style casts to Viewer* qobject_cast improves const correctness. QLabel::pixmap() is const-qualified => make Viewer::pixmap() const too. Return non-const QPixmap from Viewer::pixmap() to let compiler move the return value at the function's call sites. Introduce a named constant maxRelativeDimension. Change its type from float to double, which usually multiplies faster on x86-64. Remove redundant parentheses to improve readability. --- YACReader/magnifying_glass.cpp | 13 ++++++------- YACReader/viewer.cpp | 2 +- YACReader/viewer.h | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/YACReader/magnifying_glass.cpp b/YACReader/magnifying_glass.cpp index d2b8f458..839b1b6c 100644 --- a/YACReader/magnifying_glass.cpp +++ b/YACReader/magnifying_glass.cpp @@ -36,7 +36,7 @@ void MagnifyingGlass::updateImage(int x, int y) // image section augmented int zoomWidth = static_cast(width() * zoomLevel); int zoomHeight = static_cast(height() * zoomLevel); - auto p = (Viewer *)parent(); + auto *const p = qobject_cast(parentWidget()); int currentPos = p->verticalScrollBar()->sliderPosition(); const QPixmap image = p->pixmap(); int iWidth = image.width(); @@ -191,10 +191,11 @@ void MagnifyingGlass::zoomOut() } } +static constexpr auto maxRelativeDimension = 0.9; + void MagnifyingGlass::sizeUp() { - auto p = (Viewer *)parent(); - if (width() < (p->width() * 0.90f)) + if (width() < parentWidget()->width() * maxRelativeDimension) resizeAndUpdate(width() + 30, height() + 15); } @@ -206,8 +207,7 @@ void MagnifyingGlass::sizeDown() void MagnifyingGlass::heightUp() { - auto p = (Viewer *)parent(); - if (height() < (p->height() * 0.90f)) + if (height() < parentWidget()->height() * maxRelativeDimension) resizeAndUpdate(width(), height() + 15); } @@ -219,8 +219,7 @@ void MagnifyingGlass::heightDown() void MagnifyingGlass::widthUp() { - auto p = (Viewer *)parent(); - if (width() < (p->width() * 0.90f)) + if (width() < parentWidget()->width() * maxRelativeDimension) resizeAndUpdate(width() + 30, height()); } diff --git a/YACReader/viewer.cpp b/YACReader/viewer.cpp index edda73de..4a942df2 100644 --- a/YACReader/viewer.cpp +++ b/YACReader/viewer.cpp @@ -748,7 +748,7 @@ void Viewer::mouseMoveEvent(QMouseEvent *event) } } -const QPixmap Viewer::pixmap() +QPixmap Viewer::pixmap() const { #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) return content->pixmap(); diff --git a/YACReader/viewer.h b/YACReader/viewer.h index ee5bbda9..e86562d5 100644 --- a/YACReader/viewer.h +++ b/YACReader/viewer.h @@ -181,7 +181,7 @@ private: public: Viewer(QWidget *parent = nullptr); ~Viewer(); - const QPixmap pixmap(); + QPixmap pixmap() const; // Comic * getComic(){return comic;} const BookmarksDialog *getBookmarksDialog() { return bd; } // returns the current index starting in 1 [1,nPages] From c8697ccd2d346ba198b85cc64c2a18f1318ae463 Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Wed, 10 Mar 2021 17:16:05 +0200 Subject: [PATCH 11/15] Always limit Magnifying glass's height MagnifyingGlass::sizeUp() and MagnifyingGlass::sizeDown() grow/shrink both width and height, but check only width's limits. Thus the user can first increase Magnifying glass's height, then increase its size and make the height greater than the main window's height. The user can also first increase the width, then decrease the size until the height shrinks to 0 and Magnifying glass disappears. When Magnifying glass disappears, the only way to make it visible again is to restore its default size by restarting YACReader, because the invisible MagnifyingGlass widget does not receive wheel events and Viewer::keyPressEvent() propagates shortcuts to mglass only if it is visible. And even this workaround is possible only because YACReader does not save/restore Magnifying glass's size (should it?). Always checking both width and height limits fixes the bug. If one of the dimensions reaches a limit, only the other dimension is modified. If both dimensions reach their limits, neither is modified. --- YACReader/magnifying_glass.cpp | 74 +++++++++++++++++++++++++++------- YACReader/magnifying_glass.h | 9 +++++ 2 files changed, 69 insertions(+), 14 deletions(-) diff --git a/YACReader/magnifying_glass.cpp b/YACReader/magnifying_glass.cpp index 839b1b6c..9eb628fd 100644 --- a/YACReader/magnifying_glass.cpp +++ b/YACReader/magnifying_glass.cpp @@ -191,42 +191,48 @@ void MagnifyingGlass::zoomOut() } } -static constexpr auto maxRelativeDimension = 0.9; - void MagnifyingGlass::sizeUp() { - if (width() < parentWidget()->width() * maxRelativeDimension) - resizeAndUpdate(width() + 30, height() + 15); + auto w = width(); + auto h = height(); + if (growWidth(w) | growHeight(h)) // bitwise OR prevents short-circuiting + resizeAndUpdate(w, h); } void MagnifyingGlass::sizeDown() { - if (width() > 175) - resizeAndUpdate(width() - 30, height() - 15); + auto w = width(); + auto h = height(); + if (shrinkWidth(w) | shrinkHeight(h)) // bitwise OR prevents short-circuiting + resizeAndUpdate(w, h); } void MagnifyingGlass::heightUp() { - if (height() < parentWidget()->height() * maxRelativeDimension) - resizeAndUpdate(width(), height() + 15); + auto h = height(); + if (growHeight(h)) + resizeAndUpdate(width(), h); } void MagnifyingGlass::heightDown() { - if (height() > 80) - resizeAndUpdate(width(), height() - 15); + auto h = height(); + if (shrinkHeight(h)) + resizeAndUpdate(width(), h); } void MagnifyingGlass::widthUp() { - if (width() < parentWidget()->width() * maxRelativeDimension) - resizeAndUpdate(width() + 30, height()); + auto w = width(); + if (growWidth(w)) + resizeAndUpdate(w, height()); } void MagnifyingGlass::widthDown() { - if (width() > 175) - resizeAndUpdate(width() - 30, height()); + auto w = width(); + if (shrinkWidth(w)) + resizeAndUpdate(w, height()); } void MagnifyingGlass::resizeAndUpdate(int w, int h) @@ -235,6 +241,46 @@ void MagnifyingGlass::resizeAndUpdate(int w, int h) updateImage(); } +static constexpr auto maxRelativeDimension = 0.9; +static constexpr auto widthStep = 30; +static constexpr auto heightStep = 15; + +bool MagnifyingGlass::growWidth(int &w) const +{ + const auto maxWidth = parentWidget()->width() * maxRelativeDimension; + if (w >= maxWidth) + return false; + w += widthStep; + return true; +} + +bool MagnifyingGlass::shrinkWidth(int &w) const +{ + constexpr auto minWidth = 175; + if (w <= minWidth) + return false; + w -= widthStep; + return true; +} + +bool MagnifyingGlass::growHeight(int &h) const +{ + const auto maxHeight = parentWidget()->height() * maxRelativeDimension; + if (h >= maxHeight) + return false; + h += heightStep; + return true; +} + +bool MagnifyingGlass::shrinkHeight(int &h) const +{ + constexpr auto minHeight = 80; + if (h <= minHeight) + return false; + h -= heightStep; + return true; +} + void MagnifyingGlass::keyPressEvent(QKeyEvent *event) { bool validKey = false; diff --git a/YACReader/magnifying_glass.h b/YACReader/magnifying_glass.h index a0933e3c..69bf35f4 100644 --- a/YACReader/magnifying_glass.h +++ b/YACReader/magnifying_glass.h @@ -13,6 +13,15 @@ private: float zoomLevel; void setup(const QSize &size); void resizeAndUpdate(int w, int h); + + // The following 4 functions increase/decrease their argument and return true, + // unless the maximum dimension value has been reached, in which case they + // do not modify the argument and return false. + bool growWidth(int &w) const; + bool shrinkWidth(int &w) const; + bool growHeight(int &h) const; + bool shrinkHeight(int &h) const; + void keyPressEvent(QKeyEvent *event) override; public: From 5254e66da33c188086789b8fb19c73ad013cf74a Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Mon, 8 Mar 2021 17:54:20 +0200 Subject: [PATCH 12/15] Fix a typo in Viewer::magnifyingGlassShowed name Make Viewer::magnifyingGlassIsVisible() const. --- YACReader/viewer.cpp | 14 +++++++------- YACReader/viewer.h | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/YACReader/viewer.cpp b/YACReader/viewer.cpp index 4a942df2..e7c23f90 100644 --- a/YACReader/viewer.cpp +++ b/YACReader/viewer.cpp @@ -36,7 +36,7 @@ Viewer::Viewer(QWidget *parent) drag(false), shouldOpenNext(false), shouldOpenPrevious(false), - magnifyingGlassShowed(false), + magnifyingGlassShown(false), restoreMagnifyingGlass(false) { translator = new YACReaderTranslator(this); @@ -715,7 +715,7 @@ void Viewer::mouseMoveEvent(QMouseEvent *event) showCursor(); hideCursorTimer->start(2500); - if (magnifyingGlassShowed) + if (magnifyingGlassShown) mglass->move(static_cast(event->x() - float(mglass->width()) / 2), static_cast(event->y() - float(mglass->height()) / 2)); if (render->hasLoadedComic()) { @@ -759,7 +759,7 @@ QPixmap Viewer::pixmap() const void Viewer::magnifyingGlassSwitch() { - magnifyingGlassShowed ? hideMagnifyingGlass() : showMagnifyingGlass(); + magnifyingGlassShown ? hideMagnifyingGlass() : showMagnifyingGlass(); } void Viewer::showMagnifyingGlass() @@ -770,14 +770,14 @@ void Viewer::showMagnifyingGlass() mglass->move(static_cast(p.x() - float(mglass->width()) / 2), static_cast(p.y() - float(mglass->height()) / 2)); mglass->show(); mglass->updateImage(mglass->x() + mglass->width() / 2, mglass->y() + mglass->height() / 2); - magnifyingGlassShowed = true; + magnifyingGlassShown = true; } } void Viewer::hideMagnifyingGlass() { mglass->hide(); - magnifyingGlassShowed = false; + magnifyingGlassShown = false; } void Viewer::informationSwitch() @@ -932,7 +932,7 @@ void Viewer::resetContent() void Viewer::setLoadingMessage() { - if (magnifyingGlassShowed) { + if (magnifyingGlassShown) { hideMagnifyingGlass(); restoreMagnifyingGlass = true; } @@ -942,7 +942,7 @@ void Viewer::setLoadingMessage() void Viewer::setPageUnavailableMessage() { - if (magnifyingGlassShowed) { + if (magnifyingGlassShown) { hideMagnifyingGlass(); restoreMagnifyingGlass = true; } diff --git a/YACReader/viewer.h b/YACReader/viewer.h index e86562d5..380ae11e 100644 --- a/YACReader/viewer.h +++ b/YACReader/viewer.h @@ -78,7 +78,7 @@ public slots: void animateHideGoToFlow(); void rotateLeft(); void rotateRight(); - bool magnifyingGlassIsVisible() { return magnifyingGlassShowed; } + bool magnifyingGlassIsVisible() const { return magnifyingGlassShown; } void setBookmark(bool); void save(); void doublePageSwitch(); @@ -157,7 +157,7 @@ private: private: //! Magnifying glass MagnifyingGlass *mglass; - bool magnifyingGlassShowed; + bool magnifyingGlassShown; bool restoreMagnifyingGlass; //! Manejadores de evento: From 24e42f76d2720d3dd77879b93a45cc321f643d13 Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Mon, 8 Mar 2021 17:44:30 +0200 Subject: [PATCH 13/15] Make Magnifying glass shortcuts work with non-Latin layouts Viewer::keyPressEvent()'s and MagnifyingGlass::keyPressEvent()'s custom matching of these shortcuts is the same as MainWindowViewer::keyPressEvent()'s before the recent commit "Reader: make 3 keyboard shortcuts work with non-Latin layouts". That commit's message details the issues with the custom code. The Magnifying glass actions are now enabled/disabled when loadedComicActions are enabled/disabled - for the same reason (see the recent "Reader: make 12 keyboard shortcuts work with non-Latin layouts" commit). In addition, Viewer::keyPressEvent() propagated the Magnifying glass shortcuts to MagnifyingGlass only when it was visible. Therefore showing/hiding Magnifying glass also enables/disables these actions. Note that Viewer::showMagnifyingGlass() shows Magnifying glass only if render->hasLoadedComic() returns true, so MainWindowViewer::setMglassActionsEnabled slot can be connected directly to Viewer::magnifyingGlassVisibilityChanged signal without checking this condition again. --- YACReader/magnifying_glass.cpp | 43 ------------------------------ YACReader/magnifying_glass.h | 2 -- YACReader/main_window_viewer.cpp | 28 +++++++++++++++----- YACReader/main_window_viewer.h | 2 ++ YACReader/viewer.cpp | 45 ++++++++++++-------------------- YACReader/viewer.h | 10 +++++-- 6 files changed, 48 insertions(+), 82 deletions(-) diff --git a/YACReader/magnifying_glass.cpp b/YACReader/magnifying_glass.cpp index 9eb628fd..ce1359db 100644 --- a/YACReader/magnifying_glass.cpp +++ b/YACReader/magnifying_glass.cpp @@ -280,46 +280,3 @@ bool MagnifyingGlass::shrinkHeight(int &h) const h -= heightStep; return true; } - -void MagnifyingGlass::keyPressEvent(QKeyEvent *event) -{ - bool validKey = false; - - int _key = event->key(); - Qt::KeyboardModifiers modifiers = event->modifiers(); - - if (modifiers & Qt::ShiftModifier) - _key |= Qt::SHIFT; - if (modifiers & Qt::ControlModifier) - _key |= Qt::CTRL; - if (modifiers & Qt::MetaModifier) - _key |= Qt::META; - if (modifiers & Qt::AltModifier) - _key |= Qt::ALT; - - QKeySequence key(_key); - - if (key == ShortcutsManager::getShortcutsManager().getShortcut(SIZE_UP_MGLASS_ACTION_Y)) { - sizeUp(); - validKey = true; - } - - else if (key == ShortcutsManager::getShortcutsManager().getShortcut(SIZE_DOWN_MGLASS_ACTION_Y)) { - sizeDown(); - validKey = true; - } - - else if (key == ShortcutsManager::getShortcutsManager().getShortcut(ZOOM_IN_MGLASS_ACTION_Y)) { - zoomIn(); - validKey = true; - } - - else if (key == ShortcutsManager::getShortcutsManager().getShortcut(ZOOM_OUT_MGLASS_ACTION_Y)) { - zoomOut(); - validKey = true; - } - - if (validKey) { - event->setAccepted(true); - } -} diff --git a/YACReader/magnifying_glass.h b/YACReader/magnifying_glass.h index 69bf35f4..77d1462b 100644 --- a/YACReader/magnifying_glass.h +++ b/YACReader/magnifying_glass.h @@ -22,8 +22,6 @@ private: bool growHeight(int &h) const; bool shrinkHeight(int &h) const; - void keyPressEvent(QKeyEvent *event) override; - public: MagnifyingGlass(int width, int height, QWidget *parent); MagnifyingGlass(const QSize &size, QWidget *parent); diff --git a/YACReader/main_window_viewer.cpp b/YACReader/main_window_viewer.cpp index 3cb01319..7b7ca603 100644 --- a/YACReader/main_window_viewer.cpp +++ b/YACReader/main_window_viewer.cpp @@ -139,7 +139,12 @@ void MainWindowViewer::setupUI() // setUnifiedTitleAndToolBarOnMac(true); viewer = new Viewer(this); - connect(viewer, &Viewer::comicLoaded, this, [this] { setLoadedComicActionsEnabled(true); }); + connect(viewer, &Viewer::comicLoaded, this, [this] { + if (viewer->magnifyingGlassIsVisible()) + setMglassActionsEnabled(true); + setLoadedComicActionsEnabled(true); + }); + connect(viewer, &Viewer::magnifyingGlassVisibilityChanged, this, &MainWindowViewer::setMglassActionsEnabled); connect(viewer, &Viewer::reset, this, &MainWindowViewer::processReset); // detected end of comic connect(viewer, &Viewer::openNextComic, this, &MainWindowViewer::openNextComic); @@ -961,6 +966,7 @@ void MainWindowViewer::enableActions() void MainWindowViewer::disableActions() { setActionsEnabled(false); + setMglassActionsEnabled(false); setLoadedComicActionsEnabled(false); setBookmarkAction->setEnabled(false); } @@ -1187,30 +1193,34 @@ void MainWindowViewer::setUpShortcutsManagement() allActions << tmpList; - // keys without actions (MGlass) auto sizeUpMglassAction = new QAction(tr("Size up magnifying glass"), orphanActions); sizeUpMglassAction->setData(SIZE_UP_MGLASS_ACTION_Y); sizeUpMglassAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SIZE_UP_MGLASS_ACTION_Y)); + connect(sizeUpMglassAction, &QAction::triggered, viewer, &Viewer::magnifyingGlassSizeUp); auto sizeDownMglassAction = new QAction(tr("Size down magnifying glass"), orphanActions); sizeDownMglassAction->setData(SIZE_DOWN_MGLASS_ACTION_Y); sizeDownMglassAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SIZE_DOWN_MGLASS_ACTION_Y)); + connect(sizeDownMglassAction, &QAction::triggered, viewer, &Viewer::magnifyingGlassSizeDown); auto zoomInMglassAction = new QAction(tr("Zoom in magnifying glass"), orphanActions); zoomInMglassAction->setData(ZOOM_IN_MGLASS_ACTION_Y); zoomInMglassAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(ZOOM_IN_MGLASS_ACTION_Y)); + connect(zoomInMglassAction, &QAction::triggered, viewer, &Viewer::magnifyingGlassZoomIn); auto zoomOutMglassAction = new QAction(tr("Zoom out magnifying glass"), orphanActions); zoomOutMglassAction->setData(ZOOM_OUT_MGLASS_ACTION_Y); zoomOutMglassAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(ZOOM_OUT_MGLASS_ACTION_Y)); + connect(zoomOutMglassAction, &QAction::triggered, viewer, &Viewer::magnifyingGlassZoomOut); + + mglassActions = { sizeUpMglassAction, sizeDownMglassAction, + zoomInMglassAction, zoomOutMglassAction }; + addActions(mglassActions); editShortcutsDialog->addActionsGroup(tr("Magnifiying glass"), QIcon(":/images/shortcuts_group_mglass.png"), tmpList = QList() << showMagnifyingGlassAction - << sizeUpMglassAction - << sizeDownMglassAction - << zoomInMglassAction - << zoomOutMglassAction); + << mglassActions); allActions << tmpList; @@ -1542,6 +1552,12 @@ void MainWindowViewer::setActionsEnabled(bool enabled) a->setEnabled(enabled); } +void MainWindowViewer::setMglassActionsEnabled(bool enabled) +{ + for (auto *a : std::as_const(mglassActions)) + a->setEnabled(enabled); +} + void MainWindowViewer::setLoadedComicActionsEnabled(bool enabled) { for (auto *a : std::as_const(loadedComicActions)) diff --git a/YACReader/main_window_viewer.h b/YACReader/main_window_viewer.h index 54746725..2b25fb5f 100644 --- a/YACReader/main_window_viewer.h +++ b/YACReader/main_window_viewer.h @@ -148,6 +148,7 @@ private: QAction *showEditShortcutsAction; + QList mglassActions; QList loadedComicActions; YACReaderSlider *zoomSliderAction; @@ -163,6 +164,7 @@ private: void clearRecentFiles(); void getSiblingComics(QString path, QString currentComic); void setActionsEnabled(bool enabled); + void setMglassActionsEnabled(bool enabled); void setLoadedComicActionsEnabled(bool enabled); //! Manejadores de evento: diff --git a/YACReader/viewer.cpp b/YACReader/viewer.cpp index e7c23f90..4894f25b 100644 --- a/YACReader/viewer.cpp +++ b/YACReader/viewer.cpp @@ -20,6 +20,7 @@ #include "opengl_checker.h" #include +#include #include @@ -154,6 +155,11 @@ void Viewer::createConnections() // magnifyingGlass (update mg after a background change connect(this, &Viewer::backgroundChanges, mglass, QOverload<>::of(&MagnifyingGlass::updateImage)); + connect(this, &Viewer::magnifyingGlassSizeUp, mglass, &MagnifyingGlass::sizeUp); + connect(this, &Viewer::magnifyingGlassSizeDown, mglass, &MagnifyingGlass::sizeDown); + connect(this, &Viewer::magnifyingGlassZoomIn, mglass, &MagnifyingGlass::zoomIn); + connect(this, &Viewer::magnifyingGlassZoomOut, mglass, &MagnifyingGlass::zoomOut); + // goToDialog connect(goToDialog, &GoToDialog::goToPage, this, &Viewer::goTo); @@ -608,33 +614,6 @@ void Viewer::scrollTo(int x, int y) emit backgroundChanges(); } -void Viewer::keyPressEvent(QKeyEvent *event) -{ - if (render->hasLoadedComic()) { - int _key = event->key(); - Qt::KeyboardModifiers modifiers = event->modifiers(); - - if (modifiers & Qt::ShiftModifier) - _key |= Qt::SHIFT; - if (modifiers & Qt::ControlModifier) - _key |= Qt::CTRL; - if (modifiers & Qt::MetaModifier) - _key |= Qt::META; - if (modifiers & Qt::AltModifier) - _key |= Qt::ALT; - - QKeySequence key(_key); - - QAbstractScrollArea::keyPressEvent(event); - - if (mglass->isVisible() && (key == ShortcutsManager::getShortcutsManager().getShortcut(SIZE_UP_MGLASS_ACTION_Y) || key == ShortcutsManager::getShortcutsManager().getShortcut(SIZE_DOWN_MGLASS_ACTION_Y) || key == ShortcutsManager::getShortcutsManager().getShortcut(ZOOM_IN_MGLASS_ACTION_Y) || key == ShortcutsManager::getShortcutsManager().getShortcut(ZOOM_OUT_MGLASS_ACTION_Y))) { - QCoreApplication::sendEvent(mglass, event); - } - - } else - QAbstractScrollArea::keyPressEvent(event); -} - void Viewer::moveView(Qt::Key directionKey) { QKeyEvent event(QEvent::KeyPress, directionKey, Qt::NoModifier); @@ -770,14 +749,22 @@ void Viewer::showMagnifyingGlass() mglass->move(static_cast(p.x() - float(mglass->width()) / 2), static_cast(p.y() - float(mglass->height()) / 2)); mglass->show(); mglass->updateImage(mglass->x() + mglass->width() / 2, mglass->y() + mglass->height() / 2); - magnifyingGlassShown = true; + setMagnifyingGlassShown(true); } } void Viewer::hideMagnifyingGlass() { mglass->hide(); - magnifyingGlassShown = false; + setMagnifyingGlassShown(false); +} + +void Viewer::setMagnifyingGlassShown(bool shown) +{ + if (magnifyingGlassShown != shown) { + magnifyingGlassShown = shown; + emit magnifyingGlassVisibilityChanged(magnifyingGlassShown); + } } void Viewer::informationSwitch() diff --git a/YACReader/viewer.h b/YACReader/viewer.h index 380ae11e..42b46b85 100644 --- a/YACReader/viewer.h +++ b/YACReader/viewer.h @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include @@ -159,9 +158,9 @@ private: MagnifyingGlass *mglass; bool magnifyingGlassShown; bool restoreMagnifyingGlass; + void setMagnifyingGlassShown(bool shown); //! Manejadores de evento: - void keyPressEvent(QKeyEvent *event) override; void resizeEvent(QResizeEvent *event) override; void wheelEvent(QWheelEvent *event) override; void mouseMoveEvent(QMouseEvent *event) override; @@ -198,6 +197,13 @@ signals: void openNextComic(); void openPreviousComic(); void zoomUpdated(int); + void magnifyingGlassVisibilityChanged(bool visible); + + // The following signals are emitted by users of this class and propagated to mglass. + void magnifyingGlassSizeUp(); + void magnifyingGlassSizeDown(); + void magnifyingGlassZoomIn(); + void magnifyingGlassZoomOut(); }; #endif From 482c19b358bb59ee9065ac1d1a58cd571830e7c0 Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Tue, 9 Mar 2021 10:44:37 +0200 Subject: [PATCH 14/15] Allow triggering Open latest comic action when the toolbar is hidden This action is added to the toolbar but not to the viewer. Thus it cannot be triggered when the toolbar is hidden. Adding it to MainWindowViewer makes it available at all times. --- YACReader/main_window_viewer.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/YACReader/main_window_viewer.cpp b/YACReader/main_window_viewer.cpp index 7b7ca603..6f0a23c9 100644 --- a/YACReader/main_window_viewer.cpp +++ b/YACReader/main_window_viewer.cpp @@ -254,6 +254,7 @@ void MainWindowViewer::createActions() openLatestComicAction->setToolTip(tr("Open the latest comic opened in the previous reading session")); openLatestComicAction->setData(OPEN_LATEST_COMIC_Y); openLatestComicAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(OPEN_LATEST_COMIC_Y)); + addAction(openLatestComicAction); connect(openLatestComicAction, &QAction::triggered, this, &MainWindowViewer::openLatestComic); QAction *recentFileAction = nullptr; From 662b5c99fddfdfcf55c5cf2912a4df83eff21310 Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Tue, 9 Mar 2021 14:47:58 +0200 Subject: [PATCH 15/15] Don't leak "orphan" actions at exit The original reason to orphan these actions is likely obsolete now. Extract MainWindowViewer::addActionWithShortcut() to reduce code duplication. --- YACReader/main_window_viewer.cpp | 103 ++++++++++--------------------- YACReader/main_window_viewer.h | 1 + 2 files changed, 35 insertions(+), 69 deletions(-) diff --git a/YACReader/main_window_viewer.cpp b/YACReader/main_window_viewer.cpp index 6f0a23c9..b2147a26 100644 --- a/YACReader/main_window_viewer.cpp +++ b/YACReader/main_window_viewer.cpp @@ -250,11 +250,8 @@ void MainWindowViewer::createActions() openFolderAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(OPEN_FOLDER_ACTION_Y)); connect(openFolderAction, &QAction::triggered, this, &MainWindowViewer::openFolder); - openLatestComicAction = new QAction(tr("Open latest comic"), this); + openLatestComicAction = addActionWithShortcut(tr("Open latest comic"), OPEN_LATEST_COMIC_Y); openLatestComicAction->setToolTip(tr("Open the latest comic opened in the previous reading session")); - openLatestComicAction->setData(OPEN_LATEST_COMIC_Y); - openLatestComicAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(OPEN_LATEST_COMIC_Y)); - addAction(openLatestComicAction); connect(openLatestComicAction, &QAction::triggered, this, &MainWindowViewer::openLatestComic); QAction *recentFileAction = nullptr; @@ -501,6 +498,15 @@ void MainWindowViewer::createActions() connect(showEditShortcutsAction, &QAction::triggered, editShortcutsDialog, &QWidget::show); } +QAction *MainWindowViewer::addActionWithShortcut(const QString &text, const QString &shortcutKey) +{ + auto *const action = new QAction(text, this); + action->setData(shortcutKey); + action->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(shortcutKey)); + addAction(action); + return action; +} + void MainWindowViewer::createToolBars() { #ifdef Q_OS_MAC @@ -1147,9 +1153,6 @@ void MainWindowViewer::processReset() void MainWindowViewer::setUpShortcutsManagement() { - // actions holder - auto orphanActions = new QObject; - QList allActions; QList tmpList; @@ -1163,16 +1166,10 @@ void MainWindowViewer::setUpShortcutsManagement() allActions << tmpList; - QAction *toggleFullScreenAction = new QAction(tr("Toggle fullscreen mode"), orphanActions); - toggleFullScreenAction->setData(TOGGLE_FULL_SCREEN_ACTION_Y); - toggleFullScreenAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(TOGGLE_FULL_SCREEN_ACTION_Y)); - addAction(toggleFullScreenAction); + auto *const toggleFullScreenAction = addActionWithShortcut(tr("Toggle fullscreen mode"), TOGGLE_FULL_SCREEN_ACTION_Y); connect(toggleFullScreenAction, &QAction::triggered, this, &MainWindowViewer::toggleFullScreen); - QAction *toggleToolbarsAction = new QAction(tr("Hide/show toolbar"), orphanActions); - toggleToolbarsAction->setData(TOGGLE_TOOL_BARS_ACTION_Y); - toggleToolbarsAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(TOGGLE_TOOL_BARS_ACTION_Y)); - addAction(toggleToolbarsAction); + auto *const toggleToolbarsAction = addActionWithShortcut(tr("Hide/show toolbar"), TOGGLE_TOOL_BARS_ACTION_Y); connect(toggleToolbarsAction, &QAction::triggered, this, &MainWindowViewer::toggleToolBars); editShortcutsDialog->addActionsGroup(tr("General"), QIcon(":/images/shortcuts_group_general.png"), @@ -1194,29 +1191,20 @@ void MainWindowViewer::setUpShortcutsManagement() allActions << tmpList; - auto sizeUpMglassAction = new QAction(tr("Size up magnifying glass"), orphanActions); - sizeUpMglassAction->setData(SIZE_UP_MGLASS_ACTION_Y); - sizeUpMglassAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SIZE_UP_MGLASS_ACTION_Y)); + auto *const sizeUpMglassAction = addActionWithShortcut(tr("Size up magnifying glass"), SIZE_UP_MGLASS_ACTION_Y); connect(sizeUpMglassAction, &QAction::triggered, viewer, &Viewer::magnifyingGlassSizeUp); - auto sizeDownMglassAction = new QAction(tr("Size down magnifying glass"), orphanActions); - sizeDownMglassAction->setData(SIZE_DOWN_MGLASS_ACTION_Y); - sizeDownMglassAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SIZE_DOWN_MGLASS_ACTION_Y)); + auto *const sizeDownMglassAction = addActionWithShortcut(tr("Size down magnifying glass"), SIZE_DOWN_MGLASS_ACTION_Y); connect(sizeDownMglassAction, &QAction::triggered, viewer, &Viewer::magnifyingGlassSizeDown); - auto zoomInMglassAction = new QAction(tr("Zoom in magnifying glass"), orphanActions); - zoomInMglassAction->setData(ZOOM_IN_MGLASS_ACTION_Y); - zoomInMglassAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(ZOOM_IN_MGLASS_ACTION_Y)); + auto *const zoomInMglassAction = addActionWithShortcut(tr("Zoom in magnifying glass"), ZOOM_IN_MGLASS_ACTION_Y); connect(zoomInMglassAction, &QAction::triggered, viewer, &Viewer::magnifyingGlassZoomIn); - auto zoomOutMglassAction = new QAction(tr("Zoom out magnifying glass"), orphanActions); - zoomOutMglassAction->setData(ZOOM_OUT_MGLASS_ACTION_Y); - zoomOutMglassAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(ZOOM_OUT_MGLASS_ACTION_Y)); + auto *const zoomOutMglassAction = addActionWithShortcut(tr("Zoom out magnifying glass"), ZOOM_OUT_MGLASS_ACTION_Y); connect(zoomOutMglassAction, &QAction::triggered, viewer, &Viewer::magnifyingGlassZoomOut); mglassActions = { sizeUpMglassAction, sizeDownMglassAction, zoomInMglassAction, zoomOutMglassAction }; - addActions(mglassActions); editShortcutsDialog->addActionsGroup(tr("Magnifiying glass"), QIcon(":/images/shortcuts_group_mglass.png"), tmpList = QList() @@ -1225,10 +1213,8 @@ void MainWindowViewer::setUpShortcutsManagement() allActions << tmpList; - auto toggleFitToScreenAction = new QAction(tr("Toggle between fit to width and fit to height"), orphanActions); - toggleFitToScreenAction->setData(CHANGE_FIT_ACTION_Y); - toggleFitToScreenAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(CHANGE_FIT_ACTION_Y)); - addAction(toggleFitToScreenAction); + auto *const toggleFitToScreenAction = addActionWithShortcut(tr("Toggle between fit to width and fit to height"), + CHANGE_FIT_ACTION_Y); connect(toggleFitToScreenAction, &QAction::triggered, this, &MainWindowViewer::toggleWidthHeight); editShortcutsDialog->addActionsGroup(tr("Page adjustement"), QIcon(":/images/shortcuts_group_page.png"), @@ -1248,64 +1234,44 @@ void MainWindowViewer::setUpShortcutsManagement() allActions << tmpList; - auto autoScrollForwardAction = new QAction(tr("Autoscroll down"), orphanActions); - autoScrollForwardAction->setData(AUTO_SCROLL_FORWARD_ACTION_Y); - autoScrollForwardAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(AUTO_SCROLL_FORWARD_ACTION_Y)); + auto *const autoScrollForwardAction = addActionWithShortcut(tr("Autoscroll down"), AUTO_SCROLL_FORWARD_ACTION_Y); connect(autoScrollForwardAction, &QAction::triggered, viewer, &Viewer::scrollForward); - auto autoScrollBackwardAction = new QAction(tr("Autoscroll up"), orphanActions); - autoScrollBackwardAction->setData(AUTO_SCROLL_BACKWARD_ACTION_Y); - autoScrollBackwardAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(AUTO_SCROLL_BACKWARD_ACTION_Y)); + auto *const autoScrollBackwardAction = addActionWithShortcut(tr("Autoscroll up"), AUTO_SCROLL_BACKWARD_ACTION_Y); connect(autoScrollBackwardAction, &QAction::triggered, viewer, &Viewer::scrollBackward); - auto autoScrollForwardHorizontalFirstAction = new QAction(tr("Autoscroll forward, horizontal first"), orphanActions); - autoScrollForwardHorizontalFirstAction->setData(AUTO_SCROLL_FORWARD_HORIZONTAL_FIRST_ACTION_Y); - autoScrollForwardHorizontalFirstAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(AUTO_SCROLL_FORWARD_HORIZONTAL_FIRST_ACTION_Y)); + auto *const autoScrollForwardHorizontalFirstAction = addActionWithShortcut(tr("Autoscroll forward, horizontal first"), + AUTO_SCROLL_FORWARD_HORIZONTAL_FIRST_ACTION_Y); connect(autoScrollForwardHorizontalFirstAction, &QAction::triggered, viewer, &Viewer::scrollForwardHorizontalFirst); - auto autoScrollBackwardHorizontalFirstAction = new QAction(tr("Autoscroll backward, horizontal first"), orphanActions); - autoScrollBackwardHorizontalFirstAction->setData(AUTO_SCROLL_BACKWARD_HORIZONTAL_FIRST_ACTION_Y); - autoScrollBackwardHorizontalFirstAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(AUTO_SCROLL_BACKWARD_HORIZONTAL_FIRST_ACTION_Y)); + auto *const autoScrollBackwardHorizontalFirstAction = addActionWithShortcut(tr("Autoscroll backward, horizontal first"), + AUTO_SCROLL_BACKWARD_HORIZONTAL_FIRST_ACTION_Y); connect(autoScrollBackwardHorizontalFirstAction, &QAction::triggered, viewer, &Viewer::scrollBackwardHorizontalFirst); - auto autoScrollForwardVerticalFirstAction = new QAction(tr("Autoscroll forward, vertical first"), orphanActions); - autoScrollForwardVerticalFirstAction->setData(AUTO_SCROLL_FORWARD_VERTICAL_FIRST_ACTION_Y); - autoScrollForwardVerticalFirstAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(AUTO_SCROLL_FORWARD_VERTICAL_FIRST_ACTION_Y)); + auto *const autoScrollForwardVerticalFirstAction = addActionWithShortcut(tr("Autoscroll forward, vertical first"), + AUTO_SCROLL_FORWARD_VERTICAL_FIRST_ACTION_Y); connect(autoScrollForwardVerticalFirstAction, &QAction::triggered, viewer, &Viewer::scrollForwardVerticalFirst); - auto autoScrollBackwardVerticalFirstAction = new QAction(tr("Autoscroll backward, vertical first"), orphanActions); - autoScrollBackwardVerticalFirstAction->setData(AUTO_SCROLL_BACKWARD_VERTICAL_FIRST_ACTION_Y); - autoScrollBackwardVerticalFirstAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(AUTO_SCROLL_BACKWARD_VERTICAL_FIRST_ACTION_Y)); + auto *const autoScrollBackwardVerticalFirstAction = addActionWithShortcut(tr("Autoscroll backward, vertical first"), + AUTO_SCROLL_BACKWARD_VERTICAL_FIRST_ACTION_Y); connect(autoScrollBackwardVerticalFirstAction, &QAction::triggered, viewer, &Viewer::scrollBackwardVerticalFirst); - auto moveDownAction = new QAction(tr("Move down"), orphanActions); - moveDownAction->setData(MOVE_DOWN_ACTION_Y); - moveDownAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(MOVE_DOWN_ACTION_Y)); + auto *const moveDownAction = addActionWithShortcut(tr("Move down"), MOVE_DOWN_ACTION_Y); connect(moveDownAction, &QAction::triggered, viewer, [this] { viewer->moveView(Qt::Key_Down); }); - auto moveUpAction = new QAction(tr("Move up"), orphanActions); - moveUpAction->setData(MOVE_UP_ACTION_Y); - moveUpAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(MOVE_UP_ACTION_Y)); + auto *const moveUpAction = addActionWithShortcut(tr("Move up"), MOVE_UP_ACTION_Y); connect(moveUpAction, &QAction::triggered, viewer, [this] { viewer->moveView(Qt::Key_Up); }); - auto moveLeftAction = new QAction(tr("Move left"), orphanActions); - moveLeftAction->setData(MOVE_LEFT_ACTION_Y); - moveLeftAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(MOVE_LEFT_ACTION_Y)); + auto *const moveLeftAction = addActionWithShortcut(tr("Move left"), MOVE_LEFT_ACTION_Y); connect(moveLeftAction, &QAction::triggered, viewer, [this] { viewer->moveView(Qt::Key_Left); }); - auto moveRightAction = new QAction(tr("Move right"), orphanActions); - moveRightAction->setData(MOVE_RIGHT_ACTION_Y); - moveRightAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(MOVE_RIGHT_ACTION_Y)); + auto *const moveRightAction = addActionWithShortcut(tr("Move right"), MOVE_RIGHT_ACTION_Y); connect(moveRightAction, &QAction::triggered, viewer, [this] { viewer->moveView(Qt::Key_Right); }); - auto goToFirstPageAction = new QAction(tr("Go to the first page"), orphanActions); - goToFirstPageAction->setData(GO_TO_FIRST_PAGE_ACTION_Y); - goToFirstPageAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(GO_TO_FIRST_PAGE_ACTION_Y)); + auto *const goToFirstPageAction = addActionWithShortcut(tr("Go to the first page"), GO_TO_FIRST_PAGE_ACTION_Y); connect(goToFirstPageAction, &QAction::triggered, viewer, &Viewer::goToFirstPage); - auto goToLastPageAction = new QAction(tr("Go to the last page"), orphanActions); - goToLastPageAction->setData(GO_TO_LAST_PAGE_ACTION_Y); - goToLastPageAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(GO_TO_LAST_PAGE_ACTION_Y)); + auto *const goToLastPageAction = addActionWithShortcut(tr("Go to the last page"), GO_TO_LAST_PAGE_ACTION_Y); connect(goToLastPageAction, &QAction::triggered, viewer, &Viewer::goToLastPage); loadedComicActions = { autoScrollForwardAction, @@ -1320,7 +1286,6 @@ void MainWindowViewer::setUpShortcutsManagement() moveRightAction, goToFirstPageAction, goToLastPageAction }; - addActions(loadedComicActions); editShortcutsDialog->addActionsGroup(tr("Reading"), QIcon(":/images/shortcuts_group_reading.png"), tmpList = QList() diff --git a/YACReader/main_window_viewer.h b/YACReader/main_window_viewer.h index 2b25fb5f..dda77f13 100644 --- a/YACReader/main_window_viewer.h +++ b/YACReader/main_window_viewer.h @@ -159,6 +159,7 @@ private: //! Método que inicializa el interfaz. void setupUI(); void createActions(); + QAction *addActionWithShortcut(const QString &text, const QString &shortcutKey); void createToolBars(); void refreshRecentFilesActionList(); void clearRecentFiles();