From d2ef9608fcbe8453fd44b0b25947e8f1b79cb199 Mon Sep 17 00:00:00 2001 From: Le Tan Date: Fri, 8 Sep 2017 21:40:31 +0800 Subject: [PATCH] bug-fix: use platform-specific text of QKeySequence in context menu --- src/utils/vutils.cpp | 6 ++++++ src/utils/vutils.h | 3 +++ src/vdirectorytree.cpp | 8 ++++---- src/vfilelist.cpp | 10 +++++----- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/utils/vutils.cpp b/src/utils/vutils.cpp index d2b239af..be92d588 100644 --- a/src/utils/vutils.cpp +++ b/src/utils/vutils.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include "vfile.h" #include "vnote.h" @@ -696,3 +697,8 @@ void VUtils::decodeUrl(QString &p_url) p_url.replace(it.key(), it.value()); } } + +QString VUtils::getShortcutText(const QString &p_keySeq) +{ + return QKeySequence(p_keySeq).toString(QKeySequence::NativeText); +} diff --git a/src/utils/vutils.h b/src/utils/vutils.h index 6c863744..0e417790 100644 --- a/src/utils/vutils.h +++ b/src/utils/vutils.h @@ -121,6 +121,9 @@ public: // Decode URL by simply replacing meta-characters. static void decodeUrl(QString &p_url); + // Returns the shortcut text. + static QString getShortcutText(const QString &p_keySeq); + // Regular expression for image link. // ![image title]( http://github.com/tamlok/vnote.jpg "alt \" text" ) // Captured texts (need to be trimmed): diff --git a/src/vdirectorytree.cpp b/src/vdirectorytree.cpp index 60bb4081..ba2daa21 100644 --- a/src/vdirectorytree.cpp +++ b/src/vdirectorytree.cpp @@ -88,25 +88,25 @@ void VDirectoryTree::initActions() this, &VDirectoryTree::deleteDirectory); dirInfoAct = new QAction(QIcon(":/resources/icons/dir_info.svg"), - tr("&Info\t%1").arg(QKeySequence(c_infoShortcutSequence).toString()), this); + tr("&Info\t%1").arg(VUtils::getShortcutText(c_infoShortcutSequence)), this); dirInfoAct->setToolTip(tr("View and edit current folder's information")); connect(dirInfoAct, &QAction::triggered, this, &VDirectoryTree::editDirectoryInfo); copyAct = new QAction(QIcon(":/resources/icons/copy.svg"), - tr("&Copy\t%1").arg(QKeySequence(c_copyShortcutSequence).toString()), this); + tr("&Copy\t%1").arg(VUtils::getShortcutText(c_copyShortcutSequence)), this); copyAct->setToolTip(tr("Copy selected folders")); connect(copyAct, &QAction::triggered, this, &VDirectoryTree::copySelectedDirectories); cutAct = new QAction(QIcon(":/resources/icons/cut.svg"), - tr("C&ut\t%1").arg(QKeySequence(c_cutShortcutSequence).toString()), this); + tr("C&ut\t%1").arg(VUtils::getShortcutText(c_cutShortcutSequence)), this); cutAct->setToolTip(tr("Cut selected folders")); connect(cutAct, &QAction::triggered, this, &VDirectoryTree::cutSelectedDirectories); pasteAct = new QAction(QIcon(":/resources/icons/paste.svg"), - tr("&Paste\t%1").arg(QKeySequence(c_pasteShortcutSequence).toString()), this); + tr("&Paste\t%1").arg(VUtils::getShortcutText(c_pasteShortcutSequence)), this); pasteAct->setToolTip(tr("Paste folders in this folder")); connect(pasteAct, &QAction::triggered, this, &VDirectoryTree::pasteDirectoriesInCurDir); diff --git a/src/vfilelist.cpp b/src/vfilelist.cpp index 143c0516..d7edbea7 100644 --- a/src/vfilelist.cpp +++ b/src/vfilelist.cpp @@ -85,7 +85,7 @@ void VFileList::initActions() { newFileAct = new QAction(QIcon(":/resources/icons/create_note.svg"), tr("&New Note"), this); - QString shortcutStr = QKeySequence(g_config->getShortcutKeySequence("NewNote")).toString(); + QString shortcutStr = VUtils::getShortcutText(g_config->getShortcutKeySequence("NewNote")); if (!shortcutStr.isEmpty()) { newFileAct->setText(tr("&New Note\t%1").arg(shortcutStr)); } @@ -101,25 +101,25 @@ void VFileList::initActions() this, SLOT(deleteFile())); fileInfoAct = new QAction(QIcon(":/resources/icons/note_info.svg"), - tr("&Info\t%1").arg(QKeySequence(c_infoShortcutSequence).toString()), this); + tr("&Info\t%1").arg(VUtils::getShortcutText(c_infoShortcutSequence)), this); fileInfoAct->setToolTip(tr("View and edit current note's information")); connect(fileInfoAct, SIGNAL(triggered(bool)), this, SLOT(fileInfo())); copyAct = new QAction(QIcon(":/resources/icons/copy.svg"), - tr("&Copy\t%1").arg(QKeySequence(c_copyShortcutSequence).toString()), this); + tr("&Copy\t%1").arg(VUtils::getShortcutText(c_copyShortcutSequence)), this); copyAct->setToolTip(tr("Copy selected notes")); connect(copyAct, &QAction::triggered, this, &VFileList::copySelectedFiles); cutAct = new QAction(QIcon(":/resources/icons/cut.svg"), - tr("C&ut\t%1").arg(QKeySequence(c_cutShortcutSequence).toString()), this); + tr("C&ut\t%1").arg(VUtils::getShortcutText(c_cutShortcutSequence)), this); cutAct->setToolTip(tr("Cut selected notes")); connect(cutAct, &QAction::triggered, this, &VFileList::cutSelectedFiles); pasteAct = new QAction(QIcon(":/resources/icons/paste.svg"), - tr("&Paste\t%1").arg(QKeySequence(c_pasteShortcutSequence).toString()), this); + tr("&Paste\t%1").arg(VUtils::getShortcutText(c_pasteShortcutSequence)), this); pasteAct->setToolTip(tr("Paste notes in current folder")); connect(pasteAct, &QAction::triggered, this, &VFileList::pasteFilesInCurDir);