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 | #include "assstyles.h"
|
---|
20 | #include <QSettings>
|
---|
21 | #include <QFile>
|
---|
22 | #include <QTextStream>
|
---|
23 | #include "colorutils.h"
|
---|
24 |
|
---|
25 | AssStyles::AssStyles() {
|
---|
26 | fontname = "Arial";
|
---|
27 | fontsize = 20;
|
---|
28 | primarycolor = QColor("#FFFFFF");
|
---|
29 | backcolor = QColor("#000000");
|
---|
30 | outlinecolor = QColor("#000000");
|
---|
31 | bold = false;
|
---|
32 | italic = false;
|
---|
33 | halignment = HCenter;
|
---|
34 | valignment = Bottom;
|
---|
35 | borderstyle = Outline;
|
---|
36 | outline = 0.3;
|
---|
37 | shadow = 1;
|
---|
38 | marginl = 20;
|
---|
39 | marginr = 20;
|
---|
40 | marginv = 8;
|
---|
41 | }
|
---|
42 |
|
---|
43 | void AssStyles::save(QSettings * set) {
|
---|
44 | qDebug("AssStyles::save");
|
---|
45 |
|
---|
46 | set->setValue("styles/fontname", fontname);
|
---|
47 | set->setValue("styles/fontsize", fontsize);
|
---|
48 | set->setValue("styles/primarycolor/argb", ColorUtils::colorToAARRGGBB(primarycolor));
|
---|
49 | set->setValue("styles/backcolor/argb", ColorUtils::colorToAARRGGBB(backcolor));
|
---|
50 | set->setValue("styles/outlinecolor/argb", ColorUtils::colorToAARRGGBB(outlinecolor));
|
---|
51 | set->setValue("styles/bold", bold);
|
---|
52 | set->setValue("styles/italic", italic);
|
---|
53 | set->setValue("styles/halignment", halignment);
|
---|
54 | set->setValue("styles/valignment", valignment);
|
---|
55 | set->setValue("styles/borderstyle", borderstyle);
|
---|
56 | set->setValue("styles/outline", outline);
|
---|
57 | set->setValue("styles/shadow", shadow);
|
---|
58 | set->setValue("styles/marginl", marginl);
|
---|
59 | set->setValue("styles/marginr", marginr);
|
---|
60 | set->setValue("styles/marginv", marginv);
|
---|
61 | }
|
---|
62 |
|
---|
63 | void AssStyles::load(QSettings * set) {
|
---|
64 | qDebug("AssStyles::load");
|
---|
65 |
|
---|
66 | fontname = set->value("styles/fontname", fontname).toString();
|
---|
67 | fontsize = set->value("styles/fontsize", fontsize).toInt();
|
---|
68 |
|
---|
69 | primarycolor = ColorUtils::AARRGGBBToColor(set->value("styles/primarycolor/argb", "#FFFFFFFF").toString());
|
---|
70 | backcolor = ColorUtils::AARRGGBBToColor(set->value("styles/backcolor/argb", "#FF000000").toString());
|
---|
71 | outlinecolor = ColorUtils::AARRGGBBToColor(set->value("styles/outlinecolor/argb", "#FF000000").toString());
|
---|
72 |
|
---|
73 | bold = set->value("styles/bold", bold).toBool();
|
---|
74 | italic = set->value("styles/italic", italic).toBool();
|
---|
75 | halignment = set->value("styles/halignment", halignment).toInt();
|
---|
76 | valignment = set->value("styles/valignment", valignment).toInt();
|
---|
77 | borderstyle = set->value("styles/borderstyle", borderstyle).toInt();
|
---|
78 | outline = set->value("styles/outline", outline).toDouble();
|
---|
79 | shadow = set->value("styles/shadow", shadow).toDouble();
|
---|
80 | marginl = set->value("styles/marginl", marginl).toInt();
|
---|
81 | marginr = set->value("styles/marginr", marginr).toInt();
|
---|
82 | marginv = set->value("styles/marginv", marginv).toInt();
|
---|
83 | }
|
---|
84 |
|
---|
85 | bool AssStyles::exportStyles(const QString & filename) const {
|
---|
86 | qDebug("AssStyles::exportStyles: filename: %s", filename.toUtf8().constData());
|
---|
87 |
|
---|
88 | QFile f(filename);
|
---|
89 | if (f.open(QFile::WriteOnly)) {
|
---|
90 | QTextStream out(&f);
|
---|
91 |
|
---|
92 | int alignment = halignment;
|
---|
93 | if (valignment == 1) alignment += 3; // Middle
|
---|
94 | else
|
---|
95 | if (valignment == 2) alignment += 6; // Top
|
---|
96 |
|
---|
97 | out << "[Script Info]" << endl;
|
---|
98 | out << "ScriptType: v4.00+" << endl;
|
---|
99 | out << "Collisions: Normal" << endl;
|
---|
100 | out << endl;
|
---|
101 | out << "[V4+ Styles]" << endl;
|
---|
102 | out << "Format: Name, Fontname, Fontsize, PrimaryColour, BackColour, OutlineColour, Bold, Italic, Alignment, BorderStyle, Outline, Shadow, MarginL, MarginR, MarginV" << endl;
|
---|
103 | out << "Style: Default,";
|
---|
104 | out << fontname << "," ;
|
---|
105 | out << fontsize << "," ;
|
---|
106 | out << "&H" << ColorUtils::colorToAABBGGRR(primarycolor) << "," ;
|
---|
107 | out << "&H" << ColorUtils::colorToAABBGGRR(backcolor) << "," ;
|
---|
108 | out << "&H" << ColorUtils::colorToAABBGGRR(outlinecolor) << "," ;
|
---|
109 | out << (bold ? -1 : 0) << "," ;
|
---|
110 | out << (italic ? -1 : 0) << "," ;
|
---|
111 | out << alignment << "," ;
|
---|
112 | out << borderstyle << "," ;
|
---|
113 | out << outline << "," ;
|
---|
114 | out << shadow << "," ;
|
---|
115 | out << marginl << "," ;
|
---|
116 | out << marginr << "," ;
|
---|
117 | out << marginv;
|
---|
118 | out << endl;
|
---|
119 |
|
---|
120 | f.close();
|
---|
121 | return true;
|
---|
122 | }
|
---|
123 | return false;
|
---|
124 | }
|
---|
125 |
|
---|
126 | // Returns a string for -ass-force-style
|
---|
127 | // It seems that option ignores "ScriptType: v4.00+"
|
---|
128 | // so the function uses the v4.00 format
|
---|
129 | QString AssStyles::toString() {
|
---|
130 | int alignment = halignment;
|
---|
131 | if (valignment == 1) alignment += 8; // Middle
|
---|
132 | else
|
---|
133 | if (valignment == 2) alignment += 4; // Top
|
---|
134 |
|
---|
135 | QString s = "PlayResX=512,PlayResY=320,"; // Aspect of 1.6, it doesn't look too bad either in 4:3 and 16:9
|
---|
136 |
|
---|
137 | s += QString("Name=Default,Fontname=%1,Fontsize=%2,PrimaryColour=&H%3,BackColour=&H%4,"
|
---|
138 | "OutlineColour=&H%5,Bold=%6,Italic=%7,Alignment=%8,BorderStyle=%9,")
|
---|
139 | .arg(fontname).arg(fontsize).arg(ColorUtils::colorToAABBGGRR(primarycolor))
|
---|
140 | .arg(ColorUtils::colorToAABBGGRR(backcolor))
|
---|
141 | .arg(ColorUtils::colorToAABBGGRR(outlinecolor))
|
---|
142 | .arg(bold ? 1 : 0).arg(italic ? 1 : 0)
|
---|
143 | .arg(alignment).arg(borderstyle);
|
---|
144 |
|
---|
145 | s += QString("Outline=%1,Shadow=%2,MarginL=%3,MarginR=%4,MarginV=%5")
|
---|
146 | .arg(outline).arg(shadow).arg(marginl).arg(marginr).arg(marginv);
|
---|
147 |
|
---|
148 |
|
---|
149 | return s;
|
---|
150 | }
|
---|