OSDN Git Service

Some improvements in preferences dialog.
[x264-launcher/x264-launcher.git] / src / win_preferences.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2013 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 //
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
21
22 #include "win_preferences.h"
23
24 #include "global.h"
25 #include "model_preferences.h"
26
27 #include <QSettings>
28 #include <QDesktopServices>
29 #include <QMouseEvent>
30 #include <QMessageBox>
31
32 #define UPDATE_CHECKBOX(CHKBOX, VALUE, BLOCK) \
33 { \
34         if((BLOCK)) { (CHKBOX)->blockSignals(true); } \
35         if((CHKBOX)->isChecked() != (VALUE)) (CHKBOX)->click(); \
36         if((CHKBOX)->isChecked() != (VALUE)) (CHKBOX)->setChecked(VALUE); \
37         if((BLOCK)) { (CHKBOX)->blockSignals(false); } \
38 }
39
40 PreferencesDialog::PreferencesDialog(QWidget *parent, PreferencesModel *preferences, bool x64)
41 :
42         QDialog(parent),
43         m_x64(x64)
44 {
45         setupUi(this);
46         setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
47         setFixedSize(minimumSize());
48
49         if(WId hWindow = this->winId())
50         {
51                 HMENU hMenu = GetSystemMenu(hWindow, 0);
52                 EnableMenuItem(hMenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
53         }
54         
55         labelRunNextJob->installEventFilter(this);
56         labelUse10BitEncoding->installEventFilter(this);
57         labelUse64BitAvs2YUV->installEventFilter(this);
58         labelShutdownComputer->installEventFilter(this);
59         labelSaveLogFiles->installEventFilter(this);
60         labelSaveToSourceFolder->installEventFilter(this);
61         labelEnableSounds->installEventFilter(this);
62         labelDisableWarnings->installEventFilter(this);
63
64         connect(resetButton, SIGNAL(clicked()), this, SLOT(resetButtonPressed()));
65         connect(checkUse10BitEncoding, SIGNAL(toggled(bool)), this, SLOT(use10BitEncodingToggled(bool)));
66         connect(checkDisableWarnings, SIGNAL(toggled(bool)), this, SLOT(disableWarningsToggled(bool)));
67         
68         m_preferences = preferences;
69 }
70
71 PreferencesDialog::~PreferencesDialog(void)
72 {
73 }
74
75 void PreferencesDialog::showEvent(QShowEvent *event)
76 {
77         if(event) QDialog::showEvent(event);
78         
79         UPDATE_CHECKBOX(checkRunNextJob, m_preferences->autoRunNextJob(), false);
80         UPDATE_CHECKBOX(checkShutdownComputer, m_preferences->shutdownComputer(), false);
81         UPDATE_CHECKBOX(checkUse64BitAvs2YUV, m_preferences->useAvisyth64Bit(), false);
82         UPDATE_CHECKBOX(checkSaveLogFiles, m_preferences->saveLogFiles(), false);
83         UPDATE_CHECKBOX(checkSaveToSourceFolder, m_preferences->saveToSourcePath(), false);
84         UPDATE_CHECKBOX(checkEnableSounds, m_preferences->enableSounds(), false);
85         UPDATE_CHECKBOX(checkDisableWarnings, m_preferences->disableWarnings(), true);
86         UPDATE_CHECKBOX(checkUse10BitEncoding, m_preferences->use10BitEncoding(), true);
87
88         spinBoxJobCount->setValue(m_preferences->maxRunningJobCount());
89         comboBoxPriority->setCurrentIndex(qBound(0, m_preferences->processPriority(), comboBoxPriority->count()-1));
90
91         checkUse64BitAvs2YUV->setEnabled(m_x64);
92         labelUse64BitAvs2YUV->setEnabled(m_x64);
93 }
94
95 bool PreferencesDialog::eventFilter(QObject *o, QEvent *e)
96 {
97         emulateMouseEvent(o, e, labelRunNextJob, checkRunNextJob);
98         emulateMouseEvent(o, e, labelShutdownComputer, checkShutdownComputer);
99         emulateMouseEvent(o, e, labelUse10BitEncoding, checkUse10BitEncoding);
100         emulateMouseEvent(o, e, labelUse64BitAvs2YUV, checkUse64BitAvs2YUV);
101         emulateMouseEvent(o, e, labelSaveLogFiles, checkSaveLogFiles);
102         emulateMouseEvent(o, e, labelSaveToSourceFolder, checkSaveToSourceFolder);
103         emulateMouseEvent(o, e, labelEnableSounds, checkEnableSounds);
104         emulateMouseEvent(o, e, labelDisableWarnings, checkDisableWarnings);
105         return false;
106 }
107
108 void PreferencesDialog::emulateMouseEvent(QObject *object, QEvent *event, QWidget *source, QWidget *target)
109 {
110         if(object == source)
111         {
112                 if((event->type() == QEvent::MouseButtonPress) || (event->type() == QEvent::MouseButtonRelease))
113                 {
114                         if(QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event))
115                         {
116                                 qApp->postEvent(target, new QMouseEvent
117                                 (
118                                         event->type(),
119                                         qApp->widgetAt(mouseEvent->globalPos()) == source ? QPoint(1, 1) : QPoint(INT_MAX, INT_MAX),
120                                         Qt::LeftButton,
121                                         0, 0
122                                 ));
123                         }
124                 }
125         }
126 }
127
128 void PreferencesDialog::done(int n)
129 {
130         m_preferences->setAutoRunNextJob(checkRunNextJob->isChecked());
131         m_preferences->setShutdownComputer(checkShutdownComputer->isChecked());
132         m_preferences->setUse10BitEncoding(checkUse10BitEncoding->isChecked());
133         m_preferences->setUseAvisyth64Bit(checkUse64BitAvs2YUV->isChecked());
134         m_preferences->setSaveLogFiles(checkSaveLogFiles->isChecked());
135         m_preferences->setSaveToSourcePath(checkSaveToSourceFolder->isChecked());
136         m_preferences->setMaxRunningJobCount(spinBoxJobCount->value());
137         m_preferences->setProcessPriority(comboBoxPriority->currentIndex());
138         m_preferences->setEnableSounds(checkEnableSounds->isChecked());
139         m_preferences->setDisableWarnings(checkDisableWarnings->isChecked());
140
141         PreferencesModel::savePreferences(m_preferences);
142         QDialog::done(n);
143 }
144
145 void PreferencesDialog::resetButtonPressed(void)
146 {
147         PreferencesModel::initPreferences(m_preferences);
148         showEvent(NULL);
149 }
150
151 void PreferencesDialog::use10BitEncodingToggled(bool checked)
152 {
153         if(checked)
154         {
155                 QString text;
156                 text += QString("<nobr>%1</nobr><br>").arg(tr("Please note that 10&minus;Bit H.264 streams are <b>not</b> currently supported by hardware (standalone) players!"));
157                 text += QString("<nobr>%1</nobr><br>").arg(tr("To play such streams, you will need an <i>up&minus;to&minus;date</i> ffdshow&minus;tryouts, CoreAVC 3.x or another supported s/w decoder."));
158                 text += QString("<nobr>%1</nobr><br>").arg(tr("Also be aware that hardware&minus;acceleration (CUDA, DXVA, etc) usually will <b>not</b> work with 10&minus;Bit H.264 streams."));
159                 
160                 if(QMessageBox::warning(this, tr("10-Bit Encoding"), text.replace("-", "&minus;"), tr("Continue"), tr("Revert"), QString(), 1) != 0)
161                 {
162                         UPDATE_CHECKBOX(checkUse10BitEncoding, false, true);
163                 }
164         }
165 }
166
167 void PreferencesDialog::disableWarningsToggled(bool checked)
168 {
169         if(checked)
170         {
171                 QString text;
172                 text += QString("<nobr>%1</nobr><br>").arg(tr("Please note that Avisynth and/or VapourSynth support might be unavailable <b>without</b> any notice!"));
173                 text += QString("<nobr>%1</nobr><br>").arg(tr("Also note that the CLI option <tt>--console</tt> may be used to get more diagnostic infomation."));
174
175                 if(QMessageBox::warning(this, tr("Avisynth/VapourSynth Warnings"), text.replace("-", "&minus;"), tr("Continue"), tr("Revert"), QString(), 1) != 0)
176                 {
177                         UPDATE_CHECKBOX(checkDisableWarnings, false, true);
178                 }
179         }
180 }