1 /*
2 Copyright (C) 2007 Remon Sijrier
3
4 This file is part of Traverso
5
6 Traverso is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02100-1301 USA.
19
20 */
21
22 #include <QListWidgetItem>
23 #include <QStackedWidget>
24 #include <QDialogButtonBox>
25
26
27 #include <Config.h>
28
29 #include "SettingsDialog.h"
30 #include "Pages.h"
31
32 #include <Debugger.h>
33
SettingsDialog(QWidget * parent)34 SettingsDialog::SettingsDialog(QWidget* parent)
35 : QDialog(parent)
36 {
37 m_saving = false;
38
39 contentsWidget = new QListWidget;
40 contentsWidget->setViewMode(QListView::IconMode);
41 contentsWidget->setIconSize(QSize(32, 32));
42 contentsWidget->setMovement(QListView::Static);
43 contentsWidget->setMaximumWidth(140);
44 contentsWidget->setMinimumWidth(135);
45 contentsWidget->setMinimumHeight(390);
46 contentsWidget->setSpacing(12);
47
48 pagesWidget = new QStackedWidget;
49 pagesWidget->addWidget(new BehaviorConfigPage(this));
50 pagesWidget->addWidget(new AppearenceConfigPage(this));
51 pagesWidget->addWidget(new AudioDriverConfigPage(this));
52 pagesWidget->addWidget(new RecordingConfigPage(this));
53 pagesWidget->addWidget(new KeyboardConfigPage(this));
54 pagesWidget->addWidget(new PerformanceConfigPage(this));
55
56 createIcons();
57 contentsWidget->setCurrentRow(0);
58
59 QDialogButtonBox* buttonBox = new QDialogButtonBox(this);
60
61 QPushButton* cancelButton = buttonBox->addButton(QDialogButtonBox::Cancel);
62 QPushButton* okButton = buttonBox->addButton(QDialogButtonBox::Ok);
63 QPushButton* restoreDefaultsButton = buttonBox->addButton(QDialogButtonBox::RestoreDefaults);
64
65 connect(cancelButton, SIGNAL(clicked()), this, SLOT(close()));
66 connect(okButton, SIGNAL(clicked()), this, SLOT(save_config()));
67 connect(okButton, SIGNAL(clicked()), this, SLOT(close()));
68 connect(restoreDefaultsButton, SIGNAL(clicked()), this, SLOT(restore_defaults_button_clicked()));
69
70 QHBoxLayout *buttonsLayout = new QHBoxLayout;
71 buttonsLayout->addWidget(buttonBox);
72
73 QHBoxLayout *horizontalLayout = new QHBoxLayout;
74 horizontalLayout->addWidget(contentsWidget);
75 horizontalLayout->addWidget(pagesWidget, 1);
76
77 QVBoxLayout *mainLayout = new QVBoxLayout;
78 mainLayout->addLayout(horizontalLayout);
79 mainLayout->addLayout(buttonsLayout);
80
81 setLayout(mainLayout);
82
83 setWindowTitle(tr("Preferences - Traverso"));
84
85 connect(&config(), SIGNAL(configChanged()), this, SLOT(external_change_to_settings()));
86
87 resize(400, 300);
88 }
89
show_page(const QString & page)90 void SettingsDialog::show_page(const QString & page)
91 {
92 if (page == "Sound System") {
93 contentsWidget->setCurrentRow(2);
94 }
95 }
96
97
createIcons()98 void SettingsDialog::createIcons()
99 {
100 QListWidgetItem* behaviorButton = new QListWidgetItem(contentsWidget);
101 behaviorButton->setIcon(QIcon(":/sheetmanagement"));
102 behaviorButton->setTextAlignment(Qt::AlignHCenter);
103 behaviorButton->setText(tr("Behavior"));
104 behaviorButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
105 behaviorButton->setSizeHint(QSize(100, 50));
106
107 QListWidgetItem* appearanceButton = new QListWidgetItem(contentsWidget);
108 appearanceButton->setIcon(QIcon(":/appearance"));
109 appearanceButton->setText(tr("Appearance"));
110 appearanceButton->setTextAlignment(Qt::AlignHCenter);
111 appearanceButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
112 appearanceButton->setSizeHint(QSize(100, 50));
113
114 QListWidgetItem* driverButton = new QListWidgetItem(contentsWidget);
115 driverButton->setIcon(QIcon(":/audiocard"));
116 driverButton->setText(tr("Sound System"));
117 driverButton->setTextAlignment(Qt::AlignHCenter);
118 driverButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
119 driverButton->setSizeHint(QSize(100, 50));
120
121 QListWidgetItem* diskioButton = new QListWidgetItem(contentsWidget);
122 diskioButton->setIcon(QIcon(":/audiosettings"));
123 diskioButton->setText(tr("Audio Options"));
124 diskioButton->setTextAlignment(Qt::AlignHCenter);
125 diskioButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
126 diskioButton->setSizeHint(QSize(100, 50));
127
128 QListWidgetItem* keyboardButton = new QListWidgetItem(contentsWidget);
129 keyboardButton->setIcon(QIcon(":/keyboard"));
130 keyboardButton->setText(tr("Keyboard"));
131 keyboardButton->setTextAlignment(Qt::AlignHCenter);
132 keyboardButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
133 keyboardButton->setSizeHint(QSize(100, 50));
134
135 QListWidgetItem* performanceButton = new QListWidgetItem(contentsWidget);
136 performanceButton->setIcon(QIcon(":/performance"));
137 performanceButton->setText(tr("Performance"));
138 performanceButton->setTextAlignment(Qt::AlignHCenter);
139 performanceButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
140 performanceButton->setSizeHint(QSize(100, 50));
141
142 connect(contentsWidget,
143 SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)),
144 this, SLOT(changePage(QListWidgetItem *, QListWidgetItem*)));
145 }
146
changePage(QListWidgetItem * current,QListWidgetItem * previous)147 void SettingsDialog::changePage(QListWidgetItem *current, QListWidgetItem *previous)
148 {
149 if (!current)
150 current = previous;
151
152 pagesWidget->setCurrentIndex(contentsWidget->row(current));
153 }
154
save_config()155 void SettingsDialog::save_config()
156 {
157 for (int i=0; i<pagesWidget->count(); ++i) {
158 qobject_cast<ConfigPage*>(pagesWidget->widget(i))->save_config();
159 }
160 m_saving = true;
161 config().save();
162 m_saving = false;
163 }
164
restore_defaults_button_clicked()165 void SettingsDialog::restore_defaults_button_clicked()
166 {
167 ConfigPage* page = qobject_cast<ConfigPage*>(pagesWidget->widget(contentsWidget->row(contentsWidget->currentItem())));
168 if (page) {
169 page->reset_default_config();
170 } else {
171 PERROR("SettingsDialog::restore_defaults_button_clicked: No ConfigPage found!!??\n");
172 }
173 }
174
external_change_to_settings()175 void SettingsDialog::external_change_to_settings()
176 {
177 if (!m_saving) {
178 for (int i=0; i<pagesWidget->count(); ++i) {
179 qobject_cast<ConfigPage*>(pagesWidget->widget(i))->load_config();
180 }
181 }
182 }
183
184