NOISSUE add tooltips to new menu buttons and make them translateable
This commit is contained in:
parent
d8c8a41dfa
commit
4b90a078de
@ -91,17 +91,14 @@
|
|||||||
#include "UpdateController.h"
|
#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
|
// 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:
|
public:
|
||||||
TranslatedAction(){}
|
Translated(){}
|
||||||
TranslatedAction(QWidget *parent)
|
Translated(QWidget *parent)
|
||||||
{
|
{
|
||||||
m_contained = new QAction(parent);
|
m_contained = new T(parent);
|
||||||
}
|
|
||||||
~TranslatedAction()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
void setTooltipId(const char * tooltip)
|
void setTooltipId(const char * tooltip)
|
||||||
{
|
{
|
||||||
@ -111,11 +108,11 @@ public:
|
|||||||
{
|
{
|
||||||
m_text = text;
|
m_text = text;
|
||||||
}
|
}
|
||||||
operator QAction*()
|
operator T*()
|
||||||
{
|
{
|
||||||
return m_contained;
|
return m_contained;
|
||||||
}
|
}
|
||||||
QAction * operator->()
|
T * operator->()
|
||||||
{
|
{
|
||||||
return m_contained;
|
return m_contained;
|
||||||
}
|
}
|
||||||
@ -131,10 +128,12 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
QAction * m_contained = nullptr;
|
T * m_contained = nullptr;
|
||||||
const char * m_text = nullptr;
|
const char * m_text = nullptr;
|
||||||
const char * m_tooltip = 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
|
// 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
|
class TranslatedToolbar
|
||||||
@ -144,10 +143,6 @@ public:
|
|||||||
TranslatedToolbar(QWidget *parent)
|
TranslatedToolbar(QWidget *parent)
|
||||||
{
|
{
|
||||||
m_contained = new QToolBar(parent);
|
m_contained = new QToolBar(parent);
|
||||||
}
|
|
||||||
~TranslatedToolbar()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
void setWindowTitleId(const char * title)
|
void setWindowTitleId(const char * title)
|
||||||
{
|
{
|
||||||
@ -205,17 +200,19 @@ public:
|
|||||||
LabeledToolButton *changeIconButton = nullptr;
|
LabeledToolButton *changeIconButton = nullptr;
|
||||||
|
|
||||||
QMenu * foldersMenu = nullptr;
|
QMenu * foldersMenu = nullptr;
|
||||||
QToolButton * foldersMenuButton = nullptr;
|
TranslatedToolButton foldersMenuButton;
|
||||||
TranslatedAction actionViewInstanceFolder;
|
TranslatedAction actionViewInstanceFolder;
|
||||||
TranslatedAction actionViewCentralModsFolder;
|
TranslatedAction actionViewCentralModsFolder;
|
||||||
|
|
||||||
QMenu * helpMenu = nullptr;
|
QMenu * helpMenu = nullptr;
|
||||||
QToolButton * helpMenuButton = nullptr;
|
TranslatedToolButton helpMenuButton;
|
||||||
TranslatedAction actionReportBug;
|
TranslatedAction actionReportBug;
|
||||||
TranslatedAction actionDISCORD;
|
TranslatedAction actionDISCORD;
|
||||||
TranslatedAction actionREDDIT;
|
TranslatedAction actionREDDIT;
|
||||||
TranslatedAction actionAbout;
|
TranslatedAction actionAbout;
|
||||||
|
|
||||||
|
QVector<TranslatedToolButton *> all_toolbuttons;
|
||||||
|
|
||||||
QWidget *centralWidget = nullptr;
|
QWidget *centralWidget = nullptr;
|
||||||
QHBoxLayout *horizontalLayout = nullptr;
|
QHBoxLayout *horizontalLayout = nullptr;
|
||||||
QStatusBar *statusBar = nullptr;
|
QStatusBar *statusBar = nullptr;
|
||||||
@ -267,6 +264,7 @@ public:
|
|||||||
mainToolBar->addSeparator();
|
mainToolBar->addSeparator();
|
||||||
|
|
||||||
foldersMenu = new QMenu(MainWindow);
|
foldersMenu = new QMenu(MainWindow);
|
||||||
|
foldersMenu->setToolTipsVisible(true);
|
||||||
|
|
||||||
actionViewInstanceFolder = TranslatedAction(MainWindow);
|
actionViewInstanceFolder = TranslatedAction(MainWindow);
|
||||||
actionViewInstanceFolder->setObjectName(QStringLiteral("actionViewInstanceFolder"));
|
actionViewInstanceFolder->setObjectName(QStringLiteral("actionViewInstanceFolder"));
|
||||||
@ -284,17 +282,20 @@ public:
|
|||||||
all_actions.append(&actionViewCentralModsFolder);
|
all_actions.append(&actionViewCentralModsFolder);
|
||||||
foldersMenu->addAction(actionViewCentralModsFolder);
|
foldersMenu->addAction(actionViewCentralModsFolder);
|
||||||
|
|
||||||
foldersMenuButton = new QToolButton(MainWindow);
|
foldersMenuButton = TranslatedToolButton(MainWindow);
|
||||||
foldersMenuButton->setText(QT_TRANSLATE_NOOP("MainWindow", "Folders"));
|
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->setMenu(foldersMenu);
|
||||||
foldersMenuButton->setPopupMode(QToolButton::InstantPopup);
|
foldersMenuButton->setPopupMode(QToolButton::InstantPopup);
|
||||||
foldersMenuButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
foldersMenuButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||||
foldersMenuButton->setIcon(MMC->getThemedIcon("viewfolder"));
|
foldersMenuButton->setIcon(MMC->getThemedIcon("viewfolder"));
|
||||||
|
all_toolbuttons.append(&foldersMenuButton);
|
||||||
QWidgetAction* foldersButtonAction = new QWidgetAction(MainWindow);
|
QWidgetAction* foldersButtonAction = new QWidgetAction(MainWindow);
|
||||||
foldersButtonAction->setDefaultWidget(foldersMenuButton);
|
foldersButtonAction->setDefaultWidget(foldersMenuButton);
|
||||||
mainToolBar->addAction(foldersButtonAction);
|
mainToolBar->addAction(foldersButtonAction);
|
||||||
|
|
||||||
helpMenu = new QMenu(MainWindow);
|
helpMenu = new QMenu(MainWindow);
|
||||||
|
helpMenu->setToolTipsVisible(true);
|
||||||
|
|
||||||
actionReportBug = TranslatedAction(MainWindow);
|
actionReportBug = TranslatedAction(MainWindow);
|
||||||
actionReportBug->setObjectName(QStringLiteral("actionReportBug"));
|
actionReportBug->setObjectName(QStringLiteral("actionReportBug"));
|
||||||
@ -329,12 +330,14 @@ public:
|
|||||||
all_actions.append(&actionAbout);
|
all_actions.append(&actionAbout);
|
||||||
helpMenu->addAction(actionAbout);
|
helpMenu->addAction(actionAbout);
|
||||||
|
|
||||||
helpMenuButton = new QToolButton(MainWindow);
|
helpMenuButton = TranslatedToolButton(MainWindow);
|
||||||
helpMenuButton->setText(QT_TRANSLATE_NOOP("MainWindow", "Help"));
|
helpMenuButton.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Help"));
|
||||||
|
helpMenuButton.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Get help with MultiMC or Minecraft."));
|
||||||
helpMenuButton->setMenu(helpMenu);
|
helpMenuButton->setMenu(helpMenu);
|
||||||
helpMenuButton->setPopupMode(QToolButton::InstantPopup);
|
helpMenuButton->setPopupMode(QToolButton::InstantPopup);
|
||||||
helpMenuButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
helpMenuButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||||
helpMenuButton->setIcon(MMC->getThemedIcon("help"));
|
helpMenuButton->setIcon(MMC->getThemedIcon("help"));
|
||||||
|
all_toolbuttons.append(&helpMenuButton);
|
||||||
QWidgetAction* helpButtonAction = new QWidgetAction(MainWindow);
|
QWidgetAction* helpButtonAction = new QWidgetAction(MainWindow);
|
||||||
helpButtonAction->setDefaultWidget(helpMenuButton);
|
helpButtonAction->setDefaultWidget(helpMenuButton);
|
||||||
mainToolBar->addAction(helpButtonAction);
|
mainToolBar->addAction(helpButtonAction);
|
||||||
@ -623,6 +626,10 @@ public:
|
|||||||
{
|
{
|
||||||
item->retranslate();
|
item->retranslate();
|
||||||
}
|
}
|
||||||
|
for(auto * item: all_toolbuttons)
|
||||||
|
{
|
||||||
|
item->retranslate();
|
||||||
|
}
|
||||||
// submenu buttons
|
// submenu buttons
|
||||||
foldersMenuButton->setText(tr("Folders"));
|
foldersMenuButton->setText(tr("Folders"));
|
||||||
helpMenuButton->setText(tr("Help"));
|
helpMenuButton->setText(tr("Help"));
|
||||||
|
Loading…
Reference in New Issue
Block a user