Add icon for when no default account is selected

Also fixed a bug where the icon on the accounts button wouldn't change
when the user checked the "Use as default" checkbox in the account
selection dialog.
This commit is contained in:
Andrew 2013-11-28 15:46:04 -06:00
parent 8232271c00
commit f7b64a551b
5 changed files with 90 additions and 64 deletions

View File

@ -12,6 +12,7 @@
<file alias="settings">resources/icons/toolbar/settings.png</file>
<file alias="viewfolder">resources/icons/toolbar/viewfolder.png</file>
<file alias="cat">resources/icons/toolbar/Cat.png</file>
<file alias="noaccount">resources/icons/toolbar/NoAccount.png</file>
</qresource>
<qresource prefix="/icons/instances">
<file alias="brick">resources/icons/instances/brick.png</file>

View File

@ -168,13 +168,12 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
statusBar()->addPermanentWidget(m_statusRight, 0);
// Add "manage accounts" button, right align
QWidget* spacer = new QWidget();
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
ui->mainToolBar->addWidget(spacer);
accountMenu = new QMenu(this);
manageAccountsAction = new QAction(tr("Manage accounts"), this);
manageAccountsAction = new QAction(tr("Manage Accounts"), this);
manageAccountsAction->setCheckable(false);
connect(manageAccountsAction, SIGNAL(triggered(bool)), this, SLOT(on_actionManageAccounts_triggered()));
@ -186,12 +185,18 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
accountMenuButton->setPopupMode(QToolButton::InstantPopup);
accountMenuButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
accountMenuButton->setLayoutDirection(Qt::RightToLeft);
accountMenuButton->setIcon(QPixmap(":/icons/toolbar/noaccount").scaled(48, 48, Qt::KeepAspectRatio));
QWidgetAction *accountMenuButtonAction = new QWidgetAction(this);
accountMenuButtonAction->setDefaultWidget(accountMenuButton);
ui->mainToolBar->addAction(accountMenuButtonAction);
// Update the menu when the active account changes.
// Shouldn't have to use lambdas here like this, but if I don't, the compiler throws a fit. Template hell sucks...
connect(MMC->accounts().get(), &MojangAccountList::activeAccountChanged, [this] { activeAccountChanged(); });
connect(MMC->accounts().get(), &MojangAccountList::listChanged, [this] { repopulateAccountsMenu(); });
std::shared_ptr<MojangAccountList> accounts = MMC->accounts();
// TODO: Nicer way to iterate?
@ -302,8 +307,9 @@ void MainWindow::repopulateAccountsMenu()
}
}
QAction *action = new QAction(tr("No default"), this);
QAction *action = new QAction(tr("No Default Account"), this);
action->setCheckable(true);
action->setIcon(QPixmap(":/icons/toolbar/noaccount").scaled(48, 48, Qt::KeepAspectRatio));
action->setData("");
if(active_username.isEmpty())
{
@ -355,7 +361,8 @@ void MainWindow::activeAccountChanged()
}
}
accountMenuButton->setIcon(QIcon());
// Set the icon to the "no account" icon.
accountMenuButton->setIcon(QPixmap(":/icons/toolbar/noaccount").scaled(48, 48, Qt::KeepAspectRatio));
}
bool MainWindow::eventFilter(QObject *obj, QEvent *ev)

View File

@ -106,7 +106,7 @@ void MojangAccountList::setActiveAccount(const QString& username)
}
}
endResetModel();
onListChanged();
onActiveChanged();
}
@ -116,8 +116,15 @@ void MojangAccountList::onListChanged()
// TODO: Alert the user if this fails.
saveList();
// TODO: stop this getting called from setActiveAccount
//emit listChanged();
emit listChanged();
}
void MojangAccountList::onActiveChanged()
{
if (m_autosave)
saveList();
emit activeAccountChanged();
}

View File

@ -133,6 +133,11 @@ signals:
*/
void listChanged();
/*!
* Signal emitted to indicate that the active account has changed.
*/
void activeAccountChanged();
protected:
/*!
* Called whenever the list changes.
@ -140,6 +145,12 @@ protected:
*/
void onListChanged();
/*!
* Called whenever the active account changes.
* Emits the activeAccountChanged() signal and autosaves the list if enabled.
*/
void onActiveChanged();
QList<MojangAccountPtr> m_accounts;
/*!

Binary file not shown.

After

Width:  |  Height:  |  Size: 284 B