summaryrefslogtreecommitdiff
path: root/Source/Core/DolphinQt2/Config/SettingsWindow.cpp
blob: eb906c9ed7d5771356d94c6f39227807f8df74f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Copyright 2016 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#include <QDialogButtonBox>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QListWidget>
#include <QStackedWidget>
#include <QVBoxLayout>

#include "DolphinQt2/Config/SettingsWindow.h"
#include "DolphinQt2/Resources.h"
#include "DolphinQt2/Settings.h"
#include "DolphinQt2/Settings/GeneralPane.h"
#include "DolphinQt2/Settings/InterfacePane.h"
#include "DolphinQt2/Settings/PathPane.h"

SettingsWindow::SettingsWindow(QWidget* parent) : QDialog(parent)
{
  // Set Window Properties
  setWindowTitle(tr("Settings"));
  resize(720, 600);

  // Main Layout
  QVBoxLayout* layout = new QVBoxLayout;
  QHBoxLayout* content = new QHBoxLayout;
  QVBoxLayout* content_inner = new QVBoxLayout;
  // Content's widgets
  {
    // Category list
    MakeCategoryList();
    content->addWidget(m_categories);

    // Actual Settings UI
    SetupSettingsWidget();

    MakeUnfinishedWarning();

    content_inner->addWidget(m_warning_group);
    content_inner->addWidget(m_settings_outer);

    content->addLayout(content_inner);
  }

  // Add content to layout before dialog buttons.
  layout->addLayout(content);

  // Dialog box buttons
  QDialogButtonBox* ok_box = new QDialogButtonBox(QDialogButtonBox::Ok);
  connect(ok_box, &QDialogButtonBox::accepted, this, &SettingsWindow::accept);
  layout->addWidget(ok_box);

  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);
  m_settings_outer->addWidget(new PathPane);
}

void SettingsWindow::MakeUnfinishedWarning()
{
  m_warning_group = new QGroupBox(tr("Warning"));
  QHBoxLayout* m_warning_group_layout = new QHBoxLayout;
  QLabel* warning_text = new QLabel(tr("Some categories and settings will not work.\n"
                                       "This Settings Window is under active development."));
  m_warning_group_layout->addWidget(warning_text);
  m_warning_group->setLayout(m_warning_group_layout);
}

void SettingsWindow::AddCategoryToList(const QString& title, const std::string& icon_name)
{
  QString dir = Settings::Instance().GetThemeDir();
  QListWidgetItem* button = new QListWidgetItem();
  button->setText(title);
  button->setTextAlignment(Qt::AlignVCenter);
  button->setSizeHint(QSize(28, 28));
  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->setMaximumWidth(175);
  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("Paths"), "browse");
  connect(m_categories, &QListWidget::currentItemChanged, this, &SettingsWindow::changePage);
}

void SettingsWindow::changePage(QListWidgetItem* current, QListWidgetItem* previous)
{
  if (!current)
    current = previous;
  m_settings_outer->setCurrentIndex(m_categories->row(current));
}