Buttons toggle - Cleaning code - Fixing Icons

This commit is contained in:
Dmugetsu 2025-03-13 03:30:08 -06:00
parent fadf10f05e
commit 2ac9b39d3c
6 changed files with 91 additions and 51 deletions

View File

@ -436,7 +436,7 @@ void setVblankDiv(u32 value) {
void setIsFullscreen(bool enable) { void setIsFullscreen(bool enable) {
isFullscreen = enable; isFullscreen = enable;
} }
void setShowLabelsUnderIcons(bool enable) { static void setShowLabelsUnderIcons(bool enable) {
showLabelsUnderIcons = enable; showLabelsUnderIcons = enable;
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 965 B

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 658 B

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -145,40 +145,29 @@ void MainWindow::toggleLabelsUnderIcons() {
bool showLabels = ui->toggleLabelsAct->isChecked(); bool showLabels = ui->toggleLabelsAct->isChecked();
Config::setShowLabelsUnderIcons(); Config::setShowLabelsUnderIcons();
UpdateToolbarLabels(); UpdateToolbarLabels();
if (isGameRunning) {
UpdateToolbarButtons();
}
} }
void MainWindow::toggleFullscreen() { void MainWindow::toggleFullscreen() {
SDL_Event event; SDL_Event event;
SDL_memset(&event, 0, sizeof(event)); SDL_memset(&event, 0, sizeof(event));
event.type = SDL_EVENT_TOGGLE_FULLSCREEN; event.type = SDL_EVENT_TOGGLE_FULLSCREEN;
SDL_PushEvent(&event); SDL_PushEvent(&event);
} }
void MainWindow::AddUiWidgets() { QWidget* MainWindow::createButtonWithLabel(QPushButton* button, const QString& labelText,
// add toolbar widgets bool showLabel) {
QApplication::setStyle("Fusion");
ui->toolBar->setObjectName("mw_toolbar");
ui->toolBar->clear();
QWidget* toolbarContainer = new QWidget(this);
QHBoxLayout* mainLayout = new QHBoxLayout(toolbarContainer);
mainLayout->setContentsMargins(5, 5, 5, 5);
mainLayout->setSpacing(15);
bool showLabels = ui->toggleLabelsAct->isChecked();
QPalette palette = qApp->palette();
auto createButtonWithLabel = [&](QPushButton* button, const QString& labelText) {
QWidget* container = new QWidget(this); QWidget* container = new QWidget(this);
QVBoxLayout* layout = new QVBoxLayout(container); QVBoxLayout* layout = new QVBoxLayout(container);
layout->setAlignment(Qt::AlignHCenter | Qt::AlignBottom); layout->setAlignment(Qt::AlignCenter | Qt::AlignBottom);
layout->setContentsMargins(0, 0, 0, 0); layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(button); layout->addWidget(button);
if (showLabels) { QLabel* label = nullptr;
QLabel* label = new QLabel(labelText, this); if (showLabel && ui->toggleLabelsAct->isChecked()) {
label = new QLabel(labelText, this);
label->setAlignment(Qt::AlignCenter | Qt::AlignBottom); label->setAlignment(Qt::AlignCenter | Qt::AlignBottom);
layout->addWidget(label); layout->addWidget(label);
button->setToolTip(""); button->setToolTip("");
@ -187,51 +176,96 @@ void MainWindow::AddUiWidgets() {
} }
container->setLayout(layout); container->setLayout(layout);
container->setProperty("buttonLabel", QVariant::fromValue(label));
return container; return container;
}; }
auto createLine = [this]() { void MainWindow::AddUiWidgets() {
QFrame* line = new QFrame(this); // add toolbar widgets
line->setFrameShape(QFrame::VLine); QApplication::setStyle("Fusion");
line->setFrameShadow(QFrame::Sunken); ui->toolBar->clear();
line->setFixedWidth(2);
return line; QWidget* toolbarContainer = new QWidget(this);
}; QHBoxLayout* mainLayout = new QHBoxLayout(toolbarContainer);
mainLayout->setSpacing(2);
bool showLabels = ui->toggleLabelsAct->isChecked();
QWidget* buttonGroup = new QWidget(this); QWidget* buttonGroup = new QWidget(this);
QHBoxLayout* buttonLayout = new QHBoxLayout(buttonGroup); QHBoxLayout* buttonLayout = new QHBoxLayout(buttonGroup);
buttonLayout->setContentsMargins(0, 0, 0, 0); buttonLayout->setSpacing(2);
buttonLayout->setSpacing(15);
buttonLayout->addWidget(createButtonWithLabel(ui->playButton, tr("Play"))); buttonLayout->addWidget(createButtonWithLabel(ui->playButton, tr("Play"), showLabels));
buttonLayout->addWidget(createButtonWithLabel(ui->pauseButton, tr("Pause"))); buttonLayout->addWidget(createButtonWithLabel(ui->pauseButton, tr("Pause"), false));
buttonLayout->addWidget(createButtonWithLabel(ui->stopButton, tr("Stop"))); buttonLayout->addWidget(createButtonWithLabel(ui->stopButton, tr("Stop"), showLabels));
buttonLayout->addWidget(createButtonWithLabel(ui->settingsButton, tr("Settings"))); buttonLayout->addWidget(createButtonWithLabel(ui->settingsButton, tr("Settings"), showLabels));
buttonLayout->addWidget(createButtonWithLabel(ui->fullscreenButton, tr("Full Screen"))); buttonLayout->addWidget(
buttonLayout->addWidget(createButtonWithLabel(ui->controllerButton, tr("Controllers"))); createButtonWithLabel(ui->fullscreenButton, tr("Full Screen"), showLabels));
buttonLayout->addWidget(createButtonWithLabel(ui->keyboardButton, tr("Keyboard"))); buttonLayout->addWidget(
buttonLayout->addWidget(createButtonWithLabel(ui->refreshButton, tr("Refresh List"))); createButtonWithLabel(ui->controllerButton, tr("Controllers"), showLabels));
buttonLayout->addWidget(createButtonWithLabel(ui->keyboardButton, tr("Keyboard"), showLabels));
buttonLayout->addWidget(
createButtonWithLabel(ui->refreshButton, tr("Refresh List"), showLabels));
QWidget* searchSliderContainer = new QWidget(this); QWidget* searchSliderContainer = new QWidget(this);
QHBoxLayout* searchSliderLayout = new QHBoxLayout(searchSliderContainer); QHBoxLayout* searchSliderLayout = new QHBoxLayout(searchSliderContainer);
searchSliderLayout->setContentsMargins(0, 0, 0, 0);
searchSliderLayout->setSpacing(10);
searchSliderLayout->addWidget(ui->sizeSliderContainer); searchSliderLayout->addWidget(ui->sizeSliderContainer);
searchSliderLayout->addWidget(ui->mw_searchbar); searchSliderLayout->addWidget(ui->mw_searchbar);
searchSliderContainer->setLayout(searchSliderLayout); searchSliderContainer->setLayout(searchSliderLayout);
buttonLayout->addWidget(searchSliderContainer); buttonLayout->addWidget(searchSliderContainer);
mainLayout->addWidget(buttonGroup); mainLayout->addWidget(buttonGroup);
toolbarContainer->setLayout(mainLayout);
ui->toolBar->addWidget(toolbarContainer); ui->toolBar->addWidget(toolbarContainer);
ui->playButton->setVisible(true);
ui->pauseButton->setVisible(false);
} }
void MainWindow::UpdateToolbarLabels() { void MainWindow::UpdateToolbarLabels() {
AddUiWidgets(); AddUiWidgets();
} }
void MainWindow::UpdateToolbarButtons() {
// add toolbar widgets for when game is running
bool showLabels = ui->toggleLabelsAct->isChecked();
ui->toolBar->clear();
QWidget* toolbarContainer = new QWidget(this);
QHBoxLayout* mainLayout = new QHBoxLayout(toolbarContainer);
mainLayout->setSpacing(2);
QWidget* buttonGroup = new QWidget(this);
QHBoxLayout* buttonLayout = new QHBoxLayout(buttonGroup);
buttonLayout->setSpacing(2);
ui->playButton->setVisible(false);
ui->pauseButton->setVisible(true);
buttonLayout->addWidget(createButtonWithLabel(ui->playButton, tr("Play"), false));
buttonLayout->addWidget(createButtonWithLabel(ui->pauseButton, tr("Pause"), showLabels));
buttonLayout->addWidget(createButtonWithLabel(ui->stopButton, tr("Stop"), showLabels));
buttonLayout->addWidget(createButtonWithLabel(ui->settingsButton, tr("Settings"), showLabels));
buttonLayout->addWidget(
createButtonWithLabel(ui->fullscreenButton, tr("Full Screen"), showLabels));
buttonLayout->addWidget(
createButtonWithLabel(ui->controllerButton, tr("Controllers"), showLabels));
buttonLayout->addWidget(createButtonWithLabel(ui->keyboardButton, tr("Keyboard"), showLabels));
buttonLayout->addWidget(
createButtonWithLabel(ui->refreshButton, tr("Refresh List"), showLabels));
QWidget* searchSliderContainer = new QWidget(this);
QHBoxLayout* searchSliderLayout = new QHBoxLayout(searchSliderContainer);
searchSliderLayout->addWidget(ui->sizeSliderContainer);
searchSliderLayout->addWidget(ui->mw_searchbar);
searchSliderContainer->setLayout(searchSliderLayout);
buttonLayout->addWidget(searchSliderContainer);
mainLayout->addWidget(buttonGroup);
toolbarContainer->setLayout(mainLayout);
ui->toolBar->addWidget(toolbarContainer);
}
void MainWindow::CreateDockWindows() { void MainWindow::CreateDockWindows() {
// place holder widget is needed for good health they say :) // place holder widget is needed for good health they say :)
QWidget* phCentralWidget = new QWidget(this); QWidget* phCentralWidget = new QWidget(this);
@ -827,6 +861,8 @@ void MainWindow::StartGame() {
return; return;
} }
StartEmulator(path); StartEmulator(path);
UpdateToolbarButtons();
} }
} }

View File

@ -5,6 +5,7 @@
#include <QActionGroup> #include <QActionGroup>
#include <QDragEnterEvent> #include <QDragEnterEvent>
#include <QProcess>
#include <QTranslator> #include <QTranslator>
#include "background_music_player.h" #include "background_music_player.h"
@ -39,6 +40,7 @@ public:
void InstallDirectory(); void InstallDirectory();
void StartGame(); void StartGame();
void PauseGame(); void PauseGame();
bool showLabels;
private Q_SLOTS: private Q_SLOTS:
void ConfigureGuiFromSettings(); void ConfigureGuiFromSettings();
@ -54,6 +56,8 @@ private:
Ui_MainWindow* ui; Ui_MainWindow* ui;
void AddUiWidgets(); void AddUiWidgets();
void UpdateToolbarLabels(); void UpdateToolbarLabels();
void UpdateToolbarButtons();
QWidget* createButtonWithLabel(QPushButton* button, const QString& labelText, bool showLabel);
void CreateActions(); void CreateActions();
void toggleFullscreen(); void toggleFullscreen();
void CreateRecentGameActions(); void CreateRecentGameActions();