Permalink
Browse files

NOISSUE add tooltips to new menu buttons and make them translateable

  • Loading branch information...
peterix committed Oct 4, 2017
1 parent d8c8a41 commit 4b90a078de96bf690bcb34e309138b7cbd5cfc07
Showing with 28 additions and 21 deletions.
  1. +28 −21 application/MainWindow.cpp
View
@@ -91,17 +91,14 @@
#include "UpdateController.h"
// WHY: to hold the pre-translation strings together with the QAction pointer, so it can be retranslated without a lot of ugly code
class TranslatedAction
template <typename T>
class Translated
{
public:
TranslatedAction(){}
TranslatedAction(QWidget *parent)
Translated(){}
Translated(QWidget *parent)
{
m_contained = new QAction(parent);
}
~TranslatedAction()
{
m_contained = new T(parent);
}
void setTooltipId(const char * tooltip)
{
@@ -111,11 +108,11 @@ class TranslatedAction
{
m_text = text;
}
operator QAction*()
operator T*()
{
return m_contained;
}
QAction * operator->()
T * operator->()
{
return m_contained;
}
@@ -131,10 +128,12 @@ class TranslatedAction
}
}
private:
QAction * m_contained = nullptr;
T * m_contained = nullptr;
const char * m_text = nullptr;
const char * m_tooltip = nullptr;
};
using TranslatedAction = Translated<QAction>;
using TranslatedToolButton = Translated<QToolButton>;
// WHY: to hold the pre-translation strings together with the QToolbar pointer, so it can be retranslated without a lot of ugly code
class TranslatedToolbar
@@ -144,10 +143,6 @@ class TranslatedToolbar
TranslatedToolbar(QWidget *parent)
{
m_contained = new QToolBar(parent);
}
~TranslatedToolbar()
{
}
void setWindowTitleId(const char * title)
{
@@ -205,17 +200,19 @@ class MainWindow::Ui
LabeledToolButton *changeIconButton = nullptr;
QMenu * foldersMenu = nullptr;
QToolButton * foldersMenuButton = nullptr;
TranslatedToolButton foldersMenuButton;
TranslatedAction actionViewInstanceFolder;
TranslatedAction actionViewCentralModsFolder;
QMenu * helpMenu = nullptr;
QToolButton * helpMenuButton = nullptr;
TranslatedToolButton helpMenuButton;
TranslatedAction actionReportBug;
TranslatedAction actionDISCORD;
TranslatedAction actionREDDIT;
TranslatedAction actionAbout;
QVector<TranslatedToolButton *> all_toolbuttons;
QWidget *centralWidget = nullptr;
QHBoxLayout *horizontalLayout = nullptr;
QStatusBar *statusBar = nullptr;
@@ -267,6 +264,7 @@ class MainWindow::Ui
mainToolBar->addSeparator();
foldersMenu = new QMenu(MainWindow);
foldersMenu->setToolTipsVisible(true);
actionViewInstanceFolder = TranslatedAction(MainWindow);
actionViewInstanceFolder->setObjectName(QStringLiteral("actionViewInstanceFolder"));
@@ -284,17 +282,20 @@ class MainWindow::Ui
all_actions.append(&actionViewCentralModsFolder);
foldersMenu->addAction(actionViewCentralModsFolder);
foldersMenuButton = new QToolButton(MainWindow);
foldersMenuButton->setText(QT_TRANSLATE_NOOP("MainWindow", "Folders"));
foldersMenuButton = TranslatedToolButton(MainWindow);
foldersMenuButton.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Folders"));
foldersMenuButton.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Open one of the folders shared between instances."));
foldersMenuButton->setMenu(foldersMenu);
foldersMenuButton->setPopupMode(QToolButton::InstantPopup);
foldersMenuButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
foldersMenuButton->setIcon(MMC->getThemedIcon("viewfolder"));
all_toolbuttons.append(&foldersMenuButton);
QWidgetAction* foldersButtonAction = new QWidgetAction(MainWindow);
foldersButtonAction->setDefaultWidget(foldersMenuButton);
mainToolBar->addAction(foldersButtonAction);
helpMenu = new QMenu(MainWindow);
helpMenu->setToolTipsVisible(true);
actionReportBug = TranslatedAction(MainWindow);
actionReportBug->setObjectName(QStringLiteral("actionReportBug"));
@@ -329,12 +330,14 @@ class MainWindow::Ui
all_actions.append(&actionAbout);
helpMenu->addAction(actionAbout);
helpMenuButton = new QToolButton(MainWindow);
helpMenuButton->setText(QT_TRANSLATE_NOOP("MainWindow", "Help"));
helpMenuButton = TranslatedToolButton(MainWindow);
helpMenuButton.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Help"));
helpMenuButton.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Get help with MultiMC or Minecraft."));
helpMenuButton->setMenu(helpMenu);
helpMenuButton->setPopupMode(QToolButton::InstantPopup);
helpMenuButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
helpMenuButton->setIcon(MMC->getThemedIcon("help"));
all_toolbuttons.append(&helpMenuButton);
QWidgetAction* helpButtonAction = new QWidgetAction(MainWindow);
helpButtonAction->setDefaultWidget(helpMenuButton);
mainToolBar->addAction(helpButtonAction);
@@ -623,6 +626,10 @@ class MainWindow::Ui
{
item->retranslate();
}
for(auto * item: all_toolbuttons)
{
item->retranslate();
}
// submenu buttons
foldersMenuButton->setText(tr("Folders"));
helpMenuButton->setText(tr("Help"));

0 comments on commit 4b90a07

Please sign in to comment.