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"
23 #include "uic_win_preferences.h"
26 #include "model_preferences.h"
29 #include <QDesktopServices>
30 #include <QMouseEvent>
31 #include <QMessageBox>
33 static inline void UPDATE_CHECKBOX(QCheckBox *const chkbox, const bool value, const bool block)
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); }
41 static inline void UPDATE_COMBOBOX(QComboBox *const cobox, const int value, const int defVal)
43 const int count = cobox->count();
44 for(int i = 0; i < count; i++)
46 const int current = cobox->itemData(i).toInt();
47 if((current == value) || (current == defVal))
49 cobox->setCurrentIndex(i);
50 if((current == value)) break;
55 PreferencesDialog::PreferencesDialog(QWidget *parent, PreferencesModel *preferences, bool x64)
59 ui(new Ui::PreferencesDialog())
62 setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
63 setFixedSize(minimumSize());
64 x264_enable_close_button(this, false);
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
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);
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)));
84 m_preferences = preferences;
87 PreferencesDialog::~PreferencesDialog(void)
92 void PreferencesDialog::showEvent(QShowEvent *event)
94 if(event) QDialog::showEvent(event);
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);
105 ui->spinBoxJobCount->setValue(m_preferences->maxRunningJobCount());
107 UPDATE_COMBOBOX(ui->comboBoxPriority, qBound(-2, m_preferences->processPriority(), 1), 0);
109 ui->checkUse64BitAvs2YUV->setEnabled(m_x64);
110 ui->labelUse64BitAvs2YUV->setEnabled(m_x64);
113 bool PreferencesDialog::eventFilter(QObject *o, QEvent *e)
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);
126 void PreferencesDialog::emulateMouseEvent(QObject *object, QEvent *event, QWidget *source, QWidget *target)
130 if((event->type() == QEvent::MouseButtonPress) || (event->type() == QEvent::MouseButtonRelease))
132 if(QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event))
134 qApp->postEvent(target, new QMouseEvent
137 qApp->widgetAt(mouseEvent->globalPos()) == source ? QPoint(1, 1) : QPoint(INT_MAX, INT_MAX),
146 void PreferencesDialog::done(int n)
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());
159 PreferencesModel::savePreferences(m_preferences);
163 void PreferencesDialog::resetButtonPressed(void)
165 PreferencesModel::initPreferences(m_preferences);
169 void PreferencesDialog::use10BitEncodingToggled(bool checked)
174 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!"));
175 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."));
176 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."));
178 if(QMessageBox::warning(this, tr("10-Bit Encoding"), text.replace("-", "−"), tr("Continue"), tr("Revert"), QString(), 1) != 0)
180 UPDATE_CHECKBOX(ui->checkUse10BitEncoding, false, true);
185 void PreferencesDialog::disableWarningsToggled(bool checked)
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."));
193 if(QMessageBox::warning(this, tr("Avisynth/VapourSynth Warnings"), text.replace("-", "−"), tr("Continue"), tr("Revert"), QString(), 1) != 0)
195 UPDATE_CHECKBOX(ui->checkDisableWarnings, false, true);