hide export for floatimages.
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 *actionEditURL;
63 extern QAction *actionEditHeading2URL;
64 extern QAction *actionEditBugzilla2URL;
65 extern QAction *actionEditFATE2URL;
66 extern QAction *actionEditOpenVymLink;
67 extern QAction *actionEditVymLink;
68 extern QAction *actionEditDeleteVymLink;
69 extern QAction *actionEditToggleHideExport;
70 extern QAction *actionEditHeading;
71 extern QAction *actionEditDelete;
72 extern QAction *actionEditAddBranch;
73 extern QAction *actionEditAddBranchAbove;
74 extern QAction *actionEditAddBranchBelow;
75 extern QAction *actionEditRemoveBranchHere;
76 extern QAction *actionEditRemoveChilds;
77 extern QAction *actionEditImportAdd;
78 extern QAction *actionEditImportReplace;
79 extern QAction *actionEditSaveBranch;
80 extern QAction *actionEditSelectFirst;
81 extern QAction *actionEditSelectLast;
82 extern QAction *actionEditLoadImage;
84 extern QAction* actionFormatPickColor;
85 extern QAction* actionFormatColorBranch;
86 extern QAction* actionFormatColorSubtree;
87 extern QAction *actionFormatLinkColorHint;
88 extern QAction *actionFormatBackColor;
89 extern QAction *actionFormatLinkColor;
91 extern QActionGroup* actionGroupModModes;
92 extern QAction* actionModModeColor;
93 extern QAction* actionModModeLink;
94 extern QAction* actionModModeCopy;
96 extern QActionGroup *actionGroupFormatFrameTypes;
97 extern QAction *actionFormatFrameNone;
98 extern QAction *actionFormatFrameRectangle;
100 extern QActionGroup *actionGroupFormatLinkStyles;
101 extern QAction *actionFormatIncludeImagesVer;
102 extern QAction *actionFormatIncludeImagesHor;
103 extern QAction *actionFormatHideLinkUnselected;
104 extern QAction *actionFormatLinkStyleLine;
105 extern QAction *actionFormatLinkStyleParabel;
106 extern QAction *actionFormatLinkStylePolyLine;
107 extern QAction *actionFormatLinkStylePolyParabel;
109 extern QAction *actionViewToggleNoteEditor;
111 extern QAction *actionSettingsAutoedit;
112 extern QAction *actionSettingsAutoselectHeading;
113 extern QAction *actionSettingsAutoselectText;
114 extern QAction *actionSettingsPasteNewHeading;
115 extern QAction *actionSettingsUseFlagGroups;
117 extern QPopupMenu *branchContextMenu;
118 extern QPopupMenu *branchLinksContextMenu;
119 extern QPopupMenu *branchLinksContextMenuDup;
120 extern QPopupMenu *floatimageContextMenu;
121 extern QPopupMenu *saveImageFormatMenu;
122 extern QPopupMenu *exportImageFormatMenu;
123 extern QPopupMenu *canvasContextMenu;
125 extern Settings settings;
127 int MapEditor::mapNum=0; // make instance
129 ///////////////////////////////////////////////////////////////////////
130 ///////////////////////////////////////////////////////////////////////
131 MapEditor::MapEditor(
132 QWidget* parent, bool interactive, const char* name, WFlags f) :
133 QCanvasView(parent,name,f), urlOperator(0), imageBuffer(0)
135 //cout << "Constructor ME "<<this<<endl;
138 viewport()->setAcceptDrops(true);
140 mapCanvas = new QCanvas(1000,800);
141 mapCanvas->setAdvancePeriod(30);
142 mapCanvas->setBackgroundColor (white);
144 setCanvas (mapCanvas);
146 // Always show scroll bars (automatic would flicker sometimes)
147 setVScrollBarMode ( QScrollView::AlwaysOn );
148 setHScrollBarMode ( QScrollView::AlwaysOn );
150 mapCenter = new MapCenterObj(mapCanvas);
151 mapCenter->setVisibility (true);
152 mapCenter->setMapEditor (this);
153 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
154 mapCenter->move(mapCanvas->width()/2-mapCenter->width()/2,mapCanvas->height()/2-mapCenter->height()/2);
158 lineedit = new QLineEdit(this, "lineedit" );
159 connect( lineedit, SIGNAL( returnPressed() ), SLOT( finishedLineEditNoSave() ) );
162 actColor=black; setColor (actColor);
163 defLinkColor=QColor (0,0,255);
164 defXLinkColor=QColor (180,180,180);
165 linkcolorhint=DefaultColor;
166 linkstyle=StylePolyParabel;
168 // Create bitmap cursors, patform dependant
169 #if defined(Q_OS_MACX)
170 #include "icons/cursorhandopen16.xpm"
171 #include "icons/cursorcolorpicker16.xpm"
172 QBitmap cb( 16, 16, chandopen, TRUE );
173 QBitmap cm( 16, 16, chandopenmask, TRUE );
174 handOpenCursor=QCursor ( cb, cm );
175 // set hot spot to tip of picker
176 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 1,15 );
178 #include "icons/cursorhandopen.xpm"
179 #include "icons/cursorcolorpicker.xpm"
181 QBitmap cb( 32, 32, chandopen, TRUE );
182 QBitmap cm( 32, 32, chandopenmask, TRUE );
183 handOpenCursor=QCursor ( cb, cm );
184 // set hot spot to tip of picker
185 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 5,27 );
198 defXLinkColor=QColor (230,230,230);
209 undosTotal=settings.readNumEntry("/vym/mapeditor/undoLevels",50);
213 // Initialize find routine
220 blockReposition=false;
221 blockSaveState=false;
222 isInteractive=interactive;
224 // Create temporary files
227 // Initially set movingCentre
230 mapCenter->reposition(); // for positioning heading
233 MapEditor::~MapEditor()
235 if (imageBuffer) delete imageBuffer;
241 //cout <<"Destructor MapEditor\n";
244 //settings.writeEntry( "/vym/mapeditor/editmode/autoselect", );
248 QColor MapEditor::color()
253 QColor MapEditor::backgroundColor()
255 return mapCanvas->backgroundColor();
258 MapCenterObj* MapEditor::getMapCenter()
263 QCanvas* MapEditor::getCanvas()
268 void MapEditor::adjustCanvasSize()
270 // To adjust the canvas to map, viewport size and position, we have to
271 // do some coordinate magic...
273 // Get rectangle of (scroll-)view.
274 // We want to be in canvas coords, so
275 // we map. Important if view is zoomed...
276 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
277 visibleWidth(), visibleHeight()) );
279 // Now we need the bounding box of view AND map to calc the correct canvas size.
280 // Why? Because if the map itself is moved out of view, the view has to be enlarged
281 // to avoid jumping aroung...
282 QRect map=mapCenter->getTotalBBox();
284 // right edge - left edge
285 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
286 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
289 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
290 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
293 // move the map on canvas (in order to not move it on screen) this is neccessary
294 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
295 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
296 // to scroll to an empty area of canvas to the left.
297 // b) if topleft corner of map left of or above topleft of canvas
301 if (cw > mapCanvas->width() )
303 if (map.x()<0) dx=-map.x();
305 if (cw < mapCanvas->width() )
306 dx=-min (view.x(),map.x());
307 if (ch > mapCanvas->height() )
309 if (map.y()<0) dy=-map.y();
311 if (ch < mapCanvas->height() )
313 dy=-min (view.y(),map.y());
315 // We really have to resize now. Let's go...
316 mapCanvas->resize (cw,ch);
317 if ( (dx!=0) || (dy!=0) )
319 mapCenter->moveAllBy(dx,dy);
320 mapCenter->reposition();
322 // scroll the view (in order to not move map on screen)
328 bool MapEditor::isRepositionBlocked()
330 return blockReposition;
333 void MapEditor::makeTmpDirs()
335 // Create unique temporary directories
336 tmpMapDir=tmpVymDir+QString("/mapeditor-%1").arg(mapNum);
338 d.mkdir (tmpMapDir,true);
341 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSelection)
343 // tmpdir temporary directory to which data will be written
344 // prefix mapname, which will be appended to images etc.
345 // writeflags Only write flags for "real" save of map, not undo
346 // offset offset of bbox of whole map in canvas.
347 // Needed for XML export
363 ls="StylePolyParabel";
367 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
369 if (linkcolorhint==HeadingColor)
370 colhint=attribut("linkColorHint","HeadingColor");
372 QString mapAttr=attribut("version",__VYM_VERSION);
374 mapAttr+= attribut("author",mapCenter->getAuthor()) +
375 attribut("comment",mapCenter->getComment()) +
376 attribut("date",mapCenter->getDate()) +
377 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
378 attribut("linkStyle", ls ) +
379 attribut("linkColor", defLinkColor.name() ) +
380 attribut("defXLinkColor", defXLinkColor.name() ) +
381 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
383 s+=beginElement("vymmap",mapAttr);
386 // Find the used flags while traversing the tree
387 standardFlagsDefault->resetUsedCounter();
389 // Reset the counters before saving
390 FloatImageObj (mapCanvas).resetSaveCounter();
392 // Build xml recursivly
394 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
397 if ( typeid(*saveSelection) == typeid(BranchObj) )
398 s+=((BranchObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
399 else if ( typeid(*saveSelection) == typeid(FloatImageObj) )
400 s+=((FloatImageObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
402 else if (selection && typeid(*selection)==typeid(BranchObj))
403 // This is used if selected branch is saved from mainwindow
404 s+=((BranchObj*)selection)->saveToDir(tmpdir,prefix,offset);
407 // Save local settings
408 s+=settings.getXMLData (destPath);
411 if (selection && !saveSelection )
412 s+=valueElement("select",selection->getSelectString());
415 s+=endElement("vymmap");
418 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
422 void MapEditor::saveState()
425 saveState (CompleteMap,"",NULL,"",NULL);
428 void MapEditor::saveState(LinkableMapObj *undoSel)
430 // save the given part of the map
431 saveState (PartOfMap,"",undoSel,"",NULL);
434 void MapEditor::saveState(const QString &uc, const QString &rc)
436 // selection does not change during action,
437 // so just save commands for undo and redo
438 LinkableMapObj *unsel;
443 saveState (UndoCommand,uc,unsel,rc,unsel);
446 void MapEditor::saveState(const QString & uncom, LinkableMapObj *unsel)
448 saveState (UndoCommand,uncom,unsel,"FIXME-redoCom",NULL);
451 void MapEditor::saveState(const SaveMode &savemode, const QString &undoCom, LinkableMapObj *undoSel, const QString &redoCom, LinkableMapObj *redoSel)
455 if (blockSaveState) return;
457 /* TODO remove after testing
458 cout << "ME::saveState() begin\n"<<endl;
459 cout << " undosTotal="<<undosTotal<<endl;
460 cout << " undosAvail="<<undosAvail<<endl;
461 cout << " undoNum="<<undoNum<<endl;
462 cout << " ---------------------------"<<endl;
466 // Find out current undo directory
467 if (undosAvail<undosTotal) undosAvail++;
469 if (undoNum>undosTotal) undoNum=1;
472 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
473 QString bakMapPath=QDir::convertSeparators(bakMapDir+"/map.xml");
475 // Create bakMapDir if not available
478 makeSubDirs (bakMapDir);
480 // Save current selection
481 QString redoSelection="";
483 redoSelection=redoSel->getSelectString();
485 // Save the object, which should be undone
486 QString undoSelection="";
488 undoSelection=undoSel->getSelectString();
490 // Save depending on how much needs to be saved
491 QString undoCommand="";
492 if (savemode==UndoCommand)
497 else if (savemode==PartOfMap && undoSel)
499 undoCommand="undoPart (\""+ undoSelection+"\",\""+bakMapPath+"\")";
500 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),undoSel);
503 undoCommand="undoMap (\""+bakMapPath+"\")";
504 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),NULL);
507 if (!backupXML.isEmpty())
508 // Write XML Data to disk
509 saveStringToDisk (QString(bakMapPath),backupXML);
512 set.setEntry (QString("undoCommand"),undoCommand);
513 set.setEntry (QString("undoSelection"),undoSelection);
514 set.setEntry (QString("redoCommand"),redoCom);
515 set.setEntry (QString("redoSelection"),redoSelection);
516 set.writeSettings(QString(bakMapDir+"/commands"));
518 /* TODO remove after testing
519 cout << " into="<< bakMapDir<<endl;
520 cout << " undosAvail="<<undosAvail<<endl;
521 cout << " undoNum="<<undoNum<<endl;
522 cout << " ---------------------------"<<endl;
523 cout << " undoCom="<<undoCommand<<endl;
524 cout << " undoSel="<<undoSelection<<endl;
525 cout << " ---------------------------"<<endl;
526 cout << " redoCom="<<redoCom<<endl;
527 cout << " redoSel="<<redoSelection<<endl;
528 cout << " ---------------------------"<<endl<<endl;
532 void MapEditor::parseAtom(const QString &atom)
539 // Split string s into command and parameters
540 api.parseCommand (atom);
541 QString com=api.command();
544 if (com=="moveBranchUp")
546 else if (com=="moveBranchDown")
548 else if (com=="move")
550 if (api.checkParamCount(2) && selection )
560 else if (com=="linkBranchToPos")
562 if (selection && typeid(*selection) == typeid(BranchObj) )
564 if (api.checkParamCount(4))
566 s=api.parString(ok,0);
567 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
570 if (typeid(*dst) == typeid(BranchObj) )
572 // Get number in parent
575 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),x);
576 } else if (typeid(*dst) == typeid(MapCenterObj) )
578 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),-1);
579 // Get coordinates of mainbranch
584 if (ok) ((BranchObj*)selection)->move (x,y);
590 } else if (com=="setHeading")
592 if (api.checkParamCount(1))
594 s=api.parString (ok,0);
595 if (ok) setHeading (s);
597 } else if (com=="setURL")
599 if (api.checkParamCount(1))
601 s=api.parString (ok,0);
604 } else if (com=="setVymLink")
606 if (api.checkParamCount(1))
608 s=api.parString (ok,0);
609 if (ok) setVymLink(s);
612 // Internal commands, used for undo etc.
613 else if (com==QString("undoMap"))
615 if (api.checkParamCount(1))
616 undoXML("",api.parString (ok,0));
617 } else if (com==QString("undoPart"))
619 if (api.checkParamCount(2))
621 s=api.parString (ok,0);
622 t=api.parString (ok,1);
625 } else if (com=="select")
626 if (api.checkParamCount(1))
628 s=api.parString(ok,0);
633 api.setError ("Unknown command in: "+atom);
634 cout << "ME::parse api should have error now...\n";
640 cout << "MapEditor::parseAtom: Error!\n";
641 cout << " "<<api.errorDesc()<<endl;
646 void MapEditor::finishedLineEditNoSave()
648 // This is called by finishedLineEdit or any MapEditor method,
649 // which wants to assure, that lineedits finish, before e.g. a branch is
652 // After calling LineEdit and using the clipboard, the
653 // focus is not any longer on the main widget, we
654 // have to restore it using parentWidget()->setFocus()
658 editingBO->setHeading(lineedit->text() );
660 lineedit->releaseKeyboard();
662 parentWidget()->setFocus();
663 mapCenter->reposition();
665 ensureSelectionVisible();
670 bool MapEditor::isDefault()
675 bool MapEditor::isUnsaved()
680 bool MapEditor::hasChanged()
685 void MapEditor::setChanged()
690 actionEditUndo->setEnabled (true);
691 actionFileSave->setEnabled (true);
695 void MapEditor::closeMap()
697 // Finish open lineEdits
698 if (lineedit) finishedLineEditNoSave();
700 // Unselect before disabling the toolbar actions
701 if (selection) selection->unselect();
709 void MapEditor::setFilePath(QString fname)
711 setFilePath (fname,fname);
714 void MapEditor::setFilePath(QString fname, QString destname)
716 if (fname.isEmpty() || fname=="")
723 filePath=fname; // becomes absolute path
724 fileName=fname; // gets stripped of path
725 destPath=destname; // needed for vymlinks
727 // If fname is not an absolute path, complete it
728 filePath=QDir(fname).absPath();
729 fileDir=filePath.left (1+filePath.findRev ("/"));
731 // Set short name, too. Search from behind:
732 int i=fileName.findRev("/");
733 if (i>=0) fileName=fileName.remove (0,i+1);
735 // Forget the .vym (or .xml) for name of map
736 mapName=fileName.left(fileName.findRev(".",-1,true) );
740 QString MapEditor::getFilePath()
745 QString MapEditor::getFileName()
750 QString MapEditor::getMapName()
755 QString MapEditor::getDestPath()
760 ErrorCode MapEditor::load (QString fname, LoadMode lmode)
762 // Finish open lineEdits
763 if (lineedit) finishedLineEditNoSave();
765 ErrorCode err=success;
769 if (selection) selection->unselect();
772 mapCenter->setMapEditor(this);
773 // (map state is set later at end of load...)
776 saveState(selection);
780 mapBuilderHandler handler;
783 // I am paranoid: file should exist anyway
784 // according to check in mainwindow.
787 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
788 tr("Couldn't open map " +fname)+".");
792 blockReposition=true;
793 QXmlInputSource source( file);
794 QXmlSimpleReader reader;
795 reader.setContentHandler( &handler );
796 reader.setErrorHandler( &handler );
797 handler.setMapEditor( this );
798 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
799 handler.setInputFile (file.name());
800 handler.setLoadMode (lmode);
802 bool ok = reader.parse( source );
803 blockReposition=false;
804 blockSaveState=false;
808 mapCenter->reposition();
818 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
819 tr( handler.errorProtocol() ) );
821 // Still return "success": the map maybe at least
822 // partially read by the parser
829 int MapEditor::save (const SaveMode &savemode)
831 // Finish open lineEdits
832 if (lineedit) finishedLineEditNoSave();
836 // The SaveMode UndoCommand is not supported here
837 if (savemode==UndoCommand) return 1;
839 // Create mapName and fileDir
840 makeSubDirs (fileDir);
844 fname=mapName+".xml";
846 // use name given by user, even if he chooses .doc
851 if (savemode==CompleteMap || selection==NULL)
852 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL);
854 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection);
856 if (!saveStringToDisk(fileDir+fname,saveFile))
863 actionFileSave->setEnabled(false);
869 void MapEditor::setZipped (bool z)
874 bool MapEditor::saveZipped ()
879 void MapEditor::print()
881 // Finish open lineEdits
882 if (lineedit) finishedLineEditNoSave();
886 printer = new QPrinter;
887 printer->setColorMode (QPrinter::Color);
888 printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName()));
891 QRect totalBBox=mapCenter->getTotalBBox();
893 // Try to set orientation automagically
894 // Note: Interpretation of generated postscript is amibiguous, if
895 // there are problems with landscape mode, see
896 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
898 if (totalBBox.width()>totalBBox.height())
899 // recommend landscape
900 printer->setOrientation (QPrinter::Landscape);
902 // recommend portrait
903 printer->setOrientation (QPrinter::Portrait);
905 if ( printer->setup(this) )
906 // returns false, if printing is canceled
908 QPainter pp(printer);
910 // Don't print the visualisation of selection
911 LinkableMapObj *oldselection=NULL;
914 oldselection=selection;
915 selection->unselect();
918 // Handle sizes of map and paper:
920 // setWindow defines which part of the canvas will be transformed
921 // setViewport defines area on paper in device coordinates (dpi)
922 // e.g. (0,50,700,700) is upper part on A4
923 // see also /usr/lib/qt3/doc/html/coordsys.html
925 QPaintDeviceMetrics metrics (printer);
927 double paperAspect = (double)metrics.width() / (double)metrics.height();
928 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
930 QRect mapRect=totalBBox;
931 QCanvasRectangle *frame=NULL;
932 QCanvasText *footerFN=NULL;
933 QCanvasText *footerDate=NULL;
934 if (printFrame || printFooter)
939 // Print frame around map
940 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
941 totalBBox.width()+20, totalBBox.height()+20);
942 frame=new QCanvasRectangle (mapRect,mapCanvas);
943 frame->setBrush (QColor(white));
944 frame->setPen (QColor(black));
948 /* TODO remove after testing
949 QCanvasLine *l=new QCanvasLine (mapCanvas);
950 l->setPoints (0,0,mapRect.width(),mapRect.height());
951 l->setPen (QPen(QColor(black), 1));
958 // Print footer below map
960 font.setPointSize(10);
961 footerFN=new QCanvasText (mapCanvas);
962 footerFN->setText ("VYM - " + fileName);
963 footerFN->setFont(font);
964 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
965 footerFN->setZ(Z_TEXT);
967 footerDate=new QCanvasText (mapCanvas);
968 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
969 footerDate->setFont(font);
970 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
971 footerDate->setZ(Z_TEXT);
974 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
977 pp.setWindow (mapRect);
980 if (mapAspect>=paperAspect)
982 // Fit horizontally to paper width
983 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
986 // Fit vertically to paper height
987 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
990 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
992 // Delete Frame and footer
998 if (frame) delete (frame);
1000 // Restore selection
1003 selection=oldselection;
1004 selection->select();
1007 // Save settings in vymrc
1008 settings.writeEntry("/vym/mainwindow/printerName",printer->printerName());
1012 QPixmap MapEditor::getPixmap()
1014 QRect mapRect=mapCenter->getTotalBBox();
1015 QPixmap pix (mapRect.size());
1018 // Don't print the visualisation of selection
1019 LinkableMapObj *oldselection=NULL;
1022 oldselection=selection;
1023 selection->unselect();
1026 pp.setWindow (mapRect);
1028 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
1031 // Restore selection
1034 selection=oldselection;
1035 selection->select();
1041 void MapEditor::exportImage(QString fn)
1043 // Finish open lineEdits
1044 if (lineedit) finishedLineEditNoSave();
1046 QPixmap pix (getPixmap());
1047 pix.save(fn, "PNG");
1050 void MapEditor::exportImage(QString fn, int item)
1052 // Finish open lineEdits
1053 if (lineedit) finishedLineEditNoSave();
1055 QPixmap pix (getPixmap());
1056 pix.save(fn, exportImageFormatMenu->text(item) );
1059 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
1063 ex.setMapCenter(mapCenter);
1064 if (ex.setConfigFile(cf)) ex.exportPresentation();
1069 void MapEditor::exportXML(const QString &dir)
1071 // Create subdirectories
1074 // write to directory
1075 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1078 file.setName ( dir + "/"+mapName+".xml");
1079 if ( !file.open( IO_WriteOnly ) )
1081 // This should neverever happen
1082 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1086 // Write it finally, and write in UTF8, no matter what
1087 QTextStream ts( &file );
1088 ts.setEncoding (QTextStream::UnicodeUTF8);
1092 // Now write image, too
1093 exportImage (dir+"/images/"+mapName+".png");
1096 void MapEditor::clear()
1100 selection->unselect();
1107 void MapEditor::copy()
1109 // Finish open lineEdits
1110 if (lineedit) finishedLineEditNoSave();
1114 // write to directory
1115 QString clipfile="part";
1116 QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPoint(),selection);
1119 file.setName ( clipboardDir + "/"+clipfile+".xml");
1120 if ( !file.open( IO_WriteOnly ) )
1122 // This should neverever happen
1123 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1127 // Write it finally, and write in UTF8, no matter what
1128 QTextStream ts( &file );
1129 ts.setEncoding (QTextStream::UnicodeUTF8);
1133 clipboardEmpty=false;
1138 void MapEditor::redo()
1140 // Finish open lineEdits
1141 if (lineedit) finishedLineEditNoSave();
1143 blockSaveState=true;
1145 // Find out current undo directory
1146 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
1148 // Restore variables
1149 QString undoCommand;
1150 QString undoSelection;
1151 QString redoCommand;
1152 QString redoSelection;
1154 set.readSettings(QString(bakMapDir+"/commands"));
1155 undoCommand=set.readEntry ("undoCommand");
1156 undoSelection=set.readEntry ("undoSelection");
1157 redoCommand=set.readEntry ("redoCommand");
1158 redoSelection=set.readEntry ("redoSelection");
1160 // select object before redo
1161 if (!redoSelection.isEmpty())
1162 select (redoSelection);
1164 /* TODO remove testing
1165 cout << "ME::redo() begin\n";
1166 cout << " undosTotal="<<undosTotal<<endl;
1167 cout << " undosAvail="<<undosAvail<<endl;
1168 cout << " undoNum="<<undoNum<<endl;
1169 cout << " ---------------------------"<<endl;
1170 cout << " undoCom="<<undoCommand<<endl;
1171 cout << " undoSel="<<undoSelection<<endl;
1172 cout << " ---------------------------"<<endl;
1173 cout << " redoCom="<<redoCommand<<endl;
1174 cout << " redoSel="<<redoSelection<<endl;
1175 cout << " ---------------------------"<<endl;
1177 parseAtom (undoCommand);
1178 mapCenter->reposition();
1180 //if (!redoSelection.isEmpty())
1181 // select (redoSelection);
1185 // Undo not longer available now
1186 actionEditUndo->setEnabled (false);
1188 undoNum--; if (undoNum<1) undoNum=undosTotal;
1190 blockSaveState=false;
1191 /* TODO remove testing
1192 cout << "ME::redo() end\n";
1193 cout << " undosAvail="<<undosAvail<<endl;
1194 cout << " undoNum="<<undoNum<<endl;
1195 cout << " ---------------------------"<<endl<<endl;
1199 void MapEditor::undo()
1201 // Finish open lineEdits
1202 if (lineedit) finishedLineEditNoSave();
1204 blockSaveState=true;
1206 // Find out current undo directory
1207 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
1209 // Restore variables
1210 QString undoCommand;
1211 QString undoSelection;
1212 QString redoCommand;
1213 QString redoSelection;
1215 set.readSettings(QString(bakMapDir+"/commands"));
1216 undoCommand= set.readEntry ("undoCommand");
1217 undoSelection=set.readEntry ("undoSelection");
1218 redoCommand= set.readEntry ("redoCommand");
1219 redoSelection=set.readEntry ("redoSelection");
1221 // select object before undo
1222 if (!undoSelection.isEmpty())
1223 select (undoSelection);
1226 cout << "ME::undo() begin\n";
1227 cout << " undosTotal="<<undosTotal<<endl;
1228 cout << " undosAvail="<<undosAvail<<endl;
1229 cout << " undoNum="<<undoNum<<endl;
1230 cout << " ---------------------------"<<endl;
1231 cout << " undoCom="<<undoCommand<<endl;
1232 cout << " undoSel="<<undoSelection<<endl;
1233 cout << " ---------------------------"<<endl;
1234 cout << " redoCom="<<redoCommand<<endl;
1235 cout << " redoSel="<<redoSelection<<endl;
1236 cout << " ---------------------------"<<endl;
1238 parseAtom (undoCommand);
1239 mapCenter->reposition();
1241 //if (!redoSelection.isEmpty())
1242 // select (redoSelection);
1246 // Undo not longer available now
1247 actionEditUndo->setEnabled (false);
1249 undoNum--; if (undoNum<1) undoNum=undosTotal;
1251 blockSaveState=false;
1252 /* TODO remove testing
1253 cout << "ME::undo() end\n";
1254 cout << " undosAvail="<<undosAvail<<endl;
1255 cout << " undoNum="<<undoNum<<endl;
1256 cout << " ---------------------------"<<endl<<endl;
1260 void MapEditor::undoXML(const QString &undoSel, const QString &bakMapPath)
1262 QString bakMapDir=bakMapPath.left(bakMapPath.findRev("/"));
1264 QFile file (bakMapPath);
1268 // We need to parse saved XML data
1269 mapBuilderHandler handler;
1270 QXmlInputSource source( file);
1271 QXmlSimpleReader reader;
1272 reader.setContentHandler( &handler );
1273 reader.setErrorHandler( &handler );
1274 handler.setMapEditor( this );
1275 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1276 if (undoSel.isEmpty())
1280 handler.setLoadMode (NewMap);
1284 handler.setLoadMode (ImportReplace);
1286 blockReposition=true;
1287 bool ok = reader.parse( source );
1288 blockReposition=false;
1291 // This should never ever happen
1292 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1293 tr( handler.errorProtocol() )+" in "+bakMapDir );
1297 QMessageBox::critical( 0, tr( "Critical Error" ),
1298 tr("Temporary directory %1 used for undo is gone. \n"
1299 "I will create a new one, but at the moment no undo is available.\n"
1300 "Maybe you want to reload your original data.\n\n"
1301 "Sorry for any inconveniences.").arg(bakMapDir) );
1306 void MapEditor::pasteNoSave()
1308 // Finish open lineEdits
1309 if (lineedit) finishedLineEditNoSave();
1311 load (clipboardDir+"/part.xml",ImportAdd);
1314 void MapEditor::cutNoSave()
1320 void MapEditor::paste()
1322 if (selection && (typeid(*selection) == typeid(BranchObj) ||
1323 typeid(*selection) == typeid(MapCenterObj)))
1325 saveState(selection);
1327 mapCenter->reposition();
1332 void MapEditor::cut()
1334 saveState(selection->getParObj());
1337 mapCenter->reposition();
1341 void MapEditor::move(const int &x, const int &y)
1343 // TODO no saveState, because this is only internal at undo so far
1344 if (selection) selection->move(x,y);
1345 if (typeid(*selection) == typeid(FloatImageObj))
1346 ((FloatImageObj*)selection)->setRelPos();
1349 void MapEditor::moveBranchUp()
1351 // Finish open lineEdits
1352 if (lineedit) finishedLineEditNoSave();
1356 if (typeid(*selection) == typeid(BranchObj) )
1358 bo=(BranchObj*)selection;
1359 par=(BranchObj*)(bo->getParObj());
1360 selection->unselect();
1361 selection=par->moveBranchUp (bo);
1362 selection->select();
1363 saveState("moveBranchDown ()",bo);
1364 mapCenter->reposition();
1365 ensureSelectionVisible();
1369 void MapEditor::moveBranchDown()
1371 // Finish open lineEdits
1372 if (lineedit) finishedLineEditNoSave();
1376 if (typeid(*selection) == typeid(BranchObj) )
1378 bo=(BranchObj*)selection;
1379 par=(BranchObj*)(bo->getParObj());
1380 selection->unselect();
1381 selection=par->moveBranchDown(bo);
1382 selection->select();
1383 saveState("moveBranchUp ()",bo);
1384 mapCenter->reposition();
1385 ensureSelectionVisible();
1389 void MapEditor::editHeading()
1391 // Finish open lineEdits
1392 if (lineedit) finishedLineEditNoSave();
1395 (typeid(*selection) == typeid(BranchObj) ||
1396 typeid(*selection) == typeid(MapCenterObj) ) )
1398 editingBO=(BranchObj*)selection;
1399 saveState("setHeading (\""+((BranchObj*)selection)->getHeading()+"\")",editingBO );
1401 ensureSelectionVisible();
1402 QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
1403 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1404 QString s=editingBO->getHeading();
1405 lineedit->setText(s);
1406 lineedit->setCursorPosition(1);
1407 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1408 lineedit->selectAll();
1410 lineedit->grabKeyboard();
1411 lineedit->setFocus();
1415 void MapEditor::setHeading(const QString &s)
1417 // Internal function, no saveState needed
1419 (typeid(*selection) == typeid(BranchObj) ||
1420 typeid(*selection) == typeid(MapCenterObj) ) )
1422 ((BranchObj*)selection)->setHeading(s);
1423 mapCenter->reposition();
1425 ensureSelectionVisible();
1429 void MapEditor::setURL (const QString &s)
1431 // Internal function, no saveState needed
1433 (typeid(*selection) == typeid(BranchObj) ||
1434 typeid(*selection) == typeid(MapCenterObj) ) )
1436 ((BranchObj*)selection)->setURL(s);
1437 mapCenter->reposition();
1439 ensureSelectionVisible();
1443 void MapEditor::setVymLink (const QString &s)
1445 // Internal function, no saveState needed
1447 (typeid(*selection) == typeid(BranchObj) ||
1448 typeid(*selection) == typeid(MapCenterObj) ) )
1450 ((BranchObj*)selection)->setVymLink(s);
1451 mapCenter->reposition();
1453 ensureSelectionVisible();
1457 void MapEditor::addNewBranch(int pos)
1459 // Finish open lineEdits
1460 if (lineedit) finishedLineEditNoSave();
1463 (typeid(*selection) == typeid(BranchObj) ||
1464 typeid(*selection) == typeid(MapCenterObj) ) )
1466 saveState(selection); //TODO undoCommand
1468 BranchObj* bo1 = (BranchObj*) selection;
1469 bool wasScrolled=false;
1470 BranchObj *newbo=NULL;
1473 // save scroll state. If scrolled, automatically select
1474 // new branch in order to tmp unscroll parent...
1475 wasScrolled=bo1->isScrolled();
1476 newbo=bo1->addBranch();
1479 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1483 // add above selection
1484 newbo=parbo->insertBranch(bo1->getNum());
1486 // add below selection
1487 newbo=parbo->insertBranch(bo1->getNum()+1);
1489 // This should not happen...
1494 LinkableMapObj *oldselection=selection;
1496 mapCenter->reposition();
1498 if (actionSettingsAutoedit->isOn() ||
1499 actionSettingsAutoselectHeading->isOn() )
1501 selection->unselect();
1503 selection->select();
1504 if (actionSettingsPasteNewHeading->isOn() )
1506 BranchObj *bo2= (BranchObj*)selection;
1507 bo2->setHeading("");
1509 if (actionSettingsAutoedit->isOn() )
1511 if (!actionSettingsAutoselectHeading->isOn()
1514 selection->unselect();
1515 selection=oldselection;
1516 selection->select();
1523 void MapEditor::addNewBranchHere()
1525 // Finish open lineEdits
1526 if (lineedit) finishedLineEditNoSave();
1529 (typeid(*selection) == typeid(BranchObj) ) )
1531 saveState(selection);
1533 BranchObj* bo1 = (BranchObj*) selection;
1534 bool wasScrolled=false;
1535 BranchObj *newbo=NULL;
1536 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1539 // add below selection
1540 newbo=parbo->insertBranch(bo1->getNum()+1);
1543 LinkableMapObj *oldselection=selection;
1544 ((BranchObj*)selection)->moveBranchTo (newbo,-1);
1546 mapCenter->reposition();
1548 if (actionSettingsAutoedit->isOn() ||
1549 actionSettingsAutoselectHeading->isOn() )
1551 selection->unselect();
1553 selection->select();
1554 if (actionSettingsPasteNewHeading->isOn() )
1556 BranchObj *bo2= (BranchObj*)selection;
1557 bo2->setHeading("");
1559 if (actionSettingsAutoedit->isOn() )
1561 if (!actionSettingsAutoselectHeading->isOn()
1564 selection->unselect();
1565 selection=oldselection;
1566 selection->select();
1572 void MapEditor::deleteSelection()
1574 // Finish open lineEdits
1575 if (lineedit) finishedLineEditNoSave();
1577 if (selection && typeid(*selection) ==typeid(BranchObj) )
1579 if (selection->getDepth()>1)
1580 // Normal branch, save parent with childs
1581 saveState(selection->getParObj());
1583 // Mainbranch, save whole map
1584 // TODO Better would be to insert mainbranch again at pos
1585 // But undoCommand is missing right now
1587 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1588 BranchObj* par=(BranchObj*)(bo->getParObj());
1591 par->removeBranch(bo);
1593 selection->select();
1594 ensureSelectionVisible();
1595 mapCenter->reposition();
1598 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1600 saveState(selection->getParObj());
1601 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1602 BranchObj* par=(BranchObj*)(fio->getParObj());
1605 par->removeFloatImage(fio);
1607 selection->select();
1608 ensureSelectionVisible();
1609 mapCenter->reposition();
1614 LinkableMapObj* MapEditor::getSelection()
1619 bool MapEditor::select (const QString &s)
1621 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
1623 // Finally select the found object
1626 if (selection) unselect();
1628 selection->select();
1630 ensureSelectionVisible();
1636 void MapEditor::unselect()
1640 selectionLast=selection;
1641 selection->unselect();
1646 void MapEditor::reselect()
1650 selection=selectionLast;
1651 selection->select();
1656 void MapEditor::selectNextBranch()
1658 // Increase number of branch
1661 QString s=selection->getSelectString();
1667 part=s.section(",",-1);
1669 num=part.right(part.length() - 3);
1671 s=s.left (s.length() -num.length());
1674 num=QString ("%1").arg(num.toUInt()+1);
1678 // Try to select this one
1679 if (select (s)) return;
1681 // We have no direct successor,
1682 // try to increase the parental number in order to
1683 // find a successor with same depth
1685 int d=selection->getDepth();
1690 while (!found && d>0)
1692 s=s.section (",",0,d-1);
1693 // replace substring of current depth in s with "1"
1694 part=s.section(",",-1);
1696 num=part.right(part.length() - 3);
1700 // increase number of parent
1701 num=QString ("%1").arg(num.toUInt()+1);
1702 s=s.section (",",0,d-2) + ","+ typ+num;
1705 // Special case, look at orientation
1706 if (selection->getOrientation()==OrientRightOfCenter)
1707 num=QString ("%1").arg(num.toUInt()+1);
1709 num=QString ("%1").arg(num.toUInt()-1);
1714 // pad to oldDepth, select the first branch for each depth
1715 for (i=d;i<oldDepth;i++)
1720 if ( ((BranchObj*)selection)->countBranches()>0)
1728 // try to select the freshly built string
1736 void MapEditor::selectPrevBranch()
1738 // Decrease number of branch
1741 QString s=selection->getSelectString();
1747 part=s.section(",",-1);
1749 num=part.right(part.length() - 3);
1751 s=s.left (s.length() -num.length());
1754 num=QString ("%1").arg(num.toUInt()-1);
1758 // Try to select this one
1759 if (select (s)) return;
1761 // We have no direct precessor,
1762 // try to decrease the parental number in order to
1763 // find a precessor with same depth
1765 int d=selection->getDepth();
1770 while (!found && d>0)
1772 s=s.section (",",0,d-1);
1773 // replace substring of current depth in s with "1"
1774 part=s.section(",",-1);
1776 num=part.right(part.length() - 3);
1780 // decrease number of parent
1781 num=QString ("%1").arg(num.toUInt()-1);
1782 s=s.section (",",0,d-2) + ","+ typ+num;
1785 // Special case, look at orientation
1786 if (selection->getOrientation()==OrientRightOfCenter)
1787 num=QString ("%1").arg(num.toUInt()-1);
1789 num=QString ("%1").arg(num.toUInt()+1);
1794 // pad to oldDepth, select the last branch for each depth
1795 for (i=d;i<oldDepth;i++)
1799 if ( ((BranchObj*)selection)->countBranches()>0)
1800 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)selection)->countBranches()-1 );
1807 // try to select the freshly built string
1815 void MapEditor::selectUpperBranch()
1817 // Finish open lineEdits
1818 if (lineedit) finishedLineEditNoSave();
1822 if (typeid(*selection) == typeid(BranchObj))
1824 if (selection->getOrientation()==OrientRightOfCenter)
1827 if (selection->getDepth()==1)
1835 void MapEditor::selectLowerBranch()
1837 // Finish open lineEdits
1838 if (lineedit) finishedLineEditNoSave();
1842 if (typeid(*selection) == typeid(BranchObj))
1844 if (selection->getOrientation()==OrientRightOfCenter)
1847 if (selection->getDepth()==1)
1856 void MapEditor::selectLeftBranch()
1858 // Finish open lineEdits
1859 if (lineedit) finishedLineEditNoSave();
1865 if (typeid(*selection) == typeid(MapCenterObj))
1867 par= (BranchObj*) selection;
1868 bo=par->getLastSelectedBranch();
1871 // Workaround for reselecting on left and right side
1872 if (bo->getOrientation()==OrientRightOfCenter)
1874 bo=par->getLastBranch();
1880 selection->select();
1882 ensureSelectionVisible();
1887 par=(BranchObj*)(selection->getParObj());
1888 if (selection->getOrientation()==OrientRightOfCenter)
1890 if (typeid(*selection) == typeid(BranchObj) ||
1891 typeid(*selection) == typeid(FloatImageObj))
1893 selection->unselect();
1895 selection->select();
1897 ensureSelectionVisible();
1901 if (typeid(*selection) == typeid(BranchObj) )
1903 bo=((BranchObj*)selection)->getLastSelectedBranch();
1906 selection->unselect();
1908 selection->select();
1910 ensureSelectionVisible();
1918 void MapEditor::selectRightBranch()
1920 // Finish open lineEdits
1921 if (lineedit) finishedLineEditNoSave();
1928 if (typeid(*selection) == typeid(MapCenterObj))
1930 par= (BranchObj*) selection;
1931 bo=par->getLastSelectedBranch();
1934 // Workaround for relecting on left and right side
1935 if (bo->getOrientation()==OrientLeftOfCenter)
1936 bo=par->getFirstBranch();
1941 selection->select();
1942 ensureSelectionVisible();
1947 par=(BranchObj*)(selection->getParObj());
1948 if (selection->getOrientation()==OrientLeftOfCenter)
1950 if (typeid(*selection) == typeid(BranchObj) ||
1951 typeid(*selection) == typeid(FloatImageObj))
1953 selection->unselect();
1955 selection->select();
1957 ensureSelectionVisible();
1961 if (typeid(*selection) == typeid(BranchObj) )
1963 bo=((BranchObj*)selection)->getLastSelectedBranch();
1966 selection->unselect();
1968 selection->select();
1970 ensureSelectionVisible();
1978 void MapEditor::selectFirstBranch()
1980 // Finish open lineEdits
1981 if (lineedit) finishedLineEditNoSave();
1987 if (typeid(*selection) == typeid(BranchObj))
1989 bo1= (BranchObj*) selection;
1990 par=(BranchObj*)(bo1->getParObj());
1991 bo2=par->getFirstBranch();
1995 selection->select();
1996 ensureSelectionVisible();
2003 void MapEditor::selectLastBranch()
2005 // Finish open lineEdits
2006 if (lineedit) finishedLineEditNoSave();
2012 if (typeid(*selection) == typeid(BranchObj))
2014 bo1= (BranchObj*) selection;
2015 par=(BranchObj*)(bo1->getParObj());
2016 bo2=par->getLastBranch();
2020 selection->select();
2021 ensureSelectionVisible();
2028 void MapEditor::setColor(QColor c)
2033 void MapEditor::selectBackgroundColor()
2035 // Finish open lineEdits
2036 if (lineedit) finishedLineEditNoSave();
2038 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
2039 if ( !col.isValid() ) return;
2040 setBackgroundColor( col );
2044 void MapEditor::setBackgroundColor(QColor c)
2046 mapCanvas->setBackgroundColor (c);
2049 QColor MapEditor::pickColor()
2053 if (typeid(*selection) == typeid(BranchObj) ||
2054 typeid(*selection) == typeid(MapCenterObj))
2056 BranchObj *bo=(BranchObj*)selection;
2057 actColor=bo->getColor();
2063 void MapEditor::colorItem()
2067 if (typeid(*selection) == typeid(BranchObj) ||
2068 typeid(*selection) == typeid(MapCenterObj))
2070 saveState(selection); //TODO undoCommand
2071 BranchObj *bo=(BranchObj*)selection;
2072 bo->setColor(actColor); // color branch
2077 void MapEditor::colorBranch()
2081 if (typeid(*selection) == typeid(BranchObj) ||
2082 typeid(*selection) == typeid(MapCenterObj))
2084 saveState(selection); //TODO undoCommand
2085 BranchObj *bo=(BranchObj*)selection;
2086 bo->setColorChilds(actColor); // color links, color childs
2092 void MapEditor::toggleStandardFlag(QString f)
2096 saveState(selection);// TODO undoCommand
2097 ((BranchObj*)selection)->toggleStandardFlag (f,actionSettingsUseFlagGroups);
2102 void MapEditor::setViewCenter()
2104 // transform to CanvasView Coord:
2105 QPoint p=worldMatrix().map(movingCenter);
2106 center ( p.x(), p.y());
2110 BranchObj* MapEditor::findText (QString s, bool cs)
2113 { // Nothing found or new find process
2115 // nothing found, start again
2117 itFind=mapCenter->first();
2119 bool searching=true;
2120 bool foundNote=false;
2121 while (searching && !EOFind)
2125 // Searching in Note
2126 if (itFind->getNote().contains(s,cs))
2128 if (selection!=itFind)
2130 if (selection) ((BranchObj*)selection)->unselect();
2132 selection->select();
2134 ensureSelectionVisible();
2136 if (textEditor->findText(s,cs))
2142 // Searching in Heading
2143 if (searching && itFind->getHeading().contains (s,cs) )
2145 if (selection) ((BranchObj*)selection)->unselect();
2147 selection->select();
2149 ensureSelectionVisible();
2155 itFind=itFind->next();
2156 if (!itFind) EOFind=true;
2162 return (BranchObj*)selection;
2167 void MapEditor::findReset()
2168 { // Necessary if text to find changes during a find process
2173 void MapEditor::openURL()
2177 if (typeid(*selection) == typeid(BranchObj) ||
2178 typeid(*selection) == typeid(MapCenterObj))
2180 QString url=((BranchObj*)selection)->getURL();
2182 QProcess *proc = new QProcess( this );
2184 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL" ));
2185 proc->addArgument( url);
2187 if ( !proc->start() )
2189 if (mainWindow->settingsURL() )
2195 void MapEditor::editURL()
2197 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2198 typeid(*selection) == typeid(MapCenterObj)) )
2201 BranchObj *bo=(BranchObj*)selection;
2202 QString text = QInputDialog::getText(
2203 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2204 bo->getURL(), &ok, this );
2207 // user entered something and pressed OK
2208 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+text+"\")");
2215 void MapEditor::editHeading2URL()
2217 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2218 typeid(*selection) == typeid(MapCenterObj)) )
2220 BranchObj *bo=(BranchObj*)selection;
2221 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+bo->getHeading()+"\")");
2222 bo->setURL (bo->getHeading());
2227 void MapEditor::editBugzilla2URL()
2229 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2230 typeid(*selection) == typeid(MapCenterObj)) )
2232 BranchObj *bo=(BranchObj*)selection;
2233 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2234 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")");
2240 void MapEditor::editFATE2URL()
2242 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2243 typeid(*selection) == typeid(MapCenterObj)) )
2245 BranchObj *bo=(BranchObj*)selection;
2246 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2247 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")");
2253 void MapEditor::editVymLink()
2255 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2256 typeid(*selection) == typeid(MapCenterObj)) )
2258 BranchObj *bo=(BranchObj*)selection;
2259 QFileDialog *fd=new QFileDialog( this,__VYM " - " +tr("Link to another map"));
2260 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2261 fd->setCaption(__VYM " - " +tr("Link to another map"));
2262 if (! bo->getVymLink().isEmpty() )
2263 fd->setSelection( bo->getVymLink() );
2267 if ( fd->exec() == QDialog::Accepted )
2269 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\""+fd->selectedFile()+"\")");
2270 bo->setVymLink (fd->selectedFile() );
2272 mapCenter->reposition();
2279 void MapEditor::deleteVymLink()
2281 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2282 typeid(*selection) == typeid(MapCenterObj)) )
2284 BranchObj *bo=(BranchObj*)selection;
2285 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\"\")");
2286 bo->setVymLink ("" );
2288 mapCenter->reposition();
2294 void MapEditor::setHideExport()
2296 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2297 typeid(*selection) == typeid(MapCenterObj)) ||
2298 (typeid(*selection)==typeid(FloatImageObj))
2301 saveState(); //TODO undoCommand
2302 OrnamentedObj *oo=(OrnamentedObj*)selection;
2303 oo->setHideInExport(actionEditToggleHideExport->isOn());
2305 mapCenter->reposition();
2311 void MapEditor::toggleHideExport()
2313 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2314 typeid(*selection) == typeid(MapCenterObj)) ||
2315 (typeid(*selection)==typeid(FloatImageObj))
2318 saveState(); //TODO undoCommand
2319 OrnamentedObj *oo=(OrnamentedObj*)selection;
2320 if (oo->hideInExport())
2321 oo->setHideInExport(false);
2323 oo->setHideInExport(true);
2324 actionEditToggleHideExport->setOn (oo->hideInExport());
2326 mapCenter->reposition();
2332 QString MapEditor::getVymLink()
2334 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2335 typeid(*selection) == typeid(MapCenterObj)) )
2337 return ((BranchObj*)selection)->getVymLink();
2343 void MapEditor::removeBranchHere()
2345 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2347 BranchObj* bo=(BranchObj*)selection;
2348 BranchObj* par=(BranchObj*)(bo->getParObj());
2349 if (bo->getDepth()==1)
2352 saveState(selection->getParObj()); // TODO undoCommand
2353 QString sel=selection->getSelectString();
2355 par->removeBranchHere(bo);
2356 mapCenter->reposition();
2361 void MapEditor::removeChilds()
2363 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2365 saveState(selection->getParObj());
2366 ((BranchObj*)selection)->removeChilds();
2367 mapCenter->reposition();
2371 void MapEditor::editMapInfo()
2373 ExtraInfoDialog dia;
2374 dia.setMapName (getFileName() );
2375 dia.setAuthor (mapCenter->getAuthor() );
2376 dia.setComment(mapCenter->getComment() );
2381 QCanvasItemList l=canvas()->allItems();
2382 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2384 stats+=QString ("%1 items on canvas\n").arg (i,6);
2391 bo=mapCenter->first();
2394 if (!bo->getNote().isEmpty() ) n++;
2395 f+= bo->countFloatImages();
2397 xl+=bo->countXLinks();
2400 stats+=QString ("%1 branches\n").arg (b-1,6);
2401 stats+=QString ("%1 xLinks \n").arg (xl,6);
2402 stats+=QString ("%1 notes\n").arg (n,6);
2403 stats+=QString ("%1 images\n").arg (f,6);
2404 dia.setStats (stats);
2406 // Finally show dialog
2407 if (dia.exec() == QDialog::Accepted)
2409 saveState(); //TODO undoCommand
2410 mapCenter->setAuthor (dia.getAuthor() );
2411 mapCenter->setComment (dia.getComment() );
2415 void MapEditor::updateActions()
2418 if (getLinkColorHint()==HeadingColor)
2419 actionFormatLinkColorHint->setOn(true);
2421 actionFormatLinkColorHint->setOn(false);
2426 actionFormatLinkStyleLine->setOn(true);
2429 actionFormatLinkStyleParabel->setOn(true);
2432 actionFormatLinkStylePolyLine->setOn(true);
2434 case StylePolyParabel:
2435 actionFormatLinkStylePolyParabel->setOn(true);
2441 QPixmap pix( 16, 16 );
2442 pix.fill( mapCanvas->backgroundColor() );
2443 actionFormatBackColor->setIconSet( pix );
2444 pix.fill( defLinkColor );
2445 actionFormatLinkColor->setIconSet( pix );
2447 actionEditUndo->setEnabled( mapChanged );
2448 actionFileSave->setEnabled( mapUnsaved );
2452 if ( (typeid(*selection) == typeid(BranchObj)) ||
2453 (typeid(*selection) == typeid(MapCenterObj)) )
2455 BranchObj *bo=(BranchObj*)selection;
2456 // Take care of links
2457 if (bo->countXLinks()==0)
2459 branchLinksContextMenu->clear();
2460 branchLinksContextMenu->insertItem ("No xLink available");
2461 branchLinksContextMenuDup->clear();
2462 branchLinksContextMenuDup->insertItem ("No xLink available");
2468 branchLinksContextMenu->clear();
2469 branchLinksContextMenuDup->clear();
2470 for (int i=0; i<=bo->countXLinks();i++)
2472 bot=bo->XLinkTargetAt(i);
2475 s=bot->getHeading();
2478 branchLinksContextMenu->insertItem (s);
2479 branchLinksContextMenuDup->insertItem (s);
2484 standardFlagsDefault->setEnabled (true);
2486 actionEditToggleScroll->setEnabled (true);
2487 if ( bo->isScrolled() )
2488 actionEditToggleScroll->setOn(true);
2490 actionEditToggleScroll->setOn(false);
2492 if ( bo->getURL().isEmpty() )
2493 actionEditOpenURL->setEnabled (false);
2495 actionEditOpenURL->setEnabled (true);
2497 if ( bo->getVymLink().isEmpty() )
2499 actionEditOpenVymLink->setEnabled (false);
2500 actionEditDeleteVymLink->setEnabled (false);
2503 actionEditOpenVymLink->setEnabled (true);
2504 actionEditDeleteVymLink->setEnabled (true);
2506 actionEditToggleHideExport->setEnabled (true);
2507 actionEditToggleHideExport->setOn (bo->hideInExport() );
2509 actionEditCopy->setEnabled (true);
2510 actionEditCut->setEnabled (true);
2511 if (!clipboardEmpty)
2512 actionEditPaste->setEnabled (true);
2514 actionEditPaste->setEnabled (false);
2515 for (a=actionListBranches.first();a;a=actionListBranches.next())
2516 a->setEnabled(true);
2517 actionEditDelete->setEnabled (true);
2518 switch (selection->getFrameType())
2521 actionFormatFrameNone->setOn(true);
2524 actionFormatFrameRectangle->setOn(true);
2529 actionFormatIncludeImagesVer->setOn
2530 ( ((BranchObj*)selection)->getIncludeImagesVer());
2531 actionFormatIncludeImagesHor->setOn
2532 ( ((BranchObj*)selection)->getIncludeImagesHor());
2533 actionFormatHideLinkUnselected->setOn
2534 (selection->getHideLinkUnselected());
2536 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2538 FloatObj *fo=(FloatImageObj*)selection;
2539 standardFlagsDefault->setEnabled (false);
2541 actionEditOpenURL->setEnabled (false);
2542 actionEditOpenVymLink->setEnabled (false);
2543 actionEditDeleteVymLink->setEnabled (false);
2544 actionEditToggleHideExport->setEnabled (true);
2545 actionEditToggleHideExport->setOn (fo->hideInExport() );
2548 actionEditCopy->setEnabled (true);
2549 actionEditCut->setEnabled (true);
2550 actionEditPaste->setEnabled (false);
2551 for (a=actionListBranches.first();a;a=actionListBranches.next())
2552 a->setEnabled(false);
2553 actionEditDelete->setEnabled (true);
2554 actionFormatHideLinkUnselected->setOn
2555 ( selection->getHideLinkUnselected());
2560 standardFlagsDefault->setEnabled (false);
2562 actionEditCopy->setEnabled (false);
2563 actionEditCut->setEnabled (false);
2564 actionEditPaste->setEnabled (false);
2565 for (a=actionListBranches.first();a;a=actionListBranches.next())
2566 a->setEnabled(false);
2568 actionEditToggleScroll->setEnabled (true);
2569 actionEditOpenURL->setEnabled (false);
2570 actionEditOpenVymLink->setEnabled (false);
2571 actionEditDeleteVymLink->setEnabled (false);
2572 actionEditHeading2URL->setEnabled (false);
2573 actionEditDelete->setEnabled (false);
2577 void MapEditor::updateNoteFlag()
2580 if ( (typeid(*selection) == typeid(BranchObj)) ||
2581 (typeid(*selection) == typeid(MapCenterObj)) )
2582 ((BranchObj*)selection)->updateNoteFlag();
2585 void MapEditor::setLinkStyle (LinkStyle ls)
2589 saveState(); // TODO undoCommand
2591 bo=mapCenter->first();
2595 bo->setLinkStyle(bo->getDefLinkStyle());
2598 mapCenter->reposition();
2601 LinkStyle MapEditor::getLinkStyle ()
2606 void MapEditor::setLinkColor(QColor c)
2612 void MapEditor::setLinkColorHint()
2614 // called from setLinkColorHint(lch) or at end of parse
2616 bo=mapCenter->first();
2624 void MapEditor::setLinkColorHint(LinkColorHint lch)
2630 void MapEditor::toggleLinkColorHint()
2632 if (linkcolorhint==HeadingColor)
2633 linkcolorhint=DefaultColor;
2635 linkcolorhint=HeadingColor;
2637 bo=mapCenter->first();
2645 LinkColorHint MapEditor::getLinkColorHint()
2647 return linkcolorhint;
2650 QColor MapEditor::getDefLinkColor()
2652 return defLinkColor;
2655 void MapEditor::setDefXLinkColor(QColor col)
2660 QColor MapEditor::getDefXLinkColor()
2662 return defXLinkColor;
2665 void MapEditor::setDefXLinkWidth (int w)
2670 int MapEditor::getDefXLinkWidth()
2672 return defXLinkWidth;
2675 void MapEditor::selectLinkColor()
2677 // Finish open lineEdits
2678 if (lineedit) finishedLineEditNoSave();
2680 QColor col = QColorDialog::getColor( defLinkColor, this );
2681 if ( !col.isValid() ) return;
2682 setLinkColor( col );
2683 saveState(); //TODO undoCommand
2687 void MapEditor::toggleScroll()
2689 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2691 BranchObj *bo=((BranchObj*)selection);
2692 if (bo->countBranches()==0) return;
2693 if (bo->getDepth()==0) return;
2694 saveState(selection);
2701 void MapEditor::unScrollAll()
2704 bo=mapCenter->first();
2707 if (bo->isScrolled()) bo->toggleScroll();
2712 void MapEditor::loadFloatImage ()
2715 (typeid(*selection) == typeid(BranchObj)) ||
2716 (typeid(*selection) == typeid(MapCenterObj)) )
2718 BranchObj *bo=((BranchObj*)selection);
2720 QFileDialog *fd=new QFileDialog( this);
2721 fd->setMode (QFileDialog::ExistingFiles);
2722 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2723 ImagePreview *p =new ImagePreview (fd);
2724 fd->setContentsPreviewEnabled( TRUE );
2725 fd->setContentsPreview( p, p );
2726 fd->setPreviewMode( QFileDialog::Contents );
2727 fd->setCaption(__VYM " - " +tr("Load image"));
2728 fd->setDir (lastImageDir);
2732 if ( fd->exec() == QDialog::Accepted )
2734 saveState(selection);
2735 lastImageDir=fn.left(fn.findRev ("/"));
2736 QStringList flist = fd->selectedFiles();
2737 QStringList::Iterator it = flist.begin();
2738 while( it != flist.end() )
2741 bo->addFloatImage();
2742 // TODO check if load was successful
2743 bo->getLastFloatImage()->load(*it);
2744 bo->getLastFloatImage()->setOriginalFilename(fn);
2748 mapCenter->reposition();
2757 void MapEditor::saveFloatImage (int item)
2760 (typeid(*selection) == typeid(FloatImageObj)) )
2762 FloatImageObj *fio=((FloatImageObj*)selection);
2763 const char* fmt = saveImageFormatMenu->text(item);
2765 QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
2766 fd->addFilter ("PNG (*.png)");
2767 fd->addFilter ("BMP (*.bmp)");
2768 fd->addFilter ("XBM (*.xbm)");
2769 fd->addFilter ("JPG (*.jpg)");
2770 fd->addFilter ("XPM (*.xpm)");
2771 fd->addFilter ("GIF (*.gif)");
2772 fd->addFilter ("PNM (*.pnm)");
2773 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2774 fd->setCaption(__VYM " - " +tr("Save image as %1").arg(fmt));
2775 fd->setMode( QFileDialog::AnyFile );
2776 fd->setSelection (fio->getOriginalFilename());
2780 if ( fd->exec() == QDialog::Accepted )
2782 if (QFile (fd->selectedFile()).exists() )
2784 QMessageBox mb( __VYM,
2785 tr("The file %1 exists already.\n"
2786 "Do you want to overwrite it?").arg(fd->selectedFile()),
2787 QMessageBox::Warning,
2788 QMessageBox::Yes | QMessageBox::Default,
2789 QMessageBox::Cancel | QMessageBox::Escape,
2790 QMessageBox::QMessageBox::NoButton );
2792 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2793 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2796 case QMessageBox::Yes:
2799 case QMessageBox::Cancel:
2805 fio->save (fd->selectedFile(),fmt);
2810 void MapEditor::setFrame(const FrameType &t)
2813 (typeid(*selection) == typeid(BranchObj)) ||
2814 (typeid(*selection) == typeid(MapCenterObj)) )
2816 selection->setFrameType (t);
2817 mapCenter->reposition();
2818 selection->updateLink();
2822 void MapEditor::setIncludeImagesVer(bool b)
2825 (typeid(*selection) == typeid(BranchObj)) ||
2826 (typeid(*selection) == typeid(MapCenterObj)) )
2827 ((BranchObj*)selection)->setIncludeImagesVer(b);
2828 mapCenter->reposition();
2831 void MapEditor::setIncludeImagesHor(bool b)
2834 (typeid(*selection) == typeid(BranchObj)) ||
2835 (typeid(*selection) == typeid(MapCenterObj)) )
2836 ((BranchObj*)selection)->setIncludeImagesHor(b);
2837 mapCenter->reposition();
2840 void MapEditor::setHideLinkUnselected (bool b)
2843 (typeid(*selection) == typeid(BranchObj)) ||
2844 (typeid(*selection) == typeid(MapCenterObj)) ||
2845 (typeid(*selection) == typeid(FloatImageObj)) )
2846 selection->setHideLinkUnselected(b);
2849 void MapEditor::importDir(BranchObj *dst, QDir d)
2852 (typeid(*selection) == typeid(BranchObj)) ||
2853 (typeid(*selection) == typeid(MapCenterObj)) )
2857 // Traverse directories
2858 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2859 const QFileInfoList *dirlist = d.entryInfoList();
2860 QFileInfoListIterator itdir( *dirlist );
2863 while ( (fi = itdir.current()) != 0 )
2865 if (fi->fileName() != "." && fi->fileName() != ".." )
2868 bo=dst->getLastBranch();
2869 bo->setHeading (fi->fileName() );
2870 bo->setColor (QColor("blue"));
2872 if ( !d.cd(fi->fileName()) )
2873 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi->fileName()));
2876 // Recursively add subdirs
2884 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
2885 const QFileInfoList *filelist = d.entryInfoList();
2886 QFileInfoListIterator itfile( *filelist );
2888 while ( (fi = itfile.current()) != 0 )
2891 bo=dst->getLastBranch();
2892 bo->setHeading (fi->fileName() );
2893 bo->setColor (QColor("black"));
2894 if (fi->fileName().right(4) == ".vym" )
2895 bo->setVymLink (fi->filePath());
2902 void MapEditor::importDir()
2905 (typeid(*selection) == typeid(BranchObj)) ||
2906 (typeid(*selection) == typeid(MapCenterObj)) )
2908 QFileDialog *fd=new QFileDialog( this,__VYM " - " +tr("Choose directory structure to import"));
2909 fd->setMode (QFileDialog::DirectoryOnly);
2910 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2911 fd->setCaption(__VYM " - " +tr("Choose directory structure to import"));
2915 if ( fd->exec() == QDialog::Accepted )
2917 BranchObj *bo=((BranchObj*)selection);
2918 importDir (bo,QDir(fd->selectedFile()) );
2919 mapCenter->reposition();
2926 void MapEditor::followXLink(int i)
2929 (typeid(*selection) == typeid(BranchObj)) ||
2930 (typeid(*selection) == typeid(MapCenterObj)) )
2932 BranchObj *bo=((BranchObj*)selection)->XLinkTargetAt(i);
2935 selection->unselect();
2937 selection->select();
2938 ensureSelectionVisible();
2943 void MapEditor::editXLink(int i)
2946 (typeid(*selection) == typeid(BranchObj)) ||
2947 (typeid(*selection) == typeid(MapCenterObj)) )
2949 XLinkObj *xlo=((BranchObj*)selection)->XLinkAt(i);
2952 EditXLinkDialog dia;
2954 dia.setSelection(selection);
2955 if (dia.exec() == QDialog::Accepted)
2957 if (dia.useSettingsGlobal() )
2959 setDefXLinkColor (xlo->getColor() );
2960 setDefXLinkWidth (xlo->getWidth() );
2962 if (dia.deleteXLink())
2963 ((BranchObj*)selection)->deleteXLinkAt(i);
2964 saveState(); //TODO undoCommand
2970 void MapEditor::testFunction()
2972 cout << "MapEditor::testFunction() called\n";
2973 mapCenter->reposition();
2977 if (selection && (typeid(*selection) == typeid(BranchObj)))
2979 cout << "Note:\n"<<((BranchObj*)selection)->getNoteOpenDoc()<<endl;
2984 void MapEditor::ensureSelectionVisible()
2988 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
2990 if (selection->getOrientation() == OrientLeftOfCenter)
2991 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
2993 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
2994 ensureVisible (p.x(), p.y() );
2999 void MapEditor::updateViewCenter()
3001 // Update movingCenter, so that we can zoom comfortably later
3002 QRect rc = QRect( contentsX(), contentsY(),
3003 visibleWidth(), visibleHeight() );
3004 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
3005 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
3006 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
3009 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
3011 // Lineedits are already closed by preceding
3012 // mouseEvent, we don't need to close here.
3014 QPoint p = inverseWorldMatrix().map(e->pos());
3015 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3018 { // MapObj was found
3019 if (selection != lmo)
3021 // select the MapObj
3022 if (selection) selection->unselect();
3024 selection->select();
3030 if (typeid(*selection)==typeid(BranchObj) ||
3031 typeid(*selection)==typeid(MapCenterObj) )
3033 // Context Menu on branch or mapcenter
3035 branchContextMenu->popup(e->globalPos() );
3037 if (typeid(*selection)==typeid(FloatImageObj))
3039 // Context Menu on floatimage
3041 floatimageContextMenu->popup(e->globalPos() );
3045 { // No MapObj found, we are on the Canvas itself
3046 // Context Menu on Canvas
3048 canvasContextMenu->popup(e->globalPos() );
3052 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
3054 // Finish open lineEdits
3055 if (lineedit) finishedLineEditNoSave();
3057 QPoint p = inverseWorldMatrix().map(e->pos());
3058 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3060 // Special case: CTRL is pressed
3061 if (e->state() & QMouseEvent::ControlButton)
3063 if (actionModModeColor->isOn())
3065 if (e->state() & QMouseEvent::ControlButton)
3068 setCursor (pickColorCursor);
3072 if (actionModModeLink->isOn())
3074 BranchObj *bo_begin=NULL;
3076 bo_begin=(BranchObj*)(lmo);
3079 ((typeid(*selection) == typeid(BranchObj)) ||
3080 (typeid(*selection) == typeid(MapCenterObj))) )
3081 bo_begin=(BranchObj*)selection;
3085 linkingObj_src=bo_begin;
3086 tmpXLink=new XLinkObj (mapCanvas);
3087 tmpXLink->setBegin (bo_begin);
3088 tmpXLink->setEnd (p);
3089 tmpXLink->setColor(defXLinkColor);
3090 tmpXLink->setWidth(defXLinkWidth);
3091 tmpXLink->updateXLink();
3092 tmpXLink->setVisibility (true);
3099 { // MapObj was found
3100 if (selection != lmo)
3102 // select the MapObj
3103 if (selection) selection->unselect();
3105 selection->select();
3110 // Check, if systemFlag clicked
3111 if (typeid(*selection)==typeid(BranchObj) ||
3112 typeid(*selection)==typeid(MapCenterObj) )
3114 QString foname=((BranchObj*)selection)->getSystemFlagName(p);
3115 if (!foname.isEmpty())
3117 // Do not move, if systemFlag clicked
3120 else if (foname=="vymLink")
3122 mainWindow->editOpenVymLink();
3123 // tabWidget may change, better return now
3124 // before segfaulting...
3126 } else if (foname=="note")
3127 mainWindow->windowToggleNoteEditor();
3128 else if (foname=="hideInExport")
3133 // Left Button Move Branches
3134 if (e->button() == QMouseEvent::LeftButton )
3136 movingObj_start.setX( p.x() - selection->x() );
3137 movingObj_start.setY( p.y() - selection->y() );
3138 movingObj_orgPos.setX (lmo->x() );
3139 movingObj_orgPos.setY (lmo->y() );
3141 // If modMode==copy, then we want to "move" the _new_ object around
3142 // then we need the offset from p to the _old_ selection, because of tmp
3143 if (actionModModeCopy->isOn() &&
3144 e->state() & QMouseEvent::ControlButton)
3146 if (typeid(*selection)==typeid(BranchObj) )
3149 mapCenter->addBranch ((BranchObj*)selection);
3151 selection=mapCenter->getLastBranch();
3152 selection->select();
3153 mapCenter->reposition();
3156 movingObj=selection;
3158 // Middle Button Toggle Scroll
3159 // (On Mac OS X this won't work, but we still have
3160 // a button in the toolbar)
3161 if (e->button() == QMouseEvent::MidButton )
3165 { // No MapObj found, we are on the Canvas itself
3166 // Left Button move Pos of CanvasView
3167 if (e->button() == QMouseEvent::LeftButton )
3169 movingObj=NULL; // move Content not Obj
3170 movingObj_start=e->globalPos();
3171 movingCont_start=QPoint (contentsX(), contentsY() );
3172 movingVec=QPoint(0,0);
3173 setCursor(handOpenCursor);
3178 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3180 QPoint p = inverseWorldMatrix().map(e->pos());
3182 // Move the selected MapObj
3183 if ( selection && movingObj)
3185 // To avoid jumping of the CanvasView, only
3186 // ensureSelectionVisible, if not tmp linked
3187 if (!selection->hasParObjTmp())
3188 ensureSelectionVisible ();
3190 // Now move the selection, but add relative position
3191 // (movingObj_start) where selection was chosen with
3192 // mousepointer. (This avoids flickering resp. jumping
3193 // of selection back to absPos)
3195 LinkableMapObj *lmosel;
3196 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3198 // Check if we could link
3199 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3202 if (typeid(*selection) == typeid(FloatImageObj))
3204 FloatObj *fo=(FloatObj*)selection;
3205 saveState("move "+qpointToString(movingObj_orgPos),fo->getSelectString() );
3206 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3210 // Relink float to new mapcenter or branch, if shift is pressed
3211 // Only relink, if selection really has a new parent
3212 if ( (e->state() & QMouseEvent::ShiftButton) && lmo &&
3213 ( (typeid(*lmo)==typeid(BranchObj)) ||
3214 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3215 ( lmo != fo->getParObj())
3218 if (typeid(*fo) == typeid(FloatImageObj))
3221 FloatImageObj *fio=(FloatImageObj*)(fo);
3222 ((BranchObj*)(lmo))->addFloatImage (fio);
3224 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3225 fio=((BranchObj*)(lmo))->getLastFloatImage();
3228 selection=(LinkableMapObj*)(fio);
3229 selection->select();
3230 movingObj=(MapObj*)(fio);
3233 } else // selection != a FloatObj
3235 if (lmosel->getDepth()==0)
3237 if (e->state() == (LeftButton | !ShiftButton))
3238 // If mapCenter is moved, move all the rest by default, too.
3239 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3241 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3244 if (lmosel->getDepth()==1)
3246 // depth==1, mainbranch
3247 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3251 if (lmosel->getOrientation() == OrientLeftOfCenter)
3252 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3253 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3254 p.y()-movingObj_start.y() +lmosel->getTopPad() );
3256 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
3258 // reposition subbranch
3259 lmosel->reposition();
3260 //ensureSelectionVisible();
3262 if (lmo && (lmo!=selection) &&
3263 (typeid(*lmo) == typeid(BranchObj) ||
3264 (typeid(*lmo) == typeid(MapCenterObj) )
3267 if (e->state() & QMouseEvent::ControlButton)
3269 // Special case: CTRL to link below lmo
3270 lmosel->setParObjTmp (lmo,p,+1);
3272 else if (e->state() & QMouseEvent::ShiftButton)
3273 lmosel->setParObjTmp (lmo,p,-1);
3275 lmosel->setParObjTmp (lmo,p,0);
3278 lmosel->unsetParObjTmp();
3279 /* FIXME not needed anymore?
3280 if (lmo &&(lmo==selection))
3281 // Could link to myself (happens sometimes...)
3282 lmosel->unsetParObjTmp();
3284 // no Obj under selection, go back to original Parent
3285 lmosel->unsetParObjTmp();
3290 } // no FloatImageObj
3294 } // selection && moving_obj
3296 // Draw a link from one branch to another
3299 tmpXLink->setEnd (p);
3300 tmpXLink->updateXLink();
3304 if (!movingObj && !pickingColor &&!drawingLink)
3306 QPoint p=e->globalPos();
3307 movingVec.setX(-p.x() + movingObj_start.x() );
3308 movingVec.setY(-p.y() + movingObj_start.y() );
3309 setContentsPos( movingCont_start.x() + movingVec.x(),
3310 movingCont_start.y() + movingVec.y());
3317 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3319 LinkableMapObj *dst;
3320 // Have we been picking color?
3324 setCursor (ArrowCursor);
3325 // Check if we are over another branch
3326 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3327 if (dst && selection)
3329 if (e->state() & QMouseEvent::ShiftButton)
3331 ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor());
3332 ((BranchObj*)selection)->setLinkColor ();
3336 ((BranchObj*)selection)->setColorChilds (((BranchObj*)(dst))->getColor());
3337 ((BranchObj*)selection)->setLinkColor ();
3343 // Have we been drawing a link?
3347 // Check if we are over another branch
3348 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3349 if (dst && selection)
3351 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3352 tmpXLink->updateXLink();
3353 tmpXLink->activate();
3354 saveState(); //TODO undoCommand
3363 // Have we been moving something?
3364 if ( selection && movingObj )
3366 // Moved FloatObj? Maybe we need to reposition
3367 if(typeid(*selection)==typeid (FloatImageObj))
3369 selection->getParObj()->requestReposition();
3370 mapCenter->reposition();
3373 // Check if we are over another branch, but ignore
3374 // any found LMOs, which are FloatObjs
3375 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3376 ((LinkableMapObj*)selection) );
3379 (typeid(*dst)!=typeid(BranchObj)&&typeid(*dst)!=typeid(MapCenterObj)))
3382 // Now check, if we have been moving a branch
3383 if (typeid(*selection) == typeid(BranchObj) )
3385 // save the position in case we link to mapcenter
3386 QPoint savePos=QPoint (selection->x(),selection->y() );
3388 // Reset the temporary drawn link to the original one
3389 ((LinkableMapObj*)selection)->unsetParObjTmp();
3395 BranchObj* bs=((BranchObj*)selection);
3396 QString undoCom="linkBranchToPos (\""+
3397 (bs->getParObj())->getSelectString()+
3399 QString("%1").arg(bs->getNum())+
3401 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+
3403 // TODO we also could check, if dest and src are on same branch,
3404 // then it would be sufficient to saveState of this branch
3406 // Modifiers allow to insert above/below dst
3407 if (e->state() & QMouseEvent::ShiftButton)
3409 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum());
3411 if (e->state() & QMouseEvent::ControlButton)
3413 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum()+1);
3416 bs->moveBranchTo ((BranchObj*)(dst),-1);
3417 if (dst->getDepth()==0)
3420 saveState (undoCom,bs->getSelectString() );
3422 if (selection->getDepth()==1)
3423 // If we have moved mainbranch only save endposition
3424 saveState("move "+qpointToString(movingObj_orgPos), selection->getSelectString() );
3426 // Draw the original link, before selection was moved around
3427 mapCenter->reposition();
3429 // Finally resize canvas, if needed
3434 // maybe we moved View: set old cursor
3435 setCursor (ArrowCursor);
3439 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3441 // Finish open lineEdits
3442 if (lineedit) finishedLineEditNoSave();
3444 if (e->button() == QMouseEvent::LeftButton )
3446 QPoint p = inverseWorldMatrix().map(e->pos());
3447 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3448 if (lmo) { // MapObj was found
3449 // First select the MapObj than edit heading
3450 if (selection) selection->unselect();
3452 selection->select();
3453 saveState(selection);
3459 void MapEditor::resizeEvent (QResizeEvent* e)
3461 QCanvasView::resizeEvent( e );
3465 void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3468 // for (unsigned int i=0;event->format(i);i++) // Debug mime type
3469 // cerr << event->format(i) << endl;
3472 (typeid(*selection) == typeid(BranchObj)) ||
3473 (typeid(*selection) == typeid(MapCenterObj))) {
3475 // If QImageDrag can decode mime type
3476 if (QImageDrag::canDecode(event)) {
3481 // If image are dragged from firefox
3482 if (event->provides("application/x-moz-file-promise-url") &&
3483 event->provides("application/x-moz-nativeimage")) {
3484 event->accept(true);
3488 // If QUriDrag can decode mime type
3489 if (QUriDrag::canDecode(event)) {
3494 // If Uri are dragged from firefox
3495 if (event->provides("_NETSCAPE_URL")){
3500 // If QTextDrag can decode mime type
3501 if (QTextDrag::canDecode(event)) {
3510 bool isUnicode16(const QByteArray &d)
3512 // TODO: make more precise check for unicode 16.
3513 // Guess unicode16 if any of second bytes are zero
3514 unsigned int length = max(0,d.size()-2)/2;
3515 for (unsigned int i = 0; i<length ; i++)
3516 if (d.at(i*2+1)==0) return true;
3520 void MapEditor::contentsDropEvent(QDropEvent *event)
3523 (typeid(*selection) == typeid(BranchObj)) ||
3524 (typeid(*selection) == typeid(MapCenterObj)))
3529 if (event->provides("image/png"))
3532 if (QImageDrag::decode(event, pix))
3540 } else if (event->provides("application/x-moz-file-promise-url") &&
3541 event->provides("application/x-moz-nativeimage"))
3543 // Contains url to the img src in unicode16
3544 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3545 QString url = QString((const QChar*)d.data(),d.size()/2);
3549 } else if (event->provides ("text/uri-list"))
3550 { // Uris provided e.g. by konqueror
3551 QUriDrag::decode (event,uris);
3552 } else if (event->provides ("_NETSCAPE_URL"))
3553 { // Uris provided by Mozilla
3554 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
3557 } else if (event->provides("text/html")) {
3559 // Handels text mime types
3560 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
3561 QByteArray d = event->encodedData("text/html");
3564 text = QString((const QChar*)d.data(),d.size()/2);
3568 textEditor->setText(text);
3572 } else if (event->provides("text/plain")) {
3573 QByteArray d = event->encodedData("text/plain");
3576 text = QString((const QChar*)d.data(),d.size()/2);
3580 textEditor->setText(text);
3592 for (const char* u=uris.first(); u; u=uris.next())
3594 bo=((BranchObj*)selection)->addBranch();
3597 s=QUriDrag::uriToLocalFile(u);
3599 QString file = QDir::convertSeparators(s);
3600 heading = QFileInfo(file).baseName();
3602 if (file.endsWith(".vym", false))
3603 bo->setVymLink(file);
3612 bo->setHeading(heading);
3622 saveState(); //TODO undo Command
3623 mapCenter->reposition();
3630 void MapEditor::addFloatImage(const QPixmap &img)
3633 (typeid(*selection) == typeid(BranchObj)) ||
3634 (typeid(*selection) == typeid(MapCenterObj)) )
3636 BranchObj *bo=((BranchObj*)selection);
3637 saveState(selection);
3638 //QString fn=fd->selectedFile();
3639 //lastImageDir=fn.left(fn.findRev ("/"));
3640 bo->addFloatImage();
3641 // FIXME check if load was successful
3642 bo->getLastFloatImage()->load(img);
3643 //bo->getLastFloatImage()->setOriginalFilename(fn);
3644 mapCenter->reposition();
3651 void MapEditor::imageDataFetched(const QByteArray &a, QNetworkOperation */*nop*/)
3653 if (!imageBuffer) imageBuffer = new QBuffer();
3654 if (!imageBuffer->isOpen()) {
3655 imageBuffer->open(IO_WriteOnly | IO_Append);
3657 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
3661 void MapEditor::imageDataFinished(QNetworkOperation *nop)
3663 if (nop->state()==QNetworkProtocol::StDone) {
3664 QPixmap img(imageBuffer->buffer());
3669 imageBuffer->close();
3671 imageBuffer->close();
3678 void MapEditor::fetchImage(const QString &url)
3681 urlOperator->stop();
3682 disconnect(urlOperator);
3686 urlOperator = new QUrlOperator(url);
3687 connect(urlOperator, SIGNAL(finished(QNetworkOperation *)),
3688 this, SLOT(imageDataFinished(QNetworkOperation*)));
3690 connect(urlOperator, SIGNAL(data(const QByteArray &, QNetworkOperation *)),
3691 this, SLOT(imageDataFetched(const QByteArray &, QNetworkOperation *)));