166 const ThemeColors& c = impl_->themeManager->colors();
178 I.sidebar =
new QWidget(I.parent);
181 I.sidebar->setAutoFillBackground(
true);
182 I.sidebar->setBackgroundRole(QPalette::Window);
183 auto* sidebarLayout =
new QVBoxLayout(I.sidebar);
184 sidebarLayout->setContentsMargins(0, 0, 0, 0);
185 sidebarLayout->setSpacing(0);
187 auto* scrollArea =
new QScrollArea(I.sidebar);
188 scrollArea->setWidgetResizable(
true);
189 scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
190 scrollArea->setFrameShape(QFrame::NoFrame);
191 scrollArea->setStyleSheet(
"QScrollArea { background-color: transparent; }");
193 auto* scrollContent =
new QWidget();
195 scrollContent->setAutoFillBackground(
true);
196 scrollContent->setBackgroundRole(QPalette::Window);
197 auto* sectionsLayout =
new QVBoxLayout(scrollContent);
198 sectionsLayout->setContentsMargins(0, 0, 0, 0);
199 sectionsLayout->setSpacing(0);
201 const QString sidebarListStyle = I.buildSidebarListStyle();
206 auto* librarySection =
209 I.categoryView = I.makeListView(sidebarListStyle);
210 I.categoryView->setModel(I.categoryModel);
211 I.categoryView->setCurrentIndex(I.categoryModel->index(0));
213 connect(I.categoryView->selectionModel(), &QItemSelectionModel::currentRowChanged,
this,
214 [
this](
const QModelIndex& current,
const QModelIndex&)
215 { emit categoryChanged(current.row()); });
217 librarySection->addWidget(I.categoryView);
218 sectionsLayout->addWidget(librarySection);
222 [
this]() { impl_->categoryModel->rebuildIcons(); });
227 auto* sourceSection =
230 I.sourceView = I.makeListView(sidebarListStyle);
231 I.sourceView->setModel(I.sourceModel);
233 connect(I.sourceView->selectionModel(), &QItemSelectionModel::currentRowChanged,
this,
234 [
this](
const QModelIndex&,
const QModelIndex&) { emit sourceChanged(); });
236 sourceSection->addWidget(I.sourceView);
237 sectionsLayout->addWidget(sourceSection);
244 auto* runnerSection =
247 I.runnerView = I.makeListView(sidebarListStyle);
248 I.runnerView->setModel(I.runnerModel);
256 if (I.runnerModel->rowCount() > 0)
257 I.runnerView->setCurrentIndex(I.runnerModel->index(0));
259 connect(I.runnerView->selectionModel(), &QItemSelectionModel::currentRowChanged,
this,
260 [
this](
const QModelIndex&,
const QModelIndex&) { emit runnerChanged(); });
262 runnerSection->addWidget(I.runnerView);
263 sectionsLayout->addWidget(runnerSection);
271 "Collections",
"sidebar/collections_collapsed",
false, scrollContent);
273 auto* collectionsToolbar =
new QWidget();
274 auto* collectionsToolbarLayout =
new QHBoxLayout(collectionsToolbar);
275 collectionsToolbarLayout->setContentsMargins(10, 2, 10, 2);
276 collectionsToolbarLayout->setSpacing(4);
277 collectionsToolbarLayout->addStretch();
279 auto* addCollectionBtn =
new QPushButton(QStringLiteral(
"+"));
280 addCollectionBtn->setFixedSize(20, 20);
281 addCollectionBtn->setToolTip(QStringLiteral(
"Create new collection"));
282 addCollectionBtn->setCursor(Qt::PointingHandCursor);
283 addCollectionBtn->setStyleSheet(
284 QString(
"QPushButton { background-color: %1; color: %2; border: 1px solid %3; "
285 "border-radius: 4px; font-weight: bold; }"
286 "QPushButton:hover { background-color: %4; }")
291 connect(addCollectionBtn, &QPushButton::clicked,
this,
293 collectionsToolbarLayout->addWidget(addCollectionBtn);
295 collectionsSection->addWidget(collectionsToolbar);
297 I.collectionsView = I.makeListView(sidebarListStyle);
298 I.collectionsView->setModel(I.collectionsModel);
299 I.collectionsView->setContextMenuPolicy(Qt::CustomContextMenu);
301 connect(I.collectionsView, &QListView::customContextMenuRequested,
this,
302 [
this](
const QPoint& pos)
305 QModelIndex idx = II.collectionsView->indexAt(pos);
308 QString collectionName = II.collectionsModel->data(idx, Qt::UserRole).toString();
309 if (collectionName.isEmpty())
312 QMenu contextMenu(II.parent);
313 impl_->themeManager->styleMenu(&contextMenu);
314 QAction* deleteAction = contextMenu.addAction(QStringLiteral(
"Delete Collection"));
316 deleteAction, &QAction::triggered, this,
317 [this, collectionName]()
321 QMessageBox::question(III.parent, QStringLiteral(
"Delete Collection"),
322 QString(
"Are you sure you want to delete the "
323 "collection '%1'?\n\nGames will not be "
324 "deleted, only the collection.")
325 .arg(collectionName),
326 QMessageBox::Yes | QMessageBox::No);
327 if (reply == QMessageBox::Yes)
329 III.libraryController->removeCollection(collectionName.toStdString());
330 updateCollectionsList();
331 emit collectionDeleted(collectionName);
334 contextMenu.exec(II.collectionsView->mapToGlobal(pos));
337 connect(I.collectionsView->selectionModel(), &QItemSelectionModel::currentRowChanged,
this,
338 [
this](
const QModelIndex& current,
const QModelIndex&)
340 if (!current.isValid())
342 emit collectionChanged(QString());
345 emit collectionChanged(
346 impl_->collectionsModel->data(current, Qt::UserRole).toString());
349 updateCollectionsList();
350 collectionsSection->addWidget(I.collectionsView);
351 sectionsLayout->addWidget(collectionsSection);
355 sectionsLayout->addStretch();
356 scrollArea->setWidget(scrollContent);
357 sidebarLayout->addWidget(scrollArea);