refactor: merge retranslateUi into setupAction in ActionManager
This commit is contained in:
@@ -10,12 +10,6 @@
|
|||||||
#include <QSvgRenderer>
|
#include <QSvgRenderer>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
#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)
|
QIcon ActionManager::loadHidpiIcon(const QString &resp, QSize sz)
|
||||||
{
|
{
|
||||||
QSvgRenderer r(resp);
|
QSvgRenderer r(resp);
|
||||||
@@ -29,6 +23,14 @@ QIcon ActionManager::loadHidpiIcon(const QString &resp, QSize sz)
|
|||||||
|
|
||||||
void ActionManager::setupAction(MainWindow *mainWindow)
|
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) {
|
auto create_action = [] (QWidget *w, QAction **a, QString i, QString an, bool iconFromTheme = false) {
|
||||||
*a = new QAction(w);
|
*a = new QAction(w);
|
||||||
if (!i.isNull())
|
if (!i.isNull())
|
||||||
@@ -36,6 +38,7 @@ void ActionManager::setupAction(MainWindow *mainWindow)
|
|||||||
(*a)->setObjectName(an);
|
(*a)->setObjectName(an);
|
||||||
w->addAction(*a);
|
w->addAction(*a);
|
||||||
};
|
};
|
||||||
|
|
||||||
#define CREATE_NEW_ICON_ACTION(w, a, i) create_action(w, &a, ICON_NAME(i), ACTION_NAME(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, actionActualSize, zoom-original);
|
||||||
CREATE_NEW_ICON_ACTION(mainWindow, actionToggleMaximize, view-fullscreen);
|
CREATE_NEW_ICON_ACTION(mainWindow, actionToggleMaximize, view-fullscreen);
|
||||||
@@ -71,14 +74,13 @@ void ActionManager::setupAction(MainWindow *mainWindow)
|
|||||||
#undef CREATE_NEW_ACTION
|
#undef CREATE_NEW_ACTION
|
||||||
#undef CREATE_NEW_THEMEICON_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)
|
// region: Action Translatable Text Setup
|
||||||
{
|
|
||||||
Q_UNUSED(mainWindow);
|
|
||||||
|
|
||||||
actionOpen->setText(QCoreApplication::translate("MainWindow", "&Open...", nullptr));
|
actionOpen->setText(QCoreApplication::translate("MainWindow", "&Open...", nullptr));
|
||||||
|
|
||||||
@@ -111,13 +113,17 @@ void ActionManager::retranslateUi(MainWindow *mainWindow)
|
|||||||
QCoreApplication::translate(
|
QCoreApplication::translate(
|
||||||
"MainWindow", "Show in File Explorer",
|
"MainWindow", "Show in File Explorer",
|
||||||
"File Explorer is the name of explorer.exe under Windows"
|
"File Explorer is the name of explorer.exe under Windows"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
#else
|
#else
|
||||||
actionLocateInFileManager->setText(QCoreApplication::translate("MainWindow", "Show in directory", nullptr));
|
actionLocateInFileManager->setText(QCoreApplication::translate("MainWindow", "Show in directory", nullptr));
|
||||||
#endif // Q_OS_WIN
|
#endif // Q_OS_WIN
|
||||||
actionProperties->setText(QCoreApplication::translate("MainWindow", "Properties", nullptr));
|
actionProperties->setText(QCoreApplication::translate("MainWindow", "Properties", nullptr));
|
||||||
actionQuitApp->setText(QCoreApplication::translate("MainWindow", "Quit", nullptr));
|
actionQuitApp->setText(QCoreApplication::translate("MainWindow", "Quit", nullptr));
|
||||||
|
|
||||||
|
// endregion
|
||||||
|
|
||||||
|
QMetaObject::connectSlotsByName(mainWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActionManager::setupShortcuts()
|
void ActionManager::setupShortcuts()
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
|
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
|
|
||||||
|
/// Action Manager is separated from Main Window
|
||||||
|
/// to manage all actions specifically.
|
||||||
class ActionManager
|
class ActionManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -16,7 +18,6 @@ public:
|
|||||||
~ActionManager() = default;
|
~ActionManager() = default;
|
||||||
|
|
||||||
void setupAction(MainWindow * mainWindow);
|
void setupAction(MainWindow * mainWindow);
|
||||||
void retranslateUi(MainWindow *MainWindow);
|
|
||||||
void setupShortcuts();
|
void setupShortcuts();
|
||||||
void enablePrevNextPictureAction(bool enablePrevPictureAction, bool enableNextPictureAction);
|
void enablePrevNextPictureAction(bool enablePrevPictureAction, bool enableNextPictureAction);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user