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

Last change on this file since 119 was 119, checked in by Silvan Scherrer, 14 years ago

SMPlayer: latest svn update

  • Property svn:eol-style set to LF
File size: 19.6 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2011 Ricardo Villalba <rvm@escomposlinux.org>
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
28#include <QInputDialog>
29
30PrefSubtitles::PrefSubtitles(QWidget * parent, Qt::WindowFlags f)
31 : PrefWidget(parent, f )
32{
33 setupUi(this);
34
35 ttf_font_edit->setDialogType(FileChooser::GetFileName);
36#ifdef Q_OS_WIN
37 ttf_font_edit->setOptions(QFileDialog::DontUseNativeDialog);
38#endif
39
40 connect( style_border_style_combo, SIGNAL(currentIndexChanged(int)),
41 this, SLOT(checkBorderStyleCombo(int)) );
42
43 retranslateStrings();
44}
45
46PrefSubtitles::~PrefSubtitles()
47{
48}
49
50QString PrefSubtitles::sectionName() {
51 return tr("Subtitles");
52}
53
54QPixmap PrefSubtitles::sectionIcon() {
55 return Images::icon("pref_subtitles");
56}
57
58
59void PrefSubtitles::retranslateStrings() {
60 int font_autoscale_item = font_autoscale_combo->currentIndex();
61 int font_autoload_item = font_autoload_combo->currentIndex();
62
63 retranslateUi(this);
64
65 font_autoscale_combo->setCurrentIndex(font_autoscale_item);
66 font_autoload_combo->setCurrentIndex(font_autoload_item);
67
68 // Encodings combo
69 //int font_encoding_item = font_encoding_combo->currentIndex();
70 QString current_encoding = fontEncoding();
71 QString current_enca_lang = encaLang();
72 font_encoding_combo->clear();
73 enca_lang_combo->clear();
74
75 QMap<QString,QString> l = Languages::encodings();
76 QMapIterator<QString, QString> i(l);
77 while (i.hasNext()) {
78 i.next();
79 font_encoding_combo->addItem( i.value() + " (" + i.key() + ")", i.key() );
80 }
81 l = Languages::list(); i = l;
82 while (i.hasNext()) {
83 i.next();
84 enca_lang_combo->addItem( i.value() + " (" + i.key() + ")", i.key() );
85 }
86 font_encoding_combo->model()->sort(0);
87 enca_lang_combo->model()->sort(0);
88 //font_encoding_combo->setCurrentIndex(font_encoding_item);
89 setFontEncoding(current_encoding);
90 setEncaLang(current_enca_lang);
91
92 sub_pos_label->setNum( sub_pos_slider->value() );
93
94 ttf_font_edit->setCaption(tr("Choose a ttf file"));
95 ttf_font_edit->setFilter(tr("Truetype Fonts") + " (*.ttf)");
96
97 // Ass styles
98 int alignment_item = style_alignment_combo->currentIndex();
99 style_alignment_combo->clear();
100 style_alignment_combo->addItem(tr("Left", "horizontal alignment"), 1);
101 style_alignment_combo->addItem(tr("Centered", "horizontal alignment"), 2);
102 style_alignment_combo->addItem(tr("Right", "horizontal alignment"), 3);
103 style_alignment_combo->setCurrentIndex(alignment_item);
104
105 int valignment_item = style_valignment_combo->currentIndex();
106 style_valignment_combo->clear();
107 style_valignment_combo->addItem(tr("Bottom", "vertical alignment"));
108 style_valignment_combo->addItem(tr("Middle", "vertical alignment"));
109 style_valignment_combo->addItem(tr("Top", "vertical alignment"));
110 style_valignment_combo->setCurrentIndex(valignment_item);
111
112 int borderstyle_item = style_border_style_combo->currentIndex();
113 style_border_style_combo->clear();
114 style_border_style_combo->addItem(tr("Outline", "border style"), 1);
115 style_border_style_combo->addItem(tr("Opaque box", "border style"), 3);
116 style_border_style_combo->setCurrentIndex(borderstyle_item);
117
118 createHelp();
119}
120
121void PrefSubtitles::setData(Preferences * pref) {
122 setFontName( pref->font_name );
123 setFontFile( pref->font_file );
124 setUseFontconfig( pref->use_fontconfig );
125 setFontAutoscale( pref->font_autoscale );
126 setFontTextscale( pref->initial_sub_scale );
127 setAssFontScale( pref->initial_sub_scale_ass );
128 setAutoloadSub( pref->autoload_sub );
129 setFontFuzziness( pref->subfuzziness );
130 setFontEncoding( pref->subcp );
131 setUseEnca( pref->use_enca );
132 setEncaLang( pref->enca_lang );
133 setUseFontASS( pref->use_ass_subtitles );
134 setAssLineSpacing( pref->ass_line_spacing );
135 setSubPos( pref->initial_sub_pos );
136 setSubtitlesOnScreenshots( pref->subtitles_on_screenshots );
137 setFreetypeSupport( pref->freetype_support );
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
160void PrefSubtitles::getData(Preferences * pref) {
161 requires_restart = false;
162
163 TEST_AND_SET(pref->font_name, fontName());
164 TEST_AND_SET(pref->font_file, fontFile());
165 TEST_AND_SET(pref->use_fontconfig, useFontconfig());
166 TEST_AND_SET(pref->font_autoscale, fontAutoscale());
167 pref->initial_sub_scale = fontTextscale();
168 pref->initial_sub_scale_ass = assFontScale();
169 TEST_AND_SET(pref->autoload_sub, autoloadSub());
170 TEST_AND_SET(pref->subfuzziness, fontFuzziness());
171 TEST_AND_SET(pref->subcp, fontEncoding());
172 TEST_AND_SET(pref->use_enca, useEnca());
173 TEST_AND_SET(pref->enca_lang, encaLang());
174 TEST_AND_SET(pref->use_ass_subtitles, useFontASS());
175 TEST_AND_SET(pref->ass_line_spacing, assLineSpacing());
176 pref->initial_sub_pos = subPos();
177 TEST_AND_SET(pref->subtitles_on_screenshots, subtitlesOnScreenshots());
178 TEST_AND_SET(pref->freetype_support, freetypeSupport());
179
180 // Save ass styles
181 TEST_AND_SET(pref->ass_styles.fontname, style_font_combo->currentText());
182 TEST_AND_SET(pref->ass_styles.fontsize, style_size_spin->value());
183 TEST_AND_SET(pref->ass_styles.primarycolor, style_text_color_button->color().rgb());
184 TEST_AND_SET(pref->ass_styles.outlinecolor, style_border_color_button->color().rgb());
185 TEST_AND_SET(pref->ass_styles.backcolor, style_shadow_color_button->color().rgb());
186 TEST_AND_SET(pref->ass_styles.bold, style_bold_check->isChecked());
187 TEST_AND_SET(pref->ass_styles.italic, style_italic_check->isChecked());
188 TEST_AND_SET(pref->ass_styles.halignment, style_alignment_combo->itemData(style_alignment_combo->currentIndex()).toInt());
189 TEST_AND_SET(pref->ass_styles.valignment, style_valignment_combo->currentIndex());
190 TEST_AND_SET(pref->ass_styles.borderstyle, style_border_style_combo->itemData(style_border_style_combo->currentIndex()).toInt());
191 TEST_AND_SET(pref->ass_styles.outline, style_outline_spin->value());
192 TEST_AND_SET(pref->ass_styles.shadow, style_shadow_spin->value());
193 TEST_AND_SET(pref->ass_styles.marginl, style_marginl_spin->value());
194 TEST_AND_SET(pref->ass_styles.marginr, style_marginr_spin->value());
195 TEST_AND_SET(pref->ass_styles.marginv, style_marginv_spin->value());
196
197 pref->ass_styles.exportStyles( Paths::subtitleStyleFile() );
198
199 TEST_AND_SET(pref->force_ass_styles, forceAssStyles());
200 TEST_AND_SET(pref->user_forced_ass_style, customizedAssStyle());
201}
202
203void PrefSubtitles::checkBorderStyleCombo( int index ) {
204 bool b = (index == 0);
205 style_outline_spin->setEnabled(b);
206 style_shadow_spin->setEnabled(b);
207 style_outline_label->setEnabled(b);
208 style_shadow_label->setEnabled(b);
209}
210
211
212void PrefSubtitles::setFontName(QString font_name) {
213 fontCombo->setCurrentText(font_name);
214}
215
216QString PrefSubtitles::fontName() {
217 return fontCombo->currentText();
218}
219
220void PrefSubtitles::setFontFile(QString font_file) {
221 ttf_font_edit->setText( font_file );
222}
223
224QString PrefSubtitles::fontFile() {
225 return ttf_font_edit->text();
226}
227
228
229void PrefSubtitles::setUseFontconfig(bool b) {
230 system_font_button->setChecked(b);
231 ttf_font_button->setChecked(!b);
232}
233
234bool PrefSubtitles::useFontconfig() {
235 return system_font_button->isChecked();
236}
237
238void PrefSubtitles::setFontAutoscale(int n) {
239 font_autoscale_combo->setCurrentIndex(n);
240}
241
242int PrefSubtitles::fontAutoscale() {
243 return font_autoscale_combo->currentIndex();
244}
245
246void PrefSubtitles::setFontTextscale(double n) {
247 font_text_scale_spin->setValue(n);
248}
249
250double PrefSubtitles::fontTextscale() {
251 return font_text_scale_spin->value();
252}
253
254void PrefSubtitles::setAssFontScale(double n) {
255 ass_font_scale_spin->setValue(n);
256}
257
258double PrefSubtitles::assFontScale() {
259 return ass_font_scale_spin->value();
260}
261
262void PrefSubtitles::setAutoloadSub(bool v) {
263 font_autoload_check->setChecked(v);
264}
265
266bool PrefSubtitles::autoloadSub() {
267 return font_autoload_check->isChecked();
268}
269
270void PrefSubtitles::setFontEncoding(QString s) {
271 int i = font_encoding_combo->findData(s);
272 font_encoding_combo->setCurrentIndex(i);
273}
274
275QString PrefSubtitles::fontEncoding() {
276 int index = font_encoding_combo->currentIndex();
277 return font_encoding_combo->itemData(index).toString();
278}
279
280void PrefSubtitles::setEncaLang(QString s) {
281 int i = enca_lang_combo->findData(s);
282 enca_lang_combo->setCurrentIndex(i);
283}
284
285QString PrefSubtitles::encaLang() {
286 int index = enca_lang_combo->currentIndex();
287 return enca_lang_combo->itemData(index).toString();
288}
289
290void PrefSubtitles::setUseEnca(bool b) {
291 use_enca_check->setChecked(b);
292}
293
294bool PrefSubtitles::useEnca() {
295 return use_enca_check->isChecked();
296}
297
298void PrefSubtitles::setSubPos(int pos) {
299 sub_pos_slider->setValue(pos);
300}
301
302int PrefSubtitles::subPos() {
303 return sub_pos_slider->value();
304}
305
306void PrefSubtitles::setUseFontASS(bool v) {
307 ass_subs_button->setChecked(v);
308 normal_subs_button->setChecked(!v);
309}
310
311bool PrefSubtitles::useFontASS() {
312 return ass_subs_button->isChecked();
313}
314
315void PrefSubtitles::setFontFuzziness(int n) {
316 font_autoload_combo->setCurrentIndex(n);
317}
318
319int PrefSubtitles::fontFuzziness() {
320 return font_autoload_combo->currentIndex();
321}
322
323void PrefSubtitles::setSubtitlesOnScreenshots(bool b) {
324 subtitles_on_screeshots_check->setChecked(b);
325}
326
327bool PrefSubtitles::subtitlesOnScreenshots() {
328 return subtitles_on_screeshots_check->isChecked();
329}
330
331void PrefSubtitles::setAssLineSpacing(int spacing) {
332 ass_line_spacing_spin->setValue(spacing);
333}
334
335int PrefSubtitles::assLineSpacing() {
336 return ass_line_spacing_spin->value();
337}
338
339void PrefSubtitles::setForceAssStyles(bool b) {
340 force_ass_styles->setChecked(b);
341}
342
343bool PrefSubtitles::forceAssStyles() {
344 return force_ass_styles->isChecked();
345}
346
347void PrefSubtitles::on_ass_subs_button_toggled(bool b) {
348 if (b)
349 stackedWidget->setCurrentIndex(1);
350 else
351 stackedWidget->setCurrentIndex(0);
352}
353
354void PrefSubtitles::on_ass_customize_button_clicked() {
355 bool ok;
356
357 QString edit = forced_ass_style;
358
359 // A copy with the current values in the dialog
360 AssStyles ass_styles;
361 ass_styles.fontname = style_font_combo->currentText();
362 ass_styles.fontsize = style_size_spin->value();
363 ass_styles.primarycolor = style_text_color_button->color().rgb();
364 ass_styles.outlinecolor = style_border_color_button->color().rgb();
365 ass_styles.backcolor = style_shadow_color_button->color().rgb();
366 ass_styles.bold = style_bold_check->isChecked();
367 ass_styles.italic = style_italic_check->isChecked();
368 ass_styles.halignment = style_alignment_combo->itemData(style_alignment_combo->currentIndex()).toInt();
369 ass_styles.valignment = style_valignment_combo->currentIndex();
370 ass_styles.borderstyle = style_border_style_combo->itemData(style_border_style_combo->currentIndex()).toInt();
371 ass_styles.outline = style_outline_spin->value();
372 ass_styles.shadow = style_shadow_spin->value();
373 ass_styles.marginl = style_marginl_spin->value();
374 ass_styles.marginr = style_marginr_spin->value();
375 ass_styles.marginv = style_marginv_spin->value();
376
377 if (edit.isEmpty()) {
378 edit = ass_styles.toString();
379 }
380
381 QString s = QInputDialog::getText(this, tr("Customize SSA/ASS style"),
382 tr("Here you can enter your customized SSA/ASS style.") +"<br>"+
383 tr("Clear the edit line to disable the customized style."),
384 QLineEdit::Normal,
385 edit, &ok );
386 if (ok) {
387 if (s == ass_styles.toString()) s.clear(); // Clear string if it wasn't changed by the user
388 setCustomizedAssStyle(s);
389 }
390}
391
392void PrefSubtitles::setFreetypeSupport(bool b) {
393 freetype_check->setChecked(b);
394}
395
396bool PrefSubtitles::freetypeSupport() {
397 return freetype_check->isChecked();
398}
399
400void PrefSubtitles::on_freetype_check_toggled(bool b) {
401 qDebug("PrefSubtitles:on_freetype_check_toggled: %d", b);
402 if (!b) {
403 ass_subs_button->setChecked(false);
404 normal_subs_button->setChecked(true);
405 }
406}
407
408void PrefSubtitles::createHelp() {
409 clearHelp();
410
411 addSectionTitle(tr("Subtitles"));
412
413 setWhatsThis(font_autoload_combo, tr("Autoload"),
414 tr("Select the subtitle autoload method.") );
415
416 setWhatsThis(font_autoload_check, tr("Select first available subtitle"),
417 tr("If there are one or more subtitle tracks available, one of them "
418 "will be automatically selected, usually the first one, although if "
419 "one of them matches the user's preferred language that one will "
420 "be used instead.") );
421
422 setWhatsThis(font_encoding_combo, tr("Default subtitle encoding"),
423 tr("Select the encoding which will be used for subtitle files "
424 "by default.") );
425
426 setWhatsThis(use_enca_check, tr("Try to autodetect for this language"),
427 tr("When this option is on, the encoding of the subtitles will be "
428 "tried to be autodetected for the given language. "
429 "It will fall back to the default encoding if the autodetection "
430 "fails. This option requires a MPlayer compiled with ENCA "
431 "support.") );
432
433 setWhatsThis(enca_lang_combo, tr("Subtitle language"),
434 tr("Select the language for which you want the encoding to be guessed "
435 "automatically.") );
436
437 setWhatsThis(subtitles_on_screeshots_check,
438 tr("Include subtitles on screenshots"),
439 tr("If this option is checked, the subtitles will appear in the "
440 "screenshots. <b>Note:</b> it may cause some troubles sometimes." ) );
441
442 setWhatsThis(freetype_check, tr("Freetype support"),
443 tr("You should normally not disable this option. Do it only if your "
444 "MPlayer is compiled without freetype support. "
445 "<b>Disabling this option could make that subtitles won't work "
446 "at all!</b>") );
447
448 addSectionTitle(tr("Font"));
449
450 setWhatsThis(normal_subs_button, tr("Enable normal subtitles"),
451 tr("Click this button to select the normal/traditional subtitles. "
452 "This kind of subtitles can only display white subtitles."));
453
454 setWhatsThis(ass_subs_button, tr("Enable SSA/ASS subtitles"),
455 tr("Click this button to enable the new SSA/ASS library. "
456 "This allows to display subtitles with multiple colors, fonts..."));
457
458 addSectionTitle(tr("Normal subtitles"));
459
460 setWhatsThis(ttf_font_edit, tr("TTF font"),
461 tr("Here you can select a ttf font to be used for the subtitles. "
462 "Usually you'll find a lot of ttf fonts in %1")
463#ifdef Q_OS_WIN
464 .arg("<i>C:\\Windows\\Fonts\\</i>")
465#else
466#ifdef Q_OS_OS2
467 .arg("<i>C:\\PSFONTS</i>")
468#else
469 .arg("<i>/usr/X11R6/lib/X11/fonts/truetype/</i>")
470#endif
471#endif
472 );
473
474 setWhatsThis(fontCombo, tr("System font"),
475 tr("Here you can select a system font to be used for the subtitles "
476 "and OSD. <b>Note:</b> requires a MPlayer with fontconfig support.") );
477
478 setWhatsThis(font_autoscale_combo, tr("Autoscale"),
479 tr("Select the subtitle autoscaling method.") );
480
481 QString scale_note = tr("This option does NOT change the size of the "
482 "subtitles in the current video. To do so, use the options "
483 "<i>Size+</i> and <i>Size-</i> in the subtitles menu.");
484
485 setWhatsThis(font_text_scale_spin, tr("Default scale"),
486 tr("This option specifies the default font scale for normal "
487 "subtitles which will be used for new opened files.") +"<br>"+
488 scale_note);
489
490 setWhatsThis(sub_pos_slider, tr("Subtitle position"),
491 tr("This option specifies the position of the subtitles over the "
492 "video window. <i>100</i> means the bottom, while <i>0</i> means "
493 "the top." ) );
494
495 addSectionTitle(tr("SSA/ASS subtitles"));
496
497 setWhatsThis(ass_font_scale_spin, tr("Default scale"),
498 tr("This option specifies the default font scale for SSA/ASS "
499 "subtitles which will be used for new opened files.") +"<br>"+
500 scale_note);
501
502 setWhatsThis(ass_line_spacing_spin, tr("Line spacing"),
503 tr("This specifies the spacing that will be used to separate "
504 "multiple lines. It can have negative values.") );
505
506 setWhatsThis(styles_container, tr("SSA/ASS style"),
507 tr("The following options allows you to define the style to "
508 "be used for non-styled subtitles (srt, sub...).") );
509
510 setWhatsThis(style_font_combo, tr("Font"),
511 tr("Select the font for the subtitles.") );
512
513 setWhatsThis(style_size_spin, tr("Size"),
514 tr("The size in pixels.") );
515
516 setWhatsThis(style_bold_check, tr("Bold"),
517 tr("If checked, the text will be displayed in <b>bold</b>.") );
518
519 setWhatsThis(style_italic_check, tr("Italic"),
520 tr("If checked, the text will be displayed in <i>italic</i>.") );
521
522 setWhatsThis(style_text_color_button, tr("Text color"),
523 tr("Select the color for the text of the subtitles.") );
524
525 setWhatsThis(style_border_color_button, tr("Border color"),
526 tr("Select the color for the border of the subtitles.") );
527
528 setWhatsThis(style_shadow_color_button, tr("Shadow color"),
529 tr("This color will be used for the shadow of the subtitles.") );
530
531 setWhatsThis(style_marginl_spin, tr("Left margin"),
532 tr("Specifies the left margin in pixels.") );
533
534 setWhatsThis(style_marginr_spin, tr("Right margin"),
535 tr("Specifies the right margin in pixels.") );
536
537 setWhatsThis(style_marginv_spin, tr("Vertical margin"),
538 tr("Specifies the vertical margin in pixels.") );
539
540 setWhatsThis(style_alignment_combo, tr("Horizontal alignment"),
541 tr("Specifies the horizontal alignment. Possible values are "
542 "left, centered and right.") );
543
544 setWhatsThis(style_valignment_combo, tr("Vertical alignment"),
545 tr("Specifies the vertical alignment. Possible values: "
546 "bottom, middle and top.") );
547
548 setWhatsThis(style_border_style_combo, tr("Border style"),
549 tr("Specifies the border style. Possible values: outline "
550 "and opaque box.") );
551
552 setWhatsThis(style_outline_spin, tr("Outline"),
553 tr("If border style is set to <i>outline</i>, this option specifies "
554 "the width of the outline around the text in pixels.") );
555
556 setWhatsThis(style_shadow_spin, tr("Shadow"),
557 tr("If border style is set to <i>outline</i>, this option specifies "
558 "the depth of the drop shadow behind the text in pixels.") );
559
560 setWhatsThis(force_ass_styles, tr("Apply style to ass files too"),
561 tr("If this option is checked, the style defined above will be "
562 "applied to ass subtitles too.") );
563}
564
565#include "moc_prefsubtitles.cpp"
Note: See TracBrowser for help on using the repository browser.