kivio

kivio_text_style.cpp

00001 #include "kivio_common.h"
00002 #include "kivio_text_style.h"
00003 #include <qdom.h>
00004 #include <qpainter.h>
00005 #include <KoGlobal.h>
00006 
00007 KivioTextStyle::KivioTextStyle()
00008 {
00009     m_text = "";
00010     m_color = QColor(0,0,0);
00011     m_hTextAlign = Qt::AlignHCenter;
00012     m_vTextAlign = Qt::AlignVCenter;
00013     m_isHtml = false;
00014     //m_font = QFont("times",12);
00015     m_font = KoGlobal::defaultFont();
00016 }
00017 
00018 KivioTextStyle::~KivioTextStyle()
00019 {
00020 }
00021 
00022 void KivioTextStyle::copyInto( KivioTextStyle *pTarget )
00023 {
00024     pTarget->m_text = m_text;
00025     pTarget->m_color = m_color;
00026     pTarget->m_hTextAlign = m_hTextAlign;
00027     pTarget->m_vTextAlign = m_vTextAlign;
00028     pTarget->m_isHtml = m_isHtml;
00029     pTarget->m_font = m_font;
00030 }
00031 
00032 QDomElement KivioTextStyle::saveXML( QDomDocument &doc )
00033 {
00034     QDomElement textE = doc.createElement("KivioTextStyle");
00035 
00036     XmlWriteString( textE, "text", m_text );
00037     XmlWriteInt( textE, "isHtml", m_isHtml );
00038     XmlWriteInt( textE, "hTextAlign", m_hTextAlign );
00039     XmlWriteInt( textE, "vTextAlign", m_vTextAlign );
00040 
00041     // Text font & color
00042     QDomElement innerTextE = doc.createElement("Font");
00043     XmlWriteColor( innerTextE, "color",   m_color );
00044     XmlWriteString( innerTextE, "family", m_font.family() );
00045     XmlWriteInt( innerTextE, "size",      m_font.pointSize() );
00046     XmlWriteInt( innerTextE, "bold",      m_font.bold() );
00047     XmlWriteInt( innerTextE, "italic",    m_font.italic() );
00048     XmlWriteInt( innerTextE, "underline", m_font.underline() );
00049     XmlWriteInt( innerTextE, "strikeOut", m_font.strikeOut() );
00050     XmlWriteInt( innerTextE, "fixedPitch", m_font.fixedPitch() );
00051 
00052     textE.appendChild( innerTextE );
00053 
00054     return textE;
00055 }
00056 
00057 bool KivioTextStyle::loadXML( const QDomElement &e )
00058 {
00059     m_text = XmlReadString( e, "text", "" );
00060     m_isHtml = (bool)XmlReadInt( e, "isHtml", (int)false );
00061 
00062     m_hTextAlign = XmlReadInt( e, "hTextAlign", Qt::AlignHCenter );
00063     m_vTextAlign = XmlReadInt( e, "vTextAlign", Qt::AlignVCenter );
00064 
00065     // Search for the font
00066     QDomNode innerNode = e.firstChild();
00067     while( !innerNode.isNull() )
00068     {
00069         QString innerName = innerNode.nodeName();
00070         QDomElement innerE = innerNode.toElement();
00071 
00072         if( innerName == "Font" )
00073         {
00074             m_font.setFamily( XmlReadString(innerE, "family", "times") );
00075             m_font.setPointSize( XmlReadInt(innerE, "size", 12 ) );
00076             m_font.setBold( (bool)XmlReadInt( innerE, "bold", 12 ) );
00077             m_font.setItalic( (bool)XmlReadInt( innerE, "italic", 12 ) );
00078             m_font.setUnderline( (bool)XmlReadInt( innerE, "underline", 12 ) );
00079             m_font.setStrikeOut( (bool)XmlReadInt( innerE, "strikeOut", 12 ) );
00080             m_font.setFixedPitch( (bool)XmlReadInt( innerE, "fixedPitch", false ) );
00081             m_color = XmlReadColor( innerE, "color", QColor(0,0,0) );
00082         }
00083 
00084         innerNode = innerNode.nextSibling();
00085     }
00086 
00087     return true;
00088 }
KDE Home | KDE Accessibility Home | Description of Access Keys