game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
toolbar_manager.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// ui/qt/toolbar_manager.cpp
4// ==============================================================================
5// Extracted from MainWindow's setupToolBar() / applyTheme() on 2026-04-19.
6// Owns the DraggableToolbar widget tree and routes user input back to
7// MainWindow via signals so the toolbar is testable / movable in isolation.
8// Behaviour is preserved verbatim.
9// ==============================================================================
10
12
13#include "a11y_utils.h"
17#include "icon_font.h"
18#include "mainwindow.h" // for ViewMode / SortOption enums
20#include "theme_manager.h"
24
25#include <QAction>
26#include <QActionGroup>
27#include <QComboBox>
28#include <QLabel>
29#include <QLineEdit>
30#include <QMainWindow>
31#include <QMenu>
32#include <QMessageBox>
33#include <QPushButton>
34#include <QSlider>
35#include <QStringList>
36#include <QTimer>
37#include <QToolBar>
38#include <QToolButton>
39
40// ==============================================================================
41// Impl
42// ==============================================================================
43
45{
46 public:
47 Impl(ToolbarManager* owner, QMainWindow* window, core::GameLibraryController* libCtrl,
48 core::LaunchController* launchCtrl, core::SettingsController* settingsCtrl,
49 ThemeManager* themeMgr)
50 : q(owner), mainWindow(window), libraryController(libCtrl), launchController(launchCtrl),
51 settingsController(settingsCtrl), themeManager(themeMgr)
52 {
53 }
54
55 ToolbarManager* q = nullptr;
56
57 // Injected dependencies
58 QMainWindow* mainWindow = nullptr;
63
64 // Root widget
66
67 // Menu section
68 QToolButton* hamburgerBtn = nullptr;
69 QMenu* mainMenu = nullptr;
70 QMenu* themeSubmenu = nullptr;
71 QActionGroup* themeActionGroup = nullptr;
72
73 // Panel toggle buttons
74 QPushButton* panelSidebarBtn = nullptr;
75 QPushButton* panelGamesBtn = nullptr;
76 QPushButton* panelDetailsBtn = nullptr;
77#ifdef HAVE_QTERMWIDGET
78 QPushButton* panelMonitorBtn = nullptr;
79#endif
80#ifdef HAVE_WEBENGINE
81 QPushButton* panelHABtn = nullptr;
82#endif
83
84 // Controls section
85 QLineEdit* searchEdit = nullptr;
87 QComboBox* sortCombo = nullptr;
88 QSlider* zoomSlider = nullptr;
89 QLabel* zoomLabel = nullptr;
91
92 // View-mode actions (exposed to command palette / keyboard shortcuts)
93 QAction* listViewAction = nullptr;
94 QAction* gridViewAction = nullptr;
95 QAction* compactViewAction = nullptr;
96 QActionGroup* viewModeGroup = nullptr;
97
98 // Monitor section (HAVE_QTERMWIDGET)
99#ifdef HAVE_QTERMWIDGET
100 QComboBox* monitorTypeCombo = nullptr;
101 QPushButton* monitorRestartBtn = nullptr;
102#endif
103
104 // Running-game status widget
106
107 // Debounce timers owned by the manager
108 QTimer* searchDebounceTimer = nullptr;
109 QTimer* zoomDebounceTimer = nullptr;
110
111 // Pending search text captured from QLineEdit between keypresses; emitted
112 // when the debounce timer fires.
114
115 // Helper: map monitorTypeCombo index → command string.
116 // The "Shell" slot honours $SHELL so zsh/fish users don't get a
117 // surprise bash nested inside their login shell.
118 static QString monitorCommandForIndex(int index)
119 {
120 switch (index)
121 {
122 case 0:
123 return QStringLiteral("btop");
124 case 1:
125 return QStringLiteral("htop");
126 case 2:
127 return QStringLiteral("top");
128 case 3:
129 {
130 QString s = QString::fromLocal8Bit(qgetenv("SHELL"));
131 return s.isEmpty() ? QStringLiteral("/bin/bash") : s;
132 }
133 default:
134 return QStringLiteral("btop");
135 }
136 }
137};
138
139// ==============================================================================
140// Ctor / dtor
141// ==============================================================================
142
144 core::LaunchController* launchCtrl,
145 core::SettingsController* settingsCtrl, ThemeManager* themeManager,
146 QObject* qparent)
147 : QObject(qparent), impl_(std::make_unique<Impl>(this, mainWindow, libCtrl, launchCtrl,
148 settingsCtrl, themeManager))
149{
150}
151
153
154// ==============================================================================
155// setupToolbar — the port of MainWindow::setupToolBar()
156// ==============================================================================
157
159{
160 auto& I = *impl_;
161 const ThemeColors& c = impl_->themeManager->colors();
162
163 // ==========================================================================
164 // Create DraggableToolbar
165 // ==========================================================================
166 I.draggableToolbar = new DraggableToolbar(I.mainWindow, impl_->themeManager);
167
168 QToolBar* toolBarContainer = I.mainWindow->addToolBar("Main Toolbar");
169 toolBarContainer->setMovable(false);
170 toolBarContainer->setFloatable(false);
171 toolBarContainer->setContextMenuPolicy(Qt::NoContextMenu);
172 toolBarContainer->addWidget(I.draggableToolbar);
173
174 // Common styles
175 QString comboStyle =
176 QString("QComboBox { background-color: %1; color: %2; border: 1px solid %3; "
177 "border-radius: 3px; padding: 4px 8px; padding-right: 24px; min-width: 80px; }"
178 "QComboBox::drop-down { width: 20px; border-left: 1px solid %3; "
179 "border-top-right-radius: 3px; border-bottom-right-radius: 3px; }"
180 "QComboBox::down-arrow { border-left: 4px solid transparent; "
181 "border-right: 4px solid transparent; border-top: 5px solid %2; }"
182 "QComboBox:hover { border-color: %4; }"
183 "QComboBox QAbstractItemView { background-color: %1; color: %2; "
184 "selection-background-color: %4; border: 1px solid %3; }")
185 .arg(c.inputBackground.name())
186 .arg(c.textPrimary.name())
187 .arg(c.border.name())
188 .arg(c.accent.name());
189
190 auto panelBtnStyle = [&c]()
191 {
192 return QString("QPushButton { background-color: transparent; color: %1; border: none; "
193 "border-radius: 3px; padding: 3px 8px; font-size: 12px; }"
194 "QPushButton:hover { background-color: %2; }"
195 "QPushButton:checked { background-color: %3; color: %4; }")
196 .arg(c.textSecondary.name())
197 .arg(c.hoverBackground.name())
198 .arg(c.accent.name())
199 .arg(c.textOnAccent.name());
200 };
201
202 auto actionBtnStyle = [&c]()
203 {
204 return QString("QPushButton { background-color: transparent; color: %1; border: none; "
205 "border-radius: 3px; padding: 3px 8px; font-size: 12px; }"
206 "QPushButton:hover { background-color: %2; color: %3; }")
207 .arg(c.textSecondary.name())
208 .arg(c.hoverBackground.name())
209 .arg(c.textPrimary.name());
210 };
211
212 // ==========================================================================
213 // Section 1: Menu (fixed)
214 // ==========================================================================
215 auto* menuSection = I.draggableToolbar->addSection("menu", "Menu");
216 menuSection->setFixed(true);
217
218 I.hamburgerBtn = new QToolButton(I.mainWindow);
219 I.hamburgerBtn->setText(IconFont::text(FA::Bars));
220 I.hamburgerBtn->setToolTip("Menu");
221 a11y::describe(I.hamburgerBtn, tr("Main menu"), tr("Open the application main menu"));
222 I.hamburgerBtn->setPopupMode(QToolButton::InstantPopup);
223 I.hamburgerBtn->setFixedSize(26, 26);
224 I.hamburgerBtn->setStyleSheet(
225 QString("QToolButton { background-color: transparent; color: %1; border: none; "
226 "border-radius: 3px; font-family: '%3'; font-size: %4px; }"
227 "QToolButton:hover { background-color: %2; }"
228 "QToolButton::menu-indicator { image: none; }")
229 .arg(c.textPrimary.name(), c.hoverBackground.name(), IconFont::solidFamily())
230 .arg(impl_->themeManager->scaledFontSize(14)));
231
232 I.mainMenu = new QMenu(I.hamburgerBtn);
233 impl_->themeManager->styleMenu(I.mainMenu);
234
235 QAction* addGameAction = I.mainMenu->addAction("\u002B Add Game...");
236 connect(addGameAction, &QAction::triggered, this, [this]() { emit addGameRequested(); });
237
238 QAction* importGamesAction = I.mainMenu->addAction("\u21E9 Import Games...");
239 connect(importGamesAction, &QAction::triggered, this,
240 [this]() { emit importGamesRequested(); });
241
242 QAction* installLutrisAction = I.mainMenu->addAction("\u2617 Install from Lutris...");
243 connect(installLutrisAction, &QAction::triggered, this,
244 [this]() { emit installFromLutrisRequested(); });
245
246 QAction* refreshAction = I.mainMenu->addAction("\u21BB Refresh Library");
247 connect(refreshAction, &QAction::triggered, this, [this]() { emit refreshLibraryRequested(); });
248
249 I.mainMenu->addSeparator();
250
251 QAction* settingsAction = I.mainMenu->addAction("\u2699\ufe0f Settings...");
252 connect(settingsAction, &QAction::triggered, this, [this]() { emit settingsRequested(); });
253
254 I.mainMenu->addSeparator();
255
256 // Tools submenu
257 QMenu* toolsSubmenu = I.mainMenu->addMenu("\u2699 Tools");
258 impl_->themeManager->styleMenu(toolsSubmenu);
259
260 QAction* manageRunnersAction = toolsSubmenu->addAction("\u25A3 Manage Runners...");
261 connect(manageRunnersAction, &QAction::triggered, this,
262 [this]() { emit manageRunnersRequested(); });
263
264 QAction* systemInfoAction = toolsSubmenu->addAction("\u2261 System Info...");
265 connect(systemInfoAction, &QAction::triggered, this,
266 [this]()
267 {
268 const auto& sys = SystemInfoService::instance().getCapabilities();
269 QString syncMethod =
270 sys.canUseNTSync()
271 ? "NTSync"
272 : (sys.canUseFsync() ? "Fsync"
273 : (sys.kernel.supportsEsync ? "Esync" : "None"));
274 QString info = QString("<h3>System Information</h3>"
275 "<table>"
276 "<tr><td><b>GPU:</b></td><td>%1</td></tr>"
277 "<tr><td><b>Vulkan:</b></td><td>%2</td></tr>"
278 "<tr><td><b>CPU:</b></td><td>%3 (%4 cores)</td></tr>"
279 "<tr><td><b>Sync Method:</b></td><td>%5</td></tr>"
280 "<tr><td><b>GameMode:</b></td><td>%6</td></tr>"
281 "<tr><td><b>MangoHud:</b></td><td>%7</td></tr>"
282 "<tr><td><b>Gamescope:</b></td><td>%8</td></tr>"
283 "</table>")
284 .arg(QString::fromStdString(sys.gpu.model))
285 .arg(sys.gpu.hasVulkanSupport() ? "Available" : "Not found")
286 .arg(QString::fromStdString(sys.cpu.model))
287 .arg(sys.cpu.coreCount)
288 .arg(syncMethod)
289 .arg(sys.tools.gameMode ? "Available" : "Not installed")
290 .arg(sys.tools.mangoHud ? "Available" : "Not installed")
291 .arg(sys.tools.gamescope ? "Available" : "Not installed");
292
293 QMessageBox msgBox(impl_->mainWindow);
294 msgBox.setWindowTitle("System Information");
295 msgBox.setTextFormat(Qt::RichText);
296 msgBox.setText(info);
297 msgBox.setIcon(QMessageBox::Information);
298 msgBox.exec();
299 });
300
301 toolsSubmenu->addSeparator();
302
303 QAction* libraryStatsAction = toolsSubmenu->addAction("\u25B2 Library Statistics...");
304 connect(libraryStatsAction, &QAction::triggered, this,
305 [this]() { emit libraryStatisticsRequested(); });
306
307 QAction* exportImportAction = toolsSubmenu->addAction("\u21C5 Export/Import Library...");
308 connect(exportImportAction, &QAction::triggered, this,
309 [this]() { emit exportImportRequested(); });
310
311 QAction* downloadQueueAction = toolsSubmenu->addAction("\u21E9 Download Queue...");
312 connect(downloadQueueAction, &QAction::triggered, this,
313 [this]() { emit downloadQueueRequested(); });
314
315 I.mainMenu->addSeparator();
316
317 I.themeSubmenu = I.mainMenu->addMenu("\u25D0 Theme");
318 impl_->themeManager->styleMenu(I.themeSubmenu);
319
320 I.themeActionGroup = new QActionGroup(this);
321 I.themeActionGroup->setExclusive(true);
322 QString currentThemeId = impl_->themeManager->currentThemeId();
323
324 for (const auto& themeId : impl_->themeManager->getAvailableThemeIds())
325 {
326 const Theme* theme = impl_->themeManager->getTheme(themeId);
327 if (!theme)
328 continue;
329 QAction* action = I.themeSubmenu->addAction(theme->displayName);
330 action->setCheckable(true);
331 action->setData(themeId);
332 action->setChecked(themeId == currentThemeId);
333 I.themeActionGroup->addAction(action);
334 }
335
336 connect(I.themeActionGroup, &QActionGroup::triggered, this,
337 [this](QAction* action) { emit themeSelected(action->data().toString()); });
338
339 I.mainMenu->addSeparator();
340
341 QAction* aboutAction = I.mainMenu->addAction("\u2139\ufe0f About");
342 connect(aboutAction, &QAction::triggered, this,
343 [this]()
344 {
345 QMessageBox::about(impl_->mainWindow, "About Game Launcher",
346 "Game Launcher v1.0.0\n\n"
347 "A Linux game launcher with Steam integration.\n\n"
348 "Built with Qt and the core library.");
349 });
350
351 I.mainMenu->addSeparator();
352
353 QAction* exitAction = I.mainMenu->addAction("\u2715 Exit");
354 connect(exitAction, &QAction::triggered, this, [this]() { emit exitRequested(); });
355
356 I.hamburgerBtn->setMenu(I.mainMenu);
357 menuSection->contentLayout()->addWidget(I.hamburgerBtn);
358
359 // ==========================================================================
360 // Section 2: Panel Toggles (draggable)
361 // ==========================================================================
362 auto* panelsSection = I.draggableToolbar->addSection("panels", "Panels");
363 auto panelSettings = I.settingsController->getAppSettings();
364
365#ifdef HAVE_WEBENGINE
366 I.panelHABtn = new QPushButton("Home Assistant", I.mainWindow);
367 I.panelHABtn->setIcon(IconFont::icon(FA::House, 14, c.textSecondary));
368 I.panelHABtn->setCheckable(true);
369 I.panelHABtn->setChecked(panelSettings.panelHAVisible);
370 I.panelHABtn->setToolTip("Toggle Home Assistant panel");
371 I.panelHABtn->setStyleSheet(panelBtnStyle());
372 connect(I.panelHABtn, &QPushButton::clicked, this,
373 [this]() { emit panelToggleRequested(QStringLiteral("ha")); });
374 panelsSection->contentLayout()->addWidget(I.panelHABtn);
375 if (!panelSettings.enableHomeAssistant)
376 I.panelHABtn->setVisible(false);
377#endif
378
379 I.panelSidebarBtn = new QPushButton("Sidebar", I.mainWindow);
380 I.panelSidebarBtn->setIcon(IconFont::icon(FA::TableColumns, 14, c.textSecondary));
381 I.panelSidebarBtn->setCheckable(true);
382 I.panelSidebarBtn->setChecked(panelSettings.panelSidebarVisible);
383 I.panelSidebarBtn->setToolTip("Toggle sidebar panel");
384 I.panelSidebarBtn->setStyleSheet(panelBtnStyle());
385 connect(I.panelSidebarBtn, &QPushButton::clicked, this,
386 [this]() { emit panelToggleRequested(QStringLiteral("sidebar")); });
387 panelsSection->contentLayout()->addWidget(I.panelSidebarBtn);
388
389 I.panelGamesBtn = new QPushButton("Games", I.mainWindow);
390 I.panelGamesBtn->setIcon(IconFont::icon(FA::TableList, 14, c.textSecondary));
391 I.panelGamesBtn->setCheckable(true);
392 I.panelGamesBtn->setChecked(panelSettings.panelGamesVisible);
393 I.panelGamesBtn->setToolTip("Toggle games list panel");
394 I.panelGamesBtn->setStyleSheet(panelBtnStyle());
395 connect(I.panelGamesBtn, &QPushButton::clicked, this,
396 [this]() { emit panelToggleRequested(QStringLiteral("games")); });
397 panelsSection->contentLayout()->addWidget(I.panelGamesBtn);
398
399 I.panelDetailsBtn = new QPushButton("Details", I.mainWindow);
400 I.panelDetailsBtn->setIcon(IconFont::icon(FA::BookOpen, 14, c.textSecondary));
401 I.panelDetailsBtn->setCheckable(true);
402 I.panelDetailsBtn->setChecked(panelSettings.panelDetailsVisible);
403 I.panelDetailsBtn->setToolTip("Toggle game details panel");
404 I.panelDetailsBtn->setStyleSheet(panelBtnStyle());
405 connect(I.panelDetailsBtn, &QPushButton::clicked, this,
406 [this]() { emit panelToggleRequested(QStringLiteral("details")); });
407 panelsSection->contentLayout()->addWidget(I.panelDetailsBtn);
408
409#ifdef HAVE_QTERMWIDGET
410 I.panelMonitorBtn = new QPushButton("Monitor", I.mainWindow);
411 I.panelMonitorBtn->setIcon(IconFont::icon(FA::Terminal, 14, c.textSecondary));
412 I.panelMonitorBtn->setCheckable(true);
413 I.panelMonitorBtn->setChecked(panelSettings.panelMonitorVisible);
414 I.panelMonitorBtn->setToolTip("Toggle system monitor panel");
415 I.panelMonitorBtn->setStyleSheet(panelBtnStyle());
416 connect(I.panelMonitorBtn, &QPushButton::clicked, this,
417 [this]() { emit panelToggleRequested(QStringLiteral("monitor")); });
418 panelsSection->contentLayout()->addWidget(I.panelMonitorBtn);
419#endif
420
421 // ==========================================================================
422 // Section 3: Game Controls (draggable)
423 // ==========================================================================
424 auto* gameControlsSection = I.draggableToolbar->addSection("gameControls", "Game Controls");
425
426 int searchWidth = I.settingsController->getAppSettings().toolbarSearchWidth;
427 I.searchEdit = new QLineEdit(I.mainWindow);
428 I.searchEdit->setPlaceholderText("Search games...");
429 I.searchEdit->setMinimumWidth(searchWidth);
430 I.searchEdit->setMaximumWidth(searchWidth);
431 I.searchEdit->setToolTip("Search games (Ctrl+F)");
432 I.searchEdit->setClearButtonEnabled(true);
433 I.searchEdit->setStyleSheet(
434 QString("QLineEdit { background-color: %1; color: %2; border: 1px solid %3; "
435 "border-radius: 4px; padding: 4px 8px; }"
436 "QLineEdit:focus { border-color: %4; }")
437 .arg(c.inputBackground.name())
438 .arg(c.textPrimary.name())
439 .arg(c.border.name())
440 .arg(c.accent.name()));
441
442 // Owned debounce timer — emits `searchTextChanged` after 200ms of quiet.
443 I.searchDebounceTimer = new QTimer(this);
444 I.searchDebounceTimer->setSingleShot(true);
445 connect(I.searchDebounceTimer, &QTimer::timeout, this,
446 [this]() { emit searchTextChanged(impl_->pendingSearchText); });
447 connect(I.searchEdit, &QLineEdit::textChanged, this,
448 [this](const QString& text)
449 {
450 impl_->pendingSearchText = text;
451 impl_->searchDebounceTimer->start(200);
452 });
453 gameControlsSection->contentLayout()->addWidget(I.searchEdit);
454
455 // Resizable search handle
456 I.searchDragHandle = new ToolbarDragHandle(I.searchEdit, nullptr, I.mainWindow);
457 I.searchDragHandle->setLeftWidgetConstraints(80, 300);
458 I.searchDragHandle->setToolTip("Drag to resize search field");
459 connect(I.searchDragHandle, &ToolbarDragHandle::widthChanged, this,
460 [this](int newWidth)
461 {
462 auto settings = impl_->settingsController->getAppSettings();
463 settings.toolbarSearchWidth = newWidth;
464 impl_->settingsController->setAppSettings(settings);
465 impl_->settingsController->saveSettings();
466 });
467 gameControlsSection->contentLayout()->addWidget(I.searchDragHandle);
468
469 I.sortCombo = new QComboBox(I.mainWindow);
470 I.sortCombo->addItem("A-Z", static_cast<int>(SortOption::NameAsc));
471 I.sortCombo->addItem("Z-A", static_cast<int>(SortOption::NameDesc));
472 I.sortCombo->addItem("Recent", static_cast<int>(SortOption::LastPlayedDesc));
473 I.sortCombo->addItem("Played", static_cast<int>(SortOption::PlayTimeDesc));
474 I.sortCombo->addItem("Added", static_cast<int>(SortOption::RecentlyAddedDesc));
475 I.sortCombo->setToolTip("Sort order");
476 I.sortCombo->setStyleSheet(comboStyle);
477 connect(I.sortCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
478 [this](int index) { emit sortChanged(index); });
479 gameControlsSection->contentLayout()->addWidget(I.sortCombo);
480
481 // Visual separator
482 ToolbarDragHandle* sep1 = new ToolbarDragHandle(nullptr, nullptr, I.mainWindow);
483 gameControlsSection->contentLayout()->addWidget(sep1);
484
485 // View mode buttons
486 I.viewModeGroup = new QActionGroup(this);
487 I.viewModeGroup->setExclusive(true);
488
489 QPushButton* listBtn = new QPushButton("\u2630", I.mainWindow);
490 listBtn->setCheckable(true);
491 listBtn->setChecked(true);
492 listBtn->setToolTip("List View");
493 listBtn->setFixedSize(24, 24);
494 listBtn->setStyleSheet(panelBtnStyle());
495
496 QPushButton* gridBtn = new QPushButton("\u25A6", I.mainWindow);
497 gridBtn->setCheckable(true);
498 gridBtn->setToolTip("Grid View");
499 gridBtn->setFixedSize(24, 24);
500 gridBtn->setStyleSheet(panelBtnStyle());
501
502 QPushButton* compactBtn = new QPushButton("\u2261", I.mainWindow);
503 compactBtn->setCheckable(true);
504 compactBtn->setToolTip("Compact View");
505 compactBtn->setFixedSize(24, 24);
506 compactBtn->setStyleSheet(panelBtnStyle());
507
508 connect(listBtn, &QPushButton::clicked, this,
509 [this, listBtn, gridBtn, compactBtn]()
510 {
511 listBtn->setChecked(true);
512 gridBtn->setChecked(false);
513 compactBtn->setChecked(false);
515 });
516 connect(gridBtn, &QPushButton::clicked, this,
517 [this, listBtn, gridBtn, compactBtn]()
518 {
519 listBtn->setChecked(false);
520 gridBtn->setChecked(true);
521 compactBtn->setChecked(false);
523 });
524 connect(compactBtn, &QPushButton::clicked, this,
525 [this, listBtn, gridBtn, compactBtn]()
526 {
527 listBtn->setChecked(false);
528 gridBtn->setChecked(false);
529 compactBtn->setChecked(true);
531 });
532
533 gameControlsSection->contentLayout()->addWidget(listBtn);
534 gameControlsSection->contentLayout()->addWidget(gridBtn);
535 gameControlsSection->contentLayout()->addWidget(compactBtn);
536
537 // Zoom slider with resizable handle
538 int zoomWidth = I.settingsController->getAppSettings().toolbarZoomWidth;
539 I.zoomDragHandle = new ToolbarDragHandle(nullptr, nullptr, I.mainWindow);
540 I.zoomDragHandle->setLeftWidgetConstraints(30, 100);
541 I.zoomDragHandle->setToolTip("Drag to resize zoom slider");
542 gameControlsSection->contentLayout()->addWidget(I.zoomDragHandle);
543
544 I.zoomSlider = new QSlider(Qt::Horizontal, I.mainWindow);
545 I.zoomSlider->setRange(50, 200);
546 I.zoomSlider->setValue(100);
547 I.zoomSlider->setMinimumWidth(zoomWidth);
548 I.zoomSlider->setMaximumWidth(zoomWidth);
549 I.zoomSlider->setToolTip("Zoom (50-200%)");
550 I.zoomSlider->setStyleSheet(
551 QString("QSlider::groove:horizontal { background: %1; height: 4px; border-radius: 2px; }"
552 "QSlider::handle:horizontal { background: %2; width: 10px; margin: -3px 0; "
553 "border-radius: 5px; }")
554 .arg(c.inputBackground.name())
555 .arg(c.accent.name()));
556
557 // Owned debounce timer — emits `zoomChanged` after 150ms of quiet.
558 I.zoomDebounceTimer = new QTimer(this);
559 I.zoomDebounceTimer->setSingleShot(true);
560 I.zoomDebounceTimer->setInterval(150);
561 connect(I.zoomDebounceTimer, &QTimer::timeout, this,
562 [this]() { emit zoomChanged(impl_->zoomSlider->value()); });
563 connect(I.zoomSlider, &QSlider::valueChanged, this,
564 [this](int value)
565 {
566 if (impl_->zoomLabel)
567 impl_->zoomLabel->setText(QString("%1%").arg(value));
568 impl_->zoomDebounceTimer->start();
569 });
570 gameControlsSection->contentLayout()->addWidget(I.zoomSlider);
571
572 // Connect zoom drag handle to slider
573 connect(I.zoomDragHandle, &ToolbarDragHandle::widthChanged, this,
574 [this](int newWidth)
575 {
576 impl_->zoomSlider->setMinimumWidth(newWidth);
577 impl_->zoomSlider->setMaximumWidth(newWidth);
578 auto settings = impl_->settingsController->getAppSettings();
579 settings.toolbarZoomWidth = newWidth;
580 impl_->settingsController->setAppSettings(settings);
581 impl_->settingsController->saveSettings();
582 });
583
584 I.zoomLabel = new QLabel("100%", I.mainWindow);
585 I.zoomLabel->setFixedWidth(30);
586 I.zoomLabel->setStyleSheet(QString("color: %1; font-size: 10px;").arg(c.textMuted.name()));
587 gameControlsSection->contentLayout()->addWidget(I.zoomLabel);
588
589 // Cross-owned view-mode QActions (used by command palette + shortcuts)
590 I.listViewAction = new QAction("List", this);
591 I.listViewAction->setCheckable(true);
592 I.listViewAction->setChecked(true);
593 I.viewModeGroup->addAction(I.listViewAction);
594 I.gridViewAction = new QAction("Grid", this);
595 I.gridViewAction->setCheckable(true);
596 I.viewModeGroup->addAction(I.gridViewAction);
597 I.compactViewAction = new QAction("Compact", this);
598 I.compactViewAction->setCheckable(true);
599 I.viewModeGroup->addAction(I.compactViewAction);
600
601#ifdef HAVE_QTERMWIDGET
602 // ==========================================================================
603 // Section 4: Monitor Controls (draggable, hidden by default)
604 // ==========================================================================
605 auto* monitorSection = I.draggableToolbar->addSection("monitor", "Monitor");
606 monitorSection->setVisible(false);
607
608 I.monitorTypeCombo = new QComboBox(I.mainWindow);
609 I.monitorTypeCombo->addItem("btop++", "btop");
610 I.monitorTypeCombo->addItem("htop", "htop");
611 I.monitorTypeCombo->addItem("top", "top");
612 // Store $SHELL (fallback /bin/bash) as the Shell item's data so
613 // zsh/fish users get their actual login shell rather than bash.
614 {
615 QString userShell = QString::fromLocal8Bit(qgetenv("SHELL"));
616 if (userShell.isEmpty())
617 userShell = QStringLiteral("/bin/bash");
618 I.monitorTypeCombo->addItem("Shell", userShell);
619 }
620 I.monitorTypeCombo->setToolTip("Monitor type");
621 I.monitorTypeCombo->setStyleSheet(comboStyle);
622 connect(I.monitorTypeCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
623 [this](int index)
624 { emit monitorCommandRequested(Impl::monitorCommandForIndex(index)); });
625 monitorSection->contentLayout()->addWidget(I.monitorTypeCombo);
626
627 I.monitorRestartBtn = new QPushButton("\u21BB", I.mainWindow);
628 I.monitorRestartBtn->setToolTip("Restart monitor");
629 I.monitorRestartBtn->setFixedSize(26, 26);
630 I.monitorRestartBtn->setStyleSheet(actionBtnStyle());
631 connect(I.monitorRestartBtn, &QPushButton::clicked, this,
632 [this]() { emit monitorRestartRequested(); });
633 monitorSection->contentLayout()->addWidget(I.monitorRestartBtn);
634#else
635 Q_UNUSED(actionBtnStyle);
636#endif
637
638 // ==========================================================================
639 // Section 5: Running Game Status
640 // ==========================================================================
641 auto* runningSection = I.draggableToolbar->addSection("running", "Running");
642 runningSection->setVisible(false);
643
644 I.runningGameStatusWidget = new RunningGameStatusWidget(I.mainWindow);
645 connect(I.runningGameStatusWidget, &RunningGameStatusWidget::clicked, this,
646 [this]() { emit runningGameDetailsRequested(); });
647 runningSection->contentLayout()->addWidget(I.runningGameStatusWidget);
648
649 // Spacer (pushes sections to left)
650 I.draggableToolbar->addSpacer();
651
652 // Restore saved section order + lock state + connect persistence signals
653 QString savedOrder =
654 QString::fromStdString(I.settingsController->getAppSettings().toolbarSectionOrder);
655 if (!savedOrder.isEmpty())
656 {
657 I.draggableToolbar->setSectionOrder(savedOrder.split(',', Qt::SkipEmptyParts));
658 }
659 I.draggableToolbar->setLocked(I.settingsController->getAppSettings().toolbarLocked);
660
661 connect(I.draggableToolbar, &DraggableToolbar::sectionOrderChanged, this,
662 [this](const QStringList& order)
663 {
664 auto settings = impl_->settingsController->getAppSettings();
665 settings.toolbarSectionOrder = order.join(',').toStdString();
666 impl_->settingsController->setAppSettings(settings);
667 impl_->settingsController->saveSettings();
668 });
669 connect(I.draggableToolbar, &DraggableToolbar::lockedChanged, this,
670 [this](bool locked)
671 {
672 auto settings = impl_->settingsController->getAppSettings();
673 settings.toolbarLocked = locked;
674 impl_->settingsController->setAppSettings(settings);
675 impl_->settingsController->saveSettings();
676 });
677}
678
679// ==============================================================================
680// applyTheme — toolbar-specific portion of MainWindow::applyTheme()
681// ==============================================================================
682
684{
685 auto& I = *impl_;
686 const ThemeColors& c = impl_->themeManager->colors();
687
688 // Theme menu checked state
690
691 // Menus
692 if (I.mainMenu)
693 impl_->themeManager->styleMenu(I.mainMenu);
694 if (I.themeSubmenu)
695 impl_->themeManager->styleMenu(I.themeSubmenu);
696
697 // Hamburger button
698 if (I.hamburgerBtn)
699 {
700 I.hamburgerBtn->setStyleSheet(
701 QString("QToolButton { background-color: transparent; color: %1; border: none; "
702 "border-radius: 3px; font-family: '%3'; font-size: %4px; }"
703 "QToolButton:hover { background-color: %2; }"
704 "QToolButton::menu-indicator { image: none; }")
705 .arg(c.textPrimary.name(), c.hoverBackground.name(), IconFont::solidFamily())
706 .arg(impl_->themeManager->scaledFontSize(14)));
707 }
708
709 // DraggableToolbar frame (sections re-apply their own styles)
710 if (I.draggableToolbar)
711 {
712 I.draggableToolbar->applyTheme();
713 }
714
715 // Search bar
716 if (I.searchEdit)
717 {
718 I.searchEdit->setStyleSheet(
719 QString("QLineEdit { background-color: %1; color: %2; border: 1px solid %3; "
720 "border-radius: 4px; padding: 4px 8px; }"
721 "QLineEdit:focus { border-color: %4; }")
722 .arg(c.inputBackground.name())
723 .arg(c.textPrimary.name())
724 .arg(c.border.name())
725 .arg(c.accent.name()));
726 }
727
728 // Zoom slider
729 if (I.zoomSlider)
730 {
731 I.zoomSlider->setStyleSheet(
732 QString(
733 "QSlider::groove:horizontal { background: %1; height: 4px; border-radius: 2px; }"
734 "QSlider::handle:horizontal { background: %2; width: 10px; margin: -3px 0; "
735 "border-radius: 5px; }")
736 .arg(c.inputBackground.name())
737 .arg(c.accent.name()));
738 }
739
740 // Zoom label
741 if (I.zoomLabel)
742 {
743 I.zoomLabel->setStyleSheet(QString("color: %1; font-size: 10px;").arg(c.textMuted.name()));
744 }
745}
746
747// ==============================================================================
748// Accessors
749// ==============================================================================
750
752{
753 return impl_->draggableToolbar;
754}
756{
757 return impl_->searchEdit;
758}
760{
761 return impl_->sortCombo;
762}
764{
765 return impl_->zoomSlider;
766}
768{
769 return impl_->zoomLabel;
770}
771
773{
774 return impl_->listViewAction;
775}
777{
778 return impl_->gridViewAction;
779}
781{
782 return impl_->compactViewAction;
783}
784QActionGroup* ToolbarManager::viewModeGroup() const
785{
786 return impl_->viewModeGroup;
787}
788
790{
791 return impl_->panelSidebarBtn;
792}
794{
795 return impl_->panelGamesBtn;
796}
798{
799 return impl_->panelDetailsBtn;
800}
801#ifdef HAVE_QTERMWIDGET
802QPushButton* ToolbarManager::panelMonitorButton() const
803{
804 return impl_->panelMonitorBtn;
805}
806QComboBox* ToolbarManager::monitorTypeCombo() const
807{
808 return impl_->monitorTypeCombo;
809}
810QPushButton* ToolbarManager::monitorRestartButton() const
811{
812 return impl_->monitorRestartBtn;
813}
814#endif
815#ifdef HAVE_WEBENGINE
816QPushButton* ToolbarManager::panelHAButton() const
817{
818 return impl_->panelHABtn;
819}
820#endif
821
823{
824 return impl_->runningGameStatusWidget;
825}
826
828{
829 return impl_->hamburgerBtn;
830}
831
833{
834 if (!impl_->themeActionGroup)
835 return;
836 QString currentThemeId = impl_->themeManager->currentThemeId();
837 for (QAction* action : impl_->themeActionGroup->actions())
838 {
839 action->setChecked(action->data().toString() == currentThemeId);
840 }
841}
void sectionOrderChanged(const QStringList &newOrder)
void lockedChanged(bool locked)
static QIcon icon(char32_t codepoint, int size, const QColor &color)
Render a FontAwesome glyph as a QIcon at the given size and color.
Definition icon_font.h:119
static const QString & solidFamily()
Get the loaded Solid font family name.
Definition icon_font.h:136
static QString text(char32_t codepoint)
Convert a codepoint to a QString glyph.
Definition icon_font.h:113
Compact widget showing running game status in the toolbar.
void clicked()
Emitted when widget is clicked.
static SystemInfoService & instance()
Get singleton instance.
const SystemCapabilities & getCapabilities()
Get complete system capabilities.
void widthChanged(int newWidth)
QPushButton * panelGamesBtn
RunningGameStatusWidget * runningGameStatusWidget
ThemeManager * themeManager
static QString monitorCommandForIndex(int index)
core::GameLibraryController * libraryController
QPushButton * panelSidebarBtn
core::SettingsController * settingsController
ToolbarDragHandle * searchDragHandle
Impl(ToolbarManager *owner, QMainWindow *window, core::GameLibraryController *libCtrl, core::LaunchController *launchCtrl, core::SettingsController *settingsCtrl, ThemeManager *themeMgr)
QPushButton * panelDetailsBtn
ToolbarDragHandle * zoomDragHandle
QActionGroup * viewModeGroup
core::LaunchController * launchController
QActionGroup * themeActionGroup
DraggableToolbar * draggableToolbar
void viewModeChanged(ViewMode mode)
ToolbarManager(QMainWindow *mainWindow, core::GameLibraryController *libCtrl, core::LaunchController *launchCtrl, core::SettingsController *settingsCtrl, ThemeManager *themeManager, QObject *qparent=nullptr)
QToolButton * hamburgerButton() const
Hamburger menu button — toggled visible/hidden by MainWindow depending on the user's "hamburger vs me...
void downloadQueueRequested()
void addGameRequested()
QAction * compactViewAction() const
QLineEdit * searchEdit() const
QActionGroup * viewModeGroup() const
QPushButton * panelGamesButton() const
void setupToolbar()
Build the toolbar. Must be called exactly once after construction.
void settingsRequested()
QPushButton * panelSidebarButton() const
void installFromLutrisRequested()
QSlider * zoomSlider() const
void exitRequested()
RunningGameStatusWidget * runningGameStatusWidget() const
QPushButton * panelDetailsButton() const
void exportImportRequested()
QComboBox * sortCombo() const
void importGamesRequested()
QAction * listViewAction() const
void libraryStatisticsRequested()
QLabel * zoomLabel() const
void manageRunnersRequested()
DraggableToolbar * draggableToolbar() const
void refreshThemeMenuSelection()
Rebuild the theme submenu's checked state after a theme change.
void applyTheme()
Re-apply theme colours to toolbar widgets.
QAction * gridViewAction() const
~ToolbarManager() override
void refreshLibraryRequested()
@ RecentlyAddedDesc
Definition mainwindow.h:93
constexpr char32_t House
Definition icon_font.h:64
constexpr char32_t Bars
Definition icon_font.h:59
constexpr char32_t Terminal
Definition icon_font.h:63
constexpr char32_t BookOpen
Definition icon_font.h:62
constexpr char32_t TableColumns
Definition icon_font.h:60
constexpr char32_t TableList
Definition icon_font.h:61
void describe(QWidget *widget, const QString &name, const QString &description=QString())
Set accessibleName (short, read first by screen readers), plus a matching tooltip so sighted users ge...
Definition a11y_utils.h:35
QColor inputBackground
QColor textSecondary
QColor textPrimary
QColor textMuted
QColor hoverBackground
QColor textOnAccent
QString displayName