3 #include <qstatusbar.h>
4 #include <qmessagebox.h>
5 #include <qapplication.h>
7 #include <qpopupmenu.h>
9 #include <qpaintdevicemetrics.h>
11 #include <qfiledialog.h>
14 #include <qcolordialog.h>
17 #include <qinputdialog.h>
18 #include <qdragobject.h>
19 #include <qurloperator.h>
20 #include <qnetworkprotocol.h>
30 #include "editxlinkdialog.h"
32 #include "extrainfodialog.h"
34 #include "linkablemapobj.h"
35 #include "mainwindow.h"
38 #include "texteditor.h"
42 extern TextEditor *textEditor;
43 extern int statusbarTime;
44 extern Main *mainWindow;
45 extern QString tmpVymDir;
46 extern QString clipboardDir;
47 extern bool clipboardEmpty;
48 extern FlagRowObj *systemFlagsDefault;
49 extern FlagRowObj *standardFlagsDefault;
51 extern QPtrList <QAction> actionListBranches;
53 extern QAction *actionFileSave;
54 extern QAction *actionEditUndo;
55 extern QAction *actionEditCopy;
56 extern QAction *actionEditCut;
57 extern QAction *actionEditPaste;
58 extern QAction *actionEditMoveUp;
59 extern QAction *actionEditMoveDown;
60 extern QAction *actionEditToggleScroll;
61 extern QAction *actionEditOpenURL;
62 extern QAction *actionEditOpenURLTab;
63 extern QAction *actionEditURL;
64 extern QAction *actionEditHeading2URL;
65 extern QAction *actionEditBugzilla2URL;
66 extern QAction *actionEditFATE2URL;
67 extern QAction *actionEditOpenVymLink;
68 extern QAction *actionEditVymLink;
69 extern QAction *actionEditDeleteVymLink;
70 extern QAction *actionEditToggleHideExport;
71 extern QAction *actionEditHeading;
72 extern QAction *actionEditDelete;
73 extern QAction *actionEditAddBranch;
74 extern QAction *actionEditAddBranchAbove;
75 extern QAction *actionEditAddBranchBelow;
76 extern QAction *actionEditRemoveBranchHere;
77 extern QAction *actionEditRemoveChilds;
78 extern QAction *actionEditImportAdd;
79 extern QAction *actionEditImportReplace;
80 extern QAction *actionEditSaveBranch;
81 extern QAction *actionEditSelectFirst;
82 extern QAction *actionEditSelectLast;
83 extern QAction *actionEditLoadImage;
85 extern QAction* actionFormatPickColor;
86 extern QAction* actionFormatColorBranch;
87 extern QAction* actionFormatColorSubtree;
88 extern QAction *actionFormatLinkColorHint;
89 extern QAction *actionFormatBackColor;
90 extern QAction *actionFormatLinkColor;
92 extern QActionGroup* actionGroupModModes;
93 extern QAction* actionModModeColor;
94 extern QAction* actionModModeLink;
95 extern QAction* actionModModeCopy;
97 extern QActionGroup *actionGroupFormatFrameTypes;
98 extern QAction *actionFormatFrameNone;
99 extern QAction *actionFormatFrameRectangle;
101 extern QActionGroup *actionGroupFormatLinkStyles;
102 extern QAction *actionFormatIncludeImagesVer;
103 extern QAction *actionFormatIncludeImagesHor;
104 extern QAction *actionFormatHideLinkUnselected;
105 extern QAction *actionFormatLinkStyleLine;
106 extern QAction *actionFormatLinkStyleParabel;
107 extern QAction *actionFormatLinkStylePolyLine;
108 extern QAction *actionFormatLinkStylePolyParabel;
110 extern QAction *actionViewToggleNoteEditor;
112 extern QAction *actionSettingsAutoedit;
113 extern QAction *actionSettingsAutoselectHeading;
114 extern QAction *actionSettingsAutoselectText;
115 extern QAction *actionSettingsPasteNewHeading;
116 extern QAction *actionSettingsUseFlagGroups;
118 extern QPopupMenu *branchContextMenu;
119 extern QPopupMenu *branchLinksContextMenu;
120 extern QPopupMenu *branchLinksContextMenuDup;
121 extern QPopupMenu *floatimageContextMenu;
122 extern QPopupMenu *saveImageFormatMenu;
123 extern QPopupMenu *exportImageFormatMenu;
124 extern QPopupMenu *canvasContextMenu;
126 extern Settings settings;
128 int MapEditor::mapNum=0; // make instance
130 ///////////////////////////////////////////////////////////////////////
131 ///////////////////////////////////////////////////////////////////////
132 MapEditor::MapEditor(
133 QWidget* parent, bool interactive, const char* name, WFlags f) :
134 QCanvasView(parent,name,f), urlOperator(0), imageBuffer(0)
136 //cout << "Constructor ME "<<this<<endl;
139 viewport()->setAcceptDrops(true);
141 mapCanvas = new QCanvas(1000,800);
142 mapCanvas->setAdvancePeriod(30);
143 mapCanvas->setBackgroundColor (white);
145 setCanvas (mapCanvas);
147 // Always show scroll bars (automatic would flicker sometimes)
148 setVScrollBarMode ( QScrollView::AlwaysOn );
149 setHScrollBarMode ( QScrollView::AlwaysOn );
151 mapCenter = new MapCenterObj(mapCanvas);
152 mapCenter->setVisibility (true);
153 mapCenter->setMapEditor (this);
154 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
155 mapCenter->move(mapCanvas->width()/2-mapCenter->width()/2,mapCanvas->height()/2-mapCenter->height()/2);
159 lineedit = new QLineEdit(this, "lineedit" );
160 connect( lineedit, SIGNAL( returnPressed() ), SLOT( finishedLineEditNoSave() ) );
163 actColor=black; setColor (actColor);
164 defLinkColor=QColor (0,0,255);
165 defXLinkColor=QColor (180,180,180);
166 linkcolorhint=DefaultColor;
167 linkstyle=StylePolyParabel;
169 // Create bitmap cursors, patform dependant
170 #if defined(Q_OS_MACX)
171 #include "icons/cursorhandopen16.xpm"
172 #include "icons/cursorcolorpicker16.xpm"
173 QBitmap cb( 16, 16, chandopen, TRUE );
174 QBitmap cm( 16, 16, chandopenmask, TRUE );
175 handOpenCursor=QCursor ( cb, cm );
176 // set hot spot to tip of picker
177 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 1,15 );
179 #include "icons/cursorhandopen.xpm"
180 #include "icons/cursorcolorpicker.xpm"
182 QBitmap cb( 32, 32, chandopen, TRUE );
183 QBitmap cm( 32, 32, chandopenmask, TRUE );
184 handOpenCursor=QCursor ( cb, cm );
185 // set hot spot to tip of picker
186 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 5,27 );
199 defXLinkColor=QColor (230,230,230);
210 undosTotal=settings.readNumEntry("/vym/mapeditor/undoLevels",50);
214 // Initialize find routine
221 blockReposition=false;
222 blockSaveState=false;
226 isInteractive=interactive;
228 // Create temporary files
231 // Initially set movingCentre
234 mapCenter->reposition(); // for positioning heading
237 MapEditor::~MapEditor()
239 if (imageBuffer) delete imageBuffer;
245 //cout <<"Destructor MapEditor\n";
248 //settings.writeEntry( "/vym/mapeditor/editmode/autoselect", );
252 QColor MapEditor::color()
257 QColor MapEditor::backgroundColor()
259 return mapCanvas->backgroundColor();
262 MapCenterObj* MapEditor::getMapCenter()
267 QCanvas* MapEditor::getCanvas()
272 void MapEditor::adjustCanvasSize()
274 // To adjust the canvas to map, viewport size and position, we have to
275 // do some coordinate magic...
277 // Get rectangle of (scroll-)view.
278 // We want to be in canvas coords, so
279 // we map. Important if view is zoomed...
280 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
281 visibleWidth(), visibleHeight()) );
283 // Now we need the bounding box of view AND map to calc the correct canvas size.
284 // Why? Because if the map itself is moved out of view, the view has to be enlarged
285 // to avoid jumping aroung...
286 QRect map=mapCenter->getTotalBBox();
288 // right edge - left edge
289 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
290 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
293 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
294 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
297 // move the map on canvas (in order to not move it on screen) this is neccessary
298 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
299 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
300 // to scroll to an empty area of canvas to the left.
301 // b) if topleft corner of map left of or above topleft of canvas
305 if (cw > mapCanvas->width() )
307 if (map.x()<0) dx=-map.x();
309 if (cw < mapCanvas->width() )
310 dx=-min (view.x(),map.x());
311 if (ch > mapCanvas->height() )
313 if (map.y()<0) dy=-map.y();
315 if (ch < mapCanvas->height() )
317 dy=-min (view.y(),map.y());
319 // We really have to resize now. Let's go...
320 mapCanvas->resize (cw,ch);
321 if ( (dx!=0) || (dy!=0) )
323 mapCenter->moveAllBy(dx,dy);
324 mapCenter->reposition();
326 // scroll the view (in order to not move map on screen)
332 bool MapEditor::isRepositionBlocked()
334 return blockReposition;
337 void MapEditor::makeTmpDirs()
339 // Create unique temporary directories
340 tmpMapDir=tmpVymDir+QString("/mapeditor-%1").arg(mapNum);
342 d.mkdir (tmpMapDir,true);
345 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSelection)
347 // tmpdir temporary directory to which data will be written
348 // prefix mapname, which will be appended to images etc.
349 // writeflags Only write flags for "real" save of map, not undo
350 // offset offset of bbox of whole map in canvas.
351 // Needed for XML export
367 ls="StylePolyParabel";
371 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
373 if (linkcolorhint==HeadingColor)
374 colhint=attribut("linkColorHint","HeadingColor");
376 QString mapAttr=attribut("version",__VYM_VERSION);
378 mapAttr+= attribut("author",mapCenter->getAuthor()) +
379 attribut("comment",mapCenter->getComment()) +
380 attribut("date",mapCenter->getDate()) +
381 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
382 attribut("linkStyle", ls ) +
383 attribut("linkColor", defLinkColor.name() ) +
384 attribut("defXLinkColor", defXLinkColor.name() ) +
385 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
387 s+=beginElement("vymmap",mapAttr);
390 // Find the used flags while traversing the tree
391 standardFlagsDefault->resetUsedCounter();
393 // Reset the counters before saving
394 FloatImageObj (mapCanvas).resetSaveCounter();
396 // Build xml recursivly
398 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
401 if ( typeid(*saveSelection) == typeid(BranchObj) )
402 s+=((BranchObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
403 else if ( typeid(*saveSelection) == typeid(FloatImageObj) )
404 s+=((FloatImageObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
406 else if (selection && typeid(*selection)==typeid(BranchObj))
407 // This is used if selected branch is saved from mainwindow
408 s+=((BranchObj*)selection)->saveToDir(tmpdir,prefix,offset);
411 // Save local settings
412 s+=settings.getXMLData (destPath);
415 if (selection && !saveSelection )
416 s+=valueElement("select",selection->getSelectString());
419 s+=endElement("vymmap");
422 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
426 void MapEditor::saveState()
429 saveState (CompleteMap,"",NULL,"",NULL);
432 void MapEditor::saveState(LinkableMapObj *undoSel)
434 // save the given part of the map
435 saveState (PartOfMap,"",undoSel,"",NULL);
438 void MapEditor::saveState(const QString &uc, const QString &rc)
440 // selection does not change during action,
441 // so just save commands for undo and redo
442 LinkableMapObj *unsel;
447 saveState (UndoCommand,uc,unsel,rc,unsel);
450 void MapEditor::saveState(const QString & uncom, LinkableMapObj *unsel)
452 saveState (UndoCommand,uncom,unsel,"FIXME-redoCom",NULL);
455 void MapEditor::saveState(const SaveMode &savemode, const QString &undoCom, LinkableMapObj *undoSel, const QString &redoCom, LinkableMapObj *redoSel)
459 if (blockSaveState) return;
461 /* TODO remove after testing
462 cout << "ME::saveState() begin\n"<<endl;
463 cout << " undosTotal="<<undosTotal<<endl;
464 cout << " undosAvail="<<undosAvail<<endl;
465 cout << " undoNum="<<undoNum<<endl;
466 cout << " ---------------------------"<<endl;
470 // Find out current undo directory
471 if (undosAvail<undosTotal) undosAvail++;
473 if (undoNum>undosTotal) undoNum=1;
476 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
477 QString bakMapPath=QDir::convertSeparators(bakMapDir+"/map.xml");
479 // Create bakMapDir if not available
482 makeSubDirs (bakMapDir);
484 // Save current selection
485 QString redoSelection="";
487 redoSelection=redoSel->getSelectString();
489 // Save the object, which should be undone
490 QString undoSelection="";
492 undoSelection=undoSel->getSelectString();
494 // Save depending on how much needs to be saved
495 QString undoCommand="";
496 if (savemode==UndoCommand)
501 else if (savemode==PartOfMap && undoSel)
503 undoCommand="undoPart (\""+ undoSelection+"\",\""+bakMapPath+"\")";
504 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),undoSel);
507 undoCommand="undoMap (\""+bakMapPath+"\")";
508 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),NULL);
511 if (!backupXML.isEmpty())
512 // Write XML Data to disk
513 saveStringToDisk (QString(bakMapPath),backupXML);
516 set.setEntry (QString("undoCommand"),undoCommand);
517 set.setEntry (QString("undoSelection"),undoSelection);
518 set.setEntry (QString("redoCommand"),redoCom);
519 set.setEntry (QString("redoSelection"),redoSelection);
520 set.writeSettings(QString(bakMapDir+"/commands"));
522 /* TODO remove after testing
523 cout << " into="<< bakMapDir<<endl;
524 cout << " undosAvail="<<undosAvail<<endl;
525 cout << " undoNum="<<undoNum<<endl;
526 cout << " ---------------------------"<<endl;
527 cout << " undoCom="<<undoCommand<<endl;
528 cout << " undoSel="<<undoSelection<<endl;
529 cout << " ---------------------------"<<endl;
530 cout << " redoCom="<<redoCom<<endl;
531 cout << " redoSel="<<redoSelection<<endl;
532 cout << " ---------------------------"<<endl<<endl;
536 void MapEditor::parseAtom(const QString &atom)
543 // Split string s into command and parameters
544 api.parseCommand (atom);
545 QString com=api.command();
548 if (com=="moveBranchUp")
550 else if (com=="moveBranchDown")
552 else if (com=="move")
554 if (api.checkParamCount(2) && selection )
564 else if (com=="linkBranchToPos")
566 if (selection && typeid(*selection) == typeid(BranchObj) )
568 if (api.checkParamCount(4))
570 s=api.parString(ok,0);
571 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
574 if (typeid(*dst) == typeid(BranchObj) )
576 // Get number in parent
579 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),x);
580 } else if (typeid(*dst) == typeid(MapCenterObj) )
582 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),-1);
583 // Get coordinates of mainbranch
588 if (ok) ((BranchObj*)selection)->move (x,y);
594 } else if (com=="setHeading")
596 if (api.checkParamCount(1))
598 s=api.parString (ok,0);
599 if (ok) setHeading (s);
601 } else if (com=="setURL")
603 if (api.checkParamCount(1))
605 s=api.parString (ok,0);
608 } else if (com=="setVymLink")
610 if (api.checkParamCount(1))
612 s=api.parString (ok,0);
613 if (ok) setVymLink(s);
616 // Internal commands, used for undo etc.
617 else if (com==QString("undoMap"))
619 if (api.checkParamCount(1))
620 undoXML("",api.parString (ok,0));
621 } else if (com==QString("undoPart"))
623 if (api.checkParamCount(2))
625 s=api.parString (ok,0);
626 t=api.parString (ok,1);
629 } else if (com=="select")
630 if (api.checkParamCount(1))
632 s=api.parString(ok,0);
637 api.setError ("Unknown command in: "+atom);
638 cout << "ME::parse api should have error now...\n";
644 cout << "MapEditor::parseAtom: Error!\n";
645 cout << " "<<api.errorDesc()<<endl;
650 void MapEditor::finishedLineEditNoSave()
652 // This is called by finishedLineEdit or any MapEditor method,
653 // which wants to assure, that lineedits finish, before e.g. a branch is
656 // After calling LineEdit and using the clipboard, the
657 // focus is not any longer on the main widget, we
658 // have to restore it using parentWidget()->setFocus()
662 editingBO->setHeading(lineedit->text() );
664 lineedit->releaseKeyboard();
666 parentWidget()->setFocus();
667 mapCenter->reposition();
669 ensureSelectionVisible();
674 bool MapEditor::isDefault()
679 bool MapEditor::isUnsaved()
684 bool MapEditor::hasChanged()
689 void MapEditor::setChanged()
694 actionEditUndo->setEnabled (true);
695 actionFileSave->setEnabled (true);
699 void MapEditor::closeMap()
701 // Finish open lineEdits
702 if (lineedit) finishedLineEditNoSave();
704 // Unselect before disabling the toolbar actions
705 if (selection) selection->unselect();
713 void MapEditor::setFilePath(QString fname)
715 setFilePath (fname,fname);
718 void MapEditor::setFilePath(QString fname, QString destname)
720 if (fname.isEmpty() || fname=="")
727 filePath=fname; // becomes absolute path
728 fileName=fname; // gets stripped of path
729 destPath=destname; // needed for vymlinks
731 // If fname is not an absolute path, complete it
732 filePath=QDir(fname).absPath();
733 fileDir=filePath.left (1+filePath.findRev ("/"));
735 // Set short name, too. Search from behind:
736 int i=fileName.findRev("/");
737 if (i>=0) fileName=fileName.remove (0,i+1);
739 // Forget the .vym (or .xml) for name of map
740 mapName=fileName.left(fileName.findRev(".",-1,true) );
744 QString MapEditor::getFilePath()
749 QString MapEditor::getFileName()
754 QString MapEditor::getMapName()
759 QString MapEditor::getDestPath()
764 ErrorCode MapEditor::load (QString fname, LoadMode lmode)
766 // Finish open lineEdits
767 if (lineedit) finishedLineEditNoSave();
769 ErrorCode err=success;
773 if (selection) selection->unselect();
776 mapCenter->setMapEditor(this);
777 // (map state is set later at end of load...)
780 saveState(selection);
784 mapBuilderHandler handler;
787 // I am paranoid: file should exist anyway
788 // according to check in mainwindow.
791 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
792 tr("Couldn't open map " +fname)+".");
796 blockReposition=true;
797 QXmlInputSource source( file);
798 QXmlSimpleReader reader;
799 reader.setContentHandler( &handler );
800 reader.setErrorHandler( &handler );
801 handler.setMapEditor( this );
802 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
803 handler.setInputFile (file.name());
804 handler.setLoadMode (lmode);
806 bool ok = reader.parse( source );
807 blockReposition=false;
808 blockSaveState=false;
812 mapCenter->reposition();
822 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
823 tr( handler.errorProtocol() ) );
825 // Still return "success": the map maybe at least
826 // partially read by the parser
833 int MapEditor::save (const SaveMode &savemode)
835 // Finish open lineEdits
836 if (lineedit) finishedLineEditNoSave();
840 // The SaveMode UndoCommand is not supported here
841 if (savemode==UndoCommand) return 1;
843 // Create mapName and fileDir
844 makeSubDirs (fileDir);
848 fname=mapName+".xml";
850 // use name given by user, even if he chooses .doc
855 if (savemode==CompleteMap || selection==NULL)
856 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL);
858 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection);
860 if (!saveStringToDisk(fileDir+fname,saveFile))
867 actionFileSave->setEnabled(false);
873 void MapEditor::setZipped (bool z)
878 bool MapEditor::saveZipped ()
883 void MapEditor::print()
885 // Finish open lineEdits
886 if (lineedit) finishedLineEditNoSave();
890 printer = new QPrinter;
891 printer->setColorMode (QPrinter::Color);
892 printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName()));
895 QRect totalBBox=mapCenter->getTotalBBox();
897 // Try to set orientation automagically
898 // Note: Interpretation of generated postscript is amibiguous, if
899 // there are problems with landscape mode, see
900 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
902 if (totalBBox.width()>totalBBox.height())
903 // recommend landscape
904 printer->setOrientation (QPrinter::Landscape);
906 // recommend portrait
907 printer->setOrientation (QPrinter::Portrait);
909 if ( printer->setup(this) )
910 // returns false, if printing is canceled
912 QPainter pp(printer);
914 // Don't print the visualisation of selection
915 LinkableMapObj *oldselection=NULL;
918 oldselection=selection;
919 selection->unselect();
922 // Handle sizes of map and paper:
924 // setWindow defines which part of the canvas will be transformed
925 // setViewport defines area on paper in device coordinates (dpi)
926 // e.g. (0,50,700,700) is upper part on A4
927 // see also /usr/lib/qt3/doc/html/coordsys.html
929 QPaintDeviceMetrics metrics (printer);
931 double paperAspect = (double)metrics.width() / (double)metrics.height();
932 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
934 QRect mapRect=totalBBox;
935 QCanvasRectangle *frame=NULL;
936 QCanvasText *footerFN=NULL;
937 QCanvasText *footerDate=NULL;
938 if (printFrame || printFooter)
943 // Print frame around map
944 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
945 totalBBox.width()+20, totalBBox.height()+20);
946 frame=new QCanvasRectangle (mapRect,mapCanvas);
947 frame->setBrush (QColor(white));
948 frame->setPen (QColor(black));
952 /* TODO remove after testing
953 QCanvasLine *l=new QCanvasLine (mapCanvas);
954 l->setPoints (0,0,mapRect.width(),mapRect.height());
955 l->setPen (QPen(QColor(black), 1));
962 // Print footer below map
964 font.setPointSize(10);
965 footerFN=new QCanvasText (mapCanvas);
966 footerFN->setText ("VYM - " + fileName);
967 footerFN->setFont(font);
968 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
969 footerFN->setZ(Z_TEXT);
971 footerDate=new QCanvasText (mapCanvas);
972 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
973 footerDate->setFont(font);
974 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
975 footerDate->setZ(Z_TEXT);
978 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
981 pp.setWindow (mapRect);
984 if (mapAspect>=paperAspect)
986 // Fit horizontally to paper width
987 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
990 // Fit vertically to paper height
991 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
994 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
996 // Delete Frame and footer
1000 delete (footerDate);
1002 if (frame) delete (frame);
1004 // Restore selection
1007 selection=oldselection;
1008 selection->select();
1011 // Save settings in vymrc
1012 settings.writeEntry("/vym/mainwindow/printerName",printer->printerName());
1016 QPixmap MapEditor::getPixmap()
1018 QRect mapRect=mapCenter->getTotalBBox();
1019 QPixmap pix (mapRect.size());
1022 // Don't print the visualisation of selection
1023 LinkableMapObj *oldselection=NULL;
1026 oldselection=selection;
1027 selection->unselect();
1030 pp.setWindow (mapRect);
1032 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
1035 // Restore selection
1038 selection=oldselection;
1039 selection->select();
1045 void MapEditor::setHideTmpMode (HideTmpMode mode)
1048 mapCenter->setHideTmp (hidemode);
1049 mapCenter->reposition();
1054 HideTmpMode MapEditor::getHideTmpMode()
1059 void MapEditor::exportImage(QString fn)
1061 // Finish open lineEdits
1062 if (lineedit) finishedLineEditNoSave();
1064 setExportMode (true);
1065 QPixmap pix (getPixmap());
1066 pix.save(fn, "PNG");
1067 setExportMode (false);
1070 void MapEditor::setExportMode (bool b)
1072 // should be called before and after exports
1073 // depending on the settings
1074 if (b && settings.readEntry("/vym/export/useHideExport","yes"))
1075 setHideTmpMode (HideExport);
1077 setHideTmpMode (HideNone);
1080 void MapEditor::exportImage(QString fn, int item)
1082 // Finish open lineEdits
1083 if (lineedit) finishedLineEditNoSave();
1085 setExportMode (true);
1086 QPixmap pix (getPixmap());
1087 pix.save(fn, exportImageFormatMenu->text(item) );
1088 setExportMode (false);
1091 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
1095 ex.setMapCenter(mapCenter);
1096 if (ex.setConfigFile(cf))
1098 setExportMode (true);
1099 ex.exportPresentation();
1100 setExportMode (false);
1106 void MapEditor::exportXML(const QString &dir)
1108 // Hide stuff during export, if settings want this
1109 setExportMode (true);
1111 // Create subdirectories
1114 // write to directory
1115 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1118 file.setName ( dir + "/"+mapName+".xml");
1119 if ( !file.open( IO_WriteOnly ) )
1121 // This should neverever happen
1122 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1126 // Write it finally, and write in UTF8, no matter what
1127 QTextStream ts( &file );
1128 ts.setEncoding (QTextStream::UnicodeUTF8);
1132 // Now write image, too
1133 exportImage (dir+"/images/"+mapName+".png");
1135 setExportMode (false);
1138 void MapEditor::clear()
1142 selection->unselect();
1149 void MapEditor::copy()
1151 // Finish open lineEdits
1152 if (lineedit) finishedLineEditNoSave();
1156 // write to directory
1157 QString clipfile="part";
1158 QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPoint(),selection);
1161 file.setName ( clipboardDir + "/"+clipfile+".xml");
1162 if ( !file.open( IO_WriteOnly ) )
1164 // This should neverever happen
1165 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1169 // Write it finally, and write in UTF8, no matter what
1170 QTextStream ts( &file );
1171 ts.setEncoding (QTextStream::UnicodeUTF8);
1175 clipboardEmpty=false;
1180 void MapEditor::redo()
1182 // Finish open lineEdits
1183 if (lineedit) finishedLineEditNoSave();
1185 blockSaveState=true;
1187 // Find out current undo directory
1188 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
1190 // Restore variables
1191 QString undoCommand;
1192 QString undoSelection;
1193 QString redoCommand;
1194 QString redoSelection;
1196 set.readSettings(QString(bakMapDir+"/commands"));
1197 undoCommand=set.readEntry ("undoCommand");
1198 undoSelection=set.readEntry ("undoSelection");
1199 redoCommand=set.readEntry ("redoCommand");
1200 redoSelection=set.readEntry ("redoSelection");
1202 // select object before redo
1203 if (!redoSelection.isEmpty())
1204 select (redoSelection);
1206 /* TODO remove testing
1207 cout << "ME::redo() begin\n";
1208 cout << " undosTotal="<<undosTotal<<endl;
1209 cout << " undosAvail="<<undosAvail<<endl;
1210 cout << " undoNum="<<undoNum<<endl;
1211 cout << " ---------------------------"<<endl;
1212 cout << " undoCom="<<undoCommand<<endl;
1213 cout << " undoSel="<<undoSelection<<endl;
1214 cout << " ---------------------------"<<endl;
1215 cout << " redoCom="<<redoCommand<<endl;
1216 cout << " redoSel="<<redoSelection<<endl;
1217 cout << " ---------------------------"<<endl;
1219 parseAtom (undoCommand);
1220 mapCenter->reposition();
1222 //if (!redoSelection.isEmpty())
1223 // select (redoSelection);
1227 // Undo not longer available now
1228 actionEditUndo->setEnabled (false);
1230 undoNum--; if (undoNum<1) undoNum=undosTotal;
1232 blockSaveState=false;
1233 /* TODO remove testing
1234 cout << "ME::redo() end\n";
1235 cout << " undosAvail="<<undosAvail<<endl;
1236 cout << " undoNum="<<undoNum<<endl;
1237 cout << " ---------------------------"<<endl<<endl;
1241 void MapEditor::undo()
1243 // Finish open lineEdits
1244 if (lineedit) finishedLineEditNoSave();
1246 blockSaveState=true;
1248 // Find out current undo directory
1249 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
1251 // Restore variables
1252 QString undoCommand;
1253 QString undoSelection;
1254 QString redoCommand;
1255 QString redoSelection;
1257 set.readSettings(QString(bakMapDir+"/commands"));
1258 undoCommand= set.readEntry ("undoCommand");
1259 undoSelection=set.readEntry ("undoSelection");
1260 redoCommand= set.readEntry ("redoCommand");
1261 redoSelection=set.readEntry ("redoSelection");
1263 // select object before undo
1264 if (!undoSelection.isEmpty())
1265 select (undoSelection);
1268 cout << "ME::undo() begin\n";
1269 cout << " undosTotal="<<undosTotal<<endl;
1270 cout << " undosAvail="<<undosAvail<<endl;
1271 cout << " undoNum="<<undoNum<<endl;
1272 cout << " ---------------------------"<<endl;
1273 cout << " undoCom="<<undoCommand<<endl;
1274 cout << " undoSel="<<undoSelection<<endl;
1275 cout << " ---------------------------"<<endl;
1276 cout << " redoCom="<<redoCommand<<endl;
1277 cout << " redoSel="<<redoSelection<<endl;
1278 cout << " ---------------------------"<<endl;
1280 parseAtom (undoCommand);
1281 mapCenter->reposition();
1283 //if (!redoSelection.isEmpty())
1284 // select (redoSelection);
1288 // Undo not longer available now
1289 actionEditUndo->setEnabled (false);
1291 undoNum--; if (undoNum<1) undoNum=undosTotal;
1293 blockSaveState=false;
1294 /* TODO remove testing
1295 cout << "ME::undo() end\n";
1296 cout << " undosAvail="<<undosAvail<<endl;
1297 cout << " undoNum="<<undoNum<<endl;
1298 cout << " ---------------------------"<<endl<<endl;
1302 void MapEditor::undoXML(const QString &undoSel, const QString &bakMapPath)
1304 QString bakMapDir=bakMapPath.left(bakMapPath.findRev("/"));
1306 QFile file (bakMapPath);
1310 // We need to parse saved XML data
1311 mapBuilderHandler handler;
1312 QXmlInputSource source( file);
1313 QXmlSimpleReader reader;
1314 reader.setContentHandler( &handler );
1315 reader.setErrorHandler( &handler );
1316 handler.setMapEditor( this );
1317 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1318 if (undoSel.isEmpty())
1322 handler.setLoadMode (NewMap);
1326 handler.setLoadMode (ImportReplace);
1328 blockReposition=true;
1329 bool ok = reader.parse( source );
1330 blockReposition=false;
1333 // This should never ever happen
1334 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1335 tr( handler.errorProtocol() )+" in "+bakMapDir );
1339 QMessageBox::critical( 0, tr( "Critical Error" ),
1340 tr("Temporary directory %1 used for undo is gone. \n"
1341 "I will create a new one, but at the moment no undo is available.\n"
1342 "Maybe you want to reload your original data.\n\n"
1343 "Sorry for any inconveniences.").arg(bakMapDir) );
1348 void MapEditor::pasteNoSave()
1350 // Finish open lineEdits
1351 if (lineedit) finishedLineEditNoSave();
1353 load (clipboardDir+"/part.xml",ImportAdd);
1356 void MapEditor::cutNoSave()
1362 void MapEditor::paste()
1364 if (selection && (typeid(*selection) == typeid(BranchObj) ||
1365 typeid(*selection) == typeid(MapCenterObj)))
1367 saveState(selection);
1369 mapCenter->reposition();
1374 void MapEditor::cut()
1376 saveState(selection->getParObj());
1379 mapCenter->reposition();
1383 void MapEditor::move(const int &x, const int &y)
1385 // TODO no saveState, because this is only internal at undo so far
1386 if (selection) selection->move(x,y);
1387 if (typeid(*selection) == typeid(FloatImageObj))
1388 ((FloatImageObj*)selection)->setRelPos();
1391 void MapEditor::moveBranchUp()
1393 // Finish open lineEdits
1394 if (lineedit) finishedLineEditNoSave();
1398 if (typeid(*selection) == typeid(BranchObj) )
1400 bo=(BranchObj*)selection;
1401 par=(BranchObj*)(bo->getParObj());
1402 selection->unselect();
1403 selection=par->moveBranchUp (bo);
1404 selection->select();
1405 saveState("moveBranchDown ()",bo);
1406 mapCenter->reposition();
1407 ensureSelectionVisible();
1411 void MapEditor::moveBranchDown()
1413 // Finish open lineEdits
1414 if (lineedit) finishedLineEditNoSave();
1418 if (typeid(*selection) == typeid(BranchObj) )
1420 bo=(BranchObj*)selection;
1421 par=(BranchObj*)(bo->getParObj());
1422 selection->unselect();
1423 selection=par->moveBranchDown(bo);
1424 selection->select();
1425 saveState("moveBranchUp ()",bo);
1426 mapCenter->reposition();
1427 ensureSelectionVisible();
1431 void MapEditor::editHeading()
1433 // Finish open lineEdits
1434 if (lineedit) finishedLineEditNoSave();
1437 (typeid(*selection) == typeid(BranchObj) ||
1438 typeid(*selection) == typeid(MapCenterObj) ) )
1440 editingBO=(BranchObj*)selection;
1441 saveState("setHeading (\""+((BranchObj*)selection)->getHeading()+"\")",editingBO );
1443 ensureSelectionVisible();
1444 QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
1445 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1446 QString s=editingBO->getHeading();
1447 lineedit->setText(s);
1448 lineedit->setCursorPosition(1);
1449 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1450 lineedit->selectAll();
1452 lineedit->grabKeyboard();
1453 lineedit->setFocus();
1457 void MapEditor::setHeading(const QString &s)
1459 // Internal function, no saveState needed
1461 (typeid(*selection) == typeid(BranchObj) ||
1462 typeid(*selection) == typeid(MapCenterObj) ) )
1464 ((BranchObj*)selection)->setHeading(s);
1465 mapCenter->reposition();
1467 ensureSelectionVisible();
1471 void MapEditor::setURL (const QString &s)
1473 // Internal function, no saveState needed
1475 (typeid(*selection) == typeid(BranchObj) ||
1476 typeid(*selection) == typeid(MapCenterObj) ) )
1478 ((BranchObj*)selection)->setURL(s);
1479 mapCenter->reposition();
1481 ensureSelectionVisible();
1485 void MapEditor::setVymLink (const QString &s)
1487 // Internal function, no saveState needed
1489 (typeid(*selection) == typeid(BranchObj) ||
1490 typeid(*selection) == typeid(MapCenterObj) ) )
1492 ((BranchObj*)selection)->setVymLink(s);
1493 mapCenter->reposition();
1495 ensureSelectionVisible();
1499 void MapEditor::addNewBranch(int pos)
1501 // Finish open lineEdits
1502 if (lineedit) finishedLineEditNoSave();
1505 (typeid(*selection) == typeid(BranchObj) ||
1506 typeid(*selection) == typeid(MapCenterObj) ) )
1508 saveState(selection); //TODO undoCommand
1510 BranchObj* bo1 = (BranchObj*) selection;
1511 bool wasScrolled=false;
1512 BranchObj *newbo=NULL;
1515 // save scroll state. If scrolled, automatically select
1516 // new branch in order to tmp unscroll parent...
1517 wasScrolled=bo1->isScrolled();
1518 newbo=bo1->addBranch();
1521 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1525 // add above selection
1526 newbo=parbo->insertBranch(bo1->getNum());
1528 // add below selection
1529 newbo=parbo->insertBranch(bo1->getNum()+1);
1531 // This should not happen...
1536 LinkableMapObj *oldselection=selection;
1538 mapCenter->reposition();
1540 if (actionSettingsAutoedit->isOn() ||
1541 actionSettingsAutoselectHeading->isOn() )
1543 selection->unselect();
1545 selection->select();
1546 if (actionSettingsPasteNewHeading->isOn() )
1548 BranchObj *bo2= (BranchObj*)selection;
1549 bo2->setHeading("");
1551 if (actionSettingsAutoedit->isOn() )
1553 if (!actionSettingsAutoselectHeading->isOn()
1556 selection->unselect();
1557 selection=oldselection;
1558 selection->select();
1565 void MapEditor::addNewBranchHere()
1567 // Finish open lineEdits
1568 if (lineedit) finishedLineEditNoSave();
1571 (typeid(*selection) == typeid(BranchObj) ) )
1573 saveState(selection);
1575 BranchObj* bo1 = (BranchObj*) selection;
1576 bool wasScrolled=false;
1577 BranchObj *newbo=NULL;
1578 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1581 // add below selection
1582 newbo=parbo->insertBranch(bo1->getNum()+1);
1585 LinkableMapObj *oldselection=selection;
1586 ((BranchObj*)selection)->moveBranchTo (newbo,-1);
1588 mapCenter->reposition();
1590 if (actionSettingsAutoedit->isOn() ||
1591 actionSettingsAutoselectHeading->isOn() )
1593 selection->unselect();
1595 selection->select();
1596 if (actionSettingsPasteNewHeading->isOn() )
1598 BranchObj *bo2= (BranchObj*)selection;
1599 bo2->setHeading("");
1601 if (actionSettingsAutoedit->isOn() )
1603 if (!actionSettingsAutoselectHeading->isOn()
1606 selection->unselect();
1607 selection=oldselection;
1608 selection->select();
1614 void MapEditor::deleteSelection()
1616 // Finish open lineEdits
1617 if (lineedit) finishedLineEditNoSave();
1619 if (selection && typeid(*selection) ==typeid(BranchObj) )
1621 if (selection->getDepth()>1)
1622 // Normal branch, save parent with childs
1623 saveState(selection->getParObj());
1625 // Mainbranch, save whole map
1626 // TODO Better would be to insert mainbranch again at pos
1627 // But undoCommand is missing right now
1629 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1630 BranchObj* par=(BranchObj*)(bo->getParObj());
1633 par->removeBranch(bo);
1635 selection->select();
1636 ensureSelectionVisible();
1637 mapCenter->reposition();
1640 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1642 saveState(selection->getParObj());
1643 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1644 BranchObj* par=(BranchObj*)(fio->getParObj());
1647 par->removeFloatImage(fio);
1649 selection->select();
1650 ensureSelectionVisible();
1651 mapCenter->reposition();
1656 LinkableMapObj* MapEditor::getSelection()
1661 void MapEditor::unselect()
1665 selectionLast=selection;
1666 selection->unselect();
1671 void MapEditor::reselect()
1675 selection=selectionLast;
1676 selection->select();
1681 bool MapEditor::select (const QString &s)
1683 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
1685 // Finally select the found object
1688 if (selection) unselect();
1690 selection->select();
1692 ensureSelectionVisible();
1698 void MapEditor::select (LinkableMapObj *lmo)
1700 if (lmo && selection != lmo)
1702 // select the MapObj
1703 if (selection) selection->unselect();
1705 selection->select();
1712 void MapEditor::selectNextBranch()
1714 // Increase number of branch
1717 QString s=selection->getSelectString();
1723 part=s.section(",",-1);
1725 num=part.right(part.length() - 3);
1727 s=s.left (s.length() -num.length());
1730 num=QString ("%1").arg(num.toUInt()+1);
1734 // Try to select this one
1735 if (select (s)) return;
1737 // We have no direct successor,
1738 // try to increase the parental number in order to
1739 // find a successor with same depth
1741 int d=selection->getDepth();
1746 while (!found && d>0)
1748 s=s.section (",",0,d-1);
1749 // replace substring of current depth in s with "1"
1750 part=s.section(",",-1);
1752 num=part.right(part.length() - 3);
1756 // increase number of parent
1757 num=QString ("%1").arg(num.toUInt()+1);
1758 s=s.section (",",0,d-2) + ","+ typ+num;
1761 // Special case, look at orientation
1762 if (selection->getOrientation()==OrientRightOfCenter)
1763 num=QString ("%1").arg(num.toUInt()+1);
1765 num=QString ("%1").arg(num.toUInt()-1);
1770 // pad to oldDepth, select the first branch for each depth
1771 for (i=d;i<oldDepth;i++)
1776 if ( ((BranchObj*)selection)->countBranches()>0)
1784 // try to select the freshly built string
1792 void MapEditor::selectPrevBranch()
1794 // Decrease number of branch
1797 QString s=selection->getSelectString();
1803 part=s.section(",",-1);
1805 num=part.right(part.length() - 3);
1807 s=s.left (s.length() -num.length());
1810 num=QString ("%1").arg(num.toUInt()-1);
1814 // Try to select this one
1815 if (select (s)) return;
1817 // We have no direct precessor,
1818 // try to decrease the parental number in order to
1819 // find a precessor with same depth
1821 int d=selection->getDepth();
1826 while (!found && d>0)
1828 s=s.section (",",0,d-1);
1829 // replace substring of current depth in s with "1"
1830 part=s.section(",",-1);
1832 num=part.right(part.length() - 3);
1836 // decrease number of parent
1837 num=QString ("%1").arg(num.toUInt()-1);
1838 s=s.section (",",0,d-2) + ","+ typ+num;
1841 // Special case, look at orientation
1842 if (selection->getOrientation()==OrientRightOfCenter)
1843 num=QString ("%1").arg(num.toUInt()-1);
1845 num=QString ("%1").arg(num.toUInt()+1);
1850 // pad to oldDepth, select the last branch for each depth
1851 for (i=d;i<oldDepth;i++)
1855 if ( ((BranchObj*)selection)->countBranches()>0)
1856 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)selection)->countBranches()-1 );
1863 // try to select the freshly built string
1871 void MapEditor::selectUpperBranch()
1873 // Finish open lineEdits
1874 if (lineedit) finishedLineEditNoSave();
1878 if (typeid(*selection) == typeid(BranchObj))
1880 if (selection->getOrientation()==OrientRightOfCenter)
1883 if (selection->getDepth()==1)
1891 void MapEditor::selectLowerBranch()
1893 // Finish open lineEdits
1894 if (lineedit) finishedLineEditNoSave();
1898 if (typeid(*selection) == typeid(BranchObj))
1900 if (selection->getOrientation()==OrientRightOfCenter)
1903 if (selection->getDepth()==1)
1912 void MapEditor::selectLeftBranch()
1914 // Finish open lineEdits
1915 if (lineedit) finishedLineEditNoSave();
1921 if (typeid(*selection) == typeid(MapCenterObj))
1923 par= (BranchObj*) selection;
1924 bo=par->getLastSelectedBranch();
1927 // Workaround for reselecting on left and right side
1928 if (bo->getOrientation()==OrientRightOfCenter)
1930 bo=par->getLastBranch();
1936 selection->select();
1938 ensureSelectionVisible();
1943 par=(BranchObj*)(selection->getParObj());
1944 if (selection->getOrientation()==OrientRightOfCenter)
1946 if (typeid(*selection) == typeid(BranchObj) ||
1947 typeid(*selection) == typeid(FloatImageObj))
1949 selection->unselect();
1951 selection->select();
1953 ensureSelectionVisible();
1957 if (typeid(*selection) == typeid(BranchObj) )
1959 bo=((BranchObj*)selection)->getLastSelectedBranch();
1962 selection->unselect();
1964 selection->select();
1966 ensureSelectionVisible();
1974 void MapEditor::selectRightBranch()
1976 // Finish open lineEdits
1977 if (lineedit) finishedLineEditNoSave();
1984 if (typeid(*selection) == typeid(MapCenterObj))
1986 par= (BranchObj*) selection;
1987 bo=par->getLastSelectedBranch();
1990 // Workaround for relecting on left and right side
1991 if (bo->getOrientation()==OrientLeftOfCenter)
1992 bo=par->getFirstBranch();
1997 selection->select();
1998 ensureSelectionVisible();
2003 par=(BranchObj*)(selection->getParObj());
2004 if (selection->getOrientation()==OrientLeftOfCenter)
2006 if (typeid(*selection) == typeid(BranchObj) ||
2007 typeid(*selection) == typeid(FloatImageObj))
2009 selection->unselect();
2011 selection->select();
2013 ensureSelectionVisible();
2017 if (typeid(*selection) == typeid(BranchObj) )
2019 bo=((BranchObj*)selection)->getLastSelectedBranch();
2022 selection->unselect();
2024 selection->select();
2026 ensureSelectionVisible();
2034 void MapEditor::selectFirstBranch()
2036 // Finish open lineEdits
2037 if (lineedit) finishedLineEditNoSave();
2043 if (typeid(*selection) == typeid(BranchObj))
2045 bo1= (BranchObj*) selection;
2046 par=(BranchObj*)(bo1->getParObj());
2047 bo2=par->getFirstBranch();
2051 selection->select();
2052 ensureSelectionVisible();
2059 void MapEditor::selectLastBranch()
2061 // Finish open lineEdits
2062 if (lineedit) finishedLineEditNoSave();
2068 if (typeid(*selection) == typeid(BranchObj))
2070 bo1= (BranchObj*) selection;
2071 par=(BranchObj*)(bo1->getParObj());
2072 bo2=par->getLastBranch();
2076 selection->select();
2077 ensureSelectionVisible();
2084 void MapEditor::setColor(QColor c)
2089 void MapEditor::selectBackgroundColor()
2091 // Finish open lineEdits
2092 if (lineedit) finishedLineEditNoSave();
2094 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
2095 if ( !col.isValid() ) return;
2096 setBackgroundColor( col );
2100 void MapEditor::setBackgroundColor(QColor c)
2102 mapCanvas->setBackgroundColor (c);
2105 QColor MapEditor::pickColor()
2109 if (typeid(*selection) == typeid(BranchObj) ||
2110 typeid(*selection) == typeid(MapCenterObj))
2112 BranchObj *bo=(BranchObj*)selection;
2113 actColor=bo->getColor();
2119 void MapEditor::colorItem()
2123 if (typeid(*selection) == typeid(BranchObj) ||
2124 typeid(*selection) == typeid(MapCenterObj))
2126 saveState(selection); //TODO undoCommand
2127 BranchObj *bo=(BranchObj*)selection;
2128 bo->setColor(actColor); // color branch
2133 void MapEditor::colorBranch()
2137 if (typeid(*selection) == typeid(BranchObj) ||
2138 typeid(*selection) == typeid(MapCenterObj))
2140 saveState(selection); //TODO undoCommand
2141 BranchObj *bo=(BranchObj*)selection;
2142 bo->setColorChilds(actColor); // color links, color childs
2148 void MapEditor::toggleStandardFlag(QString f)
2152 saveState(selection);// TODO undoCommand
2153 ((BranchObj*)selection)->toggleStandardFlag (f,actionSettingsUseFlagGroups);
2158 void MapEditor::setViewCenter()
2160 // transform to CanvasView Coord:
2161 QPoint p=worldMatrix().map(movingCenter);
2162 center ( p.x(), p.y());
2166 BranchObj* MapEditor::findText (QString s, bool cs)
2169 { // Nothing found or new find process
2171 // nothing found, start again
2173 itFind=mapCenter->first();
2175 bool searching=true;
2176 bool foundNote=false;
2177 while (searching && !EOFind)
2181 // Searching in Note
2182 if (itFind->getNote().contains(s,cs))
2184 if (selection!=itFind)
2186 if (selection) ((BranchObj*)selection)->unselect();
2188 selection->select();
2190 ensureSelectionVisible();
2192 if (textEditor->findText(s,cs))
2198 // Searching in Heading
2199 if (searching && itFind->getHeading().contains (s,cs) )
2201 if (selection) ((BranchObj*)selection)->unselect();
2203 selection->select();
2205 ensureSelectionVisible();
2211 itFind=itFind->next();
2212 if (!itFind) EOFind=true;
2218 return (BranchObj*)selection;
2223 void MapEditor::findReset()
2224 { // Necessary if text to find changes during a find process
2229 void MapEditor::editURL()
2231 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2232 typeid(*selection) == typeid(MapCenterObj)) )
2235 BranchObj *bo=(BranchObj*)selection;
2236 QString text = QInputDialog::getText(
2237 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2238 bo->getURL(), &ok, this );
2241 // user entered something and pressed OK
2242 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+text+"\")");
2249 QString MapEditor::getURL()
2251 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2252 typeid(*selection) == typeid(MapCenterObj)) )
2253 return ((BranchObj*)selection)->getURL();
2258 void MapEditor::editHeading2URL()
2260 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2261 typeid(*selection) == typeid(MapCenterObj)) )
2263 BranchObj *bo=(BranchObj*)selection;
2264 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+bo->getHeading()+"\")");
2265 bo->setURL (bo->getHeading());
2270 void MapEditor::editBugzilla2URL()
2272 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2273 typeid(*selection) == typeid(MapCenterObj)) )
2275 BranchObj *bo=(BranchObj*)selection;
2276 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2277 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")");
2283 void MapEditor::editFATE2URL()
2285 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2286 typeid(*selection) == typeid(MapCenterObj)) )
2288 BranchObj *bo=(BranchObj*)selection;
2289 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2290 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")");
2296 void MapEditor::editVymLink()
2298 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2299 typeid(*selection) == typeid(MapCenterObj)) )
2301 BranchObj *bo=(BranchObj*)selection;
2302 QFileDialog *fd=new QFileDialog( this,__VYM " - " +tr("Link to another map"));
2303 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2304 fd->setCaption(__VYM " - " +tr("Link to another map"));
2305 if (! bo->getVymLink().isEmpty() )
2306 fd->setSelection( bo->getVymLink() );
2310 if ( fd->exec() == QDialog::Accepted )
2312 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\""+fd->selectedFile()+"\")");
2313 bo->setVymLink (fd->selectedFile() );
2315 mapCenter->reposition();
2322 void MapEditor::deleteVymLink()
2324 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2325 typeid(*selection) == typeid(MapCenterObj)) )
2327 BranchObj *bo=(BranchObj*)selection;
2328 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\"\")");
2329 bo->setVymLink ("" );
2331 mapCenter->reposition();
2337 void MapEditor::setHideExport()
2339 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2340 typeid(*selection) == typeid(MapCenterObj)) ||
2341 (typeid(*selection)==typeid(FloatImageObj))
2344 saveState(); //TODO undoCommand
2345 OrnamentedObj *oo=(OrnamentedObj*)selection;
2346 oo->setHideInExport(actionEditToggleHideExport->isOn());
2348 mapCenter->reposition();
2354 void MapEditor::toggleHideExport()
2356 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2357 typeid(*selection) == typeid(MapCenterObj)) ||
2358 (typeid(*selection)==typeid(FloatImageObj))
2361 saveState(); //TODO undoCommand
2362 OrnamentedObj *oo=(OrnamentedObj*)selection;
2363 if (oo->hideInExport())
2364 oo->setHideInExport(false);
2366 oo->setHideInExport(true);
2367 actionEditToggleHideExport->setOn (oo->hideInExport());
2369 mapCenter->reposition();
2375 QString MapEditor::getVymLink()
2377 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2378 typeid(*selection) == typeid(MapCenterObj)) )
2380 return ((BranchObj*)selection)->getVymLink();
2386 void MapEditor::removeBranchHere()
2388 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2390 BranchObj* bo=(BranchObj*)selection;
2391 BranchObj* par=(BranchObj*)(bo->getParObj());
2392 if (bo->getDepth()==1)
2395 saveState(selection->getParObj()); // TODO undoCommand
2396 QString sel=selection->getSelectString();
2398 par->removeBranchHere(bo);
2399 mapCenter->reposition();
2404 void MapEditor::removeChilds()
2406 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2408 saveState(selection->getParObj());
2409 ((BranchObj*)selection)->removeChilds();
2410 mapCenter->reposition();
2414 void MapEditor::editMapInfo()
2416 ExtraInfoDialog dia;
2417 dia.setMapName (getFileName() );
2418 dia.setAuthor (mapCenter->getAuthor() );
2419 dia.setComment(mapCenter->getComment() );
2424 QCanvasItemList l=canvas()->allItems();
2425 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2427 stats+=QString ("%1 items on canvas\n").arg (i,6);
2434 bo=mapCenter->first();
2437 if (!bo->getNote().isEmpty() ) n++;
2438 f+= bo->countFloatImages();
2440 xl+=bo->countXLinks();
2443 stats+=QString ("%1 branches\n").arg (b-1,6);
2444 stats+=QString ("%1 xLinks \n").arg (xl,6);
2445 stats+=QString ("%1 notes\n").arg (n,6);
2446 stats+=QString ("%1 images\n").arg (f,6);
2447 dia.setStats (stats);
2449 // Finally show dialog
2450 if (dia.exec() == QDialog::Accepted)
2452 saveState(); //TODO undoCommand
2453 mapCenter->setAuthor (dia.getAuthor() );
2454 mapCenter->setComment (dia.getComment() );
2458 void MapEditor::updateActions()
2461 if (getLinkColorHint()==HeadingColor)
2462 actionFormatLinkColorHint->setOn(true);
2464 actionFormatLinkColorHint->setOn(false);
2469 actionFormatLinkStyleLine->setOn(true);
2472 actionFormatLinkStyleParabel->setOn(true);
2475 actionFormatLinkStylePolyLine->setOn(true);
2477 case StylePolyParabel:
2478 actionFormatLinkStylePolyParabel->setOn(true);
2484 QPixmap pix( 16, 16 );
2485 pix.fill( mapCanvas->backgroundColor() );
2486 actionFormatBackColor->setIconSet( pix );
2487 pix.fill( defLinkColor );
2488 actionFormatLinkColor->setIconSet( pix );
2490 actionEditUndo->setEnabled( mapChanged );
2491 actionFileSave->setEnabled( mapUnsaved );
2495 if ( (typeid(*selection) == typeid(BranchObj)) ||
2496 (typeid(*selection) == typeid(MapCenterObj)) )
2498 BranchObj *bo=(BranchObj*)selection;
2499 // Take care of links
2500 if (bo->countXLinks()==0)
2502 branchLinksContextMenu->clear();
2503 branchLinksContextMenu->insertItem ("No xLink available");
2504 branchLinksContextMenuDup->clear();
2505 branchLinksContextMenuDup->insertItem ("No xLink available");
2511 branchLinksContextMenu->clear();
2512 branchLinksContextMenuDup->clear();
2513 for (int i=0; i<=bo->countXLinks();i++)
2515 bot=bo->XLinkTargetAt(i);
2518 s=bot->getHeading();
2521 branchLinksContextMenu->insertItem (s);
2522 branchLinksContextMenuDup->insertItem (s);
2527 standardFlagsDefault->setEnabled (true);
2529 actionEditToggleScroll->setEnabled (true);
2530 if ( bo->isScrolled() )
2531 actionEditToggleScroll->setOn(true);
2533 actionEditToggleScroll->setOn(false);
2535 if ( bo->getURL().isEmpty() )
2537 actionEditOpenURL->setEnabled (false);
2538 actionEditOpenURLTab->setEnabled (false);
2542 actionEditOpenURL->setEnabled (true);
2543 actionEditOpenURLTab->setEnabled (true);
2545 if ( bo->getVymLink().isEmpty() )
2547 actionEditOpenVymLink->setEnabled (false);
2548 actionEditDeleteVymLink->setEnabled (false);
2551 actionEditOpenVymLink->setEnabled (true);
2552 actionEditDeleteVymLink->setEnabled (true);
2554 actionEditToggleHideExport->setEnabled (true);
2555 actionEditToggleHideExport->setOn (bo->hideInExport() );
2557 actionEditCopy->setEnabled (true);
2558 actionEditCut->setEnabled (true);
2559 if (!clipboardEmpty)
2560 actionEditPaste->setEnabled (true);
2562 actionEditPaste->setEnabled (false);
2563 for (a=actionListBranches.first();a;a=actionListBranches.next())
2564 a->setEnabled(true);
2565 actionEditDelete->setEnabled (true);
2566 switch (selection->getFrameType())
2569 actionFormatFrameNone->setOn(true);
2572 actionFormatFrameRectangle->setOn(true);
2577 actionFormatIncludeImagesVer->setOn
2578 ( ((BranchObj*)selection)->getIncludeImagesVer());
2579 actionFormatIncludeImagesHor->setOn
2580 ( ((BranchObj*)selection)->getIncludeImagesHor());
2581 actionFormatHideLinkUnselected->setOn
2582 (selection->getHideLinkUnselected());
2584 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2586 FloatObj *fo=(FloatImageObj*)selection;
2587 standardFlagsDefault->setEnabled (false);
2589 actionEditOpenURL->setEnabled (false);
2590 actionEditOpenVymLink->setEnabled (false);
2591 actionEditDeleteVymLink->setEnabled (false);
2592 actionEditToggleHideExport->setEnabled (true);
2593 actionEditToggleHideExport->setOn (fo->hideInExport() );
2596 actionEditCopy->setEnabled (true);
2597 actionEditCut->setEnabled (true);
2598 actionEditPaste->setEnabled (false);
2599 for (a=actionListBranches.first();a;a=actionListBranches.next())
2600 a->setEnabled(false);
2601 actionEditDelete->setEnabled (true);
2602 actionFormatHideLinkUnselected->setOn
2603 ( selection->getHideLinkUnselected());
2608 standardFlagsDefault->setEnabled (false);
2610 actionEditCopy->setEnabled (false);
2611 actionEditCut->setEnabled (false);
2612 actionEditPaste->setEnabled (false);
2613 for (a=actionListBranches.first();a;a=actionListBranches.next())
2614 a->setEnabled(false);
2616 actionEditToggleScroll->setEnabled (true);
2617 actionEditOpenURL->setEnabled (false);
2618 actionEditOpenVymLink->setEnabled (false);
2619 actionEditDeleteVymLink->setEnabled (false);
2620 actionEditHeading2URL->setEnabled (false);
2621 actionEditDelete->setEnabled (false);
2625 void MapEditor::updateNoteFlag()
2628 if ( (typeid(*selection) == typeid(BranchObj)) ||
2629 (typeid(*selection) == typeid(MapCenterObj)) )
2630 ((BranchObj*)selection)->updateNoteFlag();
2633 void MapEditor::setLinkStyle (LinkStyle ls)
2637 saveState(); // TODO undoCommand
2639 bo=mapCenter->first();
2643 bo->setLinkStyle(bo->getDefLinkStyle());
2646 mapCenter->reposition();
2649 LinkStyle MapEditor::getLinkStyle ()
2654 void MapEditor::setLinkColor(QColor c)
2660 void MapEditor::setLinkColorHint()
2662 // called from setLinkColorHint(lch) or at end of parse
2664 bo=mapCenter->first();
2672 void MapEditor::setLinkColorHint(LinkColorHint lch)
2678 void MapEditor::toggleLinkColorHint()
2680 if (linkcolorhint==HeadingColor)
2681 linkcolorhint=DefaultColor;
2683 linkcolorhint=HeadingColor;
2685 bo=mapCenter->first();
2693 LinkColorHint MapEditor::getLinkColorHint()
2695 return linkcolorhint;
2698 QColor MapEditor::getDefLinkColor()
2700 return defLinkColor;
2703 void MapEditor::setDefXLinkColor(QColor col)
2708 QColor MapEditor::getDefXLinkColor()
2710 return defXLinkColor;
2713 void MapEditor::setDefXLinkWidth (int w)
2718 int MapEditor::getDefXLinkWidth()
2720 return defXLinkWidth;
2723 void MapEditor::selectLinkColor()
2725 // Finish open lineEdits
2726 if (lineedit) finishedLineEditNoSave();
2728 QColor col = QColorDialog::getColor( defLinkColor, this );
2729 if ( !col.isValid() ) return;
2730 setLinkColor( col );
2731 saveState(); //TODO undoCommand
2735 void MapEditor::toggleScroll()
2737 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2739 BranchObj *bo=((BranchObj*)selection);
2740 if (bo->countBranches()==0) return;
2741 if (bo->getDepth()==0) return;
2742 saveState(selection);
2749 void MapEditor::unScrollAll()
2752 bo=mapCenter->first();
2755 if (bo->isScrolled()) bo->toggleScroll();
2760 void MapEditor::loadFloatImage ()
2763 (typeid(*selection) == typeid(BranchObj)) ||
2764 (typeid(*selection) == typeid(MapCenterObj)) )
2766 BranchObj *bo=((BranchObj*)selection);
2768 QFileDialog *fd=new QFileDialog( this);
2769 fd->setMode (QFileDialog::ExistingFiles);
2770 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2771 ImagePreview *p =new ImagePreview (fd);
2772 fd->setContentsPreviewEnabled( TRUE );
2773 fd->setContentsPreview( p, p );
2774 fd->setPreviewMode( QFileDialog::Contents );
2775 fd->setCaption(__VYM " - " +tr("Load image"));
2776 fd->setDir (lastImageDir);
2780 if ( fd->exec() == QDialog::Accepted )
2782 saveState(selection);
2783 lastImageDir=fn.left(fn.findRev ("/"));
2784 QStringList flist = fd->selectedFiles();
2785 QStringList::Iterator it = flist.begin();
2786 while( it != flist.end() )
2789 bo->addFloatImage();
2790 // TODO check if load was successful
2791 bo->getLastFloatImage()->load(*it);
2792 bo->getLastFloatImage()->setOriginalFilename(fn);
2796 mapCenter->reposition();
2805 void MapEditor::saveFloatImage (int item)
2808 (typeid(*selection) == typeid(FloatImageObj)) )
2810 FloatImageObj *fio=((FloatImageObj*)selection);
2811 const char* fmt = saveImageFormatMenu->text(item);
2813 QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
2814 fd->addFilter ("PNG (*.png)");
2815 fd->addFilter ("BMP (*.bmp)");
2816 fd->addFilter ("XBM (*.xbm)");
2817 fd->addFilter ("JPG (*.jpg)");
2818 fd->addFilter ("XPM (*.xpm)");
2819 fd->addFilter ("GIF (*.gif)");
2820 fd->addFilter ("PNM (*.pnm)");
2821 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2822 fd->setCaption(__VYM " - " +tr("Save image as %1").arg(fmt));
2823 fd->setMode( QFileDialog::AnyFile );
2824 fd->setSelection (fio->getOriginalFilename());
2828 if ( fd->exec() == QDialog::Accepted )
2830 if (QFile (fd->selectedFile()).exists() )
2832 QMessageBox mb( __VYM,
2833 tr("The file %1 exists already.\n"
2834 "Do you want to overwrite it?").arg(fd->selectedFile()),
2835 QMessageBox::Warning,
2836 QMessageBox::Yes | QMessageBox::Default,
2837 QMessageBox::Cancel | QMessageBox::Escape,
2838 QMessageBox::QMessageBox::NoButton );
2840 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2841 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2844 case QMessageBox::Yes:
2847 case QMessageBox::Cancel:
2853 fio->save (fd->selectedFile(),fmt);
2858 void MapEditor::setFrame(const FrameType &t)
2861 (typeid(*selection) == typeid(BranchObj)) ||
2862 (typeid(*selection) == typeid(MapCenterObj)) )
2864 selection->setFrameType (t);
2865 mapCenter->reposition();
2866 selection->updateLink();
2870 void MapEditor::setIncludeImagesVer(bool b)
2873 (typeid(*selection) == typeid(BranchObj)) ||
2874 (typeid(*selection) == typeid(MapCenterObj)) )
2875 ((BranchObj*)selection)->setIncludeImagesVer(b);
2876 mapCenter->reposition();
2879 void MapEditor::setIncludeImagesHor(bool b)
2882 (typeid(*selection) == typeid(BranchObj)) ||
2883 (typeid(*selection) == typeid(MapCenterObj)) )
2884 ((BranchObj*)selection)->setIncludeImagesHor(b);
2885 mapCenter->reposition();
2888 void MapEditor::setHideLinkUnselected (bool b)
2891 (typeid(*selection) == typeid(BranchObj)) ||
2892 (typeid(*selection) == typeid(MapCenterObj)) ||
2893 (typeid(*selection) == typeid(FloatImageObj)) )
2894 selection->setHideLinkUnselected(b);
2897 void MapEditor::importDir(BranchObj *dst, QDir d)
2900 (typeid(*selection) == typeid(BranchObj)) ||
2901 (typeid(*selection) == typeid(MapCenterObj)) )
2905 // Traverse directories
2906 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2907 const QFileInfoList *dirlist = d.entryInfoList();
2908 QFileInfoListIterator itdir( *dirlist );
2911 while ( (fi = itdir.current()) != 0 )
2913 if (fi->fileName() != "." && fi->fileName() != ".." )
2916 bo=dst->getLastBranch();
2917 bo->setHeading (fi->fileName() );
2918 bo->setColor (QColor("blue"));
2920 if ( !d.cd(fi->fileName()) )
2921 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi->fileName()));
2924 // Recursively add subdirs
2932 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
2933 const QFileInfoList *filelist = d.entryInfoList();
2934 QFileInfoListIterator itfile( *filelist );
2936 while ( (fi = itfile.current()) != 0 )
2939 bo=dst->getLastBranch();
2940 bo->setHeading (fi->fileName() );
2941 bo->setColor (QColor("black"));
2942 if (fi->fileName().right(4) == ".vym" )
2943 bo->setVymLink (fi->filePath());
2950 void MapEditor::importDir()
2953 (typeid(*selection) == typeid(BranchObj)) ||
2954 (typeid(*selection) == typeid(MapCenterObj)) )
2956 QFileDialog *fd=new QFileDialog( this,__VYM " - " +tr("Choose directory structure to import"));
2957 fd->setMode (QFileDialog::DirectoryOnly);
2958 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2959 fd->setCaption(__VYM " - " +tr("Choose directory structure to import"));
2963 if ( fd->exec() == QDialog::Accepted )
2965 BranchObj *bo=((BranchObj*)selection);
2966 importDir (bo,QDir(fd->selectedFile()) );
2967 mapCenter->reposition();
2974 void MapEditor::followXLink(int i)
2977 (typeid(*selection) == typeid(BranchObj)) ||
2978 (typeid(*selection) == typeid(MapCenterObj)) )
2980 BranchObj *bo=((BranchObj*)selection)->XLinkTargetAt(i);
2983 selection->unselect();
2985 selection->select();
2986 ensureSelectionVisible();
2991 void MapEditor::editXLink(int i)
2994 (typeid(*selection) == typeid(BranchObj)) ||
2995 (typeid(*selection) == typeid(MapCenterObj)) )
2997 XLinkObj *xlo=((BranchObj*)selection)->XLinkAt(i);
3000 EditXLinkDialog dia;
3002 dia.setSelection(selection);
3003 if (dia.exec() == QDialog::Accepted)
3005 if (dia.useSettingsGlobal() )
3007 setDefXLinkColor (xlo->getColor() );
3008 setDefXLinkWidth (xlo->getWidth() );
3010 if (dia.deleteXLink())
3011 ((BranchObj*)selection)->deleteXLinkAt(i);
3012 saveState(); //TODO undoCommand
3018 void MapEditor::testFunction()
3020 cout << "MapEditor::testFunction() called\n";
3022 if (hidemode==HideNone)
3024 setHideTmpMode (HideExport);
3025 mapCenter->calcBBoxSizeWithChilds();
3026 QRect totalBBox=mapCenter->getTotalBBox();
3027 QRect mapRect=totalBBox;
3028 QCanvasRectangle *frame=NULL;
3030 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
3032 mapRect.setRect (totalBBox.x(), totalBBox.y(),
3033 totalBBox.width(), totalBBox.height());
3034 frame=new QCanvasRectangle (mapRect,mapCanvas);
3035 frame->setBrush (QColor(white));
3036 frame->setPen (QColor(black));
3042 setHideTmpMode (HideNone);
3044 cout <<" hidemode="<<hidemode<<endl;
3047 void MapEditor::ensureSelectionVisible()
3051 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
3053 if (selection->getOrientation() == OrientLeftOfCenter)
3054 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
3056 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
3057 ensureVisible (p.x(), p.y() );
3062 void MapEditor::updateViewCenter()
3064 // Update movingCenter, so that we can zoom comfortably later
3065 QRect rc = QRect( contentsX(), contentsY(),
3066 visibleWidth(), visibleHeight() );
3067 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
3068 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
3069 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
3072 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
3074 // Lineedits are already closed by preceding
3075 // mouseEvent, we don't need to close here.
3077 QPoint p = inverseWorldMatrix().map(e->pos());
3078 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3081 { // MapObj was found
3082 if (selection != lmo)
3084 // select the MapObj
3085 if (selection) selection->unselect();
3087 selection->select();
3093 if (typeid(*selection)==typeid(BranchObj) ||
3094 typeid(*selection)==typeid(MapCenterObj) )
3096 // Context Menu on branch or mapcenter
3098 branchContextMenu->popup(e->globalPos() );
3100 if (typeid(*selection)==typeid(FloatImageObj))
3102 // Context Menu on floatimage
3104 floatimageContextMenu->popup(e->globalPos() );
3108 { // No MapObj found, we are on the Canvas itself
3109 // Context Menu on Canvas
3111 canvasContextMenu->popup(e->globalPos() );
3115 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
3117 // Finish open lineEdits
3118 if (lineedit) finishedLineEditNoSave();
3120 QPoint p = inverseWorldMatrix().map(e->pos());
3121 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3123 //Take care of clickdesystem flags _or_ modifier modes
3125 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
3126 typeid(*lmo)==typeid(MapCenterObj) ))
3128 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
3129 if (!foname.isEmpty())
3131 // systemFlag clicked
3135 if (e->state() & QMouseEvent::ControlButton)
3136 mainWindow->editOpenURLTab();
3138 mainWindow->editOpenURL();
3140 else if (foname=="vymLink")
3142 mainWindow->editOpenVymLink();
3143 // tabWidget may change, better return now
3144 // before segfaulting...
3145 } else if (foname=="note")
3146 mainWindow->windowToggleNoteEditor();
3147 else if (foname=="hideInExport")
3152 // No system flag clicked, take care of modmodes
3154 // Special case: CTRL is pressed
3155 if (e->state() & QMouseEvent::ControlButton)
3157 if (actionModModeColor->isOn())
3160 setCursor (pickColorCursor);
3163 if (actionModModeLink->isOn())
3165 BranchObj *bo_begin=NULL;
3167 bo_begin=(BranchObj*)(lmo);
3170 ((typeid(*selection) == typeid(BranchObj)) ||
3171 (typeid(*selection) == typeid(MapCenterObj))) )
3172 bo_begin=(BranchObj*)selection;
3176 linkingObj_src=bo_begin;
3177 tmpXLink=new XLinkObj (mapCanvas);
3178 tmpXLink->setBegin (bo_begin);
3179 tmpXLink->setEnd (p);
3180 tmpXLink->setColor(defXLinkColor);
3181 tmpXLink->setWidth(defXLinkWidth);
3182 tmpXLink->updateXLink();
3183 tmpXLink->setVisibility (true);
3191 // Left Button Move Branches
3192 if (e->button() == QMouseEvent::LeftButton )
3194 movingObj_start.setX( p.x() - selection->x() );
3195 movingObj_start.setY( p.y() - selection->y() );
3196 movingObj_orgPos.setX (lmo->x() );
3197 movingObj_orgPos.setY (lmo->y() );
3199 // If modMode==copy, then we want to "move" the _new_ object around
3200 // then we need the offset from p to the _old_ selection, because of tmp
3201 if (actionModModeCopy->isOn() &&
3202 e->state() & QMouseEvent::ControlButton)
3204 if (typeid(*selection)==typeid(BranchObj) )
3207 mapCenter->addBranch ((BranchObj*)selection);
3209 selection=mapCenter->getLastBranch();
3210 selection->select();
3211 mapCenter->reposition();
3214 movingObj=selection;
3216 // Middle Button Toggle Scroll
3217 // (On Mac OS X this won't work, but we still have
3218 // a button in the toolbar)
3219 if (e->button() == QMouseEvent::MidButton )
3223 { // No MapObj found, we are on the Canvas itself
3224 // Left Button move Pos of CanvasView
3225 if (e->button() == QMouseEvent::LeftButton )
3227 movingObj=NULL; // move Content not Obj
3228 movingObj_start=e->globalPos();
3229 movingCont_start=QPoint (contentsX(), contentsY() );
3230 movingVec=QPoint(0,0);
3231 setCursor(handOpenCursor);
3236 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3238 QPoint p = inverseWorldMatrix().map(e->pos());
3240 // Move the selected MapObj
3241 if ( selection && movingObj)
3243 // To avoid jumping of the CanvasView, only
3244 // ensureSelectionVisible, if not tmp linked
3245 if (!selection->hasParObjTmp())
3246 ensureSelectionVisible ();
3248 // Now move the selection, but add relative position
3249 // (movingObj_start) where selection was chosen with
3250 // mousepointer. (This avoids flickering resp. jumping
3251 // of selection back to absPos)
3253 LinkableMapObj *lmosel;
3254 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3256 // Check if we could link
3257 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3260 if (typeid(*selection) == typeid(FloatImageObj))
3262 FloatObj *fo=(FloatObj*)selection;
3263 saveState("move "+qpointToString(movingObj_orgPos),fo->getSelectString() );
3264 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3268 // Relink float to new mapcenter or branch, if shift is pressed
3269 // Only relink, if selection really has a new parent
3270 if ( (e->state() & QMouseEvent::ShiftButton) && lmo &&
3271 ( (typeid(*lmo)==typeid(BranchObj)) ||
3272 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3273 ( lmo != fo->getParObj())
3276 if (typeid(*fo) == typeid(FloatImageObj))
3279 FloatImageObj *fio=(FloatImageObj*)(fo);
3280 ((BranchObj*)(lmo))->addFloatImage (fio);
3282 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3283 fio=((BranchObj*)(lmo))->getLastFloatImage();
3286 selection=(LinkableMapObj*)(fio);
3287 selection->select();
3288 movingObj=(MapObj*)(fio);
3291 } else // selection != a FloatObj
3293 if (lmosel->getDepth()==0)
3295 if (e->state() == (LeftButton | !ShiftButton))
3296 // If mapCenter is moved, move all the rest by default, too.
3297 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3299 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3302 if (lmosel->getDepth()==1)
3304 // depth==1, mainbranch
3305 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3309 if (lmosel->getOrientation() == OrientLeftOfCenter)
3310 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3311 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3312 p.y()-movingObj_start.y() +lmosel->getTopPad() );
3314 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
3316 // reposition subbranch
3317 lmosel->reposition();
3318 //ensureSelectionVisible();
3320 if (lmo && (lmo!=selection) &&
3321 (typeid(*lmo) == typeid(BranchObj) ||
3322 (typeid(*lmo) == typeid(MapCenterObj) )
3325 if (e->state() & QMouseEvent::ControlButton)
3327 // Special case: CTRL to link below lmo
3328 lmosel->setParObjTmp (lmo,p,+1);
3330 else if (e->state() & QMouseEvent::ShiftButton)
3331 lmosel->setParObjTmp (lmo,p,-1);
3333 lmosel->setParObjTmp (lmo,p,0);
3336 lmosel->unsetParObjTmp();
3337 /* FIXME not needed anymore?
3338 if (lmo &&(lmo==selection))
3339 // Could link to myself (happens sometimes...)
3340 lmosel->unsetParObjTmp();
3342 // no Obj under selection, go back to original Parent
3343 lmosel->unsetParObjTmp();
3348 } // no FloatImageObj
3352 } // selection && moving_obj
3354 // Draw a link from one branch to another
3357 tmpXLink->setEnd (p);
3358 tmpXLink->updateXLink();
3362 if (!movingObj && !pickingColor &&!drawingLink)
3364 QPoint p=e->globalPos();
3365 movingVec.setX(-p.x() + movingObj_start.x() );
3366 movingVec.setY(-p.y() + movingObj_start.y() );
3367 setContentsPos( movingCont_start.x() + movingVec.x(),
3368 movingCont_start.y() + movingVec.y());
3375 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3377 LinkableMapObj *dst;
3378 // Have we been picking color?
3382 setCursor (ArrowCursor);
3383 // Check if we are over another branch
3384 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3385 if (dst && selection)
3387 if (e->state() & QMouseEvent::ShiftButton)
3389 ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor());
3390 ((BranchObj*)selection)->setLinkColor ();
3394 ((BranchObj*)selection)->setColorChilds (((BranchObj*)(dst))->getColor());
3395 ((BranchObj*)selection)->setLinkColor ();
3401 // Have we been drawing a link?
3405 // Check if we are over another branch
3406 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3407 if (dst && selection)
3409 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3410 tmpXLink->updateXLink();
3411 tmpXLink->activate();
3412 saveState(); //TODO undoCommand
3421 // Have we been moving something?
3422 if ( selection && movingObj )
3424 // Moved FloatObj? Maybe we need to reposition
3425 if(typeid(*selection)==typeid (FloatImageObj))
3427 selection->getParObj()->requestReposition();
3428 mapCenter->reposition();
3431 // Check if we are over another branch, but ignore
3432 // any found LMOs, which are FloatObjs
3433 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3434 ((LinkableMapObj*)selection) );
3437 (typeid(*dst)!=typeid(BranchObj)&&typeid(*dst)!=typeid(MapCenterObj)))
3440 // Now check, if we have been moving a branch
3441 if (typeid(*selection) == typeid(BranchObj) )
3443 // save the position in case we link to mapcenter
3444 QPoint savePos=QPoint (selection->x(),selection->y() );
3446 // Reset the temporary drawn link to the original one
3447 ((LinkableMapObj*)selection)->unsetParObjTmp();
3453 BranchObj* bs=((BranchObj*)selection);
3454 QString undoCom="linkBranchToPos (\""+
3455 (bs->getParObj())->getSelectString()+
3457 QString("%1").arg(bs->getNum())+
3459 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+
3461 // TODO we also could check, if dest and src are on same branch,
3462 // then it would be sufficient to saveState of this branch
3464 // Modifiers allow to insert above/below dst
3465 if (e->state() & QMouseEvent::ShiftButton)
3467 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum());
3469 if (e->state() & QMouseEvent::ControlButton)
3471 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum()+1);
3474 bs->moveBranchTo ((BranchObj*)(dst),-1);
3475 if (dst->getDepth()==0)
3478 saveState (undoCom,bs->getSelectString() );
3480 if (selection->getDepth()==1)
3481 // If we have moved mainbranch only save endposition
3482 saveState("move "+qpointToString(movingObj_orgPos), selection->getSelectString() );
3484 // Draw the original link, before selection was moved around
3485 mapCenter->reposition();
3487 // Finally resize canvas, if needed
3492 // maybe we moved View: set old cursor
3493 setCursor (ArrowCursor);
3497 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3499 // Finish open lineEdits
3500 if (lineedit) finishedLineEditNoSave();
3502 if (e->button() == QMouseEvent::LeftButton )
3504 QPoint p = inverseWorldMatrix().map(e->pos());
3505 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3506 if (lmo) { // MapObj was found
3507 // First select the MapObj than edit heading
3508 if (selection) selection->unselect();
3510 selection->select();
3511 saveState(selection);
3517 void MapEditor::resizeEvent (QResizeEvent* e)
3519 QCanvasView::resizeEvent( e );
3523 void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3526 // for (unsigned int i=0;event->format(i);i++) // Debug mime type
3527 // cerr << event->format(i) << endl;
3530 (typeid(*selection) == typeid(BranchObj)) ||
3531 (typeid(*selection) == typeid(MapCenterObj))) {
3533 // If QImageDrag can decode mime type
3534 if (QImageDrag::canDecode(event)) {
3539 // If image are dragged from firefox
3540 if (event->provides("application/x-moz-file-promise-url") &&
3541 event->provides("application/x-moz-nativeimage")) {
3542 event->accept(true);
3546 // If QUriDrag can decode mime type
3547 if (QUriDrag::canDecode(event)) {
3552 // If Uri are dragged from firefox
3553 if (event->provides("_NETSCAPE_URL")){
3558 // If QTextDrag can decode mime type
3559 if (QTextDrag::canDecode(event)) {
3568 bool isUnicode16(const QByteArray &d)
3570 // TODO: make more precise check for unicode 16.
3571 // Guess unicode16 if any of second bytes are zero
3572 unsigned int length = max(0,d.size()-2)/2;
3573 for (unsigned int i = 0; i<length ; i++)
3574 if (d.at(i*2+1)==0) return true;
3578 void MapEditor::contentsDropEvent(QDropEvent *event)
3581 (typeid(*selection) == typeid(BranchObj)) ||
3582 (typeid(*selection) == typeid(MapCenterObj)))
3587 if (event->provides("image/png"))
3590 if (QImageDrag::decode(event, pix))
3598 } else if (event->provides("application/x-moz-file-promise-url") &&
3599 event->provides("application/x-moz-nativeimage"))
3601 // Contains url to the img src in unicode16
3602 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3603 QString url = QString((const QChar*)d.data(),d.size()/2);
3607 } else if (event->provides ("text/uri-list"))
3608 { // Uris provided e.g. by konqueror
3609 QUriDrag::decode (event,uris);
3610 } else if (event->provides ("_NETSCAPE_URL"))
3611 { // Uris provided by Mozilla
3612 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
3615 } else if (event->provides("text/html")) {
3617 // Handels text mime types
3618 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
3619 QByteArray d = event->encodedData("text/html");
3622 text = QString((const QChar*)d.data(),d.size()/2);
3626 textEditor->setText(text);
3630 } else if (event->provides("text/plain")) {
3631 QByteArray d = event->encodedData("text/plain");
3634 text = QString((const QChar*)d.data(),d.size()/2);
3638 textEditor->setText(text);
3650 for (const char* u=uris.first(); u; u=uris.next())
3652 bo=((BranchObj*)selection)->addBranch();
3655 s=QUriDrag::uriToLocalFile(u);
3657 QString file = QDir::convertSeparators(s);
3658 heading = QFileInfo(file).baseName();
3660 if (file.endsWith(".vym", false))
3661 bo->setVymLink(file);
3670 bo->setHeading(heading);
3680 saveState(); //TODO undo Command
3681 mapCenter->reposition();
3688 void MapEditor::addFloatImage(const QPixmap &img)
3691 (typeid(*selection) == typeid(BranchObj)) ||
3692 (typeid(*selection) == typeid(MapCenterObj)) )
3694 BranchObj *bo=((BranchObj*)selection);
3695 saveState(selection);
3696 //QString fn=fd->selectedFile();
3697 //lastImageDir=fn.left(fn.findRev ("/"));
3698 bo->addFloatImage();
3699 // FIXME check if load was successful
3700 bo->getLastFloatImage()->load(img);
3701 //bo->getLastFloatImage()->setOriginalFilename(fn);
3702 mapCenter->reposition();
3709 void MapEditor::imageDataFetched(const QByteArray &a, QNetworkOperation */*nop*/)
3711 if (!imageBuffer) imageBuffer = new QBuffer();
3712 if (!imageBuffer->isOpen()) {
3713 imageBuffer->open(IO_WriteOnly | IO_Append);
3715 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
3719 void MapEditor::imageDataFinished(QNetworkOperation *nop)
3721 if (nop->state()==QNetworkProtocol::StDone) {
3722 QPixmap img(imageBuffer->buffer());
3727 imageBuffer->close();
3729 imageBuffer->close();
3736 void MapEditor::fetchImage(const QString &url)
3739 urlOperator->stop();
3740 disconnect(urlOperator);
3744 urlOperator = new QUrlOperator(url);
3745 connect(urlOperator, SIGNAL(finished(QNetworkOperation *)),
3746 this, SLOT(imageDataFinished(QNetworkOperation*)));
3748 connect(urlOperator, SIGNAL(data(const QByteArray &, QNetworkOperation *)),
3749 this, SLOT(imageDataFetched(const QByteArray &, QNetworkOperation *)));