summaryrefslogtreecommitdiffstats
path: root/kivio/kiviopart/kiviosdk/kivio_text_style.cpp
blob: 28044f39b4549ab953052ffe304290f4b228c51a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "kivio_common.h"
#include "kivio_text_style.h"
#include <tqdom.h>
#include <tqpainter.h>
#include <KoGlobal.h>

KivioTextStyle::KivioTextStyle()
{
    m_text = "";
    m_color = TQColor(0,0,0);
    m_hTextAlign = TQt::AlignHCenter;
    m_vTextAlign = TQt::AlignVCenter;
    m_isHtml = false;
    //m_font = TQFont("times",12);
    m_font = KoGlobal::defaultFont();
}

KivioTextStyle::~KivioTextStyle()
{
}

void KivioTextStyle::copyInto( KivioTextStyle *pTarget )
{
    pTarget->m_text = m_text;
    pTarget->m_color = m_color;
    pTarget->m_hTextAlign = m_hTextAlign;
    pTarget->m_vTextAlign = m_vTextAlign;
    pTarget->m_isHtml = m_isHtml;
    pTarget->m_font = m_font;
}

TQDomElement KivioTextStyle::saveXML( TQDomDocument &doc )
{
    TQDomElement textE = doc.createElement("KivioTextStyle");

    XmlWriteString( textE, "text", m_text );
    XmlWriteInt( textE, "isHtml", m_isHtml );
    XmlWriteInt( textE, "hTextAlign", m_hTextAlign );
    XmlWriteInt( textE, "vTextAlign", m_vTextAlign );

    // Text font & color
    TQDomElement innerTextE = doc.createElement("Font");
    XmlWriteColor( innerTextE, "color",   m_color );
    XmlWriteString( innerTextE, "family", m_font.family() );
    XmlWriteInt( innerTextE, "size",      m_font.pointSize() );
    XmlWriteInt( innerTextE, "bold",      m_font.bold() );
    XmlWriteInt( innerTextE, "italic",    m_font.italic() );
    XmlWriteInt( innerTextE, "underline", m_font.underline() );
    XmlWriteInt( innerTextE, "strikeOut", m_font.strikeOut() );
    XmlWriteInt( innerTextE, "fixedPitch", m_font.fixedPitch() );

    textE.appendChild( innerTextE );

    return textE;
}

bool KivioTextStyle::loadXML( const TQDomElement &e )
{
    m_text = XmlReadString( e, "text", "" );
    m_isHtml = (bool)XmlReadInt( e, "isHtml", (int)false );

    m_hTextAlign = XmlReadInt( e, "hTextAlign", TQt::AlignHCenter );
    m_vTextAlign = XmlReadInt( e, "vTextAlign", TQt::AlignVCenter );

    // Search for the font
    TQDomNode innerNode = e.firstChild();
    while( !innerNode.isNull() )
    {
        TQString innerName = innerNode.nodeName();
        TQDomElement innerE = innerNode.toElement();

        if( innerName == "Font" )
        {
            m_font.setFamily( XmlReadString(innerE, "family", "times") );
            m_font.setPointSize( XmlReadInt(innerE, "size", 12 ) );
            m_font.setBold( (bool)XmlReadInt( innerE, "bold", 12 ) );
            m_font.setItalic( (bool)XmlReadInt( innerE, "italic", 12 ) );
            m_font.setUnderline( (bool)XmlReadInt( innerE, "underline", 12 ) );
            m_font.setStrikeOut( (bool)XmlReadInt( innerE, "strikeOut", 12 ) );
            m_font.setFixedPitch( (bool)XmlReadInt( innerE, "fixedPitch", false ) );
            m_color = XmlReadColor( innerE, "color", TQColor(0,0,0) );
        }

        innerNode = innerNode.nextSibling();
    }

    return true;
}