game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
command_palette.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// command_palette.cpp
4// ==============================================================================
5// VS Code-style command palette implementation
6// ==============================================================================
7
8#include "command_palette.h"
9#include "mainwindow.h"
10#include "theme_manager.h"
11
12#include <QApplication>
13#include <QKeyEvent>
14#include <QPainter>
15#include <QPainterPath>
16#include <QScreen>
17#include <QSettings>
18#include <QStyledItemDelegate>
19#include <QVBoxLayout>
20#include <algorithm>
21
22// ==============================================================================
23// Custom Item Roles
24// ==============================================================================
25
26namespace
27{
28constexpr int CommandIdRole = Qt::UserRole;
29constexpr int CommandCategoryRole = Qt::UserRole + 1;
30constexpr int CommandShortcutRole = Qt::UserRole + 2;
31constexpr int CommandEnabledRole = Qt::UserRole + 3;
32constexpr int IsSeparatorRole = Qt::UserRole + 4;
33} // namespace
34
35// ==============================================================================
36// Custom Delegate for Command Items
37// ==============================================================================
38
39class CommandItemDelegate : public QStyledItemDelegate
40{
41 public:
42 explicit CommandItemDelegate(QObject* parent, ThemeManager* themeManager)
43 : QStyledItemDelegate(parent), themeManager_(themeManager)
44 {
45 }
46
47 private:
48 ThemeManager* themeManager_;
49
50 public:
51 QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override
52 {
53 Q_UNUSED(option)
54
55 if (index.data(IsSeparatorRole).toBool())
56 {
57 return QSize(0, 24); // Separator height
58 }
59 return QSize(0, 36); // Command item height
60 }
61
62 void paint(QPainter* painter, const QStyleOptionViewItem& option,
63 const QModelIndex& index) const override
64 {
65 painter->save();
66 painter->setRenderHint(QPainter::Antialiasing);
67
68 const ThemeColors& c = themeManager_->colors();
69 bool isSelected = option.state & QStyle::State_Selected;
70 bool isEnabled = index.data(CommandEnabledRole).toBool();
71
72 // Check if this is a separator/category header
73 if (index.data(IsSeparatorRole).toBool())
74 {
75 paintSeparator(painter, option.rect, index.data(Qt::DisplayRole).toString(), c);
76 painter->restore();
77 return;
78 }
79
80 // Draw background
81 QRect bgRect = option.rect.adjusted(4, 2, -4, -2);
82 if (isSelected)
83 {
84 QPainterPath path;
85 path.addRoundedRect(bgRect, 4, 4);
86 painter->fillPath(path, c.accent);
87 }
88 else if (option.state & QStyle::State_MouseOver)
89 {
90 QPainterPath path;
91 path.addRoundedRect(bgRect, 4, 4);
92 painter->fillPath(path, c.hoverBackground);
93 }
94
95 // Colors based on state
96 QColor textColor = isSelected ? c.textOnAccent : c.textPrimary;
97 QColor mutedColor = isSelected ? c.textOnAccent : c.textMuted;
98 if (!isEnabled)
99 {
100 textColor = c.textMuted;
101 mutedColor = c.textMuted.darker(120);
102 }
103
104 // Draw icon
105 QString icon = index.data(Qt::DecorationRole).toString();
106 if (!icon.isEmpty())
107 {
108 QFont iconFont = painter->font();
109 iconFont.setPointSize(themeManager_->scaledFontSize(12));
110 painter->setFont(iconFont);
111 painter->setPen(textColor);
112 painter->drawText(bgRect.adjusted(8, 0, 0, 0), Qt::AlignVCenter | Qt::AlignLeft, icon);
113 }
114
115 // Draw label
116 QString label = index.data(Qt::DisplayRole).toString();
117 QFont labelFont = painter->font();
118 labelFont.setPointSize(themeManager_->scaledFontSize(11));
119 painter->setFont(labelFont);
120 painter->setPen(textColor);
121 int labelX = icon.isEmpty() ? 12 : 36;
122 QRect labelRect = bgRect.adjusted(labelX, 0, -80, 0);
123 painter->drawText(
124 labelRect, Qt::AlignVCenter | Qt::AlignLeft,
125 painter->fontMetrics().elidedText(label, Qt::ElideRight, labelRect.width()));
126
127 // Draw shortcut on the right
128 QString shortcut = index.data(CommandShortcutRole).toString();
129 if (!shortcut.isEmpty())
130 {
131 QFont shortcutFont = painter->font();
132 shortcutFont.setPointSize(themeManager_->scaledFontSize(9));
133 painter->setFont(shortcutFont);
134 painter->setPen(mutedColor);
135
136 // Draw shortcut in a subtle rounded rect
137 QFontMetrics fm(shortcutFont);
138 int shortcutWidth = fm.horizontalAdvance(shortcut) + 12;
139 QRect shortcutRect(bgRect.right() - shortcutWidth - 8, bgRect.center().y() - 10,
140 shortcutWidth, 20);
141
142 if (!isSelected)
143 {
144 QColor scBg = c.cardBackground;
145 scBg.setAlpha(128);
146 QPainterPath scPath;
147 scPath.addRoundedRect(shortcutRect, 3, 3);
148 painter->fillPath(scPath, scBg);
149 }
150
151 painter->drawText(shortcutRect, Qt::AlignCenter, shortcut);
152 }
153
154 painter->restore();
155 }
156
157 private:
158 void paintSeparator(QPainter* painter, const QRect& rect, const QString& category,
159 const ThemeColors& c) const
160 {
161 // Draw category name
162 QFont font = painter->font();
163 font.setPointSize(themeManager_->scaledFontSize(9));
164 font.setBold(true);
165 painter->setFont(font);
166 painter->setPen(c.textMuted);
167 painter->drawText(rect.adjusted(12, 4, 0, 0), Qt::AlignVCenter | Qt::AlignLeft,
168 category.toUpper());
169
170 // Draw separator line
171 int lineY = rect.bottom() - 2;
172 QPen linePen(c.border);
173 linePen.setWidth(1);
174 painter->setPen(linePen);
175 painter->drawLine(rect.left() + 12, lineY, rect.right() - 12, lineY);
176 }
177};
178
179// ==============================================================================
180// Fuzzy Match Scoring
181// ==============================================================================
182
183int PaletteCommand::matchScore(const QString& query) const
184{
185 if (query.isEmpty())
186 {
187 return priority + 100; // Base score for empty query
188 }
189
190 QString lowerQuery = query.toLower();
191 QString lowerLabel = label.toLower();
192 QString lowerCategory = category.toLower();
193
194 // Exact prefix match in label gets highest score
195 if (lowerLabel.startsWith(lowerQuery))
196 {
197 return 1000 + priority;
198 }
199
200 // Word boundary match in label
201 QStringList words = lowerLabel.split(' ', Qt::SkipEmptyParts);
202 for (const QString& word : words)
203 {
204 if (word.startsWith(lowerQuery))
205 {
206 return 800 + priority;
207 }
208 }
209
210 // Subsequence match (fuzzy)
211 int queryIdx = 0;
212 int consecutiveBonus = 0;
213 int lastMatchIdx = -2;
214
215 for (int i = 0; i < lowerLabel.length() && queryIdx < lowerQuery.length(); ++i)
216 {
217 if (lowerLabel[i] == lowerQuery[queryIdx])
218 {
219 if (i == lastMatchIdx + 1)
220 {
221 consecutiveBonus += 50; // Bonus for consecutive matches
222 }
223 lastMatchIdx = i;
224 ++queryIdx;
225 }
226 }
227
228 if (queryIdx == lowerQuery.length())
229 {
230 // Full match found
231 int score = 500 + consecutiveBonus + priority;
232 // Bonus for shorter labels (more precise match)
233 score += (100 - std::min(100, static_cast<int>(lowerLabel.length())));
234 return score;
235 }
236
237 // Check category match
238 if (lowerCategory.contains(lowerQuery))
239 {
240 return 200 + priority;
241 }
242
243 return 0; // No match
244}
245
246// ==============================================================================
247// CommandPalette Implementation
248// ==============================================================================
249
251 : QDialog(parent, Qt::FramelessWindowHint | Qt::Popup), mainWindow_(parent),
252 themeManager_(themeManager ? themeManager : &ThemeManager::instance())
253{
254 setObjectName("CommandPalette");
255 setAttribute(Qt::WA_TranslucentBackground);
256 setModal(true);
257
258 // Load recent commands from settings
259 QSettings settings;
260 recentCommands_ = settings.value("CommandPalette/RecentCommands").toStringList();
261
262 setupUI();
263 applyTheme();
264
265 connect(themeManager_, &ThemeManager::themeChanged, this, &CommandPalette::applyTheme);
266}
267
269{
270 // Save recent commands
271 QSettings settings;
272 settings.setValue("CommandPalette/RecentCommands", recentCommands_);
273}
274
275void CommandPalette::setupUI()
276{
277 // Main layout with margins for shadow effect
278 auto* mainLayout = new QVBoxLayout(this);
279 mainLayout->setContentsMargins(8, 8, 8, 8);
280 mainLayout->setSpacing(0);
281
282 // Container widget for actual content
283 auto* container = new QWidget(this);
284 container->setObjectName("CommandPaletteContainer");
285 auto* containerLayout = new QVBoxLayout(container);
286 containerLayout->setContentsMargins(0, 0, 0, 0);
287 containerLayout->setSpacing(0);
288
289 // Search input
290 searchEdit_ = new QLineEdit(container);
291 searchEdit_->setObjectName("CommandPaletteSearch");
292 searchEdit_->setPlaceholderText("Type a command...");
293 searchEdit_->setClearButtonEnabled(true);
294 searchEdit_->installEventFilter(this);
295 containerLayout->addWidget(searchEdit_);
296
297 // Results list
298 resultsList_ = new QListWidget(container);
299 resultsList_->setObjectName("CommandPaletteResults");
300 resultsList_->setItemDelegate(new CommandItemDelegate(resultsList_, themeManager_));
301 resultsList_->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
302 resultsList_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
303 resultsList_->setFocusPolicy(Qt::NoFocus);
304 resultsList_->setMouseTracking(true);
305 containerLayout->addWidget(resultsList_);
306
307 // Hint label at bottom
308 hintLabel_ = new QLabel(container);
309 hintLabel_->setObjectName("CommandPaletteHint");
310 hintLabel_->setText("Press Enter to execute, Escape to close");
311 hintLabel_->setAlignment(Qt::AlignCenter);
312 containerLayout->addWidget(hintLabel_);
313
314 mainLayout->addWidget(container);
315
316 // Search debounce timer
317 searchDebounceTimer_ = new QTimer(this);
318 searchDebounceTimer_->setSingleShot(true);
319 connect(searchDebounceTimer_, &QTimer::timeout, this,
320 [this]() { populateResults(searchEdit_->text()); });
321
322 // Connect signals
323 connect(searchEdit_, &QLineEdit::textChanged, this, &CommandPalette::onSearchTextChanged);
324 connect(resultsList_, &QListWidget::itemActivated, this, &CommandPalette::onItemActivated);
325 connect(resultsList_, &QListWidget::itemDoubleClicked, this,
326 &CommandPalette::onItemDoubleClicked);
327
328 // Set fixed width, dynamic height
329 setFixedWidth(600);
330 setMinimumHeight(100);
331 setMaximumHeight(500);
332}
333
334void CommandPalette::applyTheme()
335{
336 const ThemeColors& c = themeManager_->colors();
337
338 // Container styling
339 QString containerStyle = QString("#CommandPaletteContainer {"
340 " background-color: %1;"
341 " border: 1px solid %2;"
342 " border-radius: 8px;"
343 "}")
344 .arg(c.panelBackground.name(), c.border.name());
345
346 // Search input styling
347 QString searchStyle = QString("#CommandPaletteSearch {"
348 " background-color: %1;"
349 " border: none;"
350 " border-bottom: 1px solid %2;"
351 " border-radius: 8px 8px 0 0;"
352 " padding: 12px 16px;"
353 " font-size: %5px;"
354 " color: %3;"
355 "}"
356 "#CommandPaletteSearch::placeholder {"
357 " color: %4;"
358 "}")
359 .arg(c.panelBackground.name(), c.border.name(), c.textPrimary.name(),
360 c.textMuted.name())
361 .arg(themeManager_->scaledFontSize(14));
362
363 // Results list styling
364 QString resultsStyle = QString("#CommandPaletteResults {"
365 " background-color: %1;"
366 " border: none;"
367 " outline: none;"
368 "}"
369 "#CommandPaletteResults::item {"
370 " border: none;"
371 " outline: none;"
372 "}")
373 .arg(c.panelBackground.name());
374
375 // Hint label styling
376 QString hintStyle = QString("#CommandPaletteHint {"
377 " background-color: %1;"
378 " border-top: 1px solid %2;"
379 " border-radius: 0 0 8px 8px;"
380 " padding: 6px;"
381 " font-size: %4px;"
382 " color: %3;"
383 "}")
384 .arg(c.cardBackground.name(), c.border.name(), c.textMuted.name())
385 .arg(themeManager_->scaledFontSize(10));
386
387 setStyleSheet(containerStyle + searchStyle + resultsStyle + hintStyle);
388}
389
391{
392 // Check for duplicate ID
393 auto it = std::find_if(staticCommands_.begin(), staticCommands_.end(),
394 [&cmd](const PaletteCommand& c) { return c.id == cmd.id; });
395 if (it != staticCommands_.end())
396 {
397 *it = cmd; // Update existing
398 }
399 else
400 {
401 staticCommands_.push_back(cmd);
402 }
403}
404
405void CommandPalette::registerCommands(const std::vector<PaletteCommand>& commands)
406{
407 for (const auto& cmd : commands)
408 {
409 registerCommand(cmd);
410 }
411}
412
414{
415 staticCommands_.erase(std::remove_if(staticCommands_.begin(), staticCommands_.end(),
416 [&id](const PaletteCommand& c) { return c.id == id; }),
417 staticCommands_.end());
418}
419
420void CommandPalette::unregisterCategory(const QString& category)
421{
422 staticCommands_.erase(std::remove_if(staticCommands_.begin(), staticCommands_.end(),
423 [&category](const PaletteCommand& c)
424 { return c.category == category; }),
425 staticCommands_.end());
426}
427
429{
430 staticCommands_.clear();
431}
432
433void CommandPalette::registerDynamicProvider(std::function<std::vector<PaletteCommand>()> provider)
434{
435 dynamicProviders_.push_back(std::move(provider));
436}
437
439{
440 // Position at top center of parent window
441 if (parentWidget())
442 {
443 QPoint parentCenter = parentWidget()->mapToGlobal(QPoint(parentWidget()->width() / 2, 0));
444 move(parentCenter.x() - width() / 2, parentCenter.y() + 50);
445 }
446 else
447 {
448 // Center on primary screen
449 QScreen* screen = QApplication::primaryScreen();
450 if (screen)
451 {
452 QRect screenGeom = screen->availableGeometry();
453 move(screenGeom.center().x() - width() / 2, screenGeom.top() + 100);
454 }
455 }
456
457 searchEdit_->clear();
458 populateResults("");
459 show();
460 searchEdit_->setFocus();
461}
462
463void CommandPalette::showEvent(QShowEvent* event)
464{
465 QDialog::showEvent(event);
466 searchEdit_->setFocus();
467}
468
469void CommandPalette::keyPressEvent(QKeyEvent* event)
470{
471 switch (event->key())
472 {
473 case Qt::Key_Escape:
474 hide();
475 break;
476 case Qt::Key_Up:
477 selectPreviousItem();
478 break;
479 case Qt::Key_Down:
480 selectNextItem();
481 break;
482 case Qt::Key_Return:
483 case Qt::Key_Enter:
484 if (resultsList_->currentItem())
485 {
486 onItemActivated(resultsList_->currentItem());
487 }
488 break;
489 default:
490 QDialog::keyPressEvent(event);
491 }
492}
493
494bool CommandPalette::eventFilter(QObject* obj, QEvent* event)
495{
496 if (obj == searchEdit_ && event->type() == QEvent::KeyPress)
497 {
498 auto* keyEvent = static_cast<QKeyEvent*>(event);
499 switch (keyEvent->key())
500 {
501 case Qt::Key_Up:
502 selectPreviousItem();
503 return true;
504 case Qt::Key_Down:
505 selectNextItem();
506 return true;
507 case Qt::Key_Return:
508 case Qt::Key_Enter:
509 if (resultsList_->currentItem())
510 {
511 onItemActivated(resultsList_->currentItem());
512 }
513 return true;
514 default:
515 break;
516 }
517 }
518 return QDialog::eventFilter(obj, event);
519}
520
521void CommandPalette::onSearchTextChanged(const QString& text)
522{
523 Q_UNUSED(text)
524 searchDebounceTimer_->start(SEARCH_DEBOUNCE_MS);
525}
526
527void CommandPalette::onItemActivated(QListWidgetItem* item)
528{
529 if (!item || item->data(IsSeparatorRole).toBool())
530 {
531 return;
532 }
533
534 QString commandId = item->data(CommandIdRole).toString();
535 bool isEnabled = item->data(CommandEnabledRole).toBool();
536
537 if (!isEnabled)
538 {
539 return;
540 }
541
542 hide();
543 executeCommand(commandId);
544}
545
546void CommandPalette::onItemDoubleClicked(QListWidgetItem* item)
547{
548 onItemActivated(item);
549}
550
551void CommandPalette::populateResults(const QString& query)
552{
553 resultsList_->clear();
554
555 // Gather all commands
556 std::vector<PaletteCommand> allCommands = staticCommands_;
557
558 // Add dynamic commands
559 for (const auto& provider : dynamicProviders_)
560 {
561 auto dynamicCmds = provider();
562 allCommands.insert(allCommands.end(), dynamicCmds.begin(), dynamicCmds.end());
563 }
564
565 // Filter and score commands
566 struct ScoredCommand
567 {
568 const PaletteCommand* cmd;
569 int score;
570 bool isRecent;
571 };
572 std::vector<ScoredCommand> scoredCommands;
573
574 for (const auto& cmd : allCommands)
575 {
576 if (!cmd.shouldShow())
577 {
578 continue;
579 }
580
581 int score = cmd.matchScore(query);
582 if (score > 0 || query.isEmpty())
583 {
584 bool isRecent = recentCommands_.contains(cmd.id);
585 scoredCommands.push_back({&cmd, score, isRecent});
586 }
587 }
588
589 // Sort by: recent first (if no query), then by score, then alphabetically
590 std::sort(scoredCommands.begin(), scoredCommands.end(),
591 [&query](const ScoredCommand& a, const ScoredCommand& b)
592 {
593 // Recent commands first when no query
594 if (query.isEmpty())
595 {
596 if (a.isRecent != b.isRecent)
597 {
598 return a.isRecent > b.isRecent;
599 }
600 }
601 // Then by score
602 if (a.score != b.score)
603 {
604 return a.score > b.score;
605 }
606 // Then alphabetically
607 return a.cmd->label < b.cmd->label;
608 });
609
610 // Group by category and add items
611 QString lastCategory;
612 int itemCount = 0;
613 constexpr int MAX_ITEMS = 20;
614
615 for (const auto& scored : scoredCommands)
616 {
617 if (itemCount >= MAX_ITEMS)
618 {
619 break;
620 }
621
622 const PaletteCommand& cmd = *scored.cmd;
623
624 // Add category separator if category changed
625 if (cmd.category != lastCategory && !cmd.category.isEmpty())
626 {
627 auto* separator = new QListWidgetItem(cmd.category);
628 separator->setData(IsSeparatorRole, true);
629 separator->setFlags(Qt::NoItemFlags); // Not selectable
630 resultsList_->addItem(separator);
631 lastCategory = cmd.category;
632 }
633
634 resultsList_->addItem(createCommandItem(cmd));
635 ++itemCount;
636 }
637
638 // Select first selectable item
639 for (int i = 0; i < resultsList_->count(); ++i)
640 {
641 QListWidgetItem* item = resultsList_->item(i);
642 if (!item->data(IsSeparatorRole).toBool())
643 {
644 resultsList_->setCurrentItem(item);
645 break;
646 }
647 }
648
649 // Adjust height based on content
650 int itemHeight = 36;
651 int separatorHeight = 24;
652 int totalHeight = 0;
653 for (int i = 0; i < resultsList_->count(); ++i)
654 {
655 QListWidgetItem* item = resultsList_->item(i);
656 totalHeight += item->data(IsSeparatorRole).toBool() ? separatorHeight : itemHeight;
657 }
658
659 // Add search field and hint heights
660 int fixedHeight = 50 + 30; // search + hint
661 int contentHeight = std::min(totalHeight, 350); // Max results area
662 setFixedHeight(fixedHeight + contentHeight + 16); // +padding
663}
664
665QListWidgetItem* CommandPalette::createCommandItem(const PaletteCommand& cmd)
666{
667 auto* item = new QListWidgetItem();
668 item->setText(cmd.label);
669 item->setData(Qt::DecorationRole, cmd.icon);
670 item->setData(CommandIdRole, cmd.id);
671 item->setData(CommandCategoryRole, cmd.category);
672 item->setData(CommandShortcutRole, cmd.shortcut);
673 item->setData(CommandEnabledRole, cmd.enabled());
674 item->setData(IsSeparatorRole, false);
675
676 if (!cmd.enabled())
677 {
678 item->setFlags(item->flags() & ~Qt::ItemIsEnabled);
679 }
680
681 if (!cmd.description.isEmpty())
682 {
683 item->setToolTip(cmd.description);
684 }
685
686 return item;
687}
688
689void CommandPalette::executeCommand(const QString& commandId)
690{
691 // Find the command
692 const PaletteCommand* foundCmd = nullptr;
693
694 for (const auto& cmd : staticCommands_)
695 {
696 if (cmd.id == commandId)
697 {
698 foundCmd = &cmd;
699 break;
700 }
701 }
702
703 // Check dynamic commands if not found in static
704 if (!foundCmd)
705 {
706 for (const auto& provider : dynamicProviders_)
707 {
708 auto dynamicCmds = provider();
709 for (const auto& cmd : dynamicCmds)
710 {
711 if (cmd.id == commandId)
712 {
713 // Execute immediately since dynamic commands are temporary
714 if (cmd.action)
715 {
716 addToRecentCommands(commandId);
717 cmd.action();
718 }
719 return;
720 }
721 }
722 }
723 }
724
725 if (foundCmd && foundCmd->action)
726 {
727 addToRecentCommands(commandId);
728 foundCmd->action();
729 }
730}
731
732void CommandPalette::addToRecentCommands(const QString& commandId)
733{
734 // Remove if already exists (will be re-added at front)
735 recentCommands_.removeAll(commandId);
736
737 // Add to front
738 recentCommands_.prepend(commandId);
739
740 // Trim to max size
741 while (recentCommands_.size() > MAX_RECENT_COMMANDS)
742 {
743 recentCommands_.removeLast();
744 }
745}
746
747void CommandPalette::selectNextItem()
748{
749 int current = resultsList_->currentRow();
750 for (int i = current + 1; i < resultsList_->count(); ++i)
751 {
752 QListWidgetItem* item = resultsList_->item(i);
753 if (!item->data(IsSeparatorRole).toBool())
754 {
755 resultsList_->setCurrentRow(i);
756 return;
757 }
758 }
759}
760
761void CommandPalette::selectPreviousItem()
762{
763 int current = resultsList_->currentRow();
764 for (int i = current - 1; i >= 0; --i)
765 {
766 QListWidgetItem* item = resultsList_->item(i);
767 if (!item->data(IsSeparatorRole).toBool())
768 {
769 resultsList_->setCurrentRow(i);
770 return;
771 }
772 }
773}
774
775QStringList CommandPalette::getRecentCommands(int limit) const
776{
777 return recentCommands_.mid(0, limit);
778}
CommandItemDelegate(QObject *parent, ThemeManager *themeManager)
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
void clearCommands()
Clear all registered commands.
void showPalette()
Show the palette and focus the search field.
void unregisterCategory(const QString &category)
Remove all commands in a category.
void registerCommands(const std::vector< PaletteCommand > &commands)
Register multiple commands at once.
void keyPressEvent(QKeyEvent *event) override
void unregisterCommand(const QString &id)
Remove a command by ID.
bool eventFilter(QObject *obj, QEvent *event) override
void registerCommand(const PaletteCommand &cmd)
Register a single command.
void showEvent(QShowEvent *event) override
void registerDynamicProvider(std::function< std::vector< PaletteCommand >()> provider)
Register a provider for dynamic commands.
CommandPalette(MainWindow *parent, ThemeManager *themeManager=nullptr)
~CommandPalette() override
QStringList getRecentCommands(int limit=5) const
Get the list of recently used command IDs.
void themeChanged()
Emitted when theme or accent color changes.
int scaledFontSize(int baseSize) const
Get scaled font size for given base size.
Represents a single command in the palette.
int matchScore(const QString &query) const
bool enabled() const
std::function< void()> action
QColor panelBackground
QColor cardBackground
QColor textPrimary
QColor textMuted
QColor hoverBackground
QColor textOnAccent