Skip to content

Commit 2958cb3

Browse files
authored
feat: merge Random Instance Icon (#81)
2 parents f5ace6a + 55ff5d9 commit 2958cb3

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

launcher/ui/dialogs/IconPickerDialog.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <QKeyEvent>
1818
#include <QLineEdit>
1919
#include <QPushButton>
20+
#include <QRandomGenerator>
2021
#include <QSortFilterProxyModel>
2122

2223
#include "Application.h"
@@ -90,6 +91,8 @@ IconPickerDialog::IconPickerDialog(QWidget* parent) : QDialog(parent), ui(new Ui
9091
connect(searchBar, &QLineEdit::textChanged, this, &IconPickerDialog::filterIcons);
9192
// Prevent incorrect indices from e.g. filesystem changes
9293
connect(APPLICATION->icons().get(), &IconList::iconUpdated, this, [this]() { proxyModel->invalidate(); });
94+
auto randomButton = ui->buttonBox->addButton(tr("Random Icon"), QDialogButtonBox::ResetRole);
95+
connect(randomButton, &QPushButton::clicked, this, &IconPickerDialog::selectRandomIcon);
9396
}
9497

9598
bool IconPickerDialog::eventFilter(QObject* obj, QEvent* evt)
@@ -174,6 +177,20 @@ IconPickerDialog::~IconPickerDialog()
174177
delete ui;
175178
}
176179

180+
void IconPickerDialog::selectRandomIcon()
181+
{
182+
int rowAmount = ui->iconView->model()->rowCount();
183+
int randomRowNum = QRandomGenerator::global()->bounded(rowAmount);
184+
QModelIndex index = ui->iconView->model()->index(randomRowNum, 0);
185+
186+
ui->iconView->selectionModel()->select(index, QItemSelectionModel::Current | QItemSelectionModel::Select);
187+
ui->iconView->setCurrentIndex(index);
188+
ui->iconView->scrollTo(index);
189+
190+
selectedIconKey = index.data(Qt::UserRole).toString();
191+
buttonRemove->setEnabled(APPLICATION->icons()->iconFileExists(selectedIconKey));
192+
}
193+
177194
void IconPickerDialog::openFolder()
178195
{
179196
DesktopServices::openPath(APPLICATION->icons()->iconDirectory(selectedIconKey), true);

launcher/ui/dialogs/IconPickerDialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class IconPickerDialog : public QDialog {
4747
void delayed_scroll(QModelIndex);
4848
void addNewIcon();
4949
void removeSelectedIcon();
50+
void selectRandomIcon();
5051
void openFolder();
5152
void filterIcons(const QString& text);
5253
};

0 commit comments

Comments
 (0)