| 1 | /* smplayer, GUI front-end for mplayer.
|
|---|
| 2 | Copyright (C) 2006-2010 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 | #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 = 0xFFFFFF;
|
|---|
| 29 | backcolor = 0;
|
|---|
| 30 | outlinecolor = 0;
|
|---|
| 31 | bold = false;
|
|---|
| 32 | italic = false;
|
|---|
| 33 | halignment = 2; // Centered
|
|---|
| 34 | valignment = 0; // Bottom
|
|---|
| 35 | borderstyle = 1; // Outline
|
|---|
| 36 | outline = 1;
|
|---|
| 37 | shadow = 2;
|
|---|
| 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", 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);
|
|---|
| 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 | 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();
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | bool AssStyles::exportStyles(const QString & filename) {
|
|---|
| 84 | qDebug("AssStyles::exportStyles: filename: %s", filename.toUtf8().constData());
|
|---|
| 85 |
|
|---|
| 86 | QFile f(filename);
|
|---|
| 87 | if (f.open(QFile::WriteOnly)) {
|
|---|
| 88 | QTextStream out(&f);
|
|---|
| 89 |
|
|---|
| 90 | int alignment = halignment;
|
|---|
| 91 | if (valignment == 1) alignment += 3; // Middle
|
|---|
| 92 | else
|
|---|
| 93 | if (valignment == 2) alignment += 6; // Top
|
|---|
| 94 |
|
|---|
| 95 | out << "[Script Info]" << endl;
|
|---|
| 96 | out << "ScriptType: v4.00+" << endl;
|
|---|
| 97 | out << "Collisions: Normal" << endl;
|
|---|
| 98 | out << 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 << "," ;
|
|---|
| 115 | out << marginv;
|
|---|
| 116 | out << endl;
|
|---|
| 117 |
|
|---|
| 118 | f.close();
|
|---|
| 119 | return true;
|
|---|
| 120 | }
|
|---|
| 121 | return false;
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 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
|
|---|
| 130 | else
|
|---|
| 131 | if (valignment == 2) alignment += 4; // Top
|
|---|
| 132 |
|
|---|
| 133 | QString s = "PlayResX=512,PlayResY=320,"; // Aspect of 1.6, it doesn't look too bad either in 4:3 and 16:9
|
|---|
| 134 |
|
|---|
| 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);
|
|---|
| 142 |
|
|---|
| 143 | s += QString("Outline=%1,Shadow=%2,MarginL=%3,MarginR=%4,MarginV=%5")
|
|---|
| 144 | .arg(outline).arg(shadow).arg(marginl).arg(marginr).arg(marginv);
|
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 | return s;
|
|---|
| 148 | }
|
|---|