feat: add some icons for corresponding menu actions

This commit is contained in:
Gary Wang 2024-04-03 19:56:46 +08:00
parent bba4863853
commit 6145925283
No known key found for this signature in database
GPG Key ID: 5D30A4F15EA78760
2 changed files with 10 additions and 7 deletions

View File

@ -39,10 +39,10 @@ QIcon ActionManager::loadHidpiIcon(const QString &resp, QSize sz)
void ActionManager::setupAction(MainWindow *mainWindow) void ActionManager::setupAction(MainWindow *mainWindow)
{ {
auto create_action = [] (QWidget *w, QAction **a, QString i, QString an) { 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())
(*a)->setIcon(ActionManager::loadHidpiIcon(i)); (*a)->setIcon(iconFromTheme ? QIcon::fromTheme(i) : ActionManager::loadHidpiIcon(i));
(*a)->setObjectName(an); (*a)->setObjectName(an);
w->addAction(*a); w->addAction(*a);
}; };
@ -56,25 +56,27 @@ void ActionManager::setupAction(MainWindow *mainWindow)
#undef CREATE_NEW_ICON_ACTION #undef CREATE_NEW_ICON_ACTION
#define CREATE_NEW_ACTION(w, a) create_action(w, &a, QString(), ACTION_NAME(a)) #define CREATE_NEW_ACTION(w, a) create_action(w, &a, QString(), ACTION_NAME(a))
#define CREATE_NEW_THEMEICON_ACTION(w, a, i) create_action(w, &a, QLatin1String(STRIFY(i)), ACTION_NAME(a), true)
CREATE_NEW_ACTION(mainWindow, actionPrevPicture); CREATE_NEW_ACTION(mainWindow, actionPrevPicture);
CREATE_NEW_ACTION(mainWindow, actionNextPicture); CREATE_NEW_ACTION(mainWindow, actionNextPicture);
CREATE_NEW_ACTION(mainWindow, actionOpen); CREATE_NEW_THEMEICON_ACTION(mainWindow, actionOpen, document-open);
CREATE_NEW_ACTION(mainWindow, actionHorizontalFlip); CREATE_NEW_ACTION(mainWindow, actionHorizontalFlip);
CREATE_NEW_ACTION(mainWindow, actionFitInView); CREATE_NEW_ACTION(mainWindow, actionFitInView);
CREATE_NEW_ACTION(mainWindow, actionFitByWidth); CREATE_NEW_ACTION(mainWindow, actionFitByWidth);
CREATE_NEW_ACTION(mainWindow, actionCopyPixmap); CREATE_NEW_THEMEICON_ACTION(mainWindow, actionCopyPixmap, edit-copy);
CREATE_NEW_ACTION(mainWindow, actionCopyFilePath); CREATE_NEW_ACTION(mainWindow, actionCopyFilePath);
CREATE_NEW_ACTION(mainWindow, actionPaste); CREATE_NEW_THEMEICON_ACTION(mainWindow, actionPaste, edit-paste);
CREATE_NEW_ACTION(mainWindow, actionToggleStayOnTop); CREATE_NEW_ACTION(mainWindow, actionToggleStayOnTop);
CREATE_NEW_ACTION(mainWindow, actionToggleProtectMode); CREATE_NEW_ACTION(mainWindow, actionToggleProtectMode);
CREATE_NEW_ACTION(mainWindow, actionToggleAvoidResetTransform); CREATE_NEW_ACTION(mainWindow, actionToggleAvoidResetTransform);
CREATE_NEW_ACTION(mainWindow, actionSettings); CREATE_NEW_ACTION(mainWindow, actionSettings);
CREATE_NEW_ACTION(mainWindow, actionHelp); CREATE_NEW_THEMEICON_ACTION(mainWindow, actionHelp, system-help);
CREATE_NEW_ACTION(mainWindow, actionLocateInFileManager); CREATE_NEW_THEMEICON_ACTION(mainWindow, actionLocateInFileManager, system-file-manager);
CREATE_NEW_ACTION(mainWindow, actionProperties); CREATE_NEW_ACTION(mainWindow, actionProperties);
CREATE_NEW_ACTION(mainWindow, actionQuitApp); CREATE_NEW_ACTION(mainWindow, actionQuitApp);
#undef CREATE_NEW_ACTION #undef CREATE_NEW_ACTION
#undef CREATE_NEW_THEMEICON_ACTION
retranslateUi(mainWindow); retranslateUi(mainWindow);

View File

@ -438,6 +438,7 @@ void MainWindow::contextMenuEvent(QContextMenuEvent *event)
QAction * copyPixmap = m_am->actionCopyPixmap; QAction * copyPixmap = m_am->actionCopyPixmap;
QAction * copyFilePath = m_am->actionCopyFilePath; QAction * copyFilePath = m_am->actionCopyFilePath;
copyMenu->setIcon(QIcon::fromTheme(QLatin1String("edit-copy")));
copyMenu->addAction(copyPixmap); copyMenu->addAction(copyPixmap);
if (currentFileUrl.isValid()) { if (currentFileUrl.isValid()) {
copyMenu->addAction(copyFilePath); copyMenu->addAction(copyFilePath);