kivio

kivio_line_style.cpp

00001 /*
00002  * Kivio - Visual Modelling and Flowcharting
00003  * Copyright (C) 2000-2001 theKompany.com & Dave Marotti
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00018  */
00019 #include "kivio_common.h"
00020 #include "kivio_line_style.h"
00021 
00022 KivioLineStyle::KivioLineStyle()
00023 {
00024     m_color = QColor(0,0,0);
00025     m_width = 1.0f;
00026     m_capStyle = Qt::FlatCap;
00027     m_joinStyle = Qt::RoundJoin;
00028     m_style = Qt::SolidLine;
00029 }
00030 
00031 KivioLineStyle::KivioLineStyle( const KivioLineStyle &ls )
00032 {
00033     m_color     = ls.color();
00034     m_width     = ls.width();
00035     m_capStyle  = ls.capStyle();
00036     m_joinStyle = ls.joinStyle();
00037     m_style = ls.style();
00038 }
00039 
00040 KivioLineStyle::~KivioLineStyle()
00041 {
00042 }
00043 
00044 void KivioLineStyle::copyInto( KivioLineStyle *pTarget )
00045 {
00046     pTarget->m_color     = m_color;
00047     pTarget->m_width     = m_width;
00048     pTarget->m_capStyle  = m_capStyle;
00049     pTarget->m_joinStyle = m_joinStyle;
00050     pTarget->m_style     = m_style;
00051 }
00052 
00053 QDomElement KivioLineStyle::saveXML( QDomDocument &doc )
00054 {
00055     QDomElement e = doc.createElement("KivioLineStyle");
00056 
00057     XmlWriteColor( e, "color",     m_color );
00058     XmlWriteFloat( e, "width",     m_width );
00059     XmlWriteInt(   e, "capStyle",  m_capStyle );
00060     XmlWriteInt(   e, "joinStyle", m_joinStyle );
00061     XmlWriteInt(   e, "pattern",   m_style );
00062     return e;
00063 }
00064 
00065 bool KivioLineStyle::loadXML( const QDomElement &e )
00066 {
00067     m_color     = XmlReadColor( e, "color",     QColor(0,0,0) );
00068     m_width     = XmlReadFloat( e, "width",     1.0f );
00069     m_capStyle  = XmlReadInt(   e, "capStyle",  Qt::RoundCap );
00070     m_joinStyle = XmlReadInt(   e, "joinStyle", Qt::RoundJoin );
00071     m_style     = XmlReadInt(   e, "pattern",   Qt::SolidLine );
00072     return true;
00073 }
00074 
00075 QPen KivioLineStyle::pen( float scale ) const
00076 {
00077     QPen p;
00078     float s = m_width * scale;
00079 
00080     p.setColor( m_color );
00081     p.setWidth( (int)s );
00082     p.setJoinStyle( (Qt::PenJoinStyle)m_joinStyle );
00083     p.setCapStyle( (Qt::PenCapStyle)m_capStyle );
00084     p.setStyle( (Qt::PenStyle)m_style );
00085 
00086     return p;
00087 }
KDE Home | KDE Accessibility Home | Description of Access Keys