source: smplayer/trunk/src/prefsubtitles.cpp@ 188

Last change on this file since 188 was 188, checked in by Silvan Scherrer, 8 years ago

SMPlayer: update trunk to version 17.1.0

  • Property svn:eol-style set to LF
File size: 17.9 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2017 Ricardo Villalba <rvm@users.sourceforge.net>
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 2 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, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17*/
18
19
20#include "prefsubtitles.h"
21#include "images.h"
22#include "preferences.h"
23#include "paths.h"
24#include "assstyles.h"
25#include "filedialog.h"
26#include "languages.h"
27#include "playerid.h"
28
29#include <QInputDialog>
30
31PrefSubtitles::PrefSubtitles(QWidget * parent, Qt::WindowFlags f)
32 : PrefWidget(parent, f )
33{
34 setupUi(this);
35
36 ass_subs->setEnabled(false);
37
38 connect(ass_custom_check, SIGNAL(toggled(bool)),
39 ass_subs, SLOT(setEnabled(bool)));
40
41 /*
42 connect(use_ass_check, SIGNAL(toggled(bool)),
43 tab2, SLOT(setEnabled(bool)));
44 */
45
46 connect( style_border_style_combo, SIGNAL(currentIndexChanged(int)),
47 this, SLOT(checkBorderStyleCombo(int)) );
48
49#ifndef FONTS_HACK
50 windowsfontdir_check->hide();
51#endif
52
53 retranslateStrings();
54}
55
56PrefSubtitles::~PrefSubtitles()
57{
58}
59
60QString PrefSubtitles::sectionName() {
61 return tr("Subtitles");
62}
63
64QPixmap PrefSubtitles::sectionIcon() {
65 return Images::icon("pref_subtitles");
66}
67
68
69void PrefSubtitles::retranslateStrings() {
70 int font_autoload_item = font_autoload_combo->currentIndex();
71
72 retranslateUi(this);
73
74 font_autoload_combo->setCurrentIndex(font_autoload_item);
75
76 // Encodings combo
77 //int font_encoding_item = font_encoding_combo->currentIndex();
78 QString current_encoding = fontEncoding();
79 QString current_enca_lang = encaLang();
80 font_encoding_combo->clear();
81 enca_lang_combo->clear();
82
83 QMap<QString,QString> l = Languages::encodings();
84 QMapIterator<QString, QString> i(l);
85 while (i.hasNext()) {
86 i.next();
87 font_encoding_combo->addItem( i.value() + " (" + i.key() + ")", i.key() );
88 }
89
90 l = Languages::enca();
91 i = l;
92 while (i.hasNext()) {
93 i.next();
94 enca_lang_combo->addItem( i.value() + " (" + i.key() + ")", i.key() );
95 }
96
97 font_encoding_combo->model()->sort(0);
98 enca_lang_combo->model()->sort(0);
99 //font_encoding_combo->setCurrentIndex(font_encoding_item);
100 setFontEncoding(current_encoding);
101 setEncaLang(current_enca_lang);
102
103 // Ass styles
104 int alignment_item = style_alignment_combo->currentIndex();
105 style_alignment_combo->clear();
106 style_alignment_combo->addItem(tr("Left", "horizontal alignment"), AssStyles::Left);
107 style_alignment_combo->addItem(tr("Centered", "horizontal alignment"), AssStyles::HCenter);
108 style_alignment_combo->addItem(tr("Right", "horizontal alignment"), AssStyles::Right);
109 style_alignment_combo->setCurrentIndex(alignment_item);
110
111 int valignment_item = style_valignment_combo->currentIndex();
112 style_valignment_combo->clear();
113 style_valignment_combo->addItem(tr("Bottom", "vertical alignment"), AssStyles::Bottom);
114 style_valignment_combo->addItem(tr("Middle", "vertical alignment"), AssStyles::VCenter);
115 style_valignment_combo->addItem(tr("Top", "vertical alignment"), AssStyles::Top);
116 style_valignment_combo->setCurrentIndex(valignment_item);
117
118 int borderstyle_item = style_border_style_combo->currentIndex();
119 style_border_style_combo->clear();
120 style_border_style_combo->addItem(tr("Outline", "border style"), AssStyles::Outline);
121 style_border_style_combo->addItem(tr("Opaque box", "border style"), AssStyles::Opaque);
122 style_border_style_combo->setCurrentIndex(borderstyle_item);
123
124 createHelp();
125}
126
127void PrefSubtitles::setData(Preferences * pref) {
128 setAssFontScale( pref->initial_sub_scale_ass );
129 setAutoloadSub( pref->autoload_sub );
130 setFontFuzziness( pref->subfuzziness );
131 setFontEncoding( pref->subcp );
132 setUseEnca( pref->use_enca );
133 setEncaLang( pref->enca_lang );
134 setAssLineSpacing( pref->ass_line_spacing );
135 setSubtitlesOnScreenshots( pref->subtitles_on_screenshots );
136 setFreetypeSupport( pref->freetype_support );
137 use_ass_check->setChecked( pref->use_ass_subtitles );
138
139 // Load ass styles
140 style_font_combo->setCurrentText(pref->ass_styles.fontname);
141 style_size_spin->setValue(pref->ass_styles.fontsize);
142 style_text_color_button->setColor(pref->ass_styles.primarycolor);
143 style_border_color_button->setColor(pref->ass_styles.outlinecolor);
144 style_shadow_color_button->setColor(pref->ass_styles.backcolor);
145 style_bold_check->setChecked(pref->ass_styles.bold);
146 style_italic_check->setChecked(pref->ass_styles.italic);
147 style_alignment_combo->setCurrentIndex(style_alignment_combo->findData(pref->ass_styles.halignment));
148 style_valignment_combo->setCurrentIndex(pref->ass_styles.valignment);
149 style_border_style_combo->setCurrentIndex(style_border_style_combo->findData(pref->ass_styles.borderstyle));
150 style_outline_spin->setValue(pref->ass_styles.outline);
151 style_shadow_spin->setValue(pref->ass_styles.shadow);
152 style_marginl_spin->setValue(pref->ass_styles.marginl);
153 style_marginr_spin->setValue(pref->ass_styles.marginr);
154 style_marginv_spin->setValue(pref->ass_styles.marginv);
155
156 setForceAssStyles(pref->force_ass_styles);
157 setCustomizedAssStyle(pref->user_forced_ass_style);
158
159 ass_custom_check->setChecked(pref->enable_ass_styles);
160
161#ifdef FONTS_HACK
162 windowsfontdir_check->setChecked(pref->use_windowsfontdir);
163 if (!windowsfontdir_check->isChecked()) on_windowsfontdir_check_toggled(false);
164#endif
165}
166
167void PrefSubtitles::getData(Preferences * pref) {
168 requires_restart = false;
169
170 pref->initial_sub_scale_ass = assFontScale();
171 TEST_AND_SET(pref->autoload_sub, autoloadSub());
172 TEST_AND_SET(pref->subfuzziness, fontFuzziness());
173 TEST_AND_SET(pref->subcp, fontEncoding());
174 TEST_AND_SET(pref->use_enca, useEnca());
175 TEST_AND_SET(pref->enca_lang, encaLang());
176 TEST_AND_SET(pref->ass_line_spacing, assLineSpacing());
177 TEST_AND_SET(pref->subtitles_on_screenshots, subtitlesOnScreenshots());
178 TEST_AND_SET(pref->freetype_support, freetypeSupport());
179 TEST_AND_SET(pref->use_ass_subtitles, use_ass_check->isChecked());
180
181 // Save ass styles
182 TEST_AND_SET(pref->ass_styles.fontname, style_font_combo->currentText());
183 TEST_AND_SET(pref->ass_styles.fontsize, style_size_spin->value());
184 TEST_AND_SET(pref->ass_styles.primarycolor, style_text_color_button->color());
185 TEST_AND_SET(pref->ass_styles.outlinecolor, style_border_color_button->color());
186 TEST_AND_SET(pref->ass_styles.backcolor, style_shadow_color_button->color());
187 TEST_AND_SET(pref->ass_styles.bold, style_bold_check->isChecked());
188 TEST_AND_SET(pref->ass_styles.italic, style_italic_check->isChecked());
189 TEST_AND_SET(pref->ass_styles.halignment, style_alignment_combo->itemData(style_alignment_combo->currentIndex()).toInt());
190 TEST_AND_SET(pref->ass_styles.valignment, style_valignment_combo->currentIndex());
191 TEST_AND_SET(pref->ass_styles.borderstyle, style_border_style_combo->itemData(style_border_style_combo->currentIndex()).toInt());
192 TEST_AND_SET(pref->ass_styles.outline, style_outline_spin->value());
193 TEST_AND_SET(pref->ass_styles.shadow, style_shadow_spin->value());
194 TEST_AND_SET(pref->ass_styles.marginl, style_marginl_spin->value());
195 TEST_AND_SET(pref->ass_styles.marginr, style_marginr_spin->value());
196 TEST_AND_SET(pref->ass_styles.marginv, style_marginv_spin->value());
197
198 pref->ass_styles.exportStyles( Paths::subtitleStyleFile() );
199
200 TEST_AND_SET(pref->force_ass_styles, forceAssStyles());
201 TEST_AND_SET(pref->user_forced_ass_style, customizedAssStyle());
202
203 TEST_AND_SET(pref->enable_ass_styles, ass_custom_check->isChecked());
204
205#ifdef FONTS_HACK
206 pref->use_windowsfontdir = windowsfontdir_check->isChecked();
207#endif
208}
209
210void PrefSubtitles::checkBorderStyleCombo( int index ) {
211 bool b = (index == 0);
212 style_outline_spin->setEnabled(b);
213 style_shadow_spin->setEnabled(b);
214 style_outline_label->setEnabled(b);
215 style_shadow_label->setEnabled(b);
216}
217
218
219
220void PrefSubtitles::setAssFontScale(double n) {
221 ass_font_scale_spin->setValue(n);
222}
223
224double PrefSubtitles::assFontScale() {
225 return ass_font_scale_spin->value();
226}
227
228void PrefSubtitles::setAutoloadSub(bool v) {
229 font_autoload_check->setChecked(v);
230}
231
232bool PrefSubtitles::autoloadSub() {
233 return font_autoload_check->isChecked();
234}
235
236void PrefSubtitles::setFontEncoding(QString s) {
237 int i = font_encoding_combo->findData(s);
238 font_encoding_combo->setCurrentIndex(i);
239}
240
241QString PrefSubtitles::fontEncoding() {
242 int index = font_encoding_combo->currentIndex();
243 return font_encoding_combo->itemData(index).toString();
244}
245
246void PrefSubtitles::setEncaLang(QString s) {
247 int i = enca_lang_combo->findData(s);
248 enca_lang_combo->setCurrentIndex(i);
249}
250
251QString PrefSubtitles::encaLang() {
252 int index = enca_lang_combo->currentIndex();
253 return enca_lang_combo->itemData(index).toString();
254}
255
256void PrefSubtitles::setUseEnca(bool b) {
257 use_enca_check->setChecked(b);
258}
259
260bool PrefSubtitles::useEnca() {
261 return use_enca_check->isChecked();
262}
263
264void PrefSubtitles::setFontFuzziness(int n) {
265 font_autoload_combo->setCurrentIndex(n);
266}
267
268int PrefSubtitles::fontFuzziness() {
269 return font_autoload_combo->currentIndex();
270}
271
272void PrefSubtitles::setSubtitlesOnScreenshots(bool b) {
273 subtitles_on_screeshots_check->setChecked(b);
274}
275
276bool PrefSubtitles::subtitlesOnScreenshots() {
277 return subtitles_on_screeshots_check->isChecked();
278}
279
280void PrefSubtitles::setAssLineSpacing(int spacing) {
281 ass_line_spacing_spin->setValue(spacing);
282}
283
284int PrefSubtitles::assLineSpacing() {
285 return ass_line_spacing_spin->value();
286}
287
288void PrefSubtitles::setForceAssStyles(bool b) {
289 force_ass_styles->setChecked(b);
290}
291
292bool PrefSubtitles::forceAssStyles() {
293 return force_ass_styles->isChecked();
294}
295
296/*
297void PrefSubtitles::on_ass_subs_button_toggled(bool b) {
298 if (b)
299 stackedWidget->setCurrentIndex(1);
300 else
301 stackedWidget->setCurrentIndex(0);
302}
303*/
304
305void PrefSubtitles::on_ass_customize_button_clicked() {
306 bool ok;
307
308 QString edit = forced_ass_style;
309
310 // A copy with the current values in the dialog
311 AssStyles ass_styles;
312 ass_styles.fontname = style_font_combo->currentText();
313 ass_styles.fontsize = style_size_spin->value();
314 ass_styles.primarycolor = style_text_color_button->color();
315 ass_styles.outlinecolor = style_border_color_button->color();
316 ass_styles.backcolor = style_shadow_color_button->color();
317 ass_styles.bold = style_bold_check->isChecked();
318 ass_styles.italic = style_italic_check->isChecked();
319 ass_styles.halignment = style_alignment_combo->itemData(style_alignment_combo->currentIndex()).toInt();
320 ass_styles.valignment = style_valignment_combo->currentIndex();
321 ass_styles.borderstyle = style_border_style_combo->itemData(style_border_style_combo->currentIndex()).toInt();
322 ass_styles.outline = style_outline_spin->value();
323 ass_styles.shadow = style_shadow_spin->value();
324 ass_styles.marginl = style_marginl_spin->value();
325 ass_styles.marginr = style_marginr_spin->value();
326 ass_styles.marginv = style_marginv_spin->value();
327
328 if (edit.isEmpty()) {
329 edit = ass_styles.toString();
330 }
331
332 QString s = QInputDialog::getText(this, tr("Customize SSA/ASS style"),
333 tr("Here you can enter your customized SSA/ASS style.") +"<br>"+
334 tr("Clear the edit line to disable the customized style."),
335 QLineEdit::Normal,
336 edit, &ok );
337 if (ok) {
338 if (s == ass_styles.toString()) s.clear(); // Clear string if it wasn't changed by the user
339 setCustomizedAssStyle(s);
340 }
341}
342
343void PrefSubtitles::setFreetypeSupport(bool b) {
344 freetype_check->setChecked(b);
345}
346
347bool PrefSubtitles::freetypeSupport() {
348 return freetype_check->isChecked();
349}
350
351void PrefSubtitles::on_freetype_check_toggled(bool b) {
352 qDebug("PrefSubtitles:on_freetype_check_toggled: %d", b);
353}
354
355#ifdef FONTS_HACK
356void PrefSubtitles::on_windowsfontdir_check_toggled(bool b) {
357 qDebug("PrefSubtitles::on_windowsfontdir_check_toggled: %d", b);
358
359 if (b) {
360 style_font_combo->setFontsFromDir(QString::null);
361 } else {
362 QString fontdir = Paths::fontPath();
363 //QString fontdir = "/tmp/fonts/";
364 style_font_combo->setFontsFromDir(fontdir);
365
366 // Calling setFontsFromDir resets the fonts in other comboboxes!
367 // So the font list is copied from the previous combobox
368 /*
369 QString current_text = fontCombo->currentText();
370 fontCombo->clear();
371 for (int n=0; n < style_font_combo->count(); n++) {
372 fontCombo->addItem( style_font_combo->itemText(n) );
373 }
374 fontCombo->setCurrentText(current_text);
375 */
376 }
377}
378#endif
379
380void PrefSubtitles::createHelp() {
381 clearHelp();
382
383 addSectionTitle(tr("Subtitles"));
384
385 setWhatsThis(font_autoload_combo, tr("Autoload"),
386 tr("Select the subtitle autoload method.") );
387
388 setWhatsThis(font_autoload_check, tr("Select first available subtitle"),
389 tr("If there are one or more subtitle tracks available, one of them "
390 "will be automatically selected, usually the first one, although if "
391 "one of them matches the user's preferred language that one will "
392 "be used instead.") );
393
394 setWhatsThis(font_encoding_combo, tr("Default subtitle encoding"),
395 tr("Select the encoding which will be used for subtitle files "
396 "by default.") );
397
398 setWhatsThis(use_enca_check, tr("Try to autodetect for this language"),
399 tr("When this option is on, the encoding of the subtitles will be "
400 "tried to be autodetected for the given language. "
401 "It will fall back to the default encoding if the autodetection "
402 "fails. This option requires a %1 with ENCA "
403 "support.").arg(PLAYER_NAME) );
404
405 setWhatsThis(enca_lang_combo, tr("Subtitle language"),
406 tr("Select the language for which you want the encoding to be guessed "
407 "automatically.") );
408
409 setWhatsThis(subtitles_on_screeshots_check,
410 tr("Include subtitles on screenshots"),
411 tr("If this option is checked, the subtitles will appear in the "
412 "screenshots. <b>Note:</b> it may cause some troubles sometimes." ) );
413
414 setWhatsThis(use_ass_check, tr("Use the ASS library"),
415 tr("This option enables the ASS library, which allows to display "
416 "subtitles with multiple colors, fonts...") );
417
418 setWhatsThis(freetype_check, tr("Freetype support"),
419 tr("You should normally not disable this option. Do it only if your "
420 "%1 is compiled without freetype support. "
421 "<b>Disabling this option could make subtitles not to work "
422 "at all!</b>").arg(PLAYER_NAME));
423
424#ifdef FONTS_HACK
425 setWhatsThis(windowsfontdir_check, tr("Enable Windows fonts"),
426 tr("If this option is enabled the Windows system fonts will be "
427 "available for subtitles. There's an inconvenience: a font cache have "
428 "to be created which can take some time.") +"<br>"+
429 tr("If this option is not checked then only a few fonts bundled with SMPlayer "
430 "can be used, but this is faster.") );
431#endif
432
433 addSectionTitle(tr("Font"));
434
435 QString scale_note = tr("This option does NOT change the size of the "
436 "subtitles in the current video. To do so, use the options "
437 "<i>Size+</i> and <i>Size-</i> in the subtitles menu.");
438
439 setWhatsThis(ass_font_scale_spin, tr("Default scale"),
440 tr("This option specifies the default font scale for SSA/ASS "
441 "subtitles which will be used for new opened files.") +"<br>"+
442 scale_note);
443
444 setWhatsThis(ass_line_spacing_spin, tr("Line spacing"),
445 tr("This specifies the spacing that will be used to separate "
446 "multiple lines. It can have negative values.") );
447
448 setWhatsThis(styles_container, tr("SSA/ASS style"),
449 tr("The following options allows you to define the style to "
450 "be used for non-styled subtitles (srt, sub...).") );
451
452 setWhatsThis(style_font_combo, tr("Font"),
453 tr("Select the font for the subtitles.") );
454
455 setWhatsThis(style_size_spin, tr("Size"),
456 tr("The size in pixels.") );
457
458 setWhatsThis(style_bold_check, tr("Bold"),
459 tr("If checked, the text will be displayed in <b>bold</b>.") );
460
461 setWhatsThis(style_italic_check, tr("Italic"),
462 tr("If checked, the text will be displayed in <i>italic</i>.") );
463
464 setWhatsThis(style_text_color_button, tr("Text color"),
465 tr("Select the color for the text of the subtitles.") );
466
467 setWhatsThis(style_border_color_button, tr("Border color"),
468 tr("Select the color for the border of the subtitles.") );
469
470 setWhatsThis(style_shadow_color_button, tr("Shadow color"),
471 tr("This color will be used for the shadow of the subtitles.") );
472
473 setWhatsThis(style_marginl_spin, tr("Left margin"),
474 tr("Specifies the left margin in pixels.") );
475
476 setWhatsThis(style_marginr_spin, tr("Right margin"),
477 tr("Specifies the right margin in pixels.") );
478
479 setWhatsThis(style_marginv_spin, tr("Vertical margin"),
480 tr("Specifies the vertical margin in pixels.") );
481
482 setWhatsThis(style_alignment_combo, tr("Horizontal alignment"),
483 tr("Specifies the horizontal alignment. Possible values are "
484 "left, centered and right.") );
485
486 setWhatsThis(style_valignment_combo, tr("Vertical alignment"),
487 tr("Specifies the vertical alignment. Possible values: "
488 "bottom, middle and top.") );
489
490 setWhatsThis(style_border_style_combo, tr("Border style"),
491 tr("Specifies the border style. Possible values: outline "
492 "and opaque box.") );
493
494 setWhatsThis(style_outline_spin, tr("Outline"),
495 tr("If border style is set to <i>outline</i>, this option specifies "
496 "the width of the outline around the text in pixels.") );
497
498 setWhatsThis(style_shadow_spin, tr("Shadow"),
499 tr("If border style is set to <i>outline</i>, this option specifies "
500 "the depth of the drop shadow behind the text in pixels.") );
501
502 setWhatsThis(force_ass_styles, tr("Apply style to ASS files too"),
503 tr("If this option is checked, the style defined above will be "
504 "applied to ass subtitles too.") );
505}
506
507#include "moc_prefsubtitles.cpp"
Note: See TracBrowser for help on using the repository browser.