2021-01-24 00:07:58 +08:00
|
|
|
#include "actionmanager.h"
|
|
|
|
|
|
|
|
#include "mainwindow.h"
|
|
|
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
|
2021-07-02 00:06:23 +08:00
|
|
|
#define ICON_NAME(name)\
|
|
|
|
QStringLiteral(":/icons/" #name "")
|
|
|
|
|
|
|
|
#define SETUP_NEW_ACTION(window, action)\
|
2021-01-24 00:07:58 +08:00
|
|
|
action->setObjectName(QString::fromUtf8( #action ));\
|
|
|
|
window->addAction(action);
|
|
|
|
|
2021-07-02 00:06:23 +08:00
|
|
|
#define CREATE_NEW_ACTION(window, action)\
|
|
|
|
action = new QAction(window);\
|
|
|
|
SETUP_NEW_ACTION(window, action)
|
|
|
|
|
|
|
|
#define CREATE_NEW_ICON_ACTION(window, action, iconname)\
|
|
|
|
action = new QAction(QIcon(ICON_NAME(iconname)), QString(), window);\
|
|
|
|
SETUP_NEW_ACTION(window, action)
|
|
|
|
|
2021-01-24 00:07:58 +08:00
|
|
|
ActionManager::ActionManager()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ActionManager::~ActionManager()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActionManager::setupAction(MainWindow *mainWindow)
|
|
|
|
{
|
2021-07-02 00:06:23 +08:00
|
|
|
CREATE_NEW_ICON_ACTION(mainWindow, actionActualSize, zoom-original);
|
|
|
|
CREATE_NEW_ICON_ACTION(mainWindow, actionToggleMaximize, view-fullscreen);
|
|
|
|
CREATE_NEW_ICON_ACTION(mainWindow, actionZoomIn, zoom-in);
|
|
|
|
CREATE_NEW_ICON_ACTION(mainWindow, actionZoomOut, zoom-out);
|
|
|
|
CREATE_NEW_ICON_ACTION(mainWindow, actionToggleCheckerboard, view-background-checkerboard);
|
|
|
|
CREATE_NEW_ICON_ACTION(mainWindow, actionRotateClockwise, object-rotate-right);
|
|
|
|
|
2021-10-08 14:06:18 +08:00
|
|
|
CREATE_NEW_ACTION(mainWindow, actionPrevPicture);
|
|
|
|
CREATE_NEW_ACTION(mainWindow, actionNextPicture);
|
|
|
|
|
2021-11-25 22:54:37 +08:00
|
|
|
CREATE_NEW_ACTION(mainWindow, actionOpen);
|
2021-03-19 23:11:06 +08:00
|
|
|
CREATE_NEW_ACTION(mainWindow, actionHorizontalFlip);
|
2021-06-04 13:53:47 +08:00
|
|
|
CREATE_NEW_ACTION(mainWindow, actionFitInView);
|
2021-05-14 00:00:03 +08:00
|
|
|
CREATE_NEW_ACTION(mainWindow, actionFitByWidth);
|
2021-01-24 00:07:58 +08:00
|
|
|
CREATE_NEW_ACTION(mainWindow, actionCopyPixmap);
|
|
|
|
CREATE_NEW_ACTION(mainWindow, actionCopyFilePath);
|
|
|
|
CREATE_NEW_ACTION(mainWindow, actionPaste);
|
|
|
|
CREATE_NEW_ACTION(mainWindow, actionToggleStayOnTop);
|
|
|
|
CREATE_NEW_ACTION(mainWindow, actionToggleProtectMode);
|
|
|
|
CREATE_NEW_ACTION(mainWindow, actionSettings);
|
|
|
|
CREATE_NEW_ACTION(mainWindow, actionHelp);
|
2022-01-21 16:48:43 +08:00
|
|
|
CREATE_NEW_ACTION(mainWindow, actionLocateInFileManager);
|
2021-01-24 00:07:58 +08:00
|
|
|
CREATE_NEW_ACTION(mainWindow, actionProperties);
|
|
|
|
CREATE_NEW_ACTION(mainWindow, actionQuitApp);
|
|
|
|
|
|
|
|
retranslateUi(mainWindow);
|
|
|
|
|
|
|
|
QMetaObject::connectSlotsByName(mainWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActionManager::retranslateUi(MainWindow *mainWindow)
|
|
|
|
{
|
|
|
|
Q_UNUSED(mainWindow);
|
|
|
|
|
2021-11-25 22:54:37 +08:00
|
|
|
actionOpen->setText(QCoreApplication::translate("MainWindow", "&Open...", nullptr));
|
|
|
|
|
2021-07-02 00:06:23 +08:00
|
|
|
actionActualSize->setText(QCoreApplication::translate("MainWindow", "Actual size", nullptr));
|
|
|
|
actionToggleMaximize->setText(QCoreApplication::translate("MainWindow", "Toggle maximize", nullptr));
|
2021-02-18 20:03:17 +08:00
|
|
|
actionZoomIn->setText(QCoreApplication::translate("MainWindow", "Zoom in", nullptr));
|
|
|
|
actionZoomOut->setText(QCoreApplication::translate("MainWindow", "Zoom out", nullptr));
|
2021-07-02 00:06:23 +08:00
|
|
|
actionToggleCheckerboard->setText(QCoreApplication::translate("MainWindow", "Toggle Checkerboard", nullptr));
|
|
|
|
actionRotateClockwise->setText(QCoreApplication::translate("MainWindow", "Rotate right", nullptr));
|
|
|
|
|
2021-10-08 14:06:18 +08:00
|
|
|
actionPrevPicture->setText(QCoreApplication::translate("MainWindow", "Previous image", nullptr));
|
|
|
|
actionNextPicture->setText(QCoreApplication::translate("MainWindow", "Next image", nullptr));
|
|
|
|
|
2021-04-05 23:21:15 +08:00
|
|
|
actionHorizontalFlip->setText(QCoreApplication::translate("MainWindow", "Flip &Horizontally", nullptr));
|
2021-06-04 13:53:47 +08:00
|
|
|
actionFitInView->setText("Fit in view"); // TODO: what should it called?
|
2021-05-14 00:00:03 +08:00
|
|
|
actionFitByWidth->setText("Fit by width"); // TODO: what should it called?
|
2021-01-24 00:07:58 +08:00
|
|
|
actionCopyPixmap->setText(QCoreApplication::translate("MainWindow", "Copy P&ixmap", nullptr));
|
|
|
|
actionCopyFilePath->setText(QCoreApplication::translate("MainWindow", "Copy &File Path", nullptr));
|
|
|
|
actionPaste->setText(QCoreApplication::translate("MainWindow", "&Paste", nullptr));
|
|
|
|
actionToggleStayOnTop->setText(QCoreApplication::translate("MainWindow", "Stay on top", nullptr));
|
|
|
|
actionToggleProtectMode->setText(QCoreApplication::translate("MainWindow", "Protected mode", nullptr));
|
|
|
|
actionSettings->setText(QCoreApplication::translate("MainWindow", "Configure...", nullptr));
|
|
|
|
actionHelp->setText(QCoreApplication::translate("MainWindow", "Help", nullptr));
|
2022-01-21 16:48:43 +08:00
|
|
|
actionLocateInFileManager->setText("Open Containing Folder"); // TODO: what should it called?
|
2021-01-24 00:07:58 +08:00
|
|
|
actionProperties->setText(QCoreApplication::translate("MainWindow", "Properties", nullptr));
|
|
|
|
actionQuitApp->setText(QCoreApplication::translate("MainWindow", "Quit", nullptr));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActionManager::setupShortcuts()
|
|
|
|
{
|
2021-11-25 22:54:37 +08:00
|
|
|
actionOpen->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_O));
|
2021-10-08 14:06:18 +08:00
|
|
|
actionActualSize->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_0));
|
2021-02-18 23:44:23 +08:00
|
|
|
actionZoomIn->setShortcut(QKeySequence(QKeySequence::ZoomIn));
|
|
|
|
actionZoomOut->setShortcut(QKeySequence(QKeySequence::ZoomOut));
|
2021-12-17 13:36:20 +08:00
|
|
|
actionPrevPicture->setShortcuts({
|
|
|
|
QKeySequence(Qt::Key_PageUp),
|
|
|
|
QKeySequence(Qt::Key_Left),
|
|
|
|
});
|
|
|
|
actionNextPicture->setShortcuts({
|
|
|
|
QKeySequence(Qt::Key_PageDown),
|
|
|
|
QKeySequence(Qt::Key_Right),
|
|
|
|
});
|
2021-10-08 14:06:18 +08:00
|
|
|
actionHorizontalFlip->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_R));
|
2021-04-05 23:21:15 +08:00
|
|
|
actionCopyPixmap->setShortcut(QKeySequence(QKeySequence::Copy));
|
|
|
|
actionPaste->setShortcut(QKeySequence::Paste);
|
|
|
|
actionHelp->setShortcut(QKeySequence::HelpContents);
|
|
|
|
actionSettings->setShortcut(QKeySequence::Preferences);
|
2021-10-08 14:06:18 +08:00
|
|
|
actionProperties->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_I));
|
2021-01-24 00:07:58 +08:00
|
|
|
actionQuitApp->setShortcuts({
|
|
|
|
QKeySequence(Qt::Key_Space),
|
|
|
|
QKeySequence(Qt::Key_Escape)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|