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

@ -1,50 +1,51 @@
<RCC> <RCC>
<qresource prefix="/icons/toolbar"> <qresource prefix="/icons/toolbar">
<file alias="about">resources/icons/toolbar/about.png</file> <file alias="about">resources/icons/toolbar/about.png</file>
<file alias="bug">resources/icons/toolbar/ReportBug.png</file> <file alias="bug">resources/icons/toolbar/ReportBug.png</file>
<file alias="centralmods">resources/icons/toolbar/centralmods.png</file> <file alias="centralmods">resources/icons/toolbar/centralmods.png</file>
<file alias="checkupdate">resources/icons/toolbar/checkupdate.png</file> <file alias="checkupdate">resources/icons/toolbar/checkupdate.png</file>
<file alias="help">resources/icons/toolbar/help.png</file> <file alias="help">resources/icons/toolbar/help.png</file>
<file alias="new">resources/icons/toolbar/new.png</file> <file alias="new">resources/icons/toolbar/new.png</file>
<file alias="copy">resources/icons/toolbar/InstCopy.png</file> <file alias="copy">resources/icons/toolbar/InstCopy.png</file>
<file alias="news">resources/icons/toolbar/NewsIcon.png</file> <file alias="news">resources/icons/toolbar/NewsIcon.png</file>
<file alias="refresh">resources/icons/toolbar/refresh.png</file> <file alias="refresh">resources/icons/toolbar/refresh.png</file>
<file alias="settings">resources/icons/toolbar/settings.png</file> <file alias="settings">resources/icons/toolbar/settings.png</file>
<file alias="viewfolder">resources/icons/toolbar/viewfolder.png</file> <file alias="viewfolder">resources/icons/toolbar/viewfolder.png</file>
<file alias="cat">resources/icons/toolbar/Cat.png</file> <file alias="cat">resources/icons/toolbar/Cat.png</file>
</qresource> <file alias="noaccount">resources/icons/toolbar/NoAccount.png</file>
<qresource prefix="/icons/instances"> </qresource>
<file alias="brick">resources/icons/instances/brick.png</file> <qresource prefix="/icons/instances">
<file alias="chicken">resources/icons/instances/chicken128.png</file> <file alias="brick">resources/icons/instances/brick.png</file>
<file alias="creeper">resources/icons/instances/creeper128.png</file> <file alias="chicken">resources/icons/instances/chicken128.png</file>
<file alias="derp">resources/icons/instances/derp.png</file> <file alias="creeper">resources/icons/instances/creeper128.png</file>
<file alias="diamond">resources/icons/instances/diamond.png</file> <file alias="derp">resources/icons/instances/derp.png</file>
<file alias="dirt">resources/icons/instances/dirt.png</file> <file alias="diamond">resources/icons/instances/diamond.png</file>
<file alias="enderman">resources/icons/instances/enderman.png</file> <file alias="dirt">resources/icons/instances/dirt.png</file>
<file alias="enderpearl">resources/icons/instances/enderpearl128.png</file> <file alias="enderman">resources/icons/instances/enderman.png</file>
<file alias="ftb-glow">resources/icons/instances/ftb_glow128.png</file> <file alias="enderpearl">resources/icons/instances/enderpearl128.png</file>
<file alias="ftb-logo">resources/icons/instances/ftb_logo128.png</file> <file alias="ftb-glow">resources/icons/instances/ftb_glow128.png</file>
<file alias="gear">resources/icons/instances/gear128.png</file> <file alias="ftb-logo">resources/icons/instances/ftb_logo128.png</file>
<file alias="gold">resources/icons/instances/gold.png</file> <file alias="gear">resources/icons/instances/gear128.png</file>
<file alias="grass">resources/icons/instances/grass.png</file> <file alias="gold">resources/icons/instances/gold.png</file>
<file alias="herobrine">resources/icons/instances/herobrine128.png</file> <file alias="grass">resources/icons/instances/grass.png</file>
<file alias="infinity">resources/icons/instances/infinity128.png</file> <file alias="herobrine">resources/icons/instances/herobrine128.png</file>
<file alias="iron">resources/icons/instances/iron.png</file> <file alias="infinity">resources/icons/instances/infinity128.png</file>
<file alias="magitech">resources/icons/instances/magitech128.png</file> <file alias="iron">resources/icons/instances/iron.png</file>
<file alias="meat">resources/icons/instances/meat128.png</file> <file alias="magitech">resources/icons/instances/magitech128.png</file>
<file alias="netherstar">resources/icons/instances/netherstar128.png</file> <file alias="meat">resources/icons/instances/meat128.png</file>
<file alias="planks">resources/icons/instances/planks.png</file> <file alias="netherstar">resources/icons/instances/netherstar128.png</file>
<file alias="skeleton">resources/icons/instances/skeleton128.png</file> <file alias="planks">resources/icons/instances/planks.png</file>
<file alias="squarecreeper">resources/icons/instances/squarecreeper128.png</file> <file alias="skeleton">resources/icons/instances/skeleton128.png</file>
<file alias="steve">resources/icons/instances/steve128.png</file> <file alias="squarecreeper">resources/icons/instances/squarecreeper128.png</file>
<file alias="stone">resources/icons/instances/stone.png</file> <file alias="steve">resources/icons/instances/steve128.png</file>
<file alias="tnt">resources/icons/instances/tnt.png</file> <file alias="stone">resources/icons/instances/stone.png</file>
</qresource> <file alias="tnt">resources/icons/instances/tnt.png</file>
<qresource prefix="/icons/multimc"> </qresource>
<file alias="scalable/apps/multimc.svg">resources/icons/multimc.svg</file> <qresource prefix="/icons/multimc">
<file alias="index.theme">resources/XdgIcon.theme</file> <file alias="scalable/apps/multimc.svg">resources/icons/multimc.svg</file>
</qresource> <file alias="index.theme">resources/XdgIcon.theme</file>
<qresource prefix="/backgrounds"> </qresource>
<file alias="kitteh">resources/catbgrnd2.png</file> <qresource prefix="/backgrounds">
</qresource> <file alias="kitteh">resources/catbgrnd2.png</file>
</qresource>
</RCC> </RCC>

View File

@ -168,13 +168,12 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
statusBar()->addPermanentWidget(m_statusRight, 0); statusBar()->addPermanentWidget(m_statusRight, 0);
// Add "manage accounts" button, right align // Add "manage accounts" button, right align
QWidget* spacer = new QWidget(); QWidget* spacer = new QWidget();
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
ui->mainToolBar->addWidget(spacer); ui->mainToolBar->addWidget(spacer);
accountMenu = new QMenu(this); accountMenu = new QMenu(this);
manageAccountsAction = new QAction(tr("Manage accounts"), this); manageAccountsAction = new QAction(tr("Manage Accounts"), this);
manageAccountsAction->setCheckable(false); manageAccountsAction->setCheckable(false);
connect(manageAccountsAction, SIGNAL(triggered(bool)), this, SLOT(on_actionManageAccounts_triggered())); 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->setPopupMode(QToolButton::InstantPopup);
accountMenuButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); accountMenuButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
accountMenuButton->setLayoutDirection(Qt::RightToLeft); accountMenuButton->setLayoutDirection(Qt::RightToLeft);
accountMenuButton->setIcon(QPixmap(":/icons/toolbar/noaccount").scaled(48, 48, Qt::KeepAspectRatio));
QWidgetAction *accountMenuButtonAction = new QWidgetAction(this); QWidgetAction *accountMenuButtonAction = new QWidgetAction(this);
accountMenuButtonAction->setDefaultWidget(accountMenuButton); accountMenuButtonAction->setDefaultWidget(accountMenuButton);
ui->mainToolBar->addAction(accountMenuButtonAction); 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(); std::shared_ptr<MojangAccountList> accounts = MMC->accounts();
// TODO: Nicer way to iterate? // TODO: Nicer way to iterate?
@ -258,12 +263,12 @@ void MainWindow::repopulateAccountsMenu()
MojangAccountPtr active_account = accounts->activeAccount(); MojangAccountPtr active_account = accounts->activeAccount();
QString active_username = ""; QString active_username = "";
if(active_account != nullptr) if (active_account != nullptr)
{ {
active_username = accounts->activeAccount()->username(); active_username = accounts->activeAccount()->username();
} }
if(accounts->count() <= 0) if (accounts->count() <= 0)
{ {
QAction *action = new QAction(tr("No accounts added!"), this); QAction *action = new QAction(tr("No accounts added!"), this);
action->setEnabled(false); action->setEnabled(false);
@ -274,7 +279,7 @@ void MainWindow::repopulateAccountsMenu()
else else
{ {
// TODO: Nicer way to iterate? // TODO: Nicer way to iterate?
for(int i = 0; i < accounts->count(); i++) for (int i = 0; i < accounts->count(); i++)
{ {
MojangAccountPtr account = accounts->at(i); MojangAccountPtr account = accounts->at(i);
@ -283,7 +288,7 @@ void MainWindow::repopulateAccountsMenu()
section->setEnabled(false); section->setEnabled(false);
accountMenu->addAction(section); accountMenu->addAction(section);
for(AccountProfile profile : account->profiles()) for (AccountProfile profile : account->profiles())
{ {
QAction *action = new QAction(profile.name(), this); QAction *action = new QAction(profile.name(), this);
action->setData(account->username()); action->setData(account->username());
@ -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->setCheckable(true);
action->setIcon(QPixmap(":/icons/toolbar/noaccount").scaled(48, 48, Qt::KeepAspectRatio));
action->setData(""); action->setData("");
if(active_username.isEmpty()) if(active_username.isEmpty())
{ {
@ -324,12 +330,12 @@ void MainWindow::changeActiveAccount()
{ {
QAction* sAction = (QAction*) sender(); QAction* sAction = (QAction*) sender();
// Profile's associated Mojang username // Profile's associated Mojang username
// Will need to change when profiles are properly implemented // Will need to change when profiles are properly implemented
if(sAction->data().type() != QVariant::Type::String) return; if (sAction->data().type() != QVariant::Type::String) return;
QVariant data = sAction->data(); QVariant data = sAction->data();
QString id = ""; QString id = "";
if(!data.isNull()) if (!data.isNull())
{ {
id = data.toString(); id = data.toString();
} }
@ -345,17 +351,18 @@ void MainWindow::activeAccountChanged()
MojangAccountPtr account = MMC->accounts()->activeAccount(); MojangAccountPtr account = MMC->accounts()->activeAccount();
if(account != nullptr && account->username() != "") if (account != nullptr && account->username() != "")
{ {
const AccountProfile *profile = account->currentProfile(); const AccountProfile *profile = account->currentProfile();
if(profile != nullptr) if (profile != nullptr)
{ {
accountMenuButton->setIcon(SkinUtils::getFaceFromCache(profile->name())); accountMenuButton->setIcon(SkinUtils::getFaceFromCache(profile->name()));
return; return;
} }
} }
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) bool MainWindow::eventFilter(QObject *obj, QEvent *ev)

View File

@ -106,7 +106,7 @@ void MojangAccountList::setActiveAccount(const QString& username)
} }
} }
endResetModel(); endResetModel();
onListChanged(); onActiveChanged();
} }
@ -116,8 +116,15 @@ void MojangAccountList::onListChanged()
// TODO: Alert the user if this fails. // TODO: Alert the user if this fails.
saveList(); 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(); void listChanged();
/*!
* Signal emitted to indicate that the active account has changed.
*/
void activeAccountChanged();
protected: protected:
/*! /*!
* Called whenever the list changes. * Called whenever the list changes.
@ -140,6 +145,12 @@ protected:
*/ */
void onListChanged(); void onListChanged();
/*!
* Called whenever the active account changes.
* Emits the activeAccountChanged() signal and autosaves the list if enabled.
*/
void onActiveChanged();
QList<MojangAccountPtr> m_accounts; QList<MojangAccountPtr> m_accounts;
/*! /*!

Binary file not shown.

After

Width:  |  Height:  |  Size: 284 B