1 /*
2  * Copyright (c) 2020 Meltytech, LLC
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "systemsyncdialog.h"
19 #include "ui_systemsyncdialog.h"
20 #include "settings.h"
21 #include "mltcontroller.h"
22 
SystemSyncDialog(QWidget * parent)23 SystemSyncDialog::SystemSyncDialog(QWidget *parent) :
24     QDialog(parent),
25     ui(new Ui::SystemSyncDialog),
26     m_oldValue(Settings.playerVideoDelayMs())
27 {
28     ui->setupUi(this);
29     ui->syncSlider->setValue(Settings.playerVideoDelayMs());
30     ui->applyButton->hide();
31 }
32 
~SystemSyncDialog()33 SystemSyncDialog::~SystemSyncDialog()
34 {
35     delete ui;
36 }
37 
on_syncSlider_sliderReleased()38 void SystemSyncDialog::on_syncSlider_sliderReleased()
39 {
40     setDelay(ui->syncSlider->value());
41 }
42 
on_syncSpinBox_editingFinished()43 void SystemSyncDialog::on_syncSpinBox_editingFinished()
44 {
45     ui->syncSlider->setValue(ui->syncSpinBox->value());
46     setDelay(ui->syncSpinBox->value());
47 }
48 
on_buttonBox_rejected()49 void SystemSyncDialog::on_buttonBox_rejected()
50 {
51     setDelay(m_oldValue);
52 }
53 
on_undoButton_clicked()54 void SystemSyncDialog::on_undoButton_clicked()
55 {
56     ui->syncSlider->setValue(0);
57     setDelay(0);
58 }
59 
on_syncSpinBox_valueChanged(int arg1)60 void SystemSyncDialog::on_syncSpinBox_valueChanged(int arg1)
61 {
62     Q_UNUSED(arg1)
63     ui->applyButton->show();
64 }
65 
on_applyButton_clicked()66 void SystemSyncDialog::on_applyButton_clicked()
67 {
68     setDelay(ui->syncSpinBox->value());
69 }
70 
setDelay(int delay)71 void SystemSyncDialog::setDelay(int delay)
72 {
73     if (delay != Settings.playerVideoDelayMs()) {
74         Settings.setPlayerVideoDelayMs(delay);
75         MLT.consumerChanged();
76     }
77     ui->applyButton->hide();
78 
79 }
80