kivio_text_style.cpp
1#include "kivio_common.h"
2#include "kivio_text_style.h"
3#include <tqdom.h>
4#include <tqpainter.h>
5#include <KoGlobal.h>
6
7KivioTextStyle::KivioTextStyle()
8{
9 m_text = "";
10 m_color = TQColor(0,0,0);
11 m_hTextAlign = TQt::AlignHCenter;
12 m_vTextAlign = TQt::AlignVCenter;
13 m_isHtml = false;
14 //m_font = TQFont("times",12);
15 m_font = KoGlobal::defaultFont();
16}
17
18KivioTextStyle::~KivioTextStyle()
19{
20}
21
22void KivioTextStyle::copyInto( KivioTextStyle *pTarget )
23{
24 pTarget->m_text = m_text;
25 pTarget->m_color = m_color;
26 pTarget->m_hTextAlign = m_hTextAlign;
27 pTarget->m_vTextAlign = m_vTextAlign;
28 pTarget->m_isHtml = m_isHtml;
29 pTarget->m_font = m_font;
30}
31
32TQDomElement KivioTextStyle::saveXML( TQDomDocument &doc )
33{
34 TQDomElement textE = doc.createElement("KivioTextStyle");
35
36 XmlWriteString( textE, "text", m_text );
37 XmlWriteInt( textE, "isHtml", m_isHtml );
38 XmlWriteInt( textE, "hTextAlign", m_hTextAlign );
39 XmlWriteInt( textE, "vTextAlign", m_vTextAlign );
40
41 // Text font & color
42 TQDomElement innerTextE = doc.createElement("Font");
43 XmlWriteColor( innerTextE, "color", m_color );
44 XmlWriteString( innerTextE, "family", m_font.family() );
45 XmlWriteInt( innerTextE, "size", m_font.pointSize() );
46 XmlWriteInt( innerTextE, "bold", m_font.bold() );
47 XmlWriteInt( innerTextE, "italic", m_font.italic() );
48 XmlWriteInt( innerTextE, "underline", m_font.underline() );
49 XmlWriteInt( innerTextE, "strikeOut", m_font.strikeOut() );
50 XmlWriteInt( innerTextE, "fixedPitch", m_font.fixedPitch() );
51
52 textE.appendChild( innerTextE );
53
54 return textE;
55}
56
57bool KivioTextStyle::loadXML( const TQDomElement &e )
58{
59 m_text = XmlReadString( e, "text", "" );
60 m_isHtml = (bool)XmlReadInt( e, "isHtml", (int)false );
61
62 m_hTextAlign = XmlReadInt( e, "hTextAlign", TQt::AlignHCenter );
63 m_vTextAlign = XmlReadInt( e, "vTextAlign", TQt::AlignVCenter );
64
65 // Search for the font
66 TQDomNode innerNode = e.firstChild();
67 while( !innerNode.isNull() )
68 {
69 TQString innerName = innerNode.nodeName();
70 TQDomElement innerE = innerNode.toElement();
71
72 if( innerName == "Font" )
73 {
74 m_font.setFamily( XmlReadString(innerE, "family", "times") );
75 m_font.setPointSize( XmlReadInt(innerE, "size", 12 ) );
76 m_font.setBold( (bool)XmlReadInt( innerE, "bold", 12 ) );
77 m_font.setItalic( (bool)XmlReadInt( innerE, "italic", 12 ) );
78 m_font.setUnderline( (bool)XmlReadInt( innerE, "underline", 12 ) );
79 m_font.setStrikeOut( (bool)XmlReadInt( innerE, "strikeOut", 12 ) );
80 m_font.setFixedPitch( (bool)XmlReadInt( innerE, "fixedPitch", false ) );
81 m_color = XmlReadColor( innerE, "color", TQColor(0,0,0) );
82 }
83
84 innerNode = innerNode.nextSibling();
85 }
86
87 return true;
88}