Add icons in settings account list (#4684)

This commit is contained in:
Alexandru Ionut Tripon
2026-01-17 02:08:02 +02:00
committed by GitHub
5 changed files with 44 additions and 42 deletions

View File

@@ -295,6 +295,24 @@ QVariant AccountList::data(const QModelIndex& index, int role) const
MinecraftAccountPtr account = at(index.row());
switch (role) {
case Qt::SizeHintRole:
if (index.column() == ProfileNameColumn) {
return QSize(0, 30);
}
return QVariant();
case Qt::DecorationRole:
if (index.column() == ProfileNameColumn) {
auto face = account->getFace(24, 24);
if (!face.isNull()) {
return face;
} else {
return QIcon::fromTheme("noaccount").pixmap(24, 24);
}
}
return QVariant();
case Qt::DisplayRole:
switch (index.column()) {
case ProfileNameColumn:

View File

@@ -101,7 +101,7 @@ AccountState MinecraftAccount::accountState() const
return data.accountState;
}
QPixmap MinecraftAccount::getFace() const
QPixmap MinecraftAccount::getFace(int width, int height) const
{
QPixmap skinTexture;
if (!skinTexture.loadFromData(data.minecraftProfile.skin.data, "PNG")) {
@@ -112,7 +112,7 @@ QPixmap MinecraftAccount::getFace() const
QPainter painter(&skin);
painter.drawPixmap(0, 0, skinTexture.copy(8, 8, 8, 8));
painter.drawPixmap(0, 0, skinTexture.copy(40, 8, 8, 8));
return skin.scaled(64, 64, Qt::KeepAspectRatio);
return skin.scaled(width, height, Qt::KeepAspectRatio);
}
shared_qobject_ptr<AuthFlow> MinecraftAccount::login(bool useDeviceCode)

View File

@@ -135,7 +135,7 @@ class MinecraftAccount : public QObject, public Usable {
}
}
QPixmap getFace() const;
QPixmap getFace(int width = 64, int height = 64) const;
//! Returns the current state of the account
AccountState accountState() const;

View File

@@ -17,12 +17,25 @@
#include "ui_ProfileSelectDialog.h"
#include <QDebug>
#include <QIdentityProxyModel>
#include <QItemSelectionModel>
#include <QPushButton>
#include "Application.h"
#include "ui/dialogs/ProgressDialog.h"
// HACK: hide checkboxes from AccountList
class HideCheckboxProxyModel : public QIdentityProxyModel {
public:
using QIdentityProxyModel::QIdentityProxyModel;
QVariant data(const QModelIndex& index, int role) const override {
if (role == Qt::CheckStateRole) {
return {};
}
return QIdentityProxyModel::data(index, role);
}
};
ProfileSelectDialog::ProfileSelectDialog(const QString& message, int flags, QWidget* parent)
: QDialog(parent), ui(new Ui::ProfileSelectDialog)
@@ -30,33 +43,10 @@ ProfileSelectDialog::ProfileSelectDialog(const QString& message, int flags, QWid
ui->setupUi(this);
m_accounts = APPLICATION->accounts();
auto view = ui->listView;
// view->setModel(m_accounts.get());
// view->hideColumn(AccountList::ActiveColumn);
view->setColumnCount(1);
view->setRootIsDecorated(false);
// FIXME: use a real model, not this
if (QTreeWidgetItem* header = view->headerItem()) {
header->setText(0, tr("Name"));
} else {
view->setHeaderLabel(tr("Name"));
}
QList<QTreeWidgetItem*> items;
for (int i = 0; i < m_accounts->count(); i++) {
MinecraftAccountPtr account = m_accounts->at(i);
QString profileLabel;
if (account->isInUse()) {
profileLabel = tr("%1 (in use)").arg(account->profileName());
} else {
profileLabel = account->profileName();
}
auto item = new QTreeWidgetItem(view);
item->setText(0, profileLabel);
item->setIcon(0, account->getFace());
item->setData(0, AccountList::PointerRole, QVariant::fromValue(account));
items.append(item);
}
view->addTopLevelItems(items);
auto proxy = new HideCheckboxProxyModel(ui->view);
proxy->setSourceModel(m_accounts.get());
ui->view->setModel(proxy);
// Set the message label.
ui->msgLabel->setVisible(!message.isEmpty());
@@ -68,9 +58,9 @@ ProfileSelectDialog::ProfileSelectDialog(const QString& message, int flags, QWid
qDebug() << flags;
// Select the first entry in the list.
ui->listView->setCurrentIndex(ui->listView->model()->index(0, 0));
ui->view->setCurrentIndex(ui->view->model()->index(0, 0));
connect(ui->listView, &QAbstractItemView::doubleClicked, this, &ProfileSelectDialog::on_buttonBox_accepted);
connect(ui->view, &QAbstractItemView::doubleClicked, this, &ProfileSelectDialog::on_buttonBox_accepted);
ui->buttonBox->button(QDialogButtonBox::Cancel)->setText(tr("Cancel"));
ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("OK"));
@@ -98,7 +88,7 @@ bool ProfileSelectDialog::useAsInstDefaullt() const
void ProfileSelectDialog::on_buttonBox_accepted()
{
QModelIndexList selection = ui->listView->selectionModel()->selectedIndexes();
QModelIndexList selection = ui->view->selectionModel()->selectedIndexes();
if (selection.size() > 0) {
QModelIndex selected = selection.first();
m_selected = selected.data(AccountList::PointerRole).value<MinecraftAccountPtr>();

View File

@@ -22,13 +22,7 @@
</widget>
</item>
<item>
<widget class="QTreeWidget" name="listView">
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
<widget class="QListView" name="view"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
@@ -51,7 +45,7 @@
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
</property>
</widget>
</item>