1
/* smplayer, GUI front-end for mplayer.
2
Copyright (C) 2006-2009 Ricardo Villalba <rvm@escomposlinux.org>
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.
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.
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
19
#include "assstyles.h"
22
#include <QTextStream>
23
#include "colorutils.h"
25
AssStyles::AssStyles() {
28
primarycolor = 0xFFFFFF;
33
halignment = 2; // Centered
34
valignment = 0; // Bottom
35
borderstyle = 1; // Outline
43
void AssStyles::save(QSettings * set) {
44
qDebug("AssStyles::save");
46
set->setValue("styles/fontname", fontname);
47
set->setValue("styles/fontsize", fontsize);
48
set->setValue("styles/primarycolor", primarycolor);
49
set->setValue("styles/backcolor", backcolor);
50
set->setValue("styles/outlinecolor", 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);
63
void AssStyles::load(QSettings * set) {
64
qDebug("AssStyles::load");
66
fontname = set->value("styles/fontname", fontname).toString();
67
fontsize = set->value("styles/fontsize", fontsize).toInt();
68
primarycolor = set->value("styles/primarycolor", primarycolor).toInt();
69
backcolor = set->value("styles/backcolor", backcolor).toInt();
70
outlinecolor = set->value("styles/outlinecolor", outlinecolor).toInt();
71
bold = set->value("styles/bold", bold).toBool();
72
italic = set->value("styles/italic", italic).toBool();
73
halignment = set->value("styles/halignment", halignment).toInt();
74
valignment = set->value("styles/valignment", valignment).toInt();
75
borderstyle = set->value("styles/borderstyle", borderstyle).toInt();
76
outline = set->value("styles/outline", outline).toDouble();
77
shadow = set->value("styles/shadow", shadow).toDouble();
78
marginl = set->value("styles/marginl", marginl).toInt();
79
marginr = set->value("styles/marginr", marginr).toInt();
80
marginv = set->value("styles/marginv", marginv).toInt();
83
bool AssStyles::exportStyles(const QString & filename) {
84
qDebug("AssStyles::exportStyles: filename: %s", filename.toUtf8().constData());
87
if (f.open(QFile::WriteOnly)) {
90
int alignment = halignment;
91
if (valignment == 1) alignment += 3; // Middle
93
if (valignment == 2) alignment += 6; // Top
95
out << "[Script Info]" << endl;
96
out << "ScriptType: v4.00+" << endl;
97
out << "Collisions: Normal" << endl;
99
out << "[V4+ Styles]" << endl;
100
out << "Format: Name, Fontname, Fontsize, PrimaryColour, BackColour, OutlineColour, Bold, Italic, Alignment, BorderStyle, Outline, Shadow, MarginL, MarginR, MarginV" << endl;
101
out << "Style: Default,";
102
out << fontname << "," ;
103
out << fontsize << "," ;
104
out << "&H" << ColorUtils::colorToAABBGGRR(primarycolor) << "," ;
105
out << "&H" << ColorUtils::colorToAABBGGRR(backcolor) << "," ;
106
out << "&H" << ColorUtils::colorToAABBGGRR(outlinecolor) << "," ;
107
out << (bold ? -1 : 0) << "," ;
108
out << (italic ? -1 : 0) << "," ;
109
out << alignment << "," ;
110
out << borderstyle << "," ;
111
out << outline << "," ;
112
out << shadow << "," ;
113
out << marginl << "," ;
114
out << marginr << "," ;
124
// Returns a string for -ass-force-style
125
// It seems that option ignores "ScriptType: v4.00+"
126
// so the function uses the v4.00 format
127
QString AssStyles::toString() {
128
int alignment = halignment;
129
if (valignment == 1) alignment += 8; // Middle
131
if (valignment == 2) alignment += 4; // Top
133
QString s = "PlayResX=512,PlayResY=320,"; // Aspect of 1.6, it doesn't look too bad either in 4:3 and 16:9
135
s += QString("Name=Default,Fontname=%1,Fontsize=%2,PrimaryColour=&H%3,BackColour=&H%4,"
136
"OutlineColour=&H%5,Bold=%6,Italic=%7,Alignment=%8,BorderStyle=%9,")
137
.arg(fontname).arg(fontsize).arg(ColorUtils::colorToAABBGGRR(primarycolor))
138
.arg(ColorUtils::colorToAABBGGRR(backcolor))
139
.arg(ColorUtils::colorToAABBGGRR(outlinecolor))
140
.arg(bold ? 1 : 0).arg(italic ? 1 : 0)
141
.arg(alignment).arg(borderstyle);
143
s += QString("Outline=%1,Shadow=%2,MarginL=%3,MarginR=%4,MarginV=%5")
144
.arg(outline).arg(shadow).arg(marginl).arg(marginr).arg(marginv);