00001 /*************************************************************************** 00002 * file klfstyle.cpp 00003 * This file is part of the KLatexFormula Project. 00004 * Copyright (C) 2010 by Philippe Faist 00005 * philippe.faist at bluewin.ch 00006 * * 00007 * This program is free software; you can redistribute it and/or modify * 00008 * it under the terms of the GNU General Public License as published by * 00009 * the Free Software Foundation; either version 2 of the License, or * 00010 * (at your option) any later version. * 00011 * * 00012 * This program is distributed in the hope that it will be useful, * 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00015 * GNU General Public License for more details. * 00016 * * 00017 * You should have received a copy of the GNU General Public License * 00018 * along with this program; if not, write to the * 00019 * Free Software Foundation, Inc., * 00020 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00021 ***************************************************************************/ 00022 /* $Id: klfstyle.cpp 464 2010-08-28 22:48:32Z philippe $ */ 00023 00024 #include <QColor> 00025 00026 #include "klfstyle.h" 00027 00028 00029 KLF_EXPORT QDataStream& operator<<(QDataStream& stream, const KLFStyle::BBoxExpand& b) 00030 { 00031 return stream << b.top << b.right << b.bottom << b.left; 00032 } 00033 00034 KLF_EXPORT QDataStream& operator>>(QDataStream& stream, KLFStyle::BBoxExpand& b) 00035 { 00036 return stream >> b.top >> b.right >> b.bottom >> b.left; 00037 } 00038 00039 00040 KLF_EXPORT QDataStream& operator<<(QDataStream& stream, const KLFStyle& style) 00041 { 00042 // yes, QIODevice inherits QObject and we can use dynamic properties... 00043 QString compat_klfversion = stream.device()->property("klfDataStreamAppVersion").toString(); 00044 if (klfVersionCompare(compat_klfversion, "3.1") <= 0) 00045 return stream << style.name << (quint32)style.fg_color << (quint32)style.bg_color 00046 << style.mathmode << style.preamble << (quint16)style.dpi; 00047 else 00048 return stream << style.name << (quint32)style.fg_color << (quint32)style.bg_color 00049 << style.mathmode << style.preamble << (quint16)style.dpi 00050 << style.overrideBBoxExpand; 00051 } 00052 KLF_EXPORT QDataStream& operator>>(QDataStream& stream, KLFStyle& style) 00053 { 00054 QString compat_klfversion = stream.device()->property("klfDataStreamAppVersion").toString(); 00055 if (klfVersionCompare(compat_klfversion, "3.1") <= 0) { 00056 quint32 fg, bg; 00057 quint16 dpi; 00058 stream >> style.name; 00059 stream >> fg >> bg >> style.mathmode >> style.preamble >> dpi; 00060 style.fg_color = fg; 00061 style.bg_color = bg; 00062 style.dpi = dpi; 00063 return stream; 00064 } else { 00065 quint32 fg, bg; 00066 quint16 dpi; 00067 stream >> style.name; 00068 stream >> fg >> bg >> style.mathmode >> style.preamble >> dpi; 00069 style.fg_color = fg; 00070 style.bg_color = bg; 00071 style.dpi = dpi; 00072 stream >> style.overrideBBoxExpand; 00073 return stream; 00074 } 00075 } 00076 00077 KLF_EXPORT bool operator==(const KLFStyle& a, const KLFStyle& b) 00078 { 00079 return a.name == b.name && 00080 a.fg_color == b.fg_color && 00081 a.bg_color == b.bg_color && 00082 a.mathmode == b.mathmode && 00083 a.preamble == b.preamble && 00084 a.dpi == b.dpi && 00085 a.overrideBBoxExpand == b.overrideBBoxExpand; 00086 } 00087 00088 00089 // No longer needed with new KLFLibEntryEditor widget 00090 // 00091 // KLF_EXPORT QString prettyPrintStyle(const KLFStyle& sty) 00092 // { 00093 // QString s = ""; 00094 // if (sty.name != QString::null) 00095 // s = QObject::tr("<b>Style Name</b>: %1<br>").arg(sty.name); 00096 // return s + QObject::tr("<b>Math Mode</b>: %1<br>" 00097 // "<b>DPI Resolution</b>: %2<br>" 00098 // "<b>Foreground Color</b>: %3 <font color=\"%4\"><b>[SAMPLE]</b></font><br>" 00099 // "<b>Background is Transparent</b>: %5<br>" 00100 // "<b>Background Color</b>: %6 <font color=\"%7\"><b>[SAMPLE]</b></font><br>" 00101 // "<b>LaTeX Preamble:</b><br><pre>%8</pre>") 00102 // .arg(sty.mathmode) 00103 // .arg(sty.dpi) 00104 // .arg(QColor(sty.fg_color).name()).arg(QColor(sty.fg_color).name()) 00105 // .arg( (qAlpha(sty.bg_color) != 255) ? QObject::tr("YES") : QObject::tr("NO") ) 00106 // .arg(QColor(sty.bg_color).name()).arg(QColor(sty.bg_color).name()) 00107 // .arg(sty.preamble) 00108 // ; 00109 // } 00110 00111 00112 00113 00114 00115 00116