Merge pull request #1073 from leo78913/accounts-menus-fixes
This commit is contained in:
commit
3b9d822d72
@ -200,7 +200,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
|||||||
helpMenuButton->setPopupMode(QToolButton::InstantPopup);
|
helpMenuButton->setPopupMode(QToolButton::InstantPopup);
|
||||||
|
|
||||||
auto accountMenuButton = dynamic_cast<QToolButton*>(ui->mainToolBar->widgetForAction(ui->actionAccountsButton));
|
auto accountMenuButton = dynamic_cast<QToolButton*>(ui->mainToolBar->widgetForAction(ui->actionAccountsButton));
|
||||||
ui->actionAccountsButton->setMenu(ui->accountsMenu);
|
|
||||||
accountMenuButton->setPopupMode(QToolButton::InstantPopup);
|
accountMenuButton->setPopupMode(QToolButton::InstantPopup);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -417,15 +416,6 @@ void MainWindow::keyReleaseEvent(QKeyEvent *event)
|
|||||||
|
|
||||||
void MainWindow::retranslateUi()
|
void MainWindow::retranslateUi()
|
||||||
{
|
{
|
||||||
auto accounts = APPLICATION->accounts();
|
|
||||||
MinecraftAccountPtr defaultAccount = accounts->defaultAccount();
|
|
||||||
if(defaultAccount) {
|
|
||||||
auto profileLabel = profileInUseFilter(defaultAccount->profileName(), defaultAccount->isInUse());
|
|
||||||
ui->actionAccountsButton->setText(profileLabel);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ui->actionAccountsButton->setText(tr("Accounts"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_selectedInstance) {
|
if (m_selectedInstance) {
|
||||||
m_statusLeft->setText(m_selectedInstance->getStatusbarDescription());
|
m_statusLeft->setText(m_selectedInstance->getStatusbarDescription());
|
||||||
@ -435,6 +425,12 @@ void MainWindow::retranslateUi()
|
|||||||
|
|
||||||
ui->retranslateUi(this);
|
ui->retranslateUi(this);
|
||||||
|
|
||||||
|
MinecraftAccountPtr defaultAccount = APPLICATION->accounts()->defaultAccount();
|
||||||
|
if(defaultAccount) {
|
||||||
|
auto profileLabel = profileInUseFilter(defaultAccount->profileName(), defaultAccount->isInUse());
|
||||||
|
ui->actionAccountsButton->setText(profileLabel);
|
||||||
|
}
|
||||||
|
|
||||||
changeIconButton->setToolTip(ui->actionChangeInstIcon->toolTip());
|
changeIconButton->setToolTip(ui->actionChangeInstIcon->toolTip());
|
||||||
renameButton->setToolTip(ui->actionRenameInstance->toolTip());
|
renameButton->setToolTip(ui->actionRenameInstance->toolTip());
|
||||||
|
|
||||||
@ -676,6 +672,15 @@ void MainWindow::repopulateAccountsMenu()
|
|||||||
{
|
{
|
||||||
ui->accountsMenu->clear();
|
ui->accountsMenu->clear();
|
||||||
|
|
||||||
|
// NOTE: this is done so the accounts button text is not set to the accounts menu title
|
||||||
|
QMenu *accountsButtonMenu = ui->actionAccountsButton->menu();
|
||||||
|
if (accountsButtonMenu) {
|
||||||
|
accountsButtonMenu->clear();
|
||||||
|
} else {
|
||||||
|
accountsButtonMenu = new QMenu(this);
|
||||||
|
ui->actionAccountsButton->setMenu(accountsButtonMenu);
|
||||||
|
}
|
||||||
|
|
||||||
auto accounts = APPLICATION->accounts();
|
auto accounts = APPLICATION->accounts();
|
||||||
MinecraftAccountPtr defaultAccount = accounts->defaultAccount();
|
MinecraftAccountPtr defaultAccount = accounts->defaultAccount();
|
||||||
|
|
||||||
@ -690,6 +695,8 @@ void MainWindow::repopulateAccountsMenu()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QActionGroup* accountsGroup = new QActionGroup(this);
|
||||||
|
|
||||||
if (accounts->count() <= 0)
|
if (accounts->count() <= 0)
|
||||||
{
|
{
|
||||||
ui->actionNoAccountsAdded->setEnabled(false);
|
ui->actionNoAccountsAdded->setEnabled(false);
|
||||||
@ -705,6 +712,7 @@ void MainWindow::repopulateAccountsMenu()
|
|||||||
QAction *action = new QAction(profileLabel, this);
|
QAction *action = new QAction(profileLabel, this);
|
||||||
action->setData(i);
|
action->setData(i);
|
||||||
action->setCheckable(true);
|
action->setCheckable(true);
|
||||||
|
action->setActionGroup(accountsGroup);
|
||||||
if (defaultAccount == account)
|
if (defaultAccount == account)
|
||||||
{
|
{
|
||||||
action->setChecked(true);
|
action->setChecked(true);
|
||||||
@ -733,6 +741,7 @@ void MainWindow::repopulateAccountsMenu()
|
|||||||
|
|
||||||
ui->actionNoDefaultAccount->setData(-1);
|
ui->actionNoDefaultAccount->setData(-1);
|
||||||
ui->actionNoDefaultAccount->setChecked(!defaultAccount);
|
ui->actionNoDefaultAccount->setChecked(!defaultAccount);
|
||||||
|
ui->actionNoDefaultAccount->setActionGroup(accountsGroup);
|
||||||
|
|
||||||
ui->accountsMenu->addAction(ui->actionNoDefaultAccount);
|
ui->accountsMenu->addAction(ui->actionNoDefaultAccount);
|
||||||
|
|
||||||
@ -740,6 +749,8 @@ void MainWindow::repopulateAccountsMenu()
|
|||||||
|
|
||||||
ui->accountsMenu->addSeparator();
|
ui->accountsMenu->addSeparator();
|
||||||
ui->accountsMenu->addAction(ui->actionManageAccounts);
|
ui->accountsMenu->addAction(ui->actionManageAccounts);
|
||||||
|
|
||||||
|
accountsButtonMenu->addActions(ui->accountsMenu->actions());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::updatesAllowedChanged(bool allowed)
|
void MainWindow::updatesAllowedChanged(bool allowed)
|
||||||
|
@ -60,15 +60,13 @@ InstanceSettingsPage::InstanceSettingsPage(BaseInstance *inst, QWidget *parent)
|
|||||||
m_settings = inst->settings();
|
m_settings = inst->settings();
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
accountMenu = new QMenu(this);
|
|
||||||
// Use undocumented property... https://stackoverflow.com/questions/7121718/create-a-scrollbar-in-a-submenu-qt
|
|
||||||
accountMenu->setStyleSheet("QMenu { menu-scrollable: 1; }");
|
|
||||||
ui->instanceAccountSelector->setMenu(accountMenu);
|
|
||||||
|
|
||||||
connect(ui->openGlobalJavaSettingsButton, &QCommandLinkButton::clicked, this, &InstanceSettingsPage::globalSettingsButtonClicked);
|
connect(ui->openGlobalJavaSettingsButton, &QCommandLinkButton::clicked, this, &InstanceSettingsPage::globalSettingsButtonClicked);
|
||||||
connect(APPLICATION, &Application::globalSettingsAboutToOpen, this, &InstanceSettingsPage::applySettings);
|
connect(APPLICATION, &Application::globalSettingsAboutToOpen, this, &InstanceSettingsPage::applySettings);
|
||||||
connect(APPLICATION, &Application::globalSettingsClosed, this, &InstanceSettingsPage::loadSettings);
|
connect(APPLICATION, &Application::globalSettingsClosed, this, &InstanceSettingsPage::loadSettings);
|
||||||
|
connect(ui->instanceAccountSelector, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &InstanceSettingsPage::changeInstanceAccount);
|
||||||
loadSettings();
|
loadSettings();
|
||||||
|
|
||||||
|
|
||||||
updateThresholds();
|
updateThresholds();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -454,36 +452,17 @@ void InstanceSettingsPage::on_javaTestBtn_clicked()
|
|||||||
|
|
||||||
void InstanceSettingsPage::updateAccountsMenu()
|
void InstanceSettingsPage::updateAccountsMenu()
|
||||||
{
|
{
|
||||||
accountMenu->clear();
|
ui->instanceAccountSelector->clear();
|
||||||
|
|
||||||
auto accounts = APPLICATION->accounts();
|
auto accounts = APPLICATION->accounts();
|
||||||
int accountIndex = accounts->findAccountByProfileId(m_settings->get("InstanceAccountId").toString());
|
int accountIndex = accounts->findAccountByProfileId(m_settings->get("InstanceAccountId").toString());
|
||||||
MinecraftAccountPtr defaultAccount = accounts->defaultAccount();
|
|
||||||
|
|
||||||
if (accountIndex != -1 && accounts->at(accountIndex)) {
|
|
||||||
defaultAccount = accounts->at(accountIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (defaultAccount) {
|
|
||||||
ui->instanceAccountSelector->setText(defaultAccount->profileName());
|
|
||||||
ui->instanceAccountSelector->setIcon(getFaceForAccount(defaultAccount));
|
|
||||||
} else {
|
|
||||||
ui->instanceAccountSelector->setText(tr("No default account"));
|
|
||||||
ui->instanceAccountSelector->setIcon(APPLICATION->getThemedIcon("noaccount"));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < accounts->count(); i++) {
|
for (int i = 0; i < accounts->count(); i++) {
|
||||||
MinecraftAccountPtr account = accounts->at(i);
|
MinecraftAccountPtr account = accounts->at(i);
|
||||||
QAction* action = new QAction(account->profileName(), this);
|
ui->instanceAccountSelector->addItem(getFaceForAccount(account), account->profileName(), i);
|
||||||
action->setData(i);
|
if (i == accountIndex)
|
||||||
action->setCheckable(true);
|
ui->instanceAccountSelector->setCurrentIndex(i);
|
||||||
if (accountIndex == i) {
|
|
||||||
action->setChecked(true);
|
|
||||||
}
|
|
||||||
action->setIcon(getFaceForAccount(account));
|
|
||||||
accountMenu->addAction(action);
|
|
||||||
connect(action, SIGNAL(triggered(bool)), this, SLOT(changeInstanceAccount()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon InstanceSettingsPage::getFaceForAccount(MinecraftAccountPtr account)
|
QIcon InstanceSettingsPage::getFaceForAccount(MinecraftAccountPtr account)
|
||||||
@ -495,20 +474,13 @@ QIcon InstanceSettingsPage::getFaceForAccount(MinecraftAccountPtr account)
|
|||||||
return APPLICATION->getThemedIcon("noaccount");
|
return APPLICATION->getThemedIcon("noaccount");
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstanceSettingsPage::changeInstanceAccount()
|
void InstanceSettingsPage::changeInstanceAccount(int index)
|
||||||
{
|
{
|
||||||
QAction* sAction = (QAction*)sender();
|
|
||||||
|
|
||||||
Q_ASSERT(sAction->data().type() == QVariant::Type::Int);
|
|
||||||
|
|
||||||
QVariant data = sAction->data();
|
|
||||||
int index = data.toInt();
|
|
||||||
auto accounts = APPLICATION->accounts();
|
auto accounts = APPLICATION->accounts();
|
||||||
auto account = accounts->at(index);
|
if (index != -1 && accounts->at(index) && ui->instanceAccountGroupBox->isChecked()) {
|
||||||
m_settings->set("InstanceAccountId", account->profileId());
|
auto account = accounts->at(index);
|
||||||
|
m_settings->set("InstanceAccountId", account->profileId());
|
||||||
ui->instanceAccountSelector->setText(account->profileName());
|
}
|
||||||
ui->instanceAccountSelector->setIcon(getFaceForAccount(account));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstanceSettingsPage::on_maxMemSpinBox_valueChanged(int i)
|
void InstanceSettingsPage::on_maxMemSpinBox_valueChanged(int i)
|
||||||
|
@ -95,12 +95,11 @@ private slots:
|
|||||||
|
|
||||||
void updateAccountsMenu();
|
void updateAccountsMenu();
|
||||||
QIcon getFaceForAccount(MinecraftAccountPtr account);
|
QIcon getFaceForAccount(MinecraftAccountPtr account);
|
||||||
void changeInstanceAccount();
|
void changeInstanceAccount(int index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::InstanceSettingsPage *ui;
|
Ui::InstanceSettingsPage *ui;
|
||||||
BaseInstance *m_instance;
|
BaseInstance *m_instance;
|
||||||
SettingsObjectPtr m_settings;
|
SettingsObjectPtr m_settings;
|
||||||
unique_qobject_ptr<JavaCommon::TestCheck> checker;
|
unique_qobject_ptr<JavaCommon::TestCheck> checker;
|
||||||
QMenu *accountMenu = nullptr;
|
|
||||||
};
|
};
|
||||||
|
@ -636,14 +636,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QToolButton" name="instanceAccountSelector">
|
<widget class="QComboBox" name="instanceAccountSelector"/>
|
||||||
<property name="popupMode">
|
|
||||||
<enum>QToolButton::InstantPopup</enum>
|
|
||||||
</property>
|
|
||||||
<property name="toolButtonStyle">
|
|
||||||
<enum>Qt::ToolButtonTextBesideIcon</enum>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
Loading…
Reference in New Issue
Block a user