OSDN Git Service

Switched the method for including the UIC header files to "Using a Pointer Member...
[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 #include "uic_win_preferences.h"
24
25 #include "global.h"
26 #include "model_preferences.h"
27
28 #include <QSettings>
29 #include <QDesktopServices>
30 #include <QMouseEvent>
31 #include <QMessageBox>
32
33 static inline void UPDATE_CHECKBOX(QCheckBox *const chkbox, const bool value, const bool block)
34 {
35         if(block) { chkbox->blockSignals(true); }
36         if(chkbox->isChecked() != value) chkbox->click();
37         if(chkbox->isChecked() != value) chkbox->setChecked(value);
38         if(block) { chkbox->blockSignals(false); }
39 }
40
41 static inline void UPDATE_COMBOBOX(QComboBox *const cobox, const int value, const int defVal)
42 {
43         const int count = cobox->count();
44         for(int i = 0; i < count; i++)
45         {
46                 const int current = cobox->itemData(i).toInt();
47                 if((current == value) || (current == defVal))
48                 {
49                         cobox->setCurrentIndex(i);
50                         if((current == value)) break;
51                 }
52         }
53 }
54
55 PreferencesDialog::PreferencesDialog(QWidget *parent, PreferencesModel *preferences, bool x64)
56 :
57         QDialog(parent),
58         m_x64(x64),
59         ui(new Ui::PreferencesDialog())
60 {
61         ui->setupUi(this);
62         setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
63         setFixedSize(minimumSize());
64         x264_enable_close_button(this, false);
65         
66         ui->comboBoxPriority->setItemData(0, QVariant::fromValue( 1)); //Above Normal
67         ui->comboBoxPriority->setItemData(1, QVariant::fromValue( 0)); //Normal
68         ui->comboBoxPriority->setItemData(2, QVariant::fromValue(-1)); //Below Normal
69         ui->comboBoxPriority->setItemData(3, QVariant::fromValue(-2)); //Idle
70
71         ui->labelRunNextJob->installEventFilter(this);
72         ui->labelUse10BitEncoding->installEventFilter(this);
73         ui->labelUse64BitAvs2YUV->installEventFilter(this);
74         ui->labelShutdownComputer->installEventFilter(this);
75         ui->labelSaveLogFiles->installEventFilter(this);
76         ui->labelSaveToSourceFolder->installEventFilter(this);
77         ui->labelEnableSounds->installEventFilter(this);
78         ui->labelDisableWarnings->installEventFilter(this);
79
80         connect(ui->resetButton, SIGNAL(clicked()), this, SLOT(resetButtonPressed()));
81         connect(ui->checkUse10BitEncoding, SIGNAL(toggled(bool)), this, SLOT(use10BitEncodingToggled(bool)));
82         connect(ui->checkDisableWarnings, SIGNAL(toggled(bool)), this, SLOT(disableWarningsToggled(bool)));
83         
84         m_preferences = preferences;
85 }
86
87 PreferencesDialog::~PreferencesDialog(void)
88 {
89         delete ui;
90 }
91
92 void PreferencesDialog::showEvent(QShowEvent *event)
93 {
94         if(event) QDialog::showEvent(event);
95         
96         UPDATE_CHECKBOX(ui->checkRunNextJob,         m_preferences->autoRunNextJob(),   false);
97         UPDATE_CHECKBOX(ui->checkShutdownComputer,   m_preferences->shutdownComputer(), false);
98         UPDATE_CHECKBOX(ui->checkUse64BitAvs2YUV,    m_preferences->useAvisyth64Bit(),  false);
99         UPDATE_CHECKBOX(ui->checkSaveLogFiles,       m_preferences->saveLogFiles(),     false);
100         UPDATE_CHECKBOX(ui->checkSaveToSourceFolder, m_preferences->saveToSourcePath(), false);
101         UPDATE_CHECKBOX(ui->checkEnableSounds,       m_preferences->enableSounds(),     false);
102         UPDATE_CHECKBOX(ui->checkDisableWarnings,    m_preferences->disableWarnings(),  true);
103         UPDATE_CHECKBOX(ui->checkUse10BitEncoding,   m_preferences->use10BitEncoding(), true);
104
105         ui->spinBoxJobCount->setValue(m_preferences->maxRunningJobCount());
106         
107         UPDATE_COMBOBOX(ui->comboBoxPriority, qBound(-2, m_preferences->processPriority(), 1), 0);
108         
109         ui->checkUse64BitAvs2YUV->setEnabled(m_x64);
110         ui->labelUse64BitAvs2YUV->setEnabled(m_x64);
111 }
112
113 bool PreferencesDialog::eventFilter(QObject *o, QEvent *e)
114 {
115         emulateMouseEvent(o, e, ui->labelRunNextJob,         ui->checkRunNextJob);
116         emulateMouseEvent(o, e, ui->labelShutdownComputer,   ui->checkShutdownComputer);
117         emulateMouseEvent(o, e, ui->labelUse10BitEncoding,   ui->checkUse10BitEncoding);
118         emulateMouseEvent(o, e, ui->labelUse64BitAvs2YUV,    ui->checkUse64BitAvs2YUV);
119         emulateMouseEvent(o, e, ui->labelSaveLogFiles,       ui->checkSaveLogFiles);
120         emulateMouseEvent(o, e, ui->labelSaveToSourceFolder, ui->checkSaveToSourceFolder);
121         emulateMouseEvent(o, e, ui->labelEnableSounds,       ui->checkEnableSounds);
122         emulateMouseEvent(o, e, ui->labelDisableWarnings,    ui->checkDisableWarnings);
123         return false;
124 }
125
126 void PreferencesDialog::emulateMouseEvent(QObject *object, QEvent *event, QWidget *source, QWidget *target)
127 {
128         if(object == source)
129         {
130                 if((event->type() == QEvent::MouseButtonPress) || (event->type() == QEvent::MouseButtonRelease))
131                 {
132                         if(QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event))
133                         {
134                                 qApp->postEvent(target, new QMouseEvent
135                                 (
136                                         event->type(),
137                                         qApp->widgetAt(mouseEvent->globalPos()) == source ? QPoint(1, 1) : QPoint(INT_MAX, INT_MAX),
138                                         Qt::LeftButton,
139                                         0, 0
140                                 ));
141                         }
142                 }
143         }
144 }
145
146 void PreferencesDialog::done(int n)
147 {
148         m_preferences->setAutoRunNextJob(ui->checkRunNextJob->isChecked());
149         m_preferences->setShutdownComputer(ui->checkShutdownComputer->isChecked());
150         m_preferences->setUse10BitEncoding(ui->checkUse10BitEncoding->isChecked());
151         m_preferences->setUseAvisyth64Bit(ui->checkUse64BitAvs2YUV->isChecked());
152         m_preferences->setSaveLogFiles(ui->checkSaveLogFiles->isChecked());
153         m_preferences->setSaveToSourcePath(ui->checkSaveToSourceFolder->isChecked());
154         m_preferences->setMaxRunningJobCount(ui->spinBoxJobCount->value());
155         m_preferences->setProcessPriority(ui->comboBoxPriority->itemData(ui->comboBoxPriority->currentIndex()).toInt());
156         m_preferences->setEnableSounds(ui->checkEnableSounds->isChecked());
157         m_preferences->setDisableWarnings(ui->checkDisableWarnings->isChecked());
158
159         PreferencesModel::savePreferences(m_preferences);
160         QDialog::done(n);
161 }
162
163 void PreferencesDialog::resetButtonPressed(void)
164 {
165         PreferencesModel::initPreferences(m_preferences);
166         showEvent(NULL);
167 }
168
169 void PreferencesDialog::use10BitEncodingToggled(bool checked)
170 {
171         if(checked)
172         {
173                 QString text;
174                 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!"));
175                 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."));
176                 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."));
177                 
178                 if(QMessageBox::warning(this, tr("10-Bit Encoding"), text.replace("-", "&minus;"), tr("Continue"), tr("Revert"), QString(), 1) != 0)
179                 {
180                         UPDATE_CHECKBOX(ui->checkUse10BitEncoding, false, true);
181                 }
182         }
183 }
184
185 void PreferencesDialog::disableWarningsToggled(bool checked)
186 {
187         if(checked)
188         {
189                 QString text;
190                 text += QString("<nobr>%1</nobr><br>").arg(tr("Please note that Avisynth and/or VapourSynth support might be unavailable <b>without</b> any notice!"));
191                 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."));
192
193                 if(QMessageBox::warning(this, tr("Avisynth/VapourSynth Warnings"), text.replace("-", "&minus;"), tr("Continue"), tr("Revert"), QString(), 1) != 0)
194                 {
195                         UPDATE_CHECKBOX(ui->checkDisableWarnings, false, true);
196                 }
197         }
198 }