mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 05:09:34 -06:00
Qt: extract ListTabWidget from SettingsWindow
This commit is contained in:
@ -3,16 +3,11 @@
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
#include <QGroupBox>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QListWidget>
|
||||
#include <QScrollBar>
|
||||
#include <QStackedWidget>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "DolphinQt2/Config/SettingsWindow.h"
|
||||
#include "DolphinQt2/MainWindow.h"
|
||||
#include "DolphinQt2/QtUtils/ListTabWidget.h"
|
||||
#include "DolphinQt2/Resources.h"
|
||||
#include "DolphinQt2/Settings.h"
|
||||
#include "DolphinQt2/Settings/AudioPane.h"
|
||||
@ -20,6 +15,16 @@
|
||||
#include "DolphinQt2/Settings/InterfacePane.h"
|
||||
#include "DolphinQt2/Settings/PathPane.h"
|
||||
|
||||
static int AddTab(ListTabWidget* tab_widget, const QString& label, QWidget* widget,
|
||||
const char* icon_name)
|
||||
{
|
||||
int index = tab_widget->addTab(widget, label);
|
||||
auto set_icon = [=] { tab_widget->setTabIcon(index, Resources::GetScaledThemeIcon(icon_name)); };
|
||||
QObject::connect(&Settings::Instance(), &Settings::ThemeChanged, set_icon);
|
||||
set_icon();
|
||||
return index;
|
||||
}
|
||||
|
||||
SettingsWindow::SettingsWindow(QWidget* parent) : QDialog(parent)
|
||||
{
|
||||
// Set Window Properties
|
||||
@ -28,21 +33,21 @@ SettingsWindow::SettingsWindow(QWidget* parent) : QDialog(parent)
|
||||
|
||||
// Main Layout
|
||||
QVBoxLayout* layout = new QVBoxLayout;
|
||||
QHBoxLayout* content = new QHBoxLayout;
|
||||
// Content's widgets
|
||||
{
|
||||
// Category list
|
||||
MakeCategoryList();
|
||||
content->addWidget(m_categories);
|
||||
|
||||
// Actual Settings UI
|
||||
SetupSettingsWidget();
|
||||
|
||||
content->addWidget(m_settings_outer);
|
||||
}
|
||||
|
||||
// Add content to layout before dialog buttons.
|
||||
layout->addLayout(content);
|
||||
m_tabs = new ListTabWidget();
|
||||
layout->addWidget(m_tabs);
|
||||
|
||||
AddTab(m_tabs, tr("General"), new GeneralPane(), "config");
|
||||
AddTab(m_tabs, tr("Interface"), new InterfacePane(), "browse");
|
||||
auto* audio_pane = new AudioPane;
|
||||
AddTab(m_tabs, tr("Audio"), audio_pane, "play");
|
||||
AddTab(m_tabs, tr("Paths"), new PathPane(), "browse");
|
||||
|
||||
connect(this, &SettingsWindow::EmulationStarted,
|
||||
[audio_pane] { audio_pane->OnEmulationStateChanged(true); });
|
||||
connect(this, &SettingsWindow::EmulationStopped,
|
||||
[audio_pane] { audio_pane->OnEmulationStateChanged(false); });
|
||||
|
||||
// Dialog box buttons
|
||||
QDialogButtonBox* ok_box = new QDialogButtonBox(QDialogButtonBox::Ok);
|
||||
@ -51,60 +56,3 @@ SettingsWindow::SettingsWindow(QWidget* parent) : QDialog(parent)
|
||||
|
||||
setLayout(layout);
|
||||
}
|
||||
|
||||
void SettingsWindow::SetupSettingsWidget()
|
||||
{
|
||||
m_settings_outer = new QStackedWidget;
|
||||
m_settings_outer->setCurrentIndex(0);
|
||||
|
||||
// Panes initalised here
|
||||
m_settings_outer->addWidget(new GeneralPane);
|
||||
m_settings_outer->addWidget(new InterfacePane);
|
||||
|
||||
auto* audio_pane = new AudioPane;
|
||||
connect(this, &SettingsWindow::EmulationStarted,
|
||||
[audio_pane] { audio_pane->OnEmulationStateChanged(true); });
|
||||
connect(this, &SettingsWindow::EmulationStopped,
|
||||
[audio_pane] { audio_pane->OnEmulationStateChanged(false); });
|
||||
m_settings_outer->addWidget(audio_pane);
|
||||
|
||||
m_settings_outer->addWidget(new PathPane);
|
||||
}
|
||||
|
||||
void SettingsWindow::AddCategoryToList(const QString& title, const std::string& icon_name)
|
||||
{
|
||||
QListWidgetItem* button = new QListWidgetItem();
|
||||
button->setText(title);
|
||||
button->setTextAlignment(Qt::AlignVCenter);
|
||||
button->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
||||
|
||||
auto set_icon = [=] { button->setIcon(Resources::GetScaledThemeIcon(icon_name)); };
|
||||
QObject::connect(&Settings::Instance(), &Settings::ThemeChanged, set_icon);
|
||||
set_icon();
|
||||
m_categories->addItem(button);
|
||||
}
|
||||
|
||||
void SettingsWindow::MakeCategoryList()
|
||||
{
|
||||
m_categories = new QListWidget;
|
||||
m_categories->setIconSize(QSize(32, 32));
|
||||
m_categories->setMovement(QListView::Static);
|
||||
m_categories->setSpacing(0);
|
||||
|
||||
AddCategoryToList(tr("General"), "config");
|
||||
AddCategoryToList(tr("Interface"), "browse");
|
||||
AddCategoryToList(tr("Audio"), "play");
|
||||
AddCategoryToList(tr("Paths"), "browse");
|
||||
connect(m_categories, &QListWidget::currentItemChanged, this, &SettingsWindow::changePage);
|
||||
|
||||
m_categories->setFixedWidth(m_categories->sizeHintForColumn(0) +
|
||||
m_categories->verticalScrollBar()->sizeHint().width() +
|
||||
2 * m_categories->frameWidth());
|
||||
}
|
||||
|
||||
void SettingsWindow::changePage(QListWidgetItem* current, QListWidgetItem* previous)
|
||||
{
|
||||
if (!current)
|
||||
current = previous;
|
||||
m_settings_outer->setCurrentIndex(m_categories->row(current));
|
||||
}
|
||||
|
Reference in New Issue
Block a user