Merge pull request #5797 from ligfx/qtoptionsmenu
Qt: implement remainder of 'Options' menu
This commit is contained in:
commit
3cbf56a9ad
|
@ -65,6 +65,7 @@ set(SRCS
|
|||
GameList/ListProxyModel.cpp
|
||||
QtUtils/DoubleClickEventFilter.cpp
|
||||
QtUtils/ElidedButton.cpp
|
||||
QtUtils/ListTabWidget.cpp
|
||||
QtUtils/WindowActivationEventFilter.cpp
|
||||
Settings/AudioPane.cpp
|
||||
Settings/GeneralPane.cpp
|
||||
|
|
|
@ -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;
|
||||
m_audio_pane_index = 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);
|
||||
|
@ -52,59 +57,7 @@ SettingsWindow::SettingsWindow(QWidget* parent) : QDialog(parent)
|
|||
setLayout(layout);
|
||||
}
|
||||
|
||||
void SettingsWindow::SetupSettingsWidget()
|
||||
void SettingsWindow::SelectAudioPane()
|
||||
{
|
||||
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));
|
||||
m_tabs->setCurrentIndex(m_audio_pane_index);
|
||||
}
|
||||
|
|
|
@ -4,32 +4,22 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
class MainWindow;
|
||||
class QGroupBox;
|
||||
class QListWidget;
|
||||
class QListWidgetItem;
|
||||
class QStackedWidget;
|
||||
class ListTabWidget;
|
||||
|
||||
class SettingsWindow final : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SettingsWindow(QWidget* parent = nullptr);
|
||||
void SelectAudioPane();
|
||||
|
||||
signals:
|
||||
void EmulationStarted();
|
||||
void EmulationStopped();
|
||||
|
||||
public slots:
|
||||
void changePage(QListWidgetItem* current, QListWidgetItem* previous);
|
||||
|
||||
private:
|
||||
void MakeCategoryList();
|
||||
void AddCategoryToList(const QString& title, const std::string& icon_name);
|
||||
void SetupSettingsWidget();
|
||||
QStackedWidget* m_settings_outer;
|
||||
QListWidget* m_categories;
|
||||
ListTabWidget* m_tabs;
|
||||
int m_audio_pane_index = -1;
|
||||
};
|
||||
|
|
|
@ -185,6 +185,7 @@
|
|||
<ClCompile Include="MenuBar.cpp" />
|
||||
<ClCompile Include="QtUtils\DoubleClickEventFilter.cpp" />
|
||||
<ClCompile Include="QtUtils\ElidedButton.cpp" />
|
||||
<ClCompile Include="QtUtils\ListTabWidget.cpp" />
|
||||
<ClCompile Include="QtUtils\WindowActivationEventFilter.cpp" />
|
||||
<ClCompile Include="RenderWidget.cpp" />
|
||||
<ClCompile Include="Resources.cpp" />
|
||||
|
@ -214,6 +215,7 @@
|
|||
<ClInclude Include="Config\Mapping\WiimoteEmuGeneral.h" />
|
||||
<ClInclude Include="Config\Mapping\WiimoteEmuMotionControl.h" />
|
||||
<ClInclude Include="QtUtils\ElidedButton.h" />
|
||||
<ClInclude Include="QtUtils\ListTabWidget.h" />
|
||||
<ClInclude Include="Resources.h" />
|
||||
<ClInclude Include="Settings\PathPane.h" />
|
||||
<ClInclude Include="WiiUpdate.h" />
|
||||
|
|
|
@ -184,6 +184,10 @@ void MainWindow::ConnectMenuBar()
|
|||
connect(m_menu_bar, &MenuBar::SetStateSlot, this, &MainWindow::SetStateSlot);
|
||||
|
||||
// Options
|
||||
connect(m_menu_bar, &MenuBar::Configure, this, &MainWindow::ShowSettingsWindow);
|
||||
connect(m_menu_bar, &MenuBar::ConfigureGraphics, this, &MainWindow::ShowGraphicsWindow);
|
||||
connect(m_menu_bar, &MenuBar::ConfigureAudio, this, &MainWindow::ShowAudioWindow);
|
||||
connect(m_menu_bar, &MenuBar::ConfigureControllers, this, &MainWindow::ShowControllersWindow);
|
||||
connect(m_menu_bar, &MenuBar::ConfigureHotkeys, this, &MainWindow::ShowHotkeyDialog);
|
||||
|
||||
// Tools
|
||||
|
@ -505,6 +509,12 @@ void MainWindow::ShowSettingsWindow()
|
|||
m_settings_window->activateWindow();
|
||||
}
|
||||
|
||||
void MainWindow::ShowAudioWindow()
|
||||
{
|
||||
m_settings_window->SelectAudioPane();
|
||||
ShowSettingsWindow();
|
||||
}
|
||||
|
||||
void MainWindow::ShowAboutDialog()
|
||||
{
|
||||
AboutDialog* about = new AboutDialog(this);
|
||||
|
|
|
@ -83,6 +83,7 @@ private:
|
|||
void HideRenderWidget();
|
||||
|
||||
void ShowSettingsWindow();
|
||||
void ShowAudioWindow();
|
||||
void ShowControllersWindow();
|
||||
void ShowGraphicsWindow();
|
||||
void ShowAboutDialog();
|
||||
|
|
|
@ -197,7 +197,12 @@ void MenuBar::AddViewMenu()
|
|||
void MenuBar::AddOptionsMenu()
|
||||
{
|
||||
QMenu* options_menu = addMenu(tr("Options"));
|
||||
options_menu->addAction(tr("Hotkey Settings"), this, &MenuBar::ConfigureHotkeys);
|
||||
options_menu->addAction(tr("Co&nfiguration..."), this, &MenuBar::Configure);
|
||||
options_menu->addSeparator();
|
||||
options_menu->addAction(tr("&Graphics Settings..."), this, &MenuBar::ConfigureGraphics);
|
||||
options_menu->addAction(tr("&Audio Settings..."), this, &MenuBar::ConfigureAudio);
|
||||
options_menu->addAction(tr("&Controller Settings..."), this, &MenuBar::ConfigureControllers);
|
||||
options_menu->addAction(tr("&Hotkey Settings..."), this, &MenuBar::ConfigureHotkeys);
|
||||
}
|
||||
|
||||
void MenuBar::AddHelpMenu()
|
||||
|
|
|
@ -44,6 +44,10 @@ signals:
|
|||
void PerformOnlineUpdate(const std::string& region);
|
||||
|
||||
// Options
|
||||
void Configure();
|
||||
void ConfigureGraphics();
|
||||
void ConfigureAudio();
|
||||
void ConfigureControllers();
|
||||
void ConfigureHotkeys();
|
||||
|
||||
// View
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "DolphinQt2/QtUtils/ListTabWidget.h"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QListWidget>
|
||||
#include <QScrollBar>
|
||||
#include <QStackedWidget>
|
||||
|
||||
class OverriddenListWidget : public QListWidget
|
||||
{
|
||||
public:
|
||||
// We want this widget to have a fixed width that fits all items, unlike a normal QListWidget
|
||||
// which adds scrollbars and expands/contracts.
|
||||
OverriddenListWidget() { setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); }
|
||||
QSize sizeHint() const override
|
||||
{
|
||||
int width = sizeHintForColumn(0) + verticalScrollBar()->sizeHint().width() + 2 * frameWidth();
|
||||
int height = QListWidget::sizeHint().height();
|
||||
return {width, height};
|
||||
}
|
||||
|
||||
// Since this is trying to emulate tabs, an item should always be selected. If the selection tries
|
||||
// to change to empty, don't acknowledge it.
|
||||
void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected) override
|
||||
{
|
||||
if (selected.indexes().empty())
|
||||
return;
|
||||
QListWidget::selectionChanged(selected, deselected);
|
||||
}
|
||||
};
|
||||
|
||||
ListTabWidget::ListTabWidget()
|
||||
{
|
||||
QHBoxLayout* layout = new QHBoxLayout();
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
setLayout(layout);
|
||||
|
||||
m_labels = new OverriddenListWidget();
|
||||
layout->addWidget(m_labels);
|
||||
m_labels->setIconSize(QSize(32, 32));
|
||||
m_labels->setMovement(QListView::Static);
|
||||
m_labels->setSpacing(0);
|
||||
|
||||
m_display = new QStackedWidget();
|
||||
layout->addWidget(m_display);
|
||||
|
||||
connect(m_labels, &QListWidget::currentItemChanged, this,
|
||||
[=](QListWidgetItem* current, QListWidgetItem* previous) {
|
||||
m_display->setCurrentIndex(m_labels->row(current));
|
||||
});
|
||||
}
|
||||
|
||||
int ListTabWidget::addTab(QWidget* page, const QString& label)
|
||||
{
|
||||
QListWidgetItem* button = new QListWidgetItem();
|
||||
button->setText(label);
|
||||
button->setTextAlignment(Qt::AlignVCenter);
|
||||
button->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
||||
|
||||
m_labels->addItem(button);
|
||||
if (!m_labels->currentItem())
|
||||
m_labels->setCurrentItem(button);
|
||||
|
||||
return m_display->addWidget(page);
|
||||
}
|
||||
|
||||
void ListTabWidget::setTabIcon(int index, const QIcon& icon)
|
||||
{
|
||||
if (auto* label = m_labels->item(index))
|
||||
label->setIcon(icon);
|
||||
}
|
||||
|
||||
void ListTabWidget::setCurrentIndex(int index)
|
||||
{
|
||||
m_labels->setCurrentRow(index);
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class QListWidget;
|
||||
class QStackedWidget;
|
||||
|
||||
class ListTabWidget : public QWidget
|
||||
{
|
||||
public:
|
||||
ListTabWidget();
|
||||
int addTab(QWidget* page, const QString& label);
|
||||
void setTabIcon(int index, const QIcon& icon);
|
||||
void setCurrentIndex(int index);
|
||||
|
||||
private:
|
||||
QListWidget* m_labels;
|
||||
QStackedWidget* m_display;
|
||||
};
|
Loading…
Reference in New Issue