Do not use QObject::tr but directly tr.

It simplify the code and allow the translation to keep the context
(the class of the object) instead of always having the `QObject` context.
This commit is contained in:
Matthieu Gautier 2018-09-05 15:50:54 +02:00
parent 171a307a7b
commit d37cdd6e2d
5 changed files with 40 additions and 42 deletions

View File

@ -2,7 +2,6 @@
#include "zim/error.h"
#include <QLocale>
#include <QObject>
#include <QLibraryInfo>
#include <QFontDatabase>
#include <QStyleFactory>
@ -93,7 +92,7 @@ void KiwixApp::openZimFile(const QString &zimfile)
if (_zimfile.isEmpty()) {
_zimfile = QFileDialog::getOpenFileName(
getMainWindow(),
QObject::tr("Open Zim"),
tr("Open Zim"),
QString(),
"ZimFile (*.zim*)");
}
@ -171,109 +170,109 @@ QAction *KiwixApp::getAction(KiwixApp::Actions action)
void KiwixApp::createAction()
{
CREATE_ACTION_ICON(KiwixServeAction, "share", QObject::tr("Local Kiwix Server"));
CREATE_ACTION_ICON(KiwixServeAction, "share", tr("Local Kiwix Server"));
SET_SHORTCUT(KiwixServeAction, QKeySequence(Qt::CTRL+Qt::Key_I));
HIDE_ACTION(KiwixServeAction);
CREATE_ACTION_ICON(RandomArticleAction, "random", QObject::tr("Random Article"));
CREATE_ACTION_ICON(RandomArticleAction, "random", tr("Random Article"));
SET_SHORTCUT(RandomArticleAction, QKeySequence(Qt::CTRL+Qt::Key_R));
connect(mpa_actions[RandomArticleAction], &QAction::triggered,
this, [=]() { this->openRandomUrl(); });
CREATE_ACTION_ICON(PrintAction, "print", QObject::tr("Print"));
CREATE_ACTION_ICON(PrintAction, "print", tr("Print"));
SET_SHORTCUT(PrintAction, QKeySequence::Print);
connect(mpa_actions[PrintAction], &QAction::triggered,
this, &KiwixApp::printPage);
CREATE_ACTION(NewTabAction, QObject::tr("New tab"));
CREATE_ACTION(NewTabAction, tr("New tab"));
SET_SHORTCUT(NewTabAction, QKeySequence::AddTab);
CREATE_ACTION(CloseTabAction, QObject::tr("Close tab"));
CREATE_ACTION(CloseTabAction, tr("Close tab"));
SET_SHORTCUT(CloseTabAction, QKeySequence::Close);
CREATE_ACTION(ReopenClosedTabAction, QObject::tr("Reopen closed tab"));
CREATE_ACTION(ReopenClosedTabAction, tr("Reopen closed tab"));
SET_SHORTCUT(ReopenClosedTabAction, QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_T));
HIDE_ACTION(ReopenClosedTabAction);
CREATE_ACTION(BrowseLibraryAction, QObject::tr("Browse library"));
CREATE_ACTION(BrowseLibraryAction, tr("Browse library"));
SET_SHORTCUT(BrowseLibraryAction, QKeySequence(Qt::CTRL+Qt::Key_E));
HIDE_ACTION(BrowseLibraryAction);
CREATE_ACTION(OpenFileAction, QObject::tr("Open file"));
CREATE_ACTION(OpenFileAction, tr("Open file"));
SET_SHORTCUT(OpenFileAction, QKeySequence::Open);
connect(mpa_actions[OpenFileAction], &QAction::triggered,
this, [=]() { openZimFile(); });
CREATE_ACTION(OpenRecentAction, QObject::tr("Open recent"));
CREATE_ACTION(OpenRecentAction, tr("Open recent"));
HIDE_ACTION(OpenRecentAction);
CREATE_ACTION(SavePageAsAction, QObject::tr("Save page as ..."));
CREATE_ACTION(SavePageAsAction, tr("Save page as ..."));
SET_SHORTCUT(SavePageAsAction, QKeySequence::SaveAs);
HIDE_ACTION(SavePageAsAction);
CREATE_ACTION(SearchArticleAction, QObject::tr("Search article"));
CREATE_ACTION(SearchArticleAction, tr("Search article"));
SET_SHORTCUT(SearchArticleAction, QKeySequence(Qt::CTRL+Qt::Key_L));
HIDE_ACTION(SearchArticleAction);
CREATE_ACTION(SearchLibraryAction, QObject::tr("Search in library"));
CREATE_ACTION(SearchLibraryAction, tr("Search in library"));
SET_SHORTCUT(SearchLibraryAction, QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_R));
HIDE_ACTION(SearchLibraryAction);
CREATE_ACTION(FindInPageAction, QObject::tr("Find in page"));
CREATE_ACTION(FindInPageAction, tr("Find in page"));
SET_SHORTCUT(FindInPageAction, QKeySequence::Find);
CREATE_ACTION_ICON(ToggleFullscreenAction, "full-screen-enter", QObject::tr("Set fullScreen"));
CREATE_ACTION_ICON(ToggleFullscreenAction, "full-screen-enter", tr("Set fullScreen"));
SET_SHORTCUT(ToggleFullscreenAction, QKeySequence::FullScreen);
connect(mpa_actions[ToggleFullscreenAction], &QAction::toggled,
this, [=](bool checked) {
auto action = mpa_actions[ToggleFullscreenAction];
action->setIcon(
QIcon(checked ? ":/icons/full-screen-exit.svg" : ":/icons/full-screen-enter.svg"));
action->setText(checked ? QObject::tr("Quit fullScreen") : QObject::tr("Set fullScreen"));
action->setText(checked ? tr("Quit fullScreen") : tr("Set fullScreen"));
});
mpa_actions[ToggleFullscreenAction]->setCheckable(true);
CREATE_ACTION(ToggleTOCAction, QObject::tr("Table of content"));
CREATE_ACTION(ToggleTOCAction, tr("Table of content"));
SET_SHORTCUT(ToggleTOCAction, QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_1));
HIDE_ACTION(ToggleTOCAction);
CREATE_ACTION(ToggleReadingListAction, QObject::tr("Reading list"));
CREATE_ACTION(ToggleReadingListAction, tr("Reading list"));
SET_SHORTCUT(ToggleReadingListAction, QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_2));
HIDE_ACTION(ToggleReadingListAction);
CREATE_ACTION(ZoomInAction, QObject::tr("Zoom in"));
CREATE_ACTION(ZoomInAction, tr("Zoom in"));
SET_SHORTCUT(ZoomInAction, QKeySequence::ZoomIn);
CREATE_ACTION(ZoomOutAction, QObject::tr("Zoom out"));
CREATE_ACTION(ZoomOutAction, tr("Zoom out"));
SET_SHORTCUT(ZoomOutAction, QKeySequence::ZoomOut);
CREATE_ACTION(ZoomResetAction, QObject::tr("Zoom reset"));
CREATE_ACTION(ZoomResetAction, tr("Zoom reset"));
SET_SHORTCUT(ZoomResetAction, QKeySequence(Qt::CTRL+Qt::Key_0));
CREATE_ACTION(HelpAction, QObject::tr("Help"));
CREATE_ACTION(HelpAction, tr("Help"));
SET_SHORTCUT(HelpAction, QKeySequence::HelpContents);
HIDE_ACTION(HelpAction);
CREATE_ACTION(FeedbackAction, QObject::tr("Feedback"));
CREATE_ACTION(FeedbackAction, tr("Feedback"));
HIDE_ACTION(FeedbackAction);
CREATE_ACTION(ReportBugAction, QObject::tr("Repost a bug"));
CREATE_ACTION(ReportBugAction, tr("Repost a bug"));
HIDE_ACTION(ReportBugAction);
CREATE_ACTION(RequestFeatureAction, QObject::tr("Request a feature"));
CREATE_ACTION(RequestFeatureAction, tr("Request a feature"));
HIDE_ACTION(RequestFeatureAction);
CREATE_ACTION(AboutAction, QObject::tr("About Kiwix"));
CREATE_ACTION(AboutAction, tr("About Kiwix"));
CREATE_ACTION_ICON(SettingAction, "settings", QObject::tr("Settings"));
CREATE_ACTION_ICON(SettingAction, "settings", tr("Settings"));
SET_SHORTCUT(SettingAction, QKeySequence::Preferences);
HIDE_ACTION(SettingAction);
CREATE_ACTION_ICON(DonateAction, "donate", QObject::tr("Donate to support Kiwix"));
CREATE_ACTION_ICON(DonateAction, "donate", tr("Donate to support Kiwix"));
//SET_SHORTCUT(DonateAction, QKeySequence(Qt::CTRL+Qt::Key_BracketLeft+Qt::Key_3));
HIDE_ACTION(DonateAction);
CREATE_ACTION_ICON(ExitAction, "exit", QObject::tr("Exit"));
CREATE_ACTION_ICON(ExitAction, "exit", tr("Exit"));
SET_SHORTCUT(ExitAction, QKeySequence::Quit);
}

View File

@ -15,7 +15,7 @@ MainMenu::MainMenu(QWidget *parent) :
ADD_ACTION(PrintAction);
addSeparator();
m_fileMenu.setTitle(QObject::tr("File"));
m_fileMenu.setTitle(tr("File"));
m_fileMenu.ADD_ACTION(NewTabAction);
m_fileMenu.ADD_ACTION(CloseTabAction);
m_fileMenu.ADD_ACTION(ReopenClosedTabAction);
@ -25,13 +25,13 @@ MainMenu::MainMenu(QWidget *parent) :
m_fileMenu.ADD_ACTION(SavePageAsAction);
addMenu(&m_fileMenu);
m_editMenu.setTitle(QObject::tr("Edit"));
m_editMenu.setTitle(tr("Edit"));
m_editMenu.ADD_ACTION(SearchArticleAction);
m_editMenu.ADD_ACTION(SearchLibraryAction);
m_editMenu.ADD_ACTION(FindInPageAction);
addMenu(&m_editMenu);
m_viewMenu.setTitle(QObject::tr("View"));
m_viewMenu.setTitle(tr("View"));
m_viewMenu.ADD_ACTION(ToggleFullscreenAction);
m_viewMenu.ADD_ACTION(ToggleTOCAction);
m_viewMenu.ADD_ACTION(ToggleReadingListAction);
@ -40,11 +40,11 @@ MainMenu::MainMenu(QWidget *parent) :
m_viewMenu.ADD_ACTION(ZoomResetAction);
addMenu(&m_viewMenu);
m_toolsMenu.setTitle(QObject::tr("Tools"));
m_toolsMenu.setTitle(tr("Tools"));
// m_toolsMenu.addAction();
// addMenu(&m_toolsMenu);
m_helpMenu.setTitle(QObject::tr("Help"));
m_helpMenu.setTitle(tr("Help"));
m_helpMenu.ADD_ACTION(HelpAction);
m_helpMenu.ADD_ACTION(FeedbackAction);
m_helpMenu.ADD_ACTION(ReportBugAction);

View File

@ -5,6 +5,7 @@
class MainMenu : public QMenu
{
Q_OBJECT
public:
MainMenu(QWidget *parent=nullptr);

View File

@ -1,6 +1,5 @@
#include "searchbar.h"
#include <QObject>
#include <QCompleter>
#include <QTimer>
@ -10,7 +9,7 @@ SearchBar::SearchBar(QWidget *parent) :
QLineEdit(parent),
m_completer(&m_completionModel, this)
{
setPlaceholderText(QObject::tr("Search"));
setPlaceholderText(tr("Search"));
m_completer.setCompletionMode(QCompleter::UnfilteredPopupCompletion);
setCompleter(&m_completer);
connect(this, &QLineEdit::textEdited, this, &SearchBar::updateCompletion);

View File

@ -4,7 +4,6 @@
#include "kiwixapp.h"
#include "mainmenu.h"
#include <QObject>
#include <QMouseEvent>
#include <QAction>
@ -13,16 +12,16 @@ TopWidget::TopWidget(QWidget *parent) :
{
mp_historyBackAction = new QAction(this);
mp_historyBackAction->setIcon(QIcon(":/icons/back.svg"));
mp_historyBackAction->setText(QObject::tr("back"));
mp_historyBackAction->setToolTip(QObject::tr("back"));
mp_historyBackAction->setText(tr("back"));
mp_historyBackAction->setToolTip(tr("back"));
connect(mp_historyBackAction, &QAction::triggered, [this](){
KiwixApp::instance()->getTabWidget()->triggerWebPageAction(QWebEnginePage::Back);
});
addAction(mp_historyBackAction);
mp_historyForwardAction = new QAction(this);
mp_historyForwardAction->setIcon(QIcon(":/icons/forward.svg"));
mp_historyForwardAction->setText(QObject::tr("forward"));
mp_historyForwardAction->setToolTip(QObject::tr("forward"));
mp_historyForwardAction->setText(tr("forward"));
mp_historyForwardAction->setToolTip(tr("forward"));
connect(mp_historyForwardAction, &QAction::triggered, [this](){
KiwixApp::instance()->getTabWidget()->triggerWebPageAction(QWebEnginePage::Forward);
});