1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2013 LoRd_MuldeR <MuldeR2@GMX.de>
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.
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.
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.
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
22 #include "win_preferences.h"
25 #include "model_preferences.h"
28 #include <QDesktopServices>
29 #include <QMouseEvent>
30 #include <QMessageBox>
32 #define UPDATE_CHECKBOX(CHKBOX, VALUE, BLOCK) do \
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); } \
41 #define UPDATE_COMBOBOX(COBOX, VALUE, DEFAULT) do \
43 const int _cnt = (COBOX)->count(); \
44 const int _val = (VALUE); \
45 const int _def = (DEFAULT); \
46 for(int _i = 0; _i < _cnt; _i++) \
48 const int _current = (COBOX)->itemData(_i).toInt(); \
49 if((_current == _val) || (_current == _def)) \
51 (COBOX)->setCurrentIndex(_i); \
52 if((_current == _val)) break; \
58 PreferencesDialog::PreferencesDialog(QWidget *parent, PreferencesModel *preferences, bool x64)
64 setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
65 setFixedSize(minimumSize());
66 x264_enable_close_button(this, false);
68 comboBoxPriority->setItemData(0, QVariant::fromValue( 1)); //Above Normal
69 comboBoxPriority->setItemData(1, QVariant::fromValue( 0)); //Normal
70 comboBoxPriority->setItemData(2, QVariant::fromValue(-1)); //Below Normal
71 comboBoxPriority->setItemData(3, QVariant::fromValue(-2)); //Idle
73 labelRunNextJob->installEventFilter(this);
74 labelUse10BitEncoding->installEventFilter(this);
75 labelUse64BitAvs2YUV->installEventFilter(this);
76 labelShutdownComputer->installEventFilter(this);
77 labelSaveLogFiles->installEventFilter(this);
78 labelSaveToSourceFolder->installEventFilter(this);
79 labelEnableSounds->installEventFilter(this);
80 labelDisableWarnings->installEventFilter(this);
82 connect(resetButton, SIGNAL(clicked()), this, SLOT(resetButtonPressed()));
83 connect(checkUse10BitEncoding, SIGNAL(toggled(bool)), this, SLOT(use10BitEncodingToggled(bool)));
84 connect(checkDisableWarnings, SIGNAL(toggled(bool)), this, SLOT(disableWarningsToggled(bool)));
86 m_preferences = preferences;
89 PreferencesDialog::~PreferencesDialog(void)
93 void PreferencesDialog::showEvent(QShowEvent *event)
95 if(event) QDialog::showEvent(event);
97 UPDATE_CHECKBOX(checkRunNextJob, m_preferences->autoRunNextJob(), false);
98 UPDATE_CHECKBOX(checkShutdownComputer, m_preferences->shutdownComputer(), false);
99 UPDATE_CHECKBOX(checkUse64BitAvs2YUV, m_preferences->useAvisyth64Bit(), false);
100 UPDATE_CHECKBOX(checkSaveLogFiles, m_preferences->saveLogFiles(), false);
101 UPDATE_CHECKBOX(checkSaveToSourceFolder, m_preferences->saveToSourcePath(), false);
102 UPDATE_CHECKBOX(checkEnableSounds, m_preferences->enableSounds(), false);
103 UPDATE_CHECKBOX(checkDisableWarnings, m_preferences->disableWarnings(), true);
104 UPDATE_CHECKBOX(checkUse10BitEncoding, m_preferences->use10BitEncoding(), true);
106 spinBoxJobCount->setValue(m_preferences->maxRunningJobCount());
108 UPDATE_COMBOBOX(comboBoxPriority, qBound(-2, m_preferences->processPriority(), 1), 0);
110 checkUse64BitAvs2YUV->setEnabled(m_x64);
111 labelUse64BitAvs2YUV->setEnabled(m_x64);
114 bool PreferencesDialog::eventFilter(QObject *o, QEvent *e)
116 emulateMouseEvent(o, e, labelRunNextJob, checkRunNextJob);
117 emulateMouseEvent(o, e, labelShutdownComputer, checkShutdownComputer);
118 emulateMouseEvent(o, e, labelUse10BitEncoding, checkUse10BitEncoding);
119 emulateMouseEvent(o, e, labelUse64BitAvs2YUV, checkUse64BitAvs2YUV);
120 emulateMouseEvent(o, e, labelSaveLogFiles, checkSaveLogFiles);
121 emulateMouseEvent(o, e, labelSaveToSourceFolder, checkSaveToSourceFolder);
122 emulateMouseEvent(o, e, labelEnableSounds, checkEnableSounds);
123 emulateMouseEvent(o, e, labelDisableWarnings, checkDisableWarnings);
127 void PreferencesDialog::emulateMouseEvent(QObject *object, QEvent *event, QWidget *source, QWidget *target)
131 if((event->type() == QEvent::MouseButtonPress) || (event->type() == QEvent::MouseButtonRelease))
133 if(QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event))
135 qApp->postEvent(target, new QMouseEvent
138 qApp->widgetAt(mouseEvent->globalPos()) == source ? QPoint(1, 1) : QPoint(INT_MAX, INT_MAX),
147 void PreferencesDialog::done(int n)
149 m_preferences->setAutoRunNextJob(checkRunNextJob->isChecked());
150 m_preferences->setShutdownComputer(checkShutdownComputer->isChecked());
151 m_preferences->setUse10BitEncoding(checkUse10BitEncoding->isChecked());
152 m_preferences->setUseAvisyth64Bit(checkUse64BitAvs2YUV->isChecked());
153 m_preferences->setSaveLogFiles(checkSaveLogFiles->isChecked());
154 m_preferences->setSaveToSourcePath(checkSaveToSourceFolder->isChecked());
155 m_preferences->setMaxRunningJobCount(spinBoxJobCount->value());
156 m_preferences->setProcessPriority(comboBoxPriority->itemData(comboBoxPriority->currentIndex()).toInt());
157 m_preferences->setEnableSounds(checkEnableSounds->isChecked());
158 m_preferences->setDisableWarnings(checkDisableWarnings->isChecked());
160 PreferencesModel::savePreferences(m_preferences);
164 void PreferencesDialog::resetButtonPressed(void)
166 PreferencesModel::initPreferences(m_preferences);
170 void PreferencesDialog::use10BitEncodingToggled(bool checked)
175 text += QString("<nobr>%1</nobr><br>").arg(tr("Please note that 10−Bit H.264 streams are <b>not</b> currently supported by hardware (standalone) players!"));
176 text += QString("<nobr>%1</nobr><br>").arg(tr("To play such streams, you will need an <i>up−to−date</i> ffdshow−tryouts, CoreAVC 3.x or another supported s/w decoder."));
177 text += QString("<nobr>%1</nobr><br>").arg(tr("Also be aware that hardware−acceleration (CUDA, DXVA, etc) usually will <b>not</b> work with 10−Bit H.264 streams."));
179 if(QMessageBox::warning(this, tr("10-Bit Encoding"), text.replace("-", "−"), tr("Continue"), tr("Revert"), QString(), 1) != 0)
181 UPDATE_CHECKBOX(checkUse10BitEncoding, false, true);
186 void PreferencesDialog::disableWarningsToggled(bool checked)
191 text += QString("<nobr>%1</nobr><br>").arg(tr("Please note that Avisynth and/or VapourSynth support might be unavailable <b>without</b> any notice!"));
192 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."));
194 if(QMessageBox::warning(this, tr("Avisynth/VapourSynth Warnings"), text.replace("-", "−"), tr("Continue"), tr("Revert"), QString(), 1) != 0)
196 UPDATE_CHECKBOX(checkDisableWarnings, false, true);