Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Version counting is based on semantic versioning (Major.Feature.Patch)
* Add an optional circular magnifying glass, with an optional ring drawn around it. The configured size is kept as a rectangle, so switching back and forth doesn't lose it.
* Add optional edge easing for the magnifying glass. The magnified region is pushed toward the edges of the view, so content near the border can be inspected without pushing the cursor all the way into the corner.
* Require a full wheel notch before the magnifying glass changes size or zoom, so a light trackpad gesture no longer resizes it.
* Add a setting to control what the Escape key does. It can keep quitting the reader, as before, or instead cancel the topmost active mode: magnifying glass, dictionary, go to flow and then fullscreen.

### YACReaderLibrary
* Add a library repair function to restore missing covers and rescan files that previously failed to be added.
Expand Down
8 changes: 8 additions & 0 deletions YACReader/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ enum MouseMode {
HotAreas
};

enum EscapeKeyBehavior {
EscapeQuits = 0,
EscapeCancelsMode = 1
};

class Configuration : public QObject
{
Q_OBJECT
Expand Down Expand Up @@ -123,6 +128,9 @@ class Configuration : public QObject
MouseMode getMouseMode() { return static_cast<MouseMode>(settings->value(MOUSE_MODE, MouseMode::Normal).toInt()); }
void setMouseMode(MouseMode mouseMode) { settings->setValue(MOUSE_MODE, static_cast<int>(mouseMode)); }

EscapeKeyBehavior getEscapeKeyBehavior() { return static_cast<EscapeKeyBehavior>(settings->value(ESCAPE_KEY_BEHAVIOR, EscapeKeyBehavior::EscapeQuits).toInt()); }
void setEscapeKeyBehavior(EscapeKeyBehavior behavior) { settings->setValue(ESCAPE_KEY_BEHAVIOR, static_cast<int>(behavior)); }

ScaleMethod getScalingMethod() { return static_cast<ScaleMethod>(settings->value(SCALING_METHOD, static_cast<int>(ScaleMethod::Lanczos)).toInt()); }
void setScalingMethod(ScaleMethod method) { settings->setValue(SCALING_METHOD, static_cast<int>(method)); }
};
Expand Down
56 changes: 53 additions & 3 deletions YACReader/main_window_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ MainWindowViewer::~MainWindowViewer()
delete showShorcutsAction;
delete showInfoAction;
delete closeAction;
delete exitAction;
delete showDictionaryAction;
delete adjustToFullSizeAction;
delete fitToPageAction;
Expand Down Expand Up @@ -565,10 +566,19 @@ void MainWindowViewer::createActions()
showInfoAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SHOW_INFO_ACTION_Y));
connect(showInfoAction, &QAction::triggered, viewer, &Viewer::informationSwitch);

closeAction = new QAction(tr("Close"), this);
// closeAction owns the Escape key. Depending on the EscapeKeyBehavior setting it either
// quits (default) or cancels the topmost active mode. The File▸Close menu command lives
// on exitAction below, which always quits regardless of the setting.
closeAction = new QAction(tr("Escape"), this);
// The shortcuts editor lists actions by toolTip(), which otherwise falls back to the
// action text; name the behaviour rather than the key, which it already shows.
closeAction->setToolTip(tr("Escape key: quit, or cancel the active mode"));
closeAction->setData(CLOSE_ACTION_Y);
closeAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(CLOSE_ACTION_Y));
connect(closeAction, &QAction::triggered, this, &QWidget::close);
connect(closeAction, &QAction::triggered, this, &MainWindowViewer::onEscapePressed);

exitAction = new QAction(tr("Close"), this);
connect(exitAction, &QAction::triggered, this, &QWidget::close);

showDictionaryAction = new QAction(tr("Show Dictionary"), this);
// showDictionaryAction->setCheckable(true);
Expand Down Expand Up @@ -787,7 +797,7 @@ void MainWindowViewer::createToolBars()
fileMenu->addMenu(recentmenu);

fileMenu->addSeparator();
fileMenu->addAction(closeAction);
fileMenu->addAction(exitAction);

auto editMenu = new QMenu(tr("Edit"));
editMenu->addAction(leftRotationAction);
Expand Down Expand Up @@ -1187,6 +1197,45 @@ void MainWindowViewer::toggleFullScreen()
Configuration::getConfiguration().setFullScreen(fullscreen = !fullscreen);
}

void MainWindowViewer::onEscapePressed()
{
if (Configuration::getConfiguration().getEscapeKeyBehavior() == EscapeCancelsMode) {
// Cancel the topmost active mode; if none is active this is a no-op (does not quit).
cancelActiveMode();
return;
}

close();
}

bool MainWindowViewer::cancelActiveMode()
{
// This order is documented to users in the Options ▸ General ▸ "Escape key" tooltip;
// keep the two in sync when adding or reordering modes.
if (viewer->magnifyingGlassIsVisible()) {
viewer->hideMagnifyingGlass();
showMagnifyingGlassAction->setChecked(false);
return true;
}

if (viewer->translatorIsVisible()) {
viewer->animateHideTranslator();
return true;
}

if (viewer->goToFlowIsVisible()) {
viewer->animateHideGoToFlow();
return true;
}

if (fullscreen) {
toggleFullScreen();
return true;
}

return false;
}

void MainWindowViewer::toFullScreen()
{
fromMaximized = this->isMaximized();
Expand Down Expand Up @@ -1724,6 +1773,7 @@ void MainWindowViewer::applyTheme(const Theme &theme)
setIcon(showShorcutsAction, toolbarTheme.showShorcutsAction, toolbarTheme.showShorcutsAction18x18);
setIcon(showInfoAction, toolbarTheme.showInfoAction, toolbarTheme.showInfoAction18x18);
setIcon(closeAction, toolbarTheme.closeAction, toolbarTheme.closeAction18x18);
setIcon(exitAction, toolbarTheme.closeAction, toolbarTheme.closeAction18x18);
setIcon(showDictionaryAction, toolbarTheme.showDictionaryAction, toolbarTheme.showDictionaryAction18x18);
setIcon(adjustToFullSizeAction, toolbarTheme.adjustToFullSizeAction, toolbarTheme.adjustToFullSizeAction18x18);
setIcon(fitToPageAction, toolbarTheme.fitToPageAction, toolbarTheme.fitToPageAction18x18);
Expand Down
11 changes: 10 additions & 1 deletion YACReader/main_window_viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ public slots:

void toggleFitToWidthSlider();

// Escape key handling: either quits (default) or cancels the topmost active mode,
// depending on the EscapeKeyBehavior setting.
void onEscapePressed();

/*void viewComic();
void prev();
void next();
Expand Down Expand Up @@ -135,7 +139,12 @@ public slots:
QAction *leftRotationAction;
QAction *rightRotationAction;
QAction *showInfoAction;
QAction *closeAction;
QAction *closeAction; // owns the Escape key; dispatches quit vs. cancel-mode
QAction *exitAction; // File▸Close menu command, always quits

// Cancels the topmost active mode (magnifier, translator, go-to-flow, fullscreen).
// Returns true if a mode was cancelled, false if none was active.
bool cancelActiveMode();
QAction *doublePageAction;
QAction *doubleMangaPageAction;
QAction *continuousScrollAction;
Expand Down
34 changes: 34 additions & 0 deletions YACReader/options_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,31 @@ OptionsDialog::OptionsDialog(QWidget *parent)

mouseModeBox->setLayout(mouseModeLayout);

auto escapeKeyBox = new QGroupBox(tr("Escape key"));
auto escapeKeyLayout = new QVBoxLayout();

escapeQuitsRadioButton = new QRadioButton(tr("Quit the reader"));
escapeCancelsModeRadioButton = new QRadioButton(tr("Cancel the active mode"));

escapeQuitsRadioButton->setToolTip(tr("Escape closes the reader, even while a mode is active."));

// Keep this list in sync with MainWindowViewer::cancelActiveMode(), which implements the order.
//: Tooltip listing the order in which modes are cancelled. Only the first
//: active mode in the list is cancelled per Escape keypress.
escapeCancelsModeRadioButton->setToolTip(tr("Escape cancels the first of these that is active:\n"
"\n"
"1. Magnifying glass\n"
"2. Dictionary\n"
"3. Go to page bar\n"
"4. Fullscreen\n"
"\n"
"If none is active, Escape does nothing."));

escapeKeyLayout->addWidget(escapeQuitsRadioButton);
escapeKeyLayout->addWidget(escapeCancelsModeRadioButton);

escapeKeyBox->setLayout(escapeKeyLayout);

layoutGeneral->addWidget(pathBox);
layoutGeneral->addWidget(languageBox);
layoutGeneral->addWidget(displayBox);
Expand All @@ -140,6 +165,7 @@ OptionsDialog::OptionsDialog(QWidget *parent)
layoutGeneral->addWidget(colorBox);
layoutGeneral->addWidget(scrollBox);
layoutGeneral->addWidget(mouseModeBox);
layoutGeneral->addWidget(escapeKeyBox);
layoutGeneral->addWidget(shortcutsBox);
layoutGeneral->addStretch();

Expand Down Expand Up @@ -354,6 +380,9 @@ void OptionsDialog::saveOptions()
}
Configuration::getConfiguration().setMouseMode(mouseMode);

Configuration::getConfiguration().setEscapeKeyBehavior(
escapeCancelsModeRadioButton->isChecked() ? EscapeCancelsMode : EscapeQuits);

Configuration::getConfiguration().setScalingMethod(static_cast<ScaleMethod>(scalingMethodCombo->currentIndex()));
emit changedImageOptions();

Expand Down Expand Up @@ -431,6 +460,11 @@ void OptionsDialog::restoreOptions(QSettings *settings)
hotAreasMouseModeRadioButton->setChecked(true);
break;
}

if (Configuration::getConfiguration().getEscapeKeyBehavior() == EscapeCancelsMode)
escapeCancelsModeRadioButton->setChecked(true);
else
escapeQuitsRadioButton->setChecked(true);
}

void OptionsDialog::updateColor(const QColor &color)
Expand Down
3 changes: 3 additions & 0 deletions YACReader/options_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ class OptionsDialog : public YACReaderOptionsDialog, protected Themable
QRadioButton *leftRightNavigationMouseModeRadioButton;
QRadioButton *hotAreasMouseModeRadioButton;

QRadioButton *escapeQuitsRadioButton;
QRadioButton *escapeCancelsModeRadioButton;

public slots:
void saveOptions() override;
void restoreOptions(QSettings *settings) override;
Expand Down
10 changes: 10 additions & 0 deletions YACReader/viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1276,6 +1276,16 @@ void Viewer::translatorSwitch()
translator->isVisible() ? animateHideTranslator() : animateShowTranslator();
}

bool Viewer::translatorIsVisible() const
{
return translator->isVisible();
}

bool Viewer::goToFlowIsVisible() const
{
return goToFlow->isVisible();
}

void Viewer::showGoToFlow()
{
if (render->hasLoadedComic()) {
Expand Down
2 changes: 2 additions & 0 deletions YACReader/viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ public slots:
void rotateLeft();
void rotateRight();
bool magnifyingGlassIsVisible() const { return magnifyingGlassShown; }
bool translatorIsVisible() const;
bool goToFlowIsVisible() const;
void setBookmark(bool);
void save();
void doublePageSwitch();
Expand Down
1 change: 1 addition & 0 deletions common/yacreader_global_gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#define USE_SINGLE_SCROLL_STEP_TO_TURN_PAGE "USE_SINGLE_SCROLL_STEP_TO_TURN_PAGE"
#define DISABLE_SCROLL_ANIMATION "DISABLE_SCROLL_ANIMATION"
#define MOUSE_MODE "MOUSE_MODE"
#define ESCAPE_KEY_BEHAVIOR "ESCAPE_KEY_BEHAVIOR"
#define SCALING_METHOD "SCALING_METHOD"
#define SAVE_RENDERED_PAGE_DIRECTORY "SAVE_RENDERED_PAGE_DIRECTORY"
#define EXTRACT_PAGE_DIRECTORY "EXTRACT_PAGE_DIRECTORY"
Expand Down
Loading