game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
menubar_manager.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// ui/qt/menubar_manager.h
4// ==============================================================================
5// Owner of the QMenuBar + all five top-level menus (File / Game / View /
6// Tools / Help). Fourth manager in the MED-* family, extracted 2026-04-19.
7// ==============================================================================
8// Responsibilities:
9// - Build the menu bar and the five top-level menus.
10// - Populate the Game and View menus dynamically via aboutToShow, so
11// per-game actions (Launch/Stop/Configure/Favorite/Collections) and
12// current-state indicators (sort/view-mode checkboxes, panel
13// visibility checkboxes) reflect the live model.
14// - Own Quick-Settings toggles (MangoHud, GameMode, Gamescope, VkBasalt),
15// Collections add/remove per game, Change Artwork, Library
16// Statistics, and Install-from-Lutris flows — all have injected
17// dependencies and don't need MainWindow state beyond the selected
18// game id.
19//
20// Design parity with ToolbarManager / SidebarManager / DetailsPanelManager:
21// - QObject-based, signal emissions for every action whose side-effect
22// needs MainWindow state (addGame, removeGame, refresh, etc.).
23// - Inline handling for actions whose dependencies are injected
24// (libraryController mutations, dialogs that only need a parent).
25// - Pimpl pattern hides the menu construction details.
26//
27// Selected-game tracking:
28// MainWindow owns selectedGameId_. Before each Game menu open,
29// MainWindow passes it via setSelectedGameId() so the aboutToShow
30// handler has fresh state without reaching back into MainWindow.
31// ==============================================================================
32
33#pragma once
34
35#include <QObject>
36#include <QString>
37#include <functional>
38#include <memory>
39#include <string>
40
41class ThemeManager;
42class QMainWindow;
43class QMenuBar;
47
48enum class ViewMode;
49enum class SortOption;
50
51namespace core
52{
56} // namespace core
57
58class MenuBarManager : public QObject
59{
60 Q_OBJECT
61
62 public:
63 MenuBarManager(QMainWindow* mainWindow, core::GameLibraryController* libraryController,
64 core::LaunchController* launchController,
65 core::SettingsController* settingsController,
66 DetailsPanelManager* detailsPanelManager, GameThumbnailCache* imageCache,
67 GameActionFactory* actionFactory, ThemeManager* themeManager,
68 QObject* qparent = nullptr);
69 ~MenuBarManager() override;
70
71 /// Build the menu bar and all five top-level menus. Call once.
72 void setupMenus();
73
74 /// Re-apply theme styling to every menu. MainWindow::applyTheme() drives
75 /// this on theme change; individual menus were already restyled on
76 /// aboutToShow before that signal, but this keeps the menu bar itself
77 /// consistent.
78 void applyTheme();
79
80 /// Propagate the current selection. MainWindow calls this every time
81 /// selectedGameId_ changes so the Game menu's aboutToShow handler can
82 /// read fresh state without grabbing MainWindow.
83 void setSelectedGameId(const std::string& gameId);
84
85 /// Current view-mode / sort-option — needed so the View menu's
86 /// checkbox indicators and Sort By radio group reflect reality.
87 void setViewMode(ViewMode mode);
88 void setSortOption(SortOption sort);
89
90 /// Panel-visibility getter. MainWindow installs a single functor so
91 /// the View menu's aboutToShow can tick the current panels without us
92 /// holding references to the container widgets. The functor receives
93 /// a panel name ("sidebar" | "games" | "details" | "monitor" | "ha")
94 /// and returns whether that panel is currently visible.
95 using PanelVisibilityQuery = std::function<bool(const QString&)>;
97
98 signals:
99 // Shared with ToolbarManager where applicable (same semantic names so
100 // MainWindow connects both to the same slot):
111 void themeSelected(const QString& themeId);
114 void panelToggleRequested(const QString& name);
115
116 // Menu-bar-specific — relayed from the factory. MainWindow's existing
117 // slots listen here for back-compat and to avoid wiring the factory
118 // directly to MainWindow from two call sites.
119 void launchRequested(const std::string& gameId);
120 void stopRequested(const std::string& gameId);
121 void favoriteChanged(const std::string& gameId); // factory already toggled
122 void removeGameRequested(const std::string& gameId);
123 void artworkChanged(const std::string& gameId);
124
125 // Zoom (MainWindow routes to ToolbarManager's slider):
129
130 // Menu mode (hamburger vs menu bar):
131 void menuModeToggled(bool useHamburger);
132
133 // Refresh notifications — relayed from GameActionFactory after it
134 // performs per-game mutations (Quick Settings toggle, Configure dialog
135 // accept, Collections add/remove). MainWindow handles the concrete
136 // refreshes (updateCollectionsList, refreshGameList, updateGameRow,
137 // image cache invalidation, etc.). artworkChanged is declared above
138 // in the menu-bar-specific block.
139 void gameConfigUpdated(const std::string& gameId);
140 void gameListChanged(); // source filters + category counts + gameList
143
144 private:
145 class Impl;
146 std::unique_ptr<Impl> impl_;
147};
void libraryStatisticsRequested()
void installFromLutrisRequested()
void addGameRequested()
std::function< bool(const QString &)> PanelVisibilityQuery
Panel-visibility getter.
void gameListChanged()
void setSortOption(SortOption sort)
void zoomInRequested()
void sortSelected(SortOption sort)
void commandPaletteRequested()
void favoriteChanged(const std::string &gameId)
void stopRequested(const std::string &gameId)
void manageRunnersRequested()
void refreshLibraryRequested()
void setViewMode(ViewMode mode)
Current view-mode / sort-option — needed so the View menu's checkbox indicators and Sort By radio gro...
~MenuBarManager() override
void setPanelVisibilityQuery(PanelVisibilityQuery query)
void runnersListChanged()
void importGamesRequested()
void removeGameRequested(const std::string &gameId)
void setupMenus()
Build the menu bar and all five top-level menus. Call once.
void setSelectedGameId(const std::string &gameId)
Propagate the current selection.
void launchRequested(const std::string &gameId)
void viewModeSelected(ViewMode mode)
void exportImportRequested()
void gameConfigUpdated(const std::string &gameId)
void zoomOutRequested()
void panelToggleRequested(const QString &name)
void exitRequested()
void themeSelected(const QString &themeId)
void downloadQueueRequested()
void applyTheme()
Re-apply theme styling to every menu.
MenuBarManager(QMainWindow *mainWindow, core::GameLibraryController *libraryController, core::LaunchController *launchController, core::SettingsController *settingsController, DetailsPanelManager *detailsPanelManager, GameThumbnailCache *imageCache, GameActionFactory *actionFactory, ThemeManager *themeManager, QObject *qparent=nullptr)
void settingsRequested()
void artworkChanged(const std::string &gameId)
void zoomResetRequested()
void menuModeToggled(bool useHamburger)
ViewMode
Definition mainwindow.h:75
SortOption
Definition mainwindow.h:86