25#include <tqdrawutil.h>
30#include <tqptrstack.h>
32#include <tqmessagebox.h>
33#include <tqclipboard.h>
36#include <tqtextstream.h>
37#include <tqdragobject.h>
39#include <tqsortedlist.h>
40#include <tqvaluelist.h>
45#include <tdemessagebox.h>
49#include <KoZoomHandler.h>
50#include <tdeapplication.h>
51#include <KoXmlWriter.h>
55#include <KoOasisStyles.h>
56#include <KoGenStyles.h>
58#include "kivio_page.h"
61#include "kivio_canvas.h"
62#include "kivio_view.h"
63#include "kivio_config.h"
65#include "kivio_common.h"
66#include "kivio_connector_point.h"
67#include "kivio_group_stencil.h"
68#include "kivio_intra_stencil_data.h"
69#include "kivio_layer.h"
70#include "kivio_painter.h"
71#include "kivio_stencil.h"
72#include "kivio_1d_stencil.h"
73#include "KIvioPageIface.h"
74#include "kivio_command.h"
75#include "kivioglobal.h"
76#include "kiviodragobject.h"
80int KivioPage::s_id = 0L;
81TQIntDict<KivioPage>* KivioPage::s_mapPages;
83KivioPage::KivioPage( KivioMap *_map,
const TQString &pageName,
const char *_name )
84: TQObject( _map, _name ),
87 if ( s_mapPages == 0L )
88 s_mapPages =
new TQIntDict<KivioPage>;
90 s_mapPages->insert( m_id,
this );
98 m_pCurLayer =
new KivioLayer(
this);
99 m_pCurLayer->setName(i18n(
"Layer 1"));
100 m_lstLayers.append( m_pCurLayer );
101 m_lstLayers.setAutoDelete(
true);
103 m_lstSelection.setAutoDelete(
false);
105 m_strName = pageName;
111 s.sprintf(
"Page%i", s_id );
118DCOPObject* KivioPage::dcopObject()
121 m_dcop =
new KIvioPageIface(
this );
126KivioPage::~KivioPage()
128 kdDebug(43000)<<
" KivioPage::~KivioPage()************ :"<<
this<<endl;
129 s_mapPages->remove(m_id);
133KivioPage* KivioPage::find(
int _id )
138 return (*s_mapPages)[ _id ];
141void KivioPage::print( TQPainter &, KPrinter * )
145void KivioPage::printPage( TQPainter &,
const TQRect& ,
const TQRect& )
149TQDomElement KivioPage::save( TQDomDocument& doc )
152 TQDomElement page = doc.createElement(
"KivioPage" );
153 page.setAttribute(
"name", m_strName );
154 page.setAttribute(
"hide", (
int)m_bPageHide );
157 TQDomElement layoutE = saveLayout( doc );
158 page.appendChild( layoutE );
161 TQDomElement guidesElement = doc.createElement(
"GuidesLayout");
162 page.appendChild(guidesElement);
163 saveGuideLines(guidesElement);
166 KivioLayer *pLayer = m_lstLayers.first();
169 TQDomElement layerE = pLayer->saveXML(doc);
170 if( layerE.isNull() )
172 kdDebug(43000) <<
"KivioPage::save() - Oh shit. KivioLayer::saveXML() returned a bad element!" << endl;
176 page.appendChild( layerE );
179 pLayer = m_lstLayers.next();
185void KivioPage::saveOasis(KoStore* , KoXmlWriter* docWriter, KoGenStyles* styles)
187 docWriter->startElement(
"draw:page");
188 docWriter->addAttribute(
"draw:name", m_strName);
191 docWriter->addAttribute(
"draw:master-page-name",
"Standard");
193 KoGenStyle pageLayout = m_pPageLayout.saveOasis();
194 TQString layoutName = styles->lookup(pageLayout,
"PL");
196 KoGenStyle masterPage(KoGenStyle::STYLE_MASTER);
197 masterPage.addAttribute(
"style:page-layout-name", layoutName);
198 TQString masterName = styles->lookup(masterPage,
"MP");
200 docWriter->addAttribute(
"draw:master-page-name", masterName);
205 TQBuffer layerBuffer;
206 layerBuffer.open(IO_WriteOnly);
207 KoXmlWriter layerWriter(&layerBuffer);
208 layerWriter.startElement(
"draw:layer-set");
211 KivioLayer* layer = m_lstLayers.first();
214 layer->saveOasis(&layerWriter);
215 layer = m_lstLayers.next();
218 layerWriter.endElement();
219 TQString layerSet = TQString::fromUtf8(layerBuffer.buffer(), layerBuffer.buffer().size());
220 KoGenStyle pageStyle(Kivio::STYLE_PAGE,
"drawing-page");
221 pageStyle.addChildElement(
"draw:layer-set", layerSet);
222 TQString styleName = styles->lookup(pageStyle,
"PS");
223 docWriter->addAttribute(
"draw:style-name", styleName);
225 docWriter->endElement();
228TQDomElement KivioPage::saveLayout( TQDomDocument &doc )
230 TQDomElement e = doc.createElement(
"PageLayout");
231 Kivio::savePageLayout(e, m_pPageLayout);
236bool KivioPage::loadLayout(
const TQDomElement &e )
238 m_pPageLayout = Kivio::loadPageLayout(e);
242bool KivioPage::isLoading()
244 return m_pDoc->isLoading();
247bool KivioPage::loadXML(
const TQDomElement& pageE )
249 m_strName = pageE.attribute(
"name");
250 if (m_strName.isEmpty())
254 m_bPageHide = (int)pageE.attribute(
"hide").toInt();
260 TQDomNode node = pageE.firstChild();
261 while( !node.isNull() )
263 if( node.nodeName() ==
"KivioLayer" )
265 pLayer =
new KivioLayer(
this);
266 if( pLayer->loadXML( node.toElement() )==
false )
273 m_lstLayers.append( pLayer );
277 else if( node.nodeName() ==
"PageLayout" )
279 loadLayout( node.toElement() );
281 else if ( node.nodeName() ==
"GuidesLayout" ) {
282 loadGuideLines(node.toElement());
286 kdDebug(43000) <<
"KivioLayer::loadXML() - unknown node found, " << node.nodeName() << endl;
289 node = node.nextSibling();
292 m_pCurLayer = m_lstLayers.first();
295 kdDebug(43000) <<
"KivioLayer::loadXML() - No layers loaded!! BIGGGGG PROBLEMS!" << endl;
299 KivioLayer *pLayerBak;
301 pLayer = m_lstLayers.first();
306 kdDebug(43000) <<
"KivioLayer::loadXML() - loading layer connections" << endl;
307 pLayer->searchForConnections(
this);
309 m_lstLayers.find( pLayerBak );
311 pLayer = m_lstLayers.next();
317bool KivioPage::loadOasis(
const TQDomElement& page, KoOasisStyles& oasisStyles)
319 m_strName = page.attributeNS( KoXmlNS::draw,
"name", TQString());
320 TQDomElement* masterPage = oasisStyles.masterPages()[page.attributeNS( KoXmlNS::draw,
"master-page-name", TQString())];
323 kdDebug(430000) <<
"Couldn't find the master page! " << page.attributeNS( KoXmlNS::draw,
"master-page-name", TQString()) << endl;
327 const TQDomElement *pageLayout = oasisStyles.findStyle(masterPage->attributeNS( KoXmlNS::style,
"page-layout-name", TQString() ) );
330 kdDebug(430000) <<
"Couldn't find the pagelayout!" << endl;
334 m_pPageLayout.loadOasis(*pageLayout);
336 if(m_pPageLayout.ptWidth <= 1e-13 || m_pPageLayout.ptHeight <= 1e-13) {
337 kdDebug(430000) <<
"Non valid pagelayout!" << endl;
341 const TQDomElement* style = oasisStyles.findStyle(page.attributeNS( KoXmlNS::draw,
"style-name", TQString()) );
347 TQDomNode styleNode = KoDom::namedItemNS( *style, KoXmlNS::style,
"properties");
348 styleNode = KoDom::namedItemNS( styleNode, KoXmlNS::draw,
"layer-set");
349 TQDomNode currentNode = styleNode.firstChild();
352 while(!currentNode.isNull()) {
353 if(currentNode.nodeName() ==
"draw:layer") {
354 KivioLayer* layer =
new KivioLayer(
this);
355 layer->loadOasis(currentNode.toElement());
356 m_lstLayers.append(layer);
359 currentNode = currentNode.nextSibling();
365void KivioPage::update()
369KivioPage* KivioPage::findPage(
const TQString& name )
374 return m_pMap->findPage(name);
377bool KivioPage::setPageName(
const TQString& name,
bool init )
379 if ( map()->findPage( name ) )
382 if ( m_strName == name )
385 TQString old_name = m_strName;
391 emit m_pDoc->sig_pageNameChanged(
this, old_name);
402void KivioPage::paintContent( KivioPainter& painter,
const TQRect& rect,
bool transparent,
403 TQPoint p0, KoZoomHandler* zoom,
bool drawConnectorTargets,
bool drawSelection )
405 KivioLayer *pLayer = m_lstLayers.first();
408 if( pLayer->visible() )
410 pLayer->paintContent( painter, rect, transparent, p0, zoom );
413 pLayer = m_lstLayers.next();
418 if(zoom->zoom() >= 50) {
419 if(drawConnectorTargets) {
420 m_pCurLayer->paintConnectorTargets( painter, rect, transparent, p0, zoom );
421 pLayer = m_lstLayers.first();
424 if(pLayer->connectable() && (pLayer != m_pCurLayer)) {
425 pLayer->paintConnectorTargets( painter, rect, transparent, p0, zoom );
428 pLayer = m_lstLayers.next();
435 m_pCurLayer->paintSelectionHandles( painter, rect, transparent, p0, zoom );
439void KivioPage::printContent( KivioPainter& painter,
int xdpi,
int ydpi )
442 xdpi = KoGlobal::dpiX();
446 ydpi = KoGlobal::dpiY();
449 KivioLayer *pLayer = m_lstLayers.first();
453 if( pLayer->visible() )
455 pLayer->printContent( painter, xdpi, ydpi );
458 pLayer = m_lstLayers.next();
462void KivioPage::printContent(KivioPainter& painter, KoZoomHandler* zoomHandler)
464 KivioLayer *pLayer = m_lstLayers.first();
468 if(pLayer->visible())
470 pLayer->printContent(painter, zoomHandler);
473 pLayer = m_lstLayers.next();
477void KivioPage::printSelected( KivioPainter& painter,
int xdpi,
int ydpi )
480 xdpi = KoGlobal::dpiX();
484 ydpi = KoGlobal::dpiY();
487 KivioStencil *pStencil;
488 KivioIntraStencilData data;
489 KoZoomHandler zoomHandler;
490 zoomHandler.setZoomAndResolution(100, xdpi, ydpi);
492 data.painter = &painter;
493 data.zoomHandler = &zoomHandler;
494 data.printing =
true;
496 KivioLayer *pLayer = m_lstLayers.first();
500 if( pLayer->visible()==
true )
502 pStencil = pLayer->firstStencil();
506 if(pStencil->isSelected())
508 pStencil->paint(&data);
511 pStencil = pLayer->nextStencil();
515 pLayer = m_lstLayers.next();
520bool KivioPage::addStencil( KivioStencil *pStencil )
523 kdDebug(43000) <<
"KivioPage::addStencil() - Null stencil passed" << endl;
528 kdDebug(43000) <<
"KivioPage::addStencil() - NULL current layer" << endl;
532 KivioAddStencilCommand *cmd =
new KivioAddStencilCommand(i18n(
"Add Stencil"),
this, m_pCurLayer, pStencil );
533 m_pDoc->addCommand(cmd);
535 return m_pCurLayer->addStencil( pStencil );
538void KivioPage::selectStencils(
double x,
double y,
double w,
double h )
541 KivioStencil *pStencil = m_pCurLayer->stencilList()->first();
545 if(pStencil->isInRect(KoRect(x, y, w, h))) {
546 selectStencil( pStencil );
549 pStencil = m_pCurLayer->stencilList()->next();
552 m_pDoc->slotSelectionChanged();
555void KivioPage::selectStencil( KivioStencil *pStencil )
558 kdDebug(43000) <<
"KivioPage::selectStencil - AHHHH! NULL STENCIL!" << endl;
563 if(m_lstSelection.findRef(pStencil) != -1) {
567 kdDebug(43000) <<
"KivioPage::selectStencil - Selecting stencil" << endl;
569 m_lstSelection.append(pStencil);
570 m_pDoc->slotSelectionChanged();
573bool KivioPage::unselectStencil( KivioStencil *pStencil )
575 pStencil->unselect();
576 m_pDoc->slotSelectionChanged();
577 return m_lstSelection.removeRef( pStencil );
580void KivioPage::selectAllStencils()
582 unselectAllStencils();
583 KivioStencil* pStencil = m_pCurLayer->stencilList()->first();
587 m_lstSelection.append(pStencil);
588 pStencil = m_pCurLayer->stencilList()->next();
615 m_pDoc->slotSelectionChanged();
618void KivioPage::unselectAllStencils()
620 KivioStencil* pStencil = m_lstSelection.first();
624 pStencil->unselect();
625 pStencil = m_lstSelection.next();
628 m_lstSelection.clear();
629 m_pDoc->slotSelectionChanged();
632bool KivioPage::isStencilSelected(KivioStencil *pStencil)
634 return m_lstSelection.findRef( pStencil ) == -1;
646KivioStencil *KivioPage::checkForStencil( KoPoint *pPoint,
int *collisionType,
double threshold,
bool selectedOnly )
648 KivioStencil *pStencil;
672 pStencil = m_pCurLayer->checkForStencil( pPoint, &colType, threshold, selectedOnly );
675 *collisionType = colType;
680 *collisionType = kctNone;
684void KivioPage::deleteSelectedStencils()
687 KivioStencil* pStencil = m_lstSelection.first();
690 if(pStencil->protection()->at(kpDeletion)) {
691 KMessageBox::information(NULL, i18n(
"One of the selected stencils has protection from deletion and cannot be deleted."),
692 i18n(
"Protection From Deletion") );
696 pStencil = m_lstSelection.next();
700 m_lstSelection.first();
701 pStencil = m_lstSelection.take();
702 KMacroCommand *macro =
new KMacroCommand( i18n(
"Remove Stencil"));
703 bool createMacro =
false;
706 KivioRemoveStencilCommand *cmd =
new KivioRemoveStencilCommand(i18n(
"Remove Stencil"),
this, m_pCurLayer , pStencil );
708 macro->addCommand(cmd);
710 if(pStencil->type() == kstConnector) {
711 static_cast<Kivio1DStencil*
>(pStencil)->disconnectFromTargets();
714 pStencil = m_lstSelection.take();
719 m_pDoc->addCommand( macro );
725void KivioPage::groupSelectedStencils()
728 if(!m_pCurLayer || (m_lstSelection.count() <= 1)) {
732 KivioGroupStencil* pGroup =
new KivioGroupStencil();
737 KivioStencil* pStencil = m_pCurLayer->firstStencil();
738 KivioStencil* pTake = 0;
741 if(pStencil->isSelected()) {
743 pTake = m_pCurLayer->takeStencil(pStencil);
746 kdDebug(43000) <<
"KivioPage::groupSelectedStencil() - Failed to take() one of the selected stencils. CRAP!" << endl;
749 pGroup->addToGroup(pTake);
750 pStencil = m_pCurLayer->currentStencil();
753 pStencil = m_pCurLayer->nextStencil();
758 unselectAllStencils();
761 m_pCurLayer->addStencil(pGroup);
763 selectStencil(pGroup);
765 KivioGroupCommand* cmd =
new KivioGroupCommand(i18n(
"Group Selection"),
this, m_pCurLayer, pGroup);
766 doc()->addCommand(cmd);
769void KivioPage::ungroupSelectedStencils()
771 KivioStencil *pSelStencil, *pStencil;
772 TQPtrList<KivioStencil> *pList;
773 TQPtrList<KivioStencil> *pSelectThese =
new TQPtrList<KivioStencil>;
774 KMacroCommand* macro =
new KMacroCommand(i18n(
"Ungroup"));
775 bool ungrouped =
false;
777 pSelectThese->setAutoDelete(
false);
780 pSelStencil = m_lstSelection.first();
784 pList = pSelStencil->groupList();
788 pStencil = pList->first();
792 m_pCurLayer->addStencil( pStencil );
793 pSelectThese->append( pStencil );
795 pStencil = pList->next();
799 m_lstSelection.take();
802 if(!m_pCurLayer->takeStencil(pSelStencil))
804 kdDebug(43000) <<
"KivioPage::ungroupSelectedStencil() - Failed to locate the group shell for deletion"
808 KivioUnGroupCommand* cmd =
new KivioUnGroupCommand(i18n(
"Ungroup"),
this, m_pCurLayer,
809 static_cast<KivioGroupStencil*
>(pSelStencil));
810 macro->addCommand(cmd);
814 pSelStencil = m_lstSelection.next();
819 pStencil = pSelectThese->first();
822 selectStencil( pStencil );
824 if(pStencil->type() == kstConnector) {
825 pStencil->searchForConnections(
this, 4.0);
828 pStencil = pSelectThese->next();
834 doc()->addCommand(macro);
840void KivioPage::bringToFront()
842 KivioStencil *pStencil, *pMove;
845 TQPtrList <KivioStencil> newList;
847 pLayer = m_pCurLayer;
849 newList.setAutoDelete(
false);
855 pStencil = pLayer->firstStencil();
858 if( isStencilSelected( pStencil )==
true )
860 pMove = pLayer->takeStencil();
863 newList.append(pMove);
864 pStencil = pLayer->currentStencil();
868 pStencil = pLayer->nextStencil();
873 pStencil = pLayer->nextStencil();
878 pStencil = newList.last();
881 pLayer->stencilList()->insert(0, pStencil);
883 pStencil = newList.prev();
887void KivioPage::sendToBack()
889 KivioStencil *pStencil, *pMove;
892 TQPtrList <KivioStencil> newList;
894 pLayer = m_pCurLayer;
896 newList.setAutoDelete(
false);
902 pStencil = pLayer->firstStencil();
905 if( isStencilSelected( pStencil )==
true )
907 pMove = pLayer->takeStencil();
910 newList.append(pMove);
911 pStencil = pLayer->currentStencil();
915 pStencil = pLayer->nextStencil();
920 pStencil = pLayer->nextStencil();
925 pStencil = newList.first();
928 pLayer->stencilList()->append(pStencil);
930 pStencil = newList.next();
934void KivioPage::copy()
936 if(m_lstSelection.count() <= 0) {
941 KivioDragObject* kdo =
new KivioDragObject();
942 kdo->setStencilList(m_lstSelection);
943 kdo->setStencilRect(getRectForAllSelectedStencils());
944 TQApplication::clipboard()->setData(kdo, TQClipboard::Clipboard);
949 KivioStencil *pStencil;
953 if( m_lstSelection.count() <= 0 )
956 pLayer = m_pCurLayer;
959 pStencil = pLayer->firstStencil();
962 if( isStencilSelected( pStencil )==
true )
964 if( pStencil->protection()->at(kpDeletion)==
true )
970 pStencil = pLayer->nextStencil();
975 KMessageBox::information(NULL, i18n(
"One of the stencils has protection from deletion. You cannot cut or delete this stencil."), i18n(
"Protection From Delete") );
981 deleteSelectedStencils();
984void KivioPage::paste(KivioView* view)
986 TQPtrList<KivioStencil> list;
987 list.setAutoDelete(
false);
990 if(kdo.decode(TQApplication::clipboard()->data(TQClipboard::Clipboard), list,
this)) {
991 unselectAllStencils();
992 KivioStencil* stencil = list.first();
996 selectStencil(stencil);
997 stencil = list.next();
1000 view->canvasWidget()->startPasteMoving();
1004int KivioPage::generateStencilIds(
int next)
1008 pLayer = m_lstLayers.first();
1012 next = pLayer->generateStencilIds( next );
1014 pLayer = m_lstLayers.next();
1020KivioLayer *KivioPage::firstLayer()
1022 return m_lstLayers.first();
1025KivioLayer *KivioPage::nextLayer()
1027 return m_lstLayers.next();
1030KivioLayer *KivioPage::prevLayer()
1032 return m_lstLayers.prev();
1035KivioLayer *KivioPage::lastLayer()
1037 return m_lstLayers.last();
1040bool KivioPage::removeCurrentLayer()
1045 if( m_lstLayers.count() <= 1 )
1048 pLayer = m_lstLayers.first();
1050 if( pLayer != m_pCurLayer )
1052 if( m_lstLayers.find( m_pCurLayer )==
false )
1054 kdDebug(43000) <<
"KivioLayer::removeCurrentLayer() - Couldn't find current layer in the list. Bad!" << endl;
1059 pLayer = m_lstLayers.next();
1062 (void)m_lstLayers.last();
1063 pLayer = m_lstLayers.prev();
1068 kdDebug(43000) <<
"KivioLayer::removeCurrentLayer() - Couldn't find a next layer." << endl;
1072 KivioRemoveLayerCommand * cmd =
new KivioRemoveLayerCommand( i18n(
"Remove Layer"),
this , m_pCurLayer , m_lstLayers.findRef(m_pCurLayer) );
1073 doc()->addCommand( cmd );
1074 takeLayer( m_pCurLayer );
1082 m_pCurLayer = pLayer;
1088void KivioPage::takeLayer( KivioLayer *pLayer )
1090 int pos=m_lstLayers.findRef(pLayer);
1091 m_lstLayers.take( pos );
1094void KivioPage::addLayer( KivioLayer *pLayer )
1096 m_lstLayers.append( pLayer );
1099void KivioPage::insertLayer(
int position, KivioLayer *pLayer )
1101 m_lstLayers.insert( position, pLayer );
1104KivioLayer *KivioPage::layerAt(
int pos )
1106 return m_lstLayers.at(pos);
1109void KivioPage::alignStencils(AlignData d)
1111 KivioStencil* pStencil = m_lstSelection.first();
1116 if (d.v != AlignData::None || d.h != AlignData::None) {
1117 KMacroCommand *macro =
new KMacroCommand(i18n(
"Move Stencil"));
1118 double x = pStencil->x();
1119 double y = pStencil->y();
1120 double w = pStencil->w();
1121 double h = pStencil->h();
1125 KoRect oldRect = pStencil->rect();
1128 case AlignData::Top:
1131 case AlignData::Center:
1132 pStencil->setY(y+h/2-pStencil->h()/2);
1134 case AlignData::Bottom:
1135 pStencil->setY(y+h-pStencil->h());
1141 case AlignData::Left:
1144 case AlignData::Center:
1145 pStencil->setX(x+w/2-pStencil->w()/2);
1147 case AlignData::Right:
1148 pStencil->setX(x+w-pStencil->w());
1154 KivioMoveStencilCommand * cmd =
new KivioMoveStencilCommand( i18n(
"Move Stencil"),
1155 pStencil, oldRect, pStencil->rect(),
this);
1156 macro->addCommand(cmd);
1157 pStencil = m_lstSelection.next();
1160 m_pDoc->addCommand(macro);
1163 if (d.centerOfPage) {
1164 KMacroCommand *macro =
new KMacroCommand(i18n(
"Move Stencil"));
1165 double w = m_pPageLayout.ptWidth;
1166 double h = m_pPageLayout.ptHeight;
1167 KoRect r = getRectForAllSelectedStencils();
1168 double dx = ((w - r.width()) / 2.0) - r.x();
1169 double dy = ((h - r.height()) / 2.0) - r.y();
1170 pStencil = m_lstSelection.first();
1174 KoRect oldRect = pStencil->rect();
1175 pStencil->setPosition(pStencil->x() + dx, pStencil->y() + dy);
1176 KivioMoveStencilCommand * cmd =
new KivioMoveStencilCommand( i18n(
"Move Stencil"),
1177 pStencil, oldRect, pStencil->rect(),
this);
1178 macro->addCommand(cmd);
1179 pStencil = m_lstSelection.next();
1182 m_pDoc->addCommand(macro);
1186class XYSortedStencilList :
public TQPtrList<KivioStencil>
1189 XYSortedStencilList(
bool sortX) :xsort(sortX) {};
1192 int compareItems(TQPtrCollection::Item i1, TQPtrCollection::Item i2)
1194 KivioStencil* s1 = (KivioStencil*)i1;
1195 KivioStencil* s2 = (KivioStencil*)i2;
1197 if (s1->x() > s2->x())
1199 if (s1->x() < s2->x())
1203 if (s1->y() > s2->y())
1205 if (s1->y() < s2->y())
1215void KivioPage::distributeStencils(DistributeData d)
1222 KivioStencil* pStencil = m_lstSelection.first();
1226 XYSortedStencilList xSortList(
true);
1227 XYSortedStencilList ySortList(
false);
1228 TQValueList<KoRect> oldRects;
1232 xSortList.append(pStencil);
1233 ySortList.append(pStencil);
1234 oldRects.append(pStencil->rect());
1235 pStencil = m_lstSelection.next();
1241 case DistributeData::Page:
1242 x = m_pPageLayout.ptLeft;
1243 y = m_pPageLayout.ptTop;
1244 x1 = m_pPageLayout.ptWidth - m_pPageLayout.ptRight;
1245 y1 = m_pPageLayout.ptHeight - m_pPageLayout.ptBottom;
1247 case DistributeData::Selection:
1248 pStencil = m_lstSelection.first();
1251 x1 = x + pStencil->w();
1252 y1 = y + pStencil->h();
1255 x = TQMIN(x,pStencil->x());
1256 y = TQMIN(y,pStencil->y());
1257 x1 = TQMAX(x1,pStencil->x() + pStencil->w());
1258 y1 = TQMAX(y1,pStencil->y() + pStencil->h());
1259 pStencil = m_lstSelection.next();
1267 KivioStencil* firstx = xSortList.first();
1268 KivioStencil* lastx = xSortList.last();
1269 double countx = (double)(xSortList.count()-1);
1272 case DistributeData::Left:
1273 x1 = x1 - lastx->w();
1274 distx = (x1 - x)/countx;
1276 case DistributeData::Center:
1277 x = x + firstx->w()/2;
1278 x1 = x1 - lastx->w()/2;
1279 distx = (x1 - x)/countx;
1281 case DistributeData::Spacing: {
1283 pStencil = xSortList.first();
1286 allw = allw + pStencil->w();
1287 pStencil = xSortList.next();
1289 distx = (x1-x-allw)/countx;
1291 case DistributeData::Right:
1292 x = x + firstx->w();
1293 distx = (x1 - x)/countx;
1301 case DistributeData::Center:
1302 pStencil = xSortList.first();
1305 pStencil->setX(xx - pStencil->w()/2);
1307 pStencil = xSortList.next();
1310 case DistributeData::Right:
1311 pStencil = xSortList.first();
1314 pStencil->setX(xx - pStencil->w());
1316 pStencil = xSortList.next();
1319 case DistributeData::Left:
1320 pStencil = xSortList.first();
1325 pStencil = xSortList.next();
1328 case DistributeData::Spacing:
1329 pStencil = xSortList.first();
1333 xx = xx + pStencil->w() + distx;
1334 pStencil = xSortList.next();
1341 KivioStencil* firsty = ySortList.first();
1342 KivioStencil* lasty = ySortList.last();
1343 double county = (double)(ySortList.count()-1);
1346 case DistributeData::Top:
1347 y1 = y1 - lasty->h();
1348 disty = (y1 - y)/county;
1350 case DistributeData::Center:
1351 y = y + firsty->h()/2;
1352 y1 = y1 - lasty->h()/2;
1353 disty = (y1 - y)/countx;
1355 case DistributeData::Spacing: {
1357 pStencil = ySortList.first();
1360 allh = allh + pStencil->h();
1361 pStencil = ySortList.next();
1363 disty = (y1-y-allh)/county;
1365 case DistributeData::Bottom:
1366 y = y + firsty->h();
1367 disty = (y1 - y)/county;
1375 case DistributeData::Center:
1376 pStencil = ySortList.first();
1379 pStencil->setY(yy - pStencil->h()/2);
1381 pStencil = ySortList.next();
1384 case DistributeData::Bottom:
1385 pStencil = ySortList.first();
1388 pStencil->setY(yy - pStencil->h());
1390 pStencil = ySortList.next();
1393 case DistributeData::Top:
1394 pStencil = ySortList.first();
1399 pStencil = ySortList.next();
1402 case DistributeData::Spacing:
1403 pStencil = ySortList.first();
1407 yy = yy + pStencil->h() + disty;
1408 pStencil = ySortList.next();
1415 if(d.v != DistributeData::None || d.h != DistributeData::None) {
1416 KMacroCommand *macro =
new KMacroCommand(i18n(
"Move Stencil"));
1417 TQValueListIterator<KoRect> it;
1418 pStencil = m_lstSelection.first();
1420 for(it = oldRects.begin(); it != oldRects.end(); ++it) {
1421 KivioMoveStencilCommand * cmd =
new KivioMoveStencilCommand(i18n(
"Move Stencil"),
1422 pStencil, (*it), pStencil->rect(),
this);
1423 macro->addCommand( cmd);
1424 pStencil = m_lstSelection.next();
1427 m_pDoc->addCommand( macro );
1435KoRect KivioPage::getRectForAllSelectedStencils()
1439 KivioStencil *pStencil = m_lstSelection.first();
1444 rTotal = pStencil->rect();
1446 pStencil = m_lstSelection.next();
1452 r = pStencil->rect();
1454 rTotal = rTotal.unite( r );
1456 pStencil = m_lstSelection.next();
1465KoRect KivioPage::getRectForAllStencils()
1469 bool firstTime =
true;
1472 KivioStencil *pStencil;
1474 pLayer = m_lstLayers.first();
1477 pStencil = pLayer->firstStencil();
1480 if( firstTime==
true )
1482 rTotal = pStencil->rect();
1487 r = pStencil->rect();
1488 rTotal = rTotal.unite( r );
1491 pStencil = pLayer->nextStencil();
1494 pLayer = m_lstLayers.next();
1501void KivioPage::setPaperLayout(
const KoPageLayout &l)
1504 doc()->updateView(
this);
1505 emit sig_pageLayoutChanged(m_pPageLayout);
1508KivioConnectorTarget *KivioPage::connectPointToTarget( KivioConnectorPoint *p,
double )
1511 KivioLayer *pLayer, *pCurLayer;
1512 bool doneSearching =
false;
1513 KivioConnectorTarget *pTarget;
1518 if( p->connectable()==
false )
1524 pCurLayer = curLayer();
1525 pLayer = firstLayer();
1527 while( pLayer && doneSearching==
false )
1529 if( pLayer != pCurLayer )
1531 if( pLayer->connectable()==
false || pLayer->visible()==
false )
1533 pLayer = nextLayer();
1538 if( (pTarget=pLayer->connectPointToTarget(p, 8.0f )) )
1543 pLayer = nextLayer();
1549KoPoint KivioPage::snapToTarget(
const KoPoint& p,
double thresh,
bool& hit )
1551 KivioLayer *pLayer, *pCurLayer;
1554 pCurLayer = curLayer();
1555 pLayer = firstLayer();
1557 while( pLayer && !hit )
1559 if( pLayer != pCurLayer )
1561 if( pLayer->connectable()==
false || pLayer->visible()==
false )
1563 pLayer = nextLayer();
1568 retVal = pLayer->snapToTarget(p, thresh, hit);
1570 pLayer = nextLayer();
1576void KivioPage::setHidePage(
bool _hide)
1580 emit sig_PageHidden(
this);
1582 emit sig_PageShown(
this);
1585void KivioPage::setPaintSelected(
bool paint)
1587 KivioStencil *pStencil = m_lstSelection.first();
1591 pStencil->setHidden(!paint);
1592 pStencil = m_lstSelection.next();
1596bool KivioPage::checkForStencilTypeInSelection(KivioStencilType type)
1598 KivioStencil *pStencil = m_lstSelection.first();
1602 if(pStencil->type() == type) {
1606 pStencil = m_lstSelection.next();
1612bool KivioPage::checkForTextBoxesInSelection()
1614 KivioStencil *pStencil = m_lstSelection.first();
1617 if(pStencil->hasTextBox()) {
1621 pStencil = m_lstSelection.next();
1627void KivioPage::setGuideLines(
const TQValueList<double> hGuideLines,
const TQValueList<double> vGuideLines)
1629 m_hGuideLines = hGuideLines;
1630 m_vGuideLines = vGuideLines;
1633void KivioPage::saveGuideLines(TQDomElement& element)
1635 TQValueList<double>::iterator it;
1636 TQValueList<double>::iterator itEnd = m_hGuideLines.end();
1638 for(it = m_hGuideLines.begin(); it != itEnd; ++it) {
1639 TQDomElement e = element.ownerDocument().createElement(
"Guideline");
1640 element.appendChild(e);
1641 XmlWriteDouble(e,
"pos", *it);
1642 XmlWriteInt(e,
"orient", (
int)TQt::Horizontal);
1645 itEnd = m_vGuideLines.end();
1647 for(it = m_vGuideLines.begin(); it != itEnd; ++it) {
1648 TQDomElement e = element.ownerDocument().createElement(
"Guideline");
1649 element.appendChild(e);
1650 XmlWriteDouble(e,
"pos", *it);
1651 XmlWriteInt(e,
"orient", (
int)TQt::Vertical);
1655void KivioPage::loadGuideLines(
const TQDomElement& element)
1657 m_hGuideLines.clear();
1658 m_vGuideLines.clear();
1660 TQDomElement e = element.firstChild().toElement();
1662 for( ; !e.isNull(); e = e.nextSibling().toElement() )
1664 double pos = XmlReadDouble(e,
"pos", 0.0);
1665 TQt::Orientation orient = (TQt::Orientation)XmlReadInt(e,
"orient", 0);
1666 addGuideLine(orient, pos);
1670void KivioPage::addGuideLine(TQt::Orientation orientation,
double position)
1672 if(orientation == TQt::Horizontal) {
1673 m_hGuideLines.append(position);
1675 m_vGuideLines.append(position);
1679#include "kivio_page.moc"
static KoPageLayout defaultPageLayout()
Get the default page layout.