23#include "vselection.h"
27#include "vdashpattern.h"
31#include <KoPageLayout.h>
32#include <KoXmlWriter.h>
38 m_width(0.), m_height(0.),
40 m_unit( KoUnit::U_MM )
45 m_layers.setAutoDelete(
true );
46 m_layers.append(
new VLayer(
this ) );
47 m_activeLayer = m_layers.getLast();
48 m_activeLayer->setSelected(
true );
62 delete( m_selection );
68 p->setPen( TQt::black );
69 p->setBrush( TQt::white );
70 p->drawRect( 0, 0, m_width, m_height );
72 p->setPen( TQt::NoPen );
73 p->setBrush( TQt::black );
74 p->drawRect( m_width, - 2, 2, m_height );
75 p->drawRect( 0, - 2, m_width, 2 );
78 if( m_gridData.isShow )
81 s.setColor( m_gridData.color );
82 double dx = m_gridData.freq.width();
83 double dy = m_gridData.freq.height();
85 p->setBrush( TQt::NoBrush );
87 while( p0.x() < m_width )
90 p->moveTo( KoPoint( p0.x(), 0 ) );
91 p->lineTo( KoPoint( p0.x(), m_height ) );
96 while( p0.y() < m_height )
99 p->moveTo( KoPoint( 0, p0.y() ) );
100 p->lineTo( KoPoint( m_width, p0.y() ) );
107 if( showPageMargins )
109 int ml = int( pl.ptLeft );
110 int mt = int( pl.ptTop );
111 int mr = int( pl.ptRight );
112 int mb = int( pl.ptBottom );
115 s.setColor( TQt::blue );
116 TQValueList<float> dashes;
117 s.dashPattern().setArray( dashes << 5 << 5 );
119 p->setBrush( TQt::NoBrush );
120 p->drawRect(ml, mt, m_width-ml-mr, m_height-mt-mb);
127 TQPtrListIterator<VLayer> itr = m_layers;
129 for ( ; itr.current(); ++itr )
131 itr.current()->draw( painter, rect );
139 m_layers.append( layer );
140 m_activeLayer = layer;
146 m_layers.remove( layer );
147 if ( m_layers.count() == 0 )
149 m_activeLayer = m_layers.getLast();
154 int pos = m_layers.find( layer );
155 return (pos !=
int( m_layers.count() ) - 1 && pos >= 0 );
160 int pos = m_layers.find( layer );
167 int pos = m_layers.find( layer );
168 if( pos !=
int( m_layers.count() ) - 1 && pos >= 0 )
171 m_layers.insert( pos + 1, layer );
178 int pos = m_layers.find( layer );
182 m_layers.insert( pos - 1, layer );
189 return m_layers.find( layer );
195 if ( m_layers.find( layer ) != -1 )
196 m_activeLayer = layer;
202 m_activeLayer->
append(
object );
206VDocument::saveXML()
const
209 TQDomElement me = doc.createElement(
"DOC" );
210 doc.appendChild( me );
216VDocument::saveOasis( KoStore *store, KoXmlWriter *docWriter, KoGenStyles &mainStyles )
const
218 docWriter->startElement(
"draw:page" );
219 docWriter->addAttribute(
"draw:name",
name());
220 docWriter->addAttribute(
"draw:id",
"page1");
221 docWriter->addAttribute(
"draw:master-page-name",
"Default");
224 VLayerListIterator itr( m_layers );
227 for ( ; itr.current(); ++itr )
228 itr.current()->saveOasis( store, docWriter, mainStyles, ++index );
230 docWriter->endElement();
236 me.setAttribute(
"mime",
"application/x-karbon" ),
237 me.setAttribute(
"version",
"0.1" );
238 me.setAttribute(
"editor",
"Karbon14" );
239 me.setAttribute(
"syntaxVersion",
"0.1" );
241 me.setAttribute(
"width", m_width );
243 me.setAttribute(
"height", m_height );
244 me.setAttribute(
"unit", KoUnit::unitName( m_unit ) );
247 VLayerListIterator itr( m_layers );
249 for ( ; itr.current(); ++itr )
250 itr.current()->save( me );
267VDocument::loadXML(
const TQDomElement& doc )
269 if( doc.attribute(
"mime" ) !=
"application/x-karbon" ||
270 doc.attribute(
"syntaxVersion" ) !=
"0.1" )
277 m_width = doc.attribute(
"width",
"800.0" ).toDouble();
278 m_height = doc.attribute(
"height",
"550.0" ).toDouble();
280 m_unit = KoUnit::unit( doc.attribute(
"unit", KoUnit::unitName( m_unit ) ) );
282 loadDocumentContent( doc );
287VDocument::loadDocumentContent(
const TQDomElement& doc )
289 TQDomNodeList list = doc.childNodes();
290 for( uint i = 0; i < list.count(); ++i )
292 if( list.item( i ).isElement() )
294 TQDomElement e = list.item( i ).toElement();
296 if( e.tagName() ==
"LAYER" )
298 VLayer* layer =
new VLayer(
this );
309 return m_layers.current()->loadOasis( element, context );
321 TQMap<const VObject *, TQString>::ConstIterator it = m_objectNames.find( obj );
322 return it == m_objectNames.end() ? 0L : it.data();
All non-visual, static doc info is in here.
int layerPos(VLayer *layer)
Returns the position of the specified layer.
bool canLowerLayer(VLayer *layer)
Checks if specified layer can be lowered.
VDocument()
Constructs a new document.
void setActiveLayer(VLayer *layer)
Sets the active layer.
virtual void save(TQDomElement &element) const
Save this object's state to xml.
virtual VDocument * clone() const
Create an exact copy of this object.
void drawPage(VPainter *painter, const KoPageLayout &pl, bool drawPageMargins) const
Draw the document frame to a painting device.
void lowerLayer(VLayer *layer)
Lowers the layer.
void removeLayer(VLayer *layer)
Removes the layer.
virtual void load(const TQDomElement &element)
Load this object's state from xml and initialize this object accordingly.
bool canRaiseLayer(VLayer *layer)
Checks if specified layer can be raised.
virtual ~VDocument()
Destroys the document and all of the layers.
virtual bool loadOasis(const TQDomElement &element, KoOasisLoadingContext &context)
Load this object's state from OpenDocument and initialize this object accordingly.
@ ActiveLayer
selection within the active layer
virtual void draw(VPainter *painter, const KoRect *rect) const
Draw the object to a painting device.
virtual void accept(VVisitor &visitor)
Accept a VVisitor.
void append(VObject *object)
Appends a new object to the active layer.
TQString objectName(const VObject *obj) const
Returns custom name of specified object.
void raiseLayer(VLayer *layer)
Raises the layer.
void insertLayer(VLayer *layer)
Inserts a new layer.
void take(const VObject &object)
Removes the reference to child object, not the object itself.
void append(VObject *object)
Appends a new child object.
VLayer manages a set of vobjects.
virtual void load(const TQDomElement &element)
Load this object's state from xml and initialize this object accordingly.
VObject(VObject *parent, VState state=edit)
Constructs a new object that is child of parent and has the given state.
virtual TQString name() const
Returns the name of the object.
VDocument * document() const
Return document the object belongs to.
VSelection manages a set of selected vobjects.
Manages stroke properties.
The abstract visitor class.
virtual void visitVDocument(VDocument &document)
Visit method for a VDocument.