1 /******************************************************************************
2 QtAV Player Demo: this file is part of QtAV examples
3 Copyright (C) 2012-2016 Wang Bin <wbsecg1@gmail.com>
4
5 * This file is part of QtAV
6
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 ******************************************************************************/
20
21 #include "ConfigDialog.h"
22 #include <QtCore/QFile>
23 #include <QLayout>
24 #include <QPushButton>
25 #include "CaptureConfigPage.h"
26 #include "DecoderConfigPage.h"
27 #include "AVFormatConfigPage.h"
28 #include "AVFilterConfigPage.h"
29 #include "MiscPage.h"
30 #include "ShaderPage.h"
31 #include "common/Config.h"
display()32 void ConfigDialog::display()
33 {
34 static ConfigDialog *dialog = new ConfigDialog();
35 dialog->show();
36 }
37
ConfigDialog(QWidget * parent)38 ConfigDialog::ConfigDialog(QWidget *parent) :
39 QDialog(parent)
40 {
41 QVBoxLayout *vbl = new QVBoxLayout();
42 setLayout(vbl);
43 vbl->setSizeConstraint(QLayout::SetFixedSize);
44
45 mpContent = new QTabWidget();
46 mpContent->setTabPosition(QTabWidget::West);
47
48 mpButtonBox = new QDialogButtonBox(Qt::Horizontal);
49 mpButtonBox->addButton(tr("Reset"), QDialogButtonBox::ResetRole);// (QDialogButtonBox::Reset);
50 mpButtonBox->addButton(tr("Ok"), QDialogButtonBox::AcceptRole); //QDialogButtonBox::Ok
51 mpButtonBox->addButton(tr("Cancel"), QDialogButtonBox::RejectRole);
52 mpButtonBox->addButton(tr("Apply"), QDialogButtonBox::ApplyRole);
53
54 connect(mpButtonBox, SIGNAL(accepted()), SLOT(accept()));
55 connect(mpButtonBox, SIGNAL(rejected()), SLOT(reject()));
56 connect(mpButtonBox, SIGNAL(clicked(QAbstractButton*)), SLOT(onButtonClicked(QAbstractButton*)));
57
58 vbl->addWidget(mpContent);
59 vbl->addWidget(mpButtonBox);
60
61 mPages << new MiscPage()
62 << new CaptureConfigPage()
63 << new DecoderConfigPage()
64 << new AVFormatConfigPage()
65 << new AVFilterConfigPage()
66 << new ShaderPage()
67 ;
68
69 foreach (ConfigPageBase* page, mPages) {
70 page->applyToUi();
71 page->applyOnUiChange(false);
72 mpContent->addTab(page, page->name());
73 }
74 }
75
onButtonClicked(QAbstractButton * btn)76 void ConfigDialog::onButtonClicked(QAbstractButton *btn)
77 {
78 qDebug("QDialogButtonBox clicked role=%d", mpButtonBox->buttonRole(btn));
79 switch (mpButtonBox->buttonRole(btn)) {
80 case QDialogButtonBox::ResetRole:
81 qDebug("QDialogButtonBox ResetRole clicked");
82 onReset();
83 break;
84 case QDialogButtonBox::AcceptRole:
85 case QDialogButtonBox::ApplyRole:
86 qDebug("QDialogButtonBox ApplyRole clicked");
87 onApply();
88 break;
89 case QDialogButtonBox::DestructiveRole:
90 case QDialogButtonBox::RejectRole:
91 onCancel();
92 break;
93 default:
94 break;
95 }
96 }
97
onReset()98 void ConfigDialog::onReset()
99 {
100 Config::instance().reset();
101 // TODO: check change
102 foreach (ConfigPageBase* page, mPages) {
103 page->reset();
104 }
105 }
106
onApply()107 void ConfigDialog::onApply()
108 {
109 // TODO: check change
110 foreach (ConfigPageBase* page, mPages) {
111 page->apply();
112 }
113 Config::instance().save();
114 }
115
onCancel()116 void ConfigDialog::onCancel()
117 {
118 // TODO: check change
119 foreach (ConfigPageBase* page, mPages) {
120 page->cancel();
121 }
122 }
123
124