File: videodialog.cpp

package info (click to toggle)
bino 1.6.6-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 4,636 kB
  • sloc: cpp: 21,288; sh: 4,849; makefile: 314; sed: 16
file content (276 lines) | stat: -rw-r--r-- 10,177 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
/*
 * This file is part of bino, a 3D video player.
 *
 * Copyright (C) 2010, 2011, 2012, 2013, 2014
 * Martin Lambers <marlam@marlam.de>
 * Frédéric Devernay <Frederic.Devernay@inrialpes.fr>
 * Joe <cuchac@email.cz>
 * Daniel Schaal <farbing@web.de>
 * D. Matz <bandregent@yahoo.de>
 * Binocle <http://binocle.com> (author: Olivier Letz <oletz@binocle.com>)
 * Frédéric Bour <frederic.bour@lakaban.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "config.h"

#include <complex>

#include <QLabel>
#include <QComboBox>
#include <QDoubleSpinBox>
#include <QGridLayout>

#include "videodialog.h"

#include "gui_common.h"

video_dialog::video_dialog(QWidget *parent) : QWidget(parent), _lock(false)
{
    QLabel *crop_ar_label = new QLabel(_("Crop to aspect ratio:"));
    crop_ar_label->setToolTip(_("<p>Set the real aspect ratio of the video, so that borders can be cropped.</p>"));
    _crop_ar_combobox = new QComboBox();
    _crop_ar_combobox->setToolTip(crop_ar_label->toolTip());
    _crop_ar_combobox->addItem(_("Do not crop"));
    _crop_ar_combobox->addItem("16:10");
    _crop_ar_combobox->addItem("16:9");
    _crop_ar_combobox->addItem("1.85:1");
    _crop_ar_combobox->addItem("2.21:1");
    _crop_ar_combobox->addItem("2.35:1");
    _crop_ar_combobox->addItem("2.39:1");
    _crop_ar_combobox->addItem("5:3");
    _crop_ar_combobox->addItem("4:3");
    _crop_ar_combobox->addItem("5:4");
    _crop_ar_combobox->addItem("1:1");
    connect(_crop_ar_combobox, SIGNAL(currentIndexChanged(int)), this, SLOT(crop_ar_changed()));

    QLabel *source_ar_label = new QLabel(_("Force source aspect ratio:"));
    source_ar_label->setToolTip(_("<p>Force the aspect ratio of video source.</p>"));
    _source_ar_combobox = new QComboBox();
    _source_ar_combobox->setToolTip(source_ar_label->toolTip());
    _source_ar_combobox->addItem(_("Do not force"));
    _source_ar_combobox->addItem("16:10");
    _source_ar_combobox->addItem("16:9");
    _source_ar_combobox->addItem("1.85:1");
    _source_ar_combobox->addItem("2.21:1");
    _source_ar_combobox->addItem("2.35:1");
    _source_ar_combobox->addItem("2.39:1");
    _source_ar_combobox->addItem("5:3");
    _source_ar_combobox->addItem("4:3");
    _source_ar_combobox->addItem("5:4");
    _source_ar_combobox->addItem("1:1");
    connect(_source_ar_combobox, SIGNAL(currentIndexChanged(int)), this, SLOT(source_ar_changed()));

    QLabel *p_label = new QLabel(_("Parallax:"));
    p_label->setToolTip(_("<p>Adjust parallax, from -1 to +1. This changes the separation of left and right view, "
                "and thus the perceived distance of the scene.</p>"));
    _p_slider = new QSlider(Qt::Horizontal);
    _p_slider->setToolTip(p_label->toolTip());
    _p_slider->setRange(-1000, 1000);
    connect(_p_slider, SIGNAL(valueChanged(int)), this, SLOT(p_slider_changed(int)));
    _p_spinbox = new QDoubleSpinBox();
    _p_spinbox->setToolTip(p_label->toolTip());
    _p_spinbox->setRange(-1.0, +1.0);
    _p_spinbox->setDecimals(2);
    _p_spinbox->setSingleStep(0.01);
    connect(_p_spinbox, SIGNAL(valueChanged(double)), this, SLOT(p_spinbox_changed(double)));

    QLabel *sp_label = new QLabel(_("Subtitle parallax:"));
    sp_label->setToolTip(_("<p>Adjust subtitle parallax, from -1 to +1. This changes the perceived distance "
                "of the subtitles.</p>"));
    _sp_slider = new QSlider(Qt::Horizontal);
    _sp_slider->setToolTip(sp_label->toolTip());
    _sp_slider->setRange(-1000, 1000);
    connect(_sp_slider, SIGNAL(valueChanged(int)), this, SLOT(sp_slider_changed(int)));
    _sp_spinbox = new QDoubleSpinBox();
    _sp_spinbox->setToolTip(sp_label->toolTip());
    _sp_spinbox->setRange(-1.0, +1.0);
    _sp_spinbox->setDecimals(2);
    _sp_spinbox->setSingleStep(0.01);
    connect(_sp_spinbox, SIGNAL(valueChanged(double)), this, SLOT(sp_spinbox_changed(double)));

    QLabel *g_label = new QLabel(_("Ghostbusting:"));
    g_label->setToolTip(_("<p>Set the amount of crosstalk ghostbusting, from 0 to 1. "
                "You need to set the crosstalk levels of your display first. "
                "Note that crosstalk ghostbusting does not work with anaglyph glasses.</p>"));
    _g_slider = new QSlider(Qt::Horizontal);
    _g_slider->setToolTip(g_label->toolTip());
    _g_slider->setRange(0, 1000);
    connect(_g_slider, SIGNAL(valueChanged(int)), this, SLOT(g_slider_changed(int)));
    _g_spinbox = new QDoubleSpinBox();
    _g_spinbox->setToolTip(g_label->toolTip());
    _g_spinbox->setRange(0.0, +1.0);
    _g_spinbox->setDecimals(2);
    _g_spinbox->setSingleStep(0.01);
    connect(_g_spinbox, SIGNAL(valueChanged(double)), this, SLOT(g_spinbox_changed(double)));

    QGridLayout *layout = new QGridLayout;
    layout->addWidget(crop_ar_label, 0, 0);
    layout->addWidget(_crop_ar_combobox, 0, 1, 1, 2);
    layout->addWidget(source_ar_label, 1, 0);
    layout->addWidget(_source_ar_combobox, 1, 1, 1, 2);
    layout->addWidget(p_label, 2, 0);
    layout->addWidget(_p_slider, 2, 1);
    layout->addWidget(_p_spinbox, 2, 2);
    layout->addWidget(sp_label, 3, 0);
    layout->addWidget(_sp_slider, 3, 1);
    layout->addWidget(_sp_spinbox, 3, 2);
    layout->addWidget(g_label, 4, 0);
    layout->addWidget(_g_slider, 4, 1);
    layout->addWidget(_g_spinbox, 4, 2);
    setLayout(layout);

    update();
}

void video_dialog::update()
{
    _lock = true;
    set_crop_ar(dispatch::parameters().crop_aspect_ratio());
    _p_slider->setValue(dispatch::parameters().parallax() * 1000.0f);
    _p_spinbox->setValue(dispatch::parameters().parallax());
    _sp_slider->setValue(dispatch::parameters().subtitle_parallax() * 1000.0f);
    _sp_spinbox->setValue(dispatch::parameters().subtitle_parallax());
    _g_slider->setValue(dispatch::parameters().ghostbust() * 1000.0f);
    _g_spinbox->setValue(dispatch::parameters().ghostbust());
    _lock = false;
}

void video_dialog::set_crop_ar(float value)
{
    _crop_ar_combobox->setCurrentIndex(
              ( std::abs(value - 16.0f / 10.0f) < 0.01f ? 1
              : std::abs(value - 16.0f / 9.0f)  < 0.01f ? 2
              : std::abs(value - 1.85f)         < 0.01f ? 3
              : std::abs(value - 2.21f)         < 0.01f ? 4
              : std::abs(value - 2.35f)         < 0.01f ? 5
              : std::abs(value - 2.39f)         < 0.01f ? 6
              : std::abs(value - 5.0f / 3.0f)   < 0.01f ? 7
              : std::abs(value - 4.0f / 3.0f)   < 0.01f ? 8
              : std::abs(value - 5.0f / 4.0f)   < 0.01f ? 9
              : std::abs(value - 1.0f)          < 0.01f ? 10
              : 0));
}

void video_dialog::crop_ar_changed()
{
    if (!_lock)
    {
        int i = _crop_ar_combobox->currentIndex();
        float ar =
              i == 1 ? 16.0f / 10.0f
            : i == 2 ? 16.0f / 9.0f
            : i == 3 ? 1.85f
            : i == 4 ? 2.21f
            : i == 5 ? 2.35f
            : i == 6 ? 2.39f
            : i == 7 ? 5.0f / 3.0f
            : i == 8 ? 4.0f / 3.0f
            : i == 9 ? 5.0f / 4.0f
            : i == 10 ? 1.0f
            : 0.0f;
        send_cmd(command::set_crop_aspect_ratio, ar);
    }
}

void video_dialog::set_source_ar(float value)
{
    _source_ar_combobox->setCurrentIndex(
              ( std::abs(value - 16.0f / 10.0f) < 0.01f ? 1
              : std::abs(value - 16.0f / 9.0f)  < 0.01f ? 2
              : std::abs(value - 1.85f)         < 0.01f ? 3
              : std::abs(value - 2.21f)         < 0.01f ? 4
              : std::abs(value - 2.35f)         < 0.01f ? 5
              : std::abs(value - 2.39f)         < 0.01f ? 6
              : std::abs(value - 5.0f / 3.0f)   < 0.01f ? 7
              : std::abs(value - 4.0f / 3.0f)   < 0.01f ? 8
              : std::abs(value - 5.0f / 4.0f)   < 0.01f ? 9
              : std::abs(value - 1.0f)          < 0.01f ? 10
              : 0));
}

void video_dialog::source_ar_changed()
{
    if (!_lock)
    {
        int i = _source_ar_combobox->currentIndex();
        float ar =
              i == 1 ? 16.0f / 10.0f
            : i == 2 ? 16.0f / 9.0f
            : i == 3 ? 1.85f
            : i == 4 ? 2.21f
            : i == 5 ? 2.35f
            : i == 6 ? 2.39f
            : i == 7 ? 5.0f / 3.0f
            : i == 8 ? 4.0f / 3.0f
            : i == 9 ? 5.0f / 4.0f
            : i == 10 ? 1.0f
            : 0.0f;
        send_cmd(command::set_source_aspect_ratio, ar);
    }
}

void video_dialog::p_slider_changed(int val)
{
    if (!_lock)
        send_cmd(command::set_parallax, val / 1000.0f);
}

void video_dialog::p_spinbox_changed(double val)
{
    if (!_lock)
        send_cmd(command::set_parallax, static_cast<float>(val));
}

void video_dialog::sp_slider_changed(int val)
{
    if (!_lock)
        send_cmd(command::set_subtitle_parallax, val / 1000.0f);
}

void video_dialog::sp_spinbox_changed(double val)
{
    if (!_lock)
        send_cmd(command::set_subtitle_parallax, static_cast<float>(val));
}

void video_dialog::g_slider_changed(int val)
{
    if (!_lock)
        send_cmd(command::set_ghostbust, val / 1000.0f);
}

void video_dialog::g_spinbox_changed(double val)
{
    if (!_lock)
        send_cmd(command::set_ghostbust, static_cast<float>(val));
}

void video_dialog::receive_notification(const notification &note)
{
    switch (note.type)
    {
    case notification::crop_aspect_ratio:
    case notification::source_aspect_ratio:
    case notification::parallax:
    case notification::subtitle_parallax:
    case notification::ghostbust:
        update();
        break;
    default:
        /* not handled */
        break;
    }
}