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/magnifying_glass.cpp b/YACReader/magnifying_glass.cpp index 594a550e..ce1359db 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(); @@ -170,101 +170,113 @@ 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); + 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) - resize(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() { - auto p = (Viewer *)parent(); - if (height() < (p->height() * 0.90f)) - resize(width(), height() + 15); + auto h = height(); + if (growHeight(h)) + resizeAndUpdate(width(), h); } void MagnifyingGlass::heightDown() { - if (height() > 80) - resize(width(), height() - 15); + auto h = height(); + if (shrinkHeight(h)) + resizeAndUpdate(width(), h); } void MagnifyingGlass::widthUp() { - auto p = (Viewer *)parent(); - if (width() < (p->width() * 0.90f)) - resize(width() + 30, height()); + auto w = width(); + if (growWidth(w)) + resizeAndUpdate(w, height()); } void MagnifyingGlass::widthDown() { - if (width() > 175) - resize(width() - 30, height()); + auto w = width(); + if (shrinkWidth(w)) + resizeAndUpdate(w, height()); } -void MagnifyingGlass::keyPressEvent(QKeyEvent *event) +void MagnifyingGlass::resizeAndUpdate(int w, int h) { - 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) { - updateImage(); - event->setAccepted(true); - } + resize(w, 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; } diff --git a/YACReader/magnifying_glass.h b/YACReader/magnifying_glass.h index c1ca71e3..77d1462b 100644 --- a/YACReader/magnifying_glass.h +++ b/YACReader/magnifying_glass.h @@ -12,7 +12,15 @@ class MagnifyingGlass : public QLabel private: float zoomLevel; void setup(const QSize &size); - void keyPressEvent(QKeyEvent *event) override; + 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; public: MagnifyingGlass(int width, int height, QWidget *parent); diff --git a/YACReader/main_window_viewer.cpp b/YACReader/main_window_viewer.cpp index afd6b100..b2147a26 100644 --- a/YACReader/main_window_viewer.cpp +++ b/YACReader/main_window_viewer.cpp @@ -24,6 +24,8 @@ #include #include +#include + #include #include #include @@ -70,7 +72,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 +120,6 @@ MainWindowViewer::~MainWindowViewer() delete showInfoAction; delete closeAction; delete showDictionaryAction; - delete alwaysOnTopAction; delete adjustToFullSizeAction; delete fitToPageAction; delete showFlowAction; @@ -138,6 +139,12 @@ void MainWindowViewer::setupUI() // setUnifiedTitleAndToolBarOnMac(true); viewer = new Viewer(this); + 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); @@ -179,6 +186,8 @@ void MainWindowViewer::setupUI() createActions(); setUpShortcutsManagement(); + disableActions(); + disablePreviousNextComicActions(); createToolBars(); @@ -188,11 +197,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(); @@ -246,10 +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)); connect(openLatestComicAction, &QAction::triggered, this, &MainWindowViewer::openLatestComic); QAction *recentFileAction = nullptr; @@ -268,7 +270,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 +277,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 +284,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 +292,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 +300,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 +307,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 +317,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 +327,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 +334,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 +364,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 +396,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 +406,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 +415,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 +438,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 +446,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 +456,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 +469,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,24 +482,12 @@ 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); - // 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->setDisabled(true); showFlowAction->setData(SHOW_FLOW_ACTION_Y); showFlowAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SHOW_FLOW_ACTION_Y)); connect(showFlowAction, &QAction::triggered, viewer, &Viewer::goToFlowSwitch); @@ -530,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 @@ -987,31 +964,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,61 +972,16 @@ 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); + setMglassActionsEnabled(false); + setLoadedComicActionsEnabled(false); + setBookmarkAction->setEnabled(false); } -void MainWindowViewer::keyPressEvent(QKeyEvent *event) +void MainWindowViewer::disablePreviousNextComicActions() { - // 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); + for (auto *a : { openComicOnTheLeftAction, openComicOnTheRightAction }) + a->setEnabled(false); } void MainWindowViewer::mouseDoubleClickEvent(QMouseEvent *event) @@ -1238,24 +1146,13 @@ 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() { - // actions holder - auto orphanActions = new QObject; - QList allActions; QList tmpList; @@ -1269,14 +1166,11 @@ 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)); + 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)); + 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"), tmpList = QList() @@ -1297,37 +1191,31 @@ 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)); + 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 }; editShortcutsDialog->addActionsGroup(tr("Magnifiying glass"), QIcon(":/images/shortcuts_group_mglass.png"), tmpList = QList() << showMagnifyingGlassAction - << sizeUpMglassAction - << sizeDownMglassAction - << zoomInMglassAction - << zoomOutMglassAction); + << mglassActions); 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)); + 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"), tmpList = QList() @@ -1346,53 +1234,58 @@ 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, + autoScrollBackwardAction, + autoScrollForwardHorizontalFirstAction, + autoScrollBackwardHorizontalFirstAction, + autoScrollForwardVerticalFirstAction, + autoScrollBackwardVerticalFirstAction, + moveDownAction, + moveUpAction, + moveLeftAction, + moveRightAction, + goToFirstPageAction, + goToLastPageAction }; editShortcutsDialog->addActionsGroup(tr("Reading"), QIcon(":/images/shortcuts_group_reading.png"), tmpList = QList() @@ -1400,18 +1293,7 @@ void MainWindowViewer::setUpShortcutsManagement() << goToPageOnTheLeftAction << setBookmarkAction << showBookmarksAction - << autoScrollForwardAction - << autoScrollBackwardAction - << autoScrollForwardHorizontalFirstAction - << autoScrollBackwardHorizontalFirstAction - << autoScrollForwardVerticalFirstAction - << autoScrollBackwardVerticalFirstAction - << moveDownAction - << moveUpAction - << moveLeftAction - << moveRightAction - << goToFirstPageAction - << goToLastPageAction + << loadedComicActions << goToPageAction); allActions << tmpList; @@ -1608,6 +1490,46 @@ 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::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)) + a->setEnabled(enabled); +} + void MainWindowViewer::dropEvent(QDropEvent *event) { QList urlList; @@ -1644,18 +1566,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 2c83c054..dda77f13 100644 --- a/YACReader/main_window_viewer.h +++ b/YACReader/main_window_viewer.h @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include @@ -46,6 +45,7 @@ public slots: void showToolBars(); void enableActions(); void disableActions(); + void disablePreviousNextComicActions(); void toggleFullScreen(); void toFullScreen(); void toNormal(); @@ -60,7 +60,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(); @@ -86,7 +85,6 @@ private: //! State bool fullscreen; bool toolbars; - bool alwaysOnTop; bool fromMaximized; // QTBUG-41883 @@ -140,7 +138,6 @@ private: QAction *doubleMangaPageAction; QAction *showShorcutsAction; QAction *showDictionaryAction; - QAction *alwaysOnTopAction; QAction *adjustToFullSizeAction; QAction *fitToPageAction; QAction *resetZoomAction; @@ -151,6 +148,9 @@ private: QAction *showEditShortcutsAction; + QList mglassActions; + QList loadedComicActions; + YACReaderSlider *zoomSliderAction; HttpVersionChecker *versionChecker; @@ -159,13 +159,16 @@ 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(); void getSiblingComics(QString path, QString currentComic); + void setActionsEnabled(bool enabled); + void setMglassActionsEnabled(bool enabled); + void setLoadedComicActionsEnabled(bool enabled); //! Manejadores de evento: - void keyPressEvent(QKeyEvent *event) override; // void resizeEvent(QResizeEvent * event); void mouseDoubleClickEvent(QMouseEvent *event) override; void dropEvent(QDropEvent *event) override; diff --git a/YACReader/viewer.cpp b/YACReader/viewer.cpp index 9db26b13..4894f25b 100644 --- a/YACReader/viewer.cpp +++ b/YACReader/viewer.cpp @@ -20,6 +20,7 @@ #include "opengl_checker.h" #include +#include #include @@ -34,10 +35,9 @@ Viewer::Viewer(QWidget *parent) wheelStop(false), direction(1), drag(false), - numScrollSteps(22), shouldOpenNext(false), shouldOpenPrevious(false), - magnifyingGlassShowed(false), + magnifyingGlassShown(false), restoreMagnifyingGlass(false) { translator = new YACReaderTranslator(this); @@ -155,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); @@ -179,6 +184,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); @@ -285,6 +291,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 @@ -457,6 +471,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) { @@ -493,6 +519,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) @@ -510,15 +548,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; @@ -534,13 +572,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 { @@ -576,99 +614,11 @@ void Viewer::scrollTo(int x, int y) emit backgroundChanges(); } -void Viewer::keyPressEvent(QKeyEvent *event) +void Viewer::moveView(Qt::Key directionKey) { - 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); - /*if(goToFlow->isVisible() && event->key()!=Qt::Key_S) - QCoreApplication::sendEvent(goToFlow,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(); - } - - 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); - - 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::moveAction(const QKeySequence &key) -{ - 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) @@ -744,7 +694,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()) { @@ -777,7 +727,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(); @@ -788,7 +738,7 @@ const QPixmap Viewer::pixmap() void Viewer::magnifyingGlassSwitch() { - magnifyingGlassShowed ? hideMagnifyingGlass() : showMagnifyingGlass(); + magnifyingGlassShown ? hideMagnifyingGlass() : showMagnifyingGlass(); } void Viewer::showMagnifyingGlass() @@ -799,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); - magnifyingGlassShowed = true; + setMagnifyingGlassShown(true); } } void Viewer::hideMagnifyingGlass() { mglass->hide(); - magnifyingGlassShowed = false; + setMagnifyingGlassShown(false); +} + +void Viewer::setMagnifyingGlassShown(bool shown) +{ + if (magnifyingGlassShown != shown) { + magnifyingGlassShown = shown; + emit magnifyingGlassVisibilityChanged(magnifyingGlassShown); + } } void Viewer::informationSwitch() @@ -961,7 +919,7 @@ void Viewer::resetContent() void Viewer::setLoadingMessage() { - if (magnifyingGlassShowed) { + if (magnifyingGlassShown) { hideMagnifyingGlass(); restoreMagnifyingGlass = true; } @@ -971,7 +929,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 393815d9..42b46b85 100644 --- a/YACReader/viewer.h +++ b/YACReader/viewer.h @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include @@ -51,6 +50,8 @@ public slots: void left(); void right(); void showGoToDialog(); + void goToFirstPage(); + void goToLastPage(); void goTo(unsigned int page); void updatePage(); void updateContentSize(); @@ -58,6 +59,8 @@ public slots: void updateOptions(); void scrollDown(); void scrollUp(); + void scrollForward(); + void scrollBackward(); void scrollForwardHorizontalFirst(); void scrollBackwardHorizontalFirst(); void scrollForwardVerticalFirst(); @@ -74,7 +77,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(); @@ -119,7 +122,6 @@ private: QPropertyAnimation *verticalScroller; QPropertyAnimation *horizontalScroller; QParallelAnimationGroup *groupScroller; - int posByStep; int nextPos; GoToFlowWidget *goToFlow; QPropertyAnimation *showGoToFlowAnimation; @@ -135,7 +137,6 @@ private: QTimer *hideCursorTimer; int direction; bool drag; - int numScrollSteps; //! Widgets QLabel *content; @@ -155,16 +156,17 @@ private: private: //! Magnifying glass MagnifyingGlass *mglass; - bool magnifyingGlassShowed; + 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; - void moveAction(const QKeySequence &key); + int verticalScrollStep() const; + int horizontalScrollStep() const; //! ZigzagScroll enum scrollDirection { UP, @@ -178,20 +180,30 @@ 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] 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(); 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 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"