From 4d4a018ccfecf380132d205952f317b2aa820223 Mon Sep 17 00:00:00 2001 From: spycrab Date: Mon, 16 Apr 2018 22:55:37 +0200 Subject: [PATCH] Qt/SettingsWindow: Use tabs --- Source/Core/DolphinQt2/CMakeLists.txt | 1 - .../Core/DolphinQt2/Config/SettingsWindow.cpp | 34 +++----- .../Core/DolphinQt2/Config/SettingsWindow.h | 12 ++- Source/Core/DolphinQt2/DolphinQt2.vcxproj | 4 +- .../Core/DolphinQt2/QtUtils/ListTabWidget.cpp | 79 ------------------- .../Core/DolphinQt2/QtUtils/ListTabWidget.h | 23 ------ 6 files changed, 21 insertions(+), 132 deletions(-) delete mode 100644 Source/Core/DolphinQt2/QtUtils/ListTabWidget.cpp delete mode 100644 Source/Core/DolphinQt2/QtUtils/ListTabWidget.h diff --git a/Source/Core/DolphinQt2/CMakeLists.txt b/Source/Core/DolphinQt2/CMakeLists.txt index b023fb9a4c..7b885a1908 100644 --- a/Source/Core/DolphinQt2/CMakeLists.txt +++ b/Source/Core/DolphinQt2/CMakeLists.txt @@ -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 diff --git a/Source/Core/DolphinQt2/Config/SettingsWindow.cpp b/Source/Core/DolphinQt2/Config/SettingsWindow.cpp index 7cd50debc0..a9e3d46fd9 100644 --- a/Source/Core/DolphinQt2/Config/SettingsWindow.cpp +++ b/Source/Core/DolphinQt2/Config/SettingsWindow.cpp @@ -4,11 +4,11 @@ #include #include +#include #include #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(TabIndex::Audio)); } void SettingsWindow::SelectGeneralPane() { - m_tabs->setCurrentIndex(m_general_pane_index); + m_tab_widget->setCurrentIndex(static_cast(TabIndex::Audio)); } diff --git a/Source/Core/DolphinQt2/Config/SettingsWindow.h b/Source/Core/DolphinQt2/Config/SettingsWindow.h index 50efd2ad8f..6eaed033fa 100644 --- a/Source/Core/DolphinQt2/Config/SettingsWindow.h +++ b/Source/Core/DolphinQt2/Config/SettingsWindow.h @@ -6,7 +6,13 @@ #include -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; }; diff --git a/Source/Core/DolphinQt2/DolphinQt2.vcxproj b/Source/Core/DolphinQt2/DolphinQt2.vcxproj index fe5665e090..7a287effab 100644 --- a/Source/Core/DolphinQt2/DolphinQt2.vcxproj +++ b/Source/Core/DolphinQt2/DolphinQt2.vcxproj @@ -288,7 +288,6 @@ - @@ -335,7 +334,6 @@ - @@ -425,4 +423,4 @@ - \ No newline at end of file + diff --git a/Source/Core/DolphinQt2/QtUtils/ListTabWidget.cpp b/Source/Core/DolphinQt2/QtUtils/ListTabWidget.cpp deleted file mode 100644 index a7a94618c2..0000000000 --- a/Source/Core/DolphinQt2/QtUtils/ListTabWidget.cpp +++ /dev/null @@ -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 -#include -#include -#include - -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); -} diff --git a/Source/Core/DolphinQt2/QtUtils/ListTabWidget.h b/Source/Core/DolphinQt2/QtUtils/ListTabWidget.h deleted file mode 100644 index 57a23db36c..0000000000 --- a/Source/Core/DolphinQt2/QtUtils/ListTabWidget.h +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2017 Dolphin Emulator Project -// Licensed under GPLv2+ -// Refer to the license.txt file included. - -#pragma once - -#include - -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; -};