mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
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.
This commit is contained in:
parent
5254e66da3
commit
24e42f76d2
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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<QAction *>()
|
||||
<< 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))
|
||||
|
@ -148,6 +148,7 @@ private:
|
||||
|
||||
QAction *showEditShortcutsAction;
|
||||
|
||||
QList<QAction *> mglassActions;
|
||||
QList<QAction *> 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:
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "opengl_checker.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QKeyEvent>
|
||||
|
||||
#include <QsLog.h>
|
||||
|
||||
@ -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<int>(p.x() - float(mglass->width()) / 2), static_cast<int>(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()
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include <QTimer>
|
||||
#include <QLabel>
|
||||
#include <QPixmap>
|
||||
#include <QKeyEvent>
|
||||
#include <QResizeEvent>
|
||||
#include <QWheelEvent>
|
||||
#include <QMouseEvent>
|
||||
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user