filters
ImportStyle.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <qfontinfo.h>
00021
00022 #include <kglobalsettings.h>
00023 #include <kdebug.h>
00024
00025 #include <KoGlobal.h>
00026
00027 #include "ImportStyle.h"
00028
00029 StyleData::StyleData(void): m_level(-1)
00030 {
00031 }
00032
00033 StyleDataMap::StyleDataMap(void)
00034 {
00035 }
00036
00037 QString StyleDataMap::getDefaultStyle(void)
00038 {
00039
00040 QFontInfo fontInfo(KoGlobal::defaultFont());
00041 QString strReturn;
00042
00043 strReturn += "font-family:";
00044 strReturn += fontInfo.family();
00045 strReturn += "; font-size: 12pt;";
00046
00047
00048 return strReturn;
00049 }
00050
00051 void StyleDataMap::defineNewStyleFromOld(const QString& strName, const QString& strOld,
00052 const int level, const QString& strProps)
00053 {
00054 if (strOld.isEmpty())
00055 {
00056 defineNewStyle(strName,level,strProps);
00057 return;
00058 }
00059
00060 StyleDataMap::Iterator it=find(strOld);
00061 if (it==end())
00062 {
00063 defineNewStyle(strName,level,strProps);
00064 }
00065 else
00066 {
00067 QString strAllProps=it.data().m_props;
00068 strAllProps+=strProps;
00069 defineNewStyle(strName,level,strAllProps);
00070 }
00071 }
00072
00073
00074 void StyleDataMap::defineNewStyle(const QString& strName, const int level,
00075 const QString& strProps)
00076 {
00077
00078
00079 StyleDataMap::Iterator it=find(strName);
00080 if (it==end())
00081 {
00082
00083 it=insert(strName,StyleData());
00084 }
00085 StyleData& styleData=it.data();
00086 styleData.m_level=level;
00087 styleData.m_props+=getDefaultStyle();
00088 if (!strProps.isEmpty())
00089 {
00090 styleData.m_props+=strProps;
00091 styleData.m_props+=";";
00092 }
00093 }
00094
00095 StyleDataMap::Iterator StyleDataMap::useOrCreateStyle(const QString& strName)
00096 {
00097
00098 StyleDataMap::Iterator it=find(strName);
00099 if (it==end())
00100 {
00101
00102 StyleData data;
00103 data.m_level=-1;
00104 data.m_props=getDefaultStyle();
00105 it=insert(strName,data);
00106 }
00107 return it;
00108 }
00109
00110 void StyleDataMap::defineDefaultStyles(void)
00111 {
00112
00113
00114 defineNewStyle("Normal",-1,QString::null);
00115
00116
00117 QString strHeading("font-weight: bold; margin-top: 22pt; margin-bottom: 3pt; ");
00118 defineNewStyle("Heading 1",1,strHeading+"font-size: 17pt");
00119 defineNewStyle("Heading 2",2,strHeading+"font-size: 14pt");
00120 defineNewStyle("Heading 3",3,strHeading+"font-size: 12pt");
00121 defineNewStyle("Block Text",-1,"margin-left: 1in; margin-right: 1in; margin-bottom: 6pt");
00122 QFontInfo fixedInfo(KGlobalSettings::fixedFont());
00123 QString strPlainText=QString("font-family: %1")
00124 .arg(fixedInfo.family());
00125 kdDebug(30506) << "Plain Text: " << strPlainText << endl;
00126 defineNewStyle("Plain Text",-1,strPlainText);
00127
00128 }
|