Qt/SettingsWindow: Use tabs
This commit is contained in:
parent
6224b9bd37
commit
4d4a018ccf
|
@ -92,7 +92,6 @@ add_executable(dolphin-emu-qt2
|
|||
QtUtils/DoubleClickEventFilter.cpp
|
||||
QtUtils/ElidedButton.cpp
|
||||
QtUtils/ImageConverter.cpp
|
||||
QtUtils/ListTabWidget.cpp
|
||||
QtUtils/WindowActivationEventFilter.cpp
|
||||
QtUtils/WinIconHelper.cpp
|
||||
QtUtils/WrapInScrollArea.cpp
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
|
||||
#include <QDialogButtonBox>
|
||||
#include <QPushButton>
|
||||
#include <QTabWidget>
|
||||
#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/AdvancedPane.h"
|
||||
|
@ -21,16 +21,6 @@
|
|||
|
||||
#include "Core/Core.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
|
||||
|
@ -41,23 +31,23 @@ SettingsWindow::SettingsWindow(QWidget* parent) : QDialog(parent)
|
|||
QVBoxLayout* layout = new QVBoxLayout;
|
||||
|
||||
// Add content to layout before dialog buttons.
|
||||
m_tabs = new ListTabWidget();
|
||||
layout->addWidget(m_tabs);
|
||||
m_tab_widget = new QTabWidget();
|
||||
layout->addWidget(m_tab_widget);
|
||||
|
||||
m_general_pane_index = AddTab(m_tabs, tr("General"), new GeneralPane(), "config");
|
||||
AddTab(m_tabs, tr("Interface"), new InterfacePane(), "browse");
|
||||
m_audio_pane_index = AddTab(m_tabs, tr("Audio"), new AudioPane(), "play");
|
||||
AddTab(m_tabs, tr("GameCube"), new GameCubePane(), "gcpad");
|
||||
AddTab(m_tabs, tr("Paths"), new PathPane(), "browse");
|
||||
m_tab_widget->addTab(new GeneralPane(), tr("General"));
|
||||
m_tab_widget->addTab(new InterfacePane(), tr("Interface"));
|
||||
m_tab_widget->addTab(new AudioPane(), tr("Audio"));
|
||||
m_tab_widget->addTab(new PathPane(), tr("Paths"));
|
||||
m_tab_widget->addTab(new GameCubePane(), tr("GameCube"));
|
||||
|
||||
auto* wii_pane = new WiiPane;
|
||||
AddTab(m_tabs, tr("Wii"), wii_pane, "wiimote");
|
||||
m_tab_widget->addTab(wii_pane, tr("Wii"));
|
||||
|
||||
connect(&Settings::Instance(), &Settings::EmulationStateChanged, [wii_pane](Core::State state) {
|
||||
wii_pane->OnEmulationStateChanged(state != Core::State::Uninitialized);
|
||||
});
|
||||
|
||||
AddTab(m_tabs, tr("Advanced"), new AdvancedPane(), "config");
|
||||
m_tab_widget->addTab(new AdvancedPane(), tr("Advanced"));
|
||||
|
||||
// Dialog box buttons
|
||||
QDialogButtonBox* close_box = new QDialogButtonBox(QDialogButtonBox::Close);
|
||||
|
@ -71,10 +61,10 @@ SettingsWindow::SettingsWindow(QWidget* parent) : QDialog(parent)
|
|||
|
||||
void SettingsWindow::SelectAudioPane()
|
||||
{
|
||||
m_tabs->setCurrentIndex(m_audio_pane_index);
|
||||
m_tab_widget->setCurrentIndex(static_cast<int>(TabIndex::Audio));
|
||||
}
|
||||
|
||||
void SettingsWindow::SelectGeneralPane()
|
||||
{
|
||||
m_tabs->setCurrentIndex(m_general_pane_index);
|
||||
m_tab_widget->setCurrentIndex(static_cast<int>(TabIndex::Audio));
|
||||
}
|
||||
|
|
|
@ -6,7 +6,13 @@
|
|||
|
||||
#include <QDialog>
|
||||
|
||||
class ListTabWidget;
|
||||
class QTabWidget;
|
||||
|
||||
enum class TabIndex
|
||||
{
|
||||
General = 0,
|
||||
Audio = 2
|
||||
};
|
||||
|
||||
class SettingsWindow final : public QDialog
|
||||
{
|
||||
|
@ -17,7 +23,5 @@ public:
|
|||
void SelectAudioPane();
|
||||
|
||||
private:
|
||||
ListTabWidget* m_tabs;
|
||||
int m_audio_pane_index = -1;
|
||||
int m_general_pane_index = -1;
|
||||
QTabWidget* m_tab_widget;
|
||||
};
|
||||
|
|
|
@ -288,7 +288,6 @@
|
|||
<ClCompile Include="QtUtils\DoubleClickEventFilter.cpp" />
|
||||
<ClCompile Include="QtUtils\ElidedButton.cpp" />
|
||||
<ClCompile Include="QtUtils\ImageConverter.cpp" />
|
||||
<ClCompile Include="QtUtils\ListTabWidget.cpp" />
|
||||
<ClCompile Include="QtUtils\WindowActivationEventFilter.cpp" />
|
||||
<ClCompile Include="QtUtils\WrapInScrollArea.cpp" />
|
||||
<ClCompile Include="QtUtils\AspectRatioWidget.cpp" />
|
||||
|
@ -335,7 +334,6 @@
|
|||
<ClInclude Include="QtUtils\BlockUserInputFilter.h" />
|
||||
<ClInclude Include="QtUtils\ElidedButton.h" />
|
||||
<ClInclude Include="QtUtils\ImageConverter.h" />
|
||||
<ClInclude Include="QtUtils\ListTabWidget.h" />
|
||||
<ClInclude Include="Resources.h" />
|
||||
<ClInclude Include="Settings\GameCubePane.h" />
|
||||
<ClInclude Include="Settings\PathPane.h" />
|
||||
|
@ -425,4 +423,4 @@
|
|||
<Message Text="Copy: @(BinaryFiles) -> $(BinaryOutputDir)" Importance="High" />
|
||||
<Copy SourceFiles="@(BinaryFiles)" DestinationFolder="$(BinaryOutputDir)" />
|
||||
</Target>
|
||||
</Project>
|
||||
</Project>
|
||||
|
|
|
@ -1,79 +0,0 @@
|
|||
// 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);
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
// 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