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) \
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); } \
40 PreferencesDialog::PreferencesDialog(QWidget *parent, PreferencesModel *preferences, bool x64)
46 setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
47 setFixedSize(minimumSize());
49 if(WId hWindow = this->winId())
51 HMENU hMenu = GetSystemMenu(hWindow, 0);
52 EnableMenuItem(hMenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
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);
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)));
68 m_preferences = preferences;
71 PreferencesDialog::~PreferencesDialog(void)
75 void PreferencesDialog::showEvent(QShowEvent *event)
77 if(event) QDialog::showEvent(event);
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);
88 spinBoxJobCount->setValue(m_preferences->maxRunningJobCount());
89 comboBoxPriority->setCurrentIndex(qBound(0, m_preferences->processPriority(), comboBoxPriority->count()-1));
91 checkUse64BitAvs2YUV->setEnabled(m_x64);
92 labelUse64BitAvs2YUV->setEnabled(m_x64);
95 bool PreferencesDialog::eventFilter(QObject *o, QEvent *e)
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);
108 void PreferencesDialog::emulateMouseEvent(QObject *object, QEvent *event, QWidget *source, QWidget *target)
112 if((event->type() == QEvent::MouseButtonPress) || (event->type() == QEvent::MouseButtonRelease))
114 if(QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event))
116 qApp->postEvent(target, new QMouseEvent
119 qApp->widgetAt(mouseEvent->globalPos()) == source ? QPoint(1, 1) : QPoint(INT_MAX, INT_MAX),
128 void PreferencesDialog::done(int n)
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());
141 PreferencesModel::savePreferences(m_preferences);
145 void PreferencesDialog::resetButtonPressed(void)
147 PreferencesModel::initPreferences(m_preferences);
151 void PreferencesDialog::use10BitEncodingToggled(bool checked)
156 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!"));
157 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."));
158 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."));
160 if(QMessageBox::warning(this, tr("10-Bit Encoding"), text.replace("-", "−"), tr("Continue"), tr("Revert"), QString(), 1) != 0)
162 UPDATE_CHECKBOX(checkUse10BitEncoding, false, true);
167 void PreferencesDialog::disableWarningsToggled(bool checked)
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."));
175 if(QMessageBox::warning(this, tr("Avisynth/VapourSynth Warnings"), text.replace("-", "−"), tr("Continue"), tr("Revert"), QString(), 1) != 0)
177 UPDATE_CHECKBOX(checkDisableWarnings, false, true);