diff --git a/app/actionmanager.cpp b/app/actionmanager.cpp index 3de0d7f..da1ebba 100644 --- a/app/actionmanager.cpp +++ b/app/actionmanager.cpp @@ -10,12 +10,6 @@ #include #include -#define ICON_NAME(name)\ - QStringLiteral(":/icons/" #name ".svg") - -#define ACTION_NAME(s) QStringLiteral(STRIFY(s)) -#define STRIFY(s) #s - QIcon ActionManager::loadHidpiIcon(const QString &resp, QSize sz) { QSvgRenderer r(resp); @@ -29,6 +23,14 @@ QIcon ActionManager::loadHidpiIcon(const QString &resp, QSize sz) void ActionManager::setupAction(MainWindow *mainWindow) { + // region: Action and Its Icon Creation + + #define ICON_NAME(name)\ + QStringLiteral(":/icons/" #name ".svg") + + #define ACTION_NAME(s) QStringLiteral(STRIFY(s)) + #define STRIFY(s) #s + auto create_action = [] (QWidget *w, QAction **a, QString i, QString an, bool iconFromTheme = false) { *a = new QAction(w); if (!i.isNull()) @@ -36,6 +38,7 @@ void ActionManager::setupAction(MainWindow *mainWindow) (*a)->setObjectName(an); w->addAction(*a); }; + #define CREATE_NEW_ICON_ACTION(w, a, i) create_action(w, &a, ICON_NAME(i), ACTION_NAME(a)) CREATE_NEW_ICON_ACTION(mainWindow, actionActualSize, zoom-original); CREATE_NEW_ICON_ACTION(mainWindow, actionToggleMaximize, view-fullscreen); @@ -71,14 +74,13 @@ void ActionManager::setupAction(MainWindow *mainWindow) #undef CREATE_NEW_ACTION #undef CREATE_NEW_THEMEICON_ACTION - retranslateUi(mainWindow); + #undef STRIFY + #undef ACTION_NAME + #undef ICON_NAME - QMetaObject::connectSlotsByName(mainWindow); -} + // endregion -void ActionManager::retranslateUi(MainWindow *mainWindow) -{ - Q_UNUSED(mainWindow); + // region: Action Translatable Text Setup actionOpen->setText(QCoreApplication::translate("MainWindow", "&Open...", nullptr)); @@ -111,13 +113,17 @@ void ActionManager::retranslateUi(MainWindow *mainWindow) QCoreApplication::translate( "MainWindow", "Show in File Explorer", "File Explorer is the name of explorer.exe under Windows" - ) - ); + ) + ); #else actionLocateInFileManager->setText(QCoreApplication::translate("MainWindow", "Show in directory", nullptr)); #endif // Q_OS_WIN actionProperties->setText(QCoreApplication::translate("MainWindow", "Properties", nullptr)); actionQuitApp->setText(QCoreApplication::translate("MainWindow", "Quit", nullptr)); + + // endregion + + QMetaObject::connectSlotsByName(mainWindow); } void ActionManager::setupShortcuts() diff --git a/app/actionmanager.h b/app/actionmanager.h index edf0740..4523173 100644 --- a/app/actionmanager.h +++ b/app/actionmanager.h @@ -9,6 +9,8 @@ class MainWindow; +/// Action Manager is separated from Main Window +/// to manage all actions specifically. class ActionManager { public: @@ -16,7 +18,6 @@ public: ~ActionManager() = default; void setupAction(MainWindow * mainWindow); - void retranslateUi(MainWindow *MainWindow); void setupShortcuts(); void enablePrevNextPictureAction(bool enablePrevPictureAction, bool enableNextPictureAction);