mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2026-06-29 01:54:20 +03:00
add category selector to icon picker dialog
it uses some regex shenanigans for this, probably not ideal, idk if theres a good way to filter the icons without adding extra metadata or storing them in subfolders Signed-off-by: Tayou <git@tayou.org>
This commit is contained in:
parent
031015b332
commit
74308fcaa5
3 changed files with 110 additions and 8 deletions
|
|
@ -35,9 +35,25 @@ IconPickerDialog::IconPickerDialog(QWidget* parent) : QDialog(parent), ui(new Ui
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
setWindowModality(Qt::WindowModal);
|
setWindowModality(Qt::WindowModal);
|
||||||
|
|
||||||
searchBar = new QLineEdit(this);
|
static const QString context_text[] = {
|
||||||
searchBar->setPlaceholderText(tr("Search..."));
|
tr("All"),
|
||||||
ui->verticalLayout->insertWidget(0, searchBar);
|
tr("Modern"),
|
||||||
|
tr("Legacy"),
|
||||||
|
tr("Modpacks"),
|
||||||
|
};
|
||||||
|
static const Context context_id[] = {
|
||||||
|
Any,
|
||||||
|
Modern,
|
||||||
|
Legacy,
|
||||||
|
Modpacks,
|
||||||
|
};
|
||||||
|
const int cnt = sizeof(context_text) / sizeof(context_text[0]);
|
||||||
|
for (int i = 0; i < cnt; ++i) {
|
||||||
|
ui->contextCombo->addItem(context_text[i], context_id[i]);
|
||||||
|
if (i == 0) {
|
||||||
|
ui->contextCombo->insertSeparator(i + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
proxyModel = new QSortFilterProxyModel(this);
|
proxyModel = new QSortFilterProxyModel(this);
|
||||||
proxyModel->setSourceModel(APPLICATION->icons());
|
proxyModel->setSourceModel(APPLICATION->icons());
|
||||||
|
|
@ -45,11 +61,8 @@ IconPickerDialog::IconPickerDialog(QWidget* parent) : QDialog(parent), ui(new Ui
|
||||||
ui->iconView->setModel(proxyModel);
|
ui->iconView->setModel(proxyModel);
|
||||||
|
|
||||||
auto contentsWidget = ui->iconView;
|
auto contentsWidget = ui->iconView;
|
||||||
contentsWidget->setViewMode(QListView::IconMode);
|
|
||||||
contentsWidget->setFlow(QListView::LeftToRight);
|
contentsWidget->setFlow(QListView::LeftToRight);
|
||||||
contentsWidget->setIconSize(QSize(48, 48));
|
contentsWidget->setIconSize(QSize(48, 48));
|
||||||
contentsWidget->setMovement(QListView::Static);
|
|
||||||
contentsWidget->setResizeMode(QListView::Adjust);
|
|
||||||
contentsWidget->setSelectionMode(QAbstractItemView::SingleSelection);
|
contentsWidget->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||||
contentsWidget->setSpacing(5);
|
contentsWidget->setSpacing(5);
|
||||||
contentsWidget->setWordWrap(false);
|
contentsWidget->setWordWrap(false);
|
||||||
|
|
@ -86,7 +99,11 @@ IconPickerDialog::IconPickerDialog(QWidget* parent) : QDialog(parent), ui(new Ui
|
||||||
|
|
||||||
auto buttonFolder = ui->buttonBox->addButton(tr("Open Folder"), QDialogButtonBox::ResetRole);
|
auto buttonFolder = ui->buttonBox->addButton(tr("Open Folder"), QDialogButtonBox::ResetRole);
|
||||||
connect(buttonFolder, &QPushButton::clicked, this, &IconPickerDialog::openFolder);
|
connect(buttonFolder, &QPushButton::clicked, this, &IconPickerDialog::openFolder);
|
||||||
connect(searchBar, &QLineEdit::textChanged, this, &IconPickerDialog::filterIcons);
|
connect(ui->searchLine, &QLineEdit::textChanged, this, &IconPickerDialog::filterIcons);
|
||||||
|
connect(ui->contextCombo, &QComboBox::currentIndexChanged, this, [this](int index) {
|
||||||
|
Context category = static_cast<Context>(ui->contextCombo->itemData(index).toInt());
|
||||||
|
filterIconsByCategory(category);
|
||||||
|
});
|
||||||
// Prevent incorrect indices from e.g. filesystem changes
|
// Prevent incorrect indices from e.g. filesystem changes
|
||||||
connect(APPLICATION->icons(), &IconList::iconUpdated, this, [this]() { proxyModel->invalidate(); });
|
connect(APPLICATION->icons(), &IconList::iconUpdated, this, [this]() { proxyModel->invalidate(); });
|
||||||
}
|
}
|
||||||
|
|
@ -182,3 +199,22 @@ void IconPickerDialog::filterIcons(const QString& query)
|
||||||
{
|
{
|
||||||
proxyModel->setFilterFixedString(query);
|
proxyModel->setFilterFixedString(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IconPickerDialog::filterIconsByCategory(Context category)
|
||||||
|
{
|
||||||
|
switch (category) {
|
||||||
|
default:
|
||||||
|
case Any:
|
||||||
|
proxyModel->setFilterRegularExpression("");
|
||||||
|
break;
|
||||||
|
case Modern:
|
||||||
|
proxyModel->setFilterRegularExpression("^(?:ftb_logo|(?!.*_legacy$)(?!^(?:curseforge_|modrinth_|ftb_|technic_|atl_))[A-Za-z0-9._-]+)$");
|
||||||
|
break;
|
||||||
|
case Legacy:
|
||||||
|
proxyModel->setFilterRegularExpression("^(?:[A-Za-z0-9._-]+_legacy|ftb_glow)$");
|
||||||
|
break;
|
||||||
|
case Modpacks:
|
||||||
|
proxyModel->setFilterRegularExpression("^(?!(?:ftb_glow|ftb_logo))(?:curseforge_|modrinth_|ftb_|technic_|atl_)[A-Za-z0-9._-]*$");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,14 @@ class IconPickerDialog : public QDialog {
|
||||||
QLineEdit* searchBar;
|
QLineEdit* searchBar;
|
||||||
QSortFilterProxyModel* proxyModel;
|
QSortFilterProxyModel* proxyModel;
|
||||||
|
|
||||||
|
enum Context {
|
||||||
|
Any,
|
||||||
|
Modern,
|
||||||
|
Legacy,
|
||||||
|
Modpacks,
|
||||||
|
};
|
||||||
|
Q_ENUM(Context)
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void selectionChanged(QItemSelection, QItemSelection);
|
void selectionChanged(QItemSelection, QItemSelection);
|
||||||
void activated(QModelIndex);
|
void activated(QModelIndex);
|
||||||
|
|
@ -49,4 +57,5 @@ class IconPickerDialog : public QDialog {
|
||||||
void removeSelectedIcon();
|
void removeSelectedIcon();
|
||||||
void openFolder();
|
void openFolder();
|
||||||
void filterIcons(const QString& text);
|
void filterIcons(const QString& text);
|
||||||
|
void filterIconsByCategory(Context);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,64 @@
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QListView" name="iconView"/>
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="contextCombo">
|
||||||
|
<property name="accessibleName">
|
||||||
|
<string>Icon category</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="searchLine">
|
||||||
|
<property name="placeholderText">
|
||||||
|
<string>Search Icons...</string>
|
||||||
|
</property>
|
||||||
|
<property name="clearButtonEnabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QListView" name="iconView">
|
||||||
|
<property name="iconSize">
|
||||||
|
<size>
|
||||||
|
<width>60</width>
|
||||||
|
<height>60</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="movement">
|
||||||
|
<enum>QListView::Static</enum>
|
||||||
|
</property>
|
||||||
|
<property name="resizeMode">
|
||||||
|
<enum>QListView::Adjust</enum>
|
||||||
|
</property>
|
||||||
|
<property name="viewMode">
|
||||||
|
<enum>QListView::IconMode</enum>
|
||||||
|
</property>
|
||||||
|
<property name="uniformItemSizes">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QDialogButtonBox" name="buttonBox">
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue