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>
31 #include "texteditor.h"
32 #include "linkablemapobj.h"
35 #include "mainwindow.h"
36 #include "extrainfodialog.h"
37 #include "editxlinkdialog.h"
41 extern TextEditor *textEditor;
42 extern int statusbarTime;
43 extern Main *mainWindow;
44 extern QString tmpVymDir;
45 extern QString clipboardDir;
46 extern bool clipboardEmpty;
47 extern FlagRowObj *systemFlagsDefault;
48 extern FlagRowObj *standardFlagsDefault;
50 extern QPtrList <QAction> actionListBranches;
52 extern QAction *actionFileSave;
53 extern QAction *actionEditUndo;
54 extern QAction *actionEditCopy;
55 extern QAction *actionEditCut;
56 extern QAction *actionEditPaste;
57 extern QAction *actionEditMoveUp;
58 extern QAction *actionEditMoveDown;
59 extern QAction *actionEditToggleScroll;
60 extern QAction *actionEditOpenURL;
61 extern QAction *actionEditURL;
62 extern QAction *actionEditHeading2URL;
63 extern QAction *actionEditBugzilla2URL;
64 extern QAction *actionEditOpenVymLink;
65 extern QAction *actionEditVymLink;
66 extern QAction *actionEditDeleteVymLink;
67 extern QAction *actionEditHeading;
68 extern QAction *actionEditDelete;
69 extern QAction *actionEditAddBranch;
70 extern QAction *actionEditAddBranchAbove;
71 extern QAction *actionEditAddBranchBelow;
72 extern QAction *actionEditRemoveBranchHere;
73 extern QAction *actionEditRemoveChilds;
74 extern QAction *actionEditImportAdd;
75 extern QAction *actionEditImportReplace;
76 extern QAction *actionEditSaveBranch;
77 extern QAction *actionEditSelectFirst;
78 extern QAction *actionEditSelectLast;
79 extern QAction *actionEditLoadImage;
80 extern QAction *actionEditToggleFloatExport;
82 extern QAction* actionFormatPickColor;
83 extern QAction* actionFormatColorBranch;
84 extern QAction* actionFormatColorSubtree;
85 extern QAction *actionFormatLinkColorHint;
86 extern QAction *actionFormatBackColor;
87 extern QAction *actionFormatLinkColor;
89 extern QActionGroup* actionGroupModModes;
90 extern QAction* actionModModeColor;
91 extern QAction* actionModModeLink;
92 extern QAction* actionModModeCopy;
94 extern QActionGroup *actionGroupFormatFrameTypes;
95 extern QAction *actionFormatFrameNone;
96 extern QAction *actionFormatFrameRectangle;
98 extern QActionGroup *actionGroupFormatLinkStyles;
99 extern QAction *actionFormatHideLinkUnselected;
100 extern QAction *actionFormatLinkStyleLine;
101 extern QAction *actionFormatLinkStyleParabel;
102 extern QAction *actionFormatLinkStylePolyLine;
103 extern QAction *actionFormatLinkStylePolyParabel;
105 extern QAction *actionViewToggleNoteEditor;
107 extern QAction *actionSettingsAutoedit;
108 extern QAction *actionSettingsAutoselectHeading;
109 extern QAction *actionSettingsAutoselectText;
110 extern QAction *actionSettingsPasteNewHeading;
111 extern QAction *actionSettingsUseFlagGroups;
113 extern QPopupMenu *branchContextMenu;
114 extern QPopupMenu *branchLinksContextMenu;
115 extern QPopupMenu *branchLinksContextMenuDup;
116 extern QPopupMenu *floatimageContextMenu;
117 extern QPopupMenu *saveImageFormatMenu;
118 extern QPopupMenu *exportImageFormatMenu;
119 extern QPopupMenu *canvasContextMenu;
121 extern Settings settings;
123 int MapEditor::mapNum=0; // make instance
125 ///////////////////////////////////////////////////////////////////////
126 ///////////////////////////////////////////////////////////////////////
127 MapEditor::MapEditor(
128 QWidget* parent, bool interactive, const char* name, WFlags f) :
129 QCanvasView(parent,name,f), urlOperator(0), imageBuffer(0)
131 //cout << "Constructor ME "<<this<<endl;
134 viewport()->setAcceptDrops(true);
136 mapCanvas = new QCanvas(1000,800);
137 mapCanvas->setAdvancePeriod(30);
138 mapCanvas->setBackgroundColor (white);
140 setCanvas (mapCanvas);
142 // Always show scroll bars (automatic would flicker sometimes)
143 setVScrollBarMode ( QScrollView::AlwaysOn );
144 setHScrollBarMode ( QScrollView::AlwaysOn );
146 mapCenter = new MapCenterObj(mapCanvas);
147 mapCenter->setVisibility (true);
148 mapCenter->setMapEditor (this);
149 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
150 mapCenter->move(mapCanvas->width()/2-mapCenter->width()/2,mapCanvas->height()/2-mapCenter->width()/2);
154 lineedit = new QLineEdit(this, "lineedit" );
155 connect( lineedit, SIGNAL( returnPressed() ), SLOT( finishedLineEditNoSave() ) );
158 actColor=black; setColor (actColor);
159 defLinkColor=QColor (0,0,255);
160 defXLinkColor=QColor (180,180,180);
161 linkcolorhint=DefaultColor;
162 linkstyle=StylePolyParabel;
164 // Create bitmap cursors, patform dependant
165 #if defined(Q_OS_MACX)
166 #include "icons/cursorhandopen16.xpm"
167 #include "icons/cursorcolorpicker16.xpm"
168 QBitmap cb( 16, 16, chandopen, TRUE );
169 QBitmap cm( 16, 16, chandopenmask, TRUE );
170 handOpenCursor=QCursor ( cb, cm );
171 // set hot spot to tip of picker
172 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 1,15 );
174 #include "icons/cursorhandopen.xpm"
175 #include "icons/cursorcolorpicker.xpm"
177 QBitmap cb( 32, 32, chandopen, TRUE );
178 QBitmap cm( 32, 32, chandopenmask, TRUE );
179 handOpenCursor=QCursor ( cb, cm );
180 // set hot spot to tip of picker
181 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 5,27 );
194 defXLinkColor=QColor (230,230,230);
205 undosTotal=settings.readNumEntry("/vym/mapeditor/undoLevels",50);
209 // Initialize find routine
216 blockReposition=false;
217 blockSaveState=false;
218 isInteractive=interactive;
220 // Create temporary files
223 // Initially set movingCentre
226 mapCenter->reposition(); // for positioning heading
229 MapEditor::~MapEditor()
231 if (imageBuffer) delete imageBuffer;
237 //cout <<"Destructor MapEditor\n";
240 //settings.writeEntry( "/vym/mapeditor/editmode/autoselect", );
244 QColor MapEditor::color()
249 QColor MapEditor::backgroundColor()
251 return mapCanvas->backgroundColor();
254 MapCenterObj* MapEditor::getMapCenter()
259 QCanvas* MapEditor::getCanvas()
264 void MapEditor::adjustCanvasSize()
266 // To adjust the canvas to map, viewport size and position, we have to
267 // do some coordinate magic...
269 // Get rectangle of (scroll-)view.
270 // We want to be in canvas coords, so
271 // we map. Important if view is zoomed...
272 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
273 visibleWidth(), visibleHeight()) );
275 // Now we need the bounding box of view AND map to calc the correct canvas size.
276 // Why? Because if the map itself is moved out of view, the view has to be enlarged
277 // to avoid jumping aroung...
278 QRect map=mapCenter->getTotalBBox();
280 // right edge - left edge
281 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
282 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
285 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
286 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
289 // move the map on canvas (in order to not move it on screen) this is neccessary
290 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
291 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
292 // to scroll to an empty area of canvas to the left.
293 // b) if topleft corner of map left of or above topleft of canvas
297 if (cw > mapCanvas->width() )
299 if (map.x()<0) dx=-map.x();
301 if (cw < mapCanvas->width() )
302 dx=-min (view.x(),map.x());
303 if (ch > mapCanvas->height() )
305 if (map.y()<0) dy=-map.y();
307 if (ch < mapCanvas->height() )
309 dy=-min (view.y(),map.y());
311 // We really have to resize now. Let's go...
312 mapCanvas->resize (cw,ch);
313 if ( (dx!=0) || (dy!=0) )
315 cout << "ME:: canvas="<<cw<<","<<ch<<endl;
316 mapCenter->moveAllBy(dx,dy);
317 mapCenter->reposition();
319 // scroll the view (in order to not move map on screen)
325 bool MapEditor::isRepositionBlocked()
327 return blockReposition;
330 void MapEditor::makeTmpDirs()
332 // Create unique temporary directories
333 tmpMapDir=tmpVymDir+QString("/mapeditor-%1").arg(mapNum);
335 d.mkdir (tmpMapDir,true);
338 void MapEditor::delTmpDirs()
340 removeDir (QDir(tmpMapDir));
343 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSelection)
345 // tmpdir temporary directory to which data will be written
346 // prefix mapname, which will be appended to images etc.
347 // writeflags Only write flags for "real" save of map, not undo
348 // offset offset of bbox of whole map in canvas.
349 // Needed for XML export
365 ls="StylePolyParabel";
369 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
371 if (linkcolorhint==HeadingColor)
372 colhint=attribut("linkColorHint","HeadingColor");
374 QString mapAttr=attribut("version",__VYM_VERSION__);
376 mapAttr+= attribut("author",mapCenter->getAuthor()) +
377 attribut("comment",mapCenter->getComment()) +
378 attribut("date",mapCenter->getDate()) +
379 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
380 attribut("linkStyle", ls ) +
381 attribut("linkColor", defLinkColor.name() ) +
382 attribut("defXLinkColor", defXLinkColor.name() ) +
383 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
385 s+=beginElement("vymmap",mapAttr);
388 // Find the used flags while traversing the tree
389 standardFlagsDefault->resetUsedCounter();
391 // Reset the counters before saving
392 FloatImageObj (mapCanvas).resetSaveCounter();
394 // Build xml recursivly
396 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
399 if ( typeid(*saveSelection) == typeid(BranchObj) )
400 s+=((BranchObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
401 else if ( typeid(*saveSelection) == typeid(FloatImageObj) )
402 s+=((FloatImageObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
404 else if (selection && typeid(*selection)==typeid(BranchObj))
405 // This is used if selected branch is saved from mainwindow
406 s+=((BranchObj*)selection)->saveToDir(tmpdir,prefix,offset);
409 // Save local settings
410 s+=settings.getXMLData (destPath);
413 if (selection && !saveSelection )
414 s+=valueElement("select",selection->getSelectString());
417 s+=endElement("vymmap");
420 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
424 void MapEditor::saveState()
427 saveState (CompleteMap,"",NULL,"",NULL);
430 void MapEditor::saveState(LinkableMapObj *undoSel)
432 // save the given part of the map
433 saveState (PartOfMap,"",undoSel,"",NULL);
436 void MapEditor::saveState(const QString &uc, const QString &rc)
438 // selection does not change during action,
439 // so just save commands for undo and redo
440 LinkableMapObj *unsel;
445 saveState (UndoCommand,uc,unsel,rc,unsel);
448 void MapEditor::saveState(const QString & uncom, LinkableMapObj *unsel)
450 saveState (UndoCommand,uncom,unsel,"FIXME-redoCom",NULL);
453 void MapEditor::saveState(const SaveMode &savemode, const QString &undoCom, LinkableMapObj *undoSel, const QString &redoCom, LinkableMapObj *redoSel)
457 if (blockSaveState) return;
459 /* TODO remove after testing
460 cout << "ME::saveState() begin\n"<<endl;
461 cout << " undosTotal="<<undosTotal<<endl;
462 cout << " undosAvail="<<undosAvail<<endl;
463 cout << " undoNum="<<undoNum<<endl;
464 cout << " ---------------------------"<<endl;
468 // Find out current undo directory
469 if (undosAvail<undosTotal) undosAvail++;
471 if (undoNum>undosTotal) undoNum=1;
474 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
475 QString bakMapPath=QDir::convertSeparators(bakMapDir+"/map.xml");
477 // Create bakMapDir if not available
480 makeSubDirs (bakMapDir);
482 // Save current selection
483 QString redoSelection="";
485 redoSelection=redoSel->getSelectString();
487 // Save the object, which should be undone
488 QString undoSelection="";
490 undoSelection=undoSel->getSelectString();
492 // Save depending on how much needs to be saved
493 QString undoCommand="";
494 if (savemode==UndoCommand)
499 else if (savemode==PartOfMap && undoSel)
501 undoCommand="undoPart (\""+ undoSelection+"\",\""+bakMapPath+"\")";
502 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),undoSel);
505 undoCommand="undoMap (\""+bakMapPath+"\")";
506 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),NULL);
509 if (!backupXML.isEmpty())
510 // Write XML Data to disk
511 saveStringToDisk (QString(bakMapPath),backupXML);
514 set.setEntry (QString("undoCommand"),undoCommand);
515 set.setEntry (QString("undoSelection"),undoSelection);
516 set.setEntry (QString("redoCommand"),redoCom);
517 set.setEntry (QString("redoSelection"),redoSelection);
518 set.writeSettings(QString(bakMapDir+"/commands"));
520 /* TODO remove after testing
521 cout << " into="<< bakMapDir<<endl;
522 cout << " undosAvail="<<undosAvail<<endl;
523 cout << " undoNum="<<undoNum<<endl;
524 cout << " ---------------------------"<<endl;
525 cout << " undoCom="<<undoCommand<<endl;
526 cout << " undoSel="<<undoSelection<<endl;
527 cout << " ---------------------------"<<endl;
528 cout << " redoCom="<<redoCom<<endl;
529 cout << " redoSel="<<redoSelection<<endl;
530 cout << " ---------------------------"<<endl<<endl;
534 void MapEditor::parseAtom(const QString &atom)
541 // Split string s into command and parameters
542 api.parseCommand (atom);
543 QString com=api.command();
546 if (com=="moveBranchUp")
548 else if (com=="moveBranchDown")
550 else if (com=="move")
552 if (api.checkParamCount(2) && selection )
562 else if (com=="linkBranchToPos")
564 if (selection && typeid(*selection) == typeid(BranchObj) )
566 if (api.checkParamCount(4))
568 s=api.parString(ok,0);
569 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
572 if (typeid(*dst) == typeid(BranchObj) )
574 // Get number in parent
577 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),x);
578 } else if (typeid(*dst) == typeid(MapCenterObj) )
580 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),-1);
581 // Get coordinates of mainbranch
586 if (ok) ((BranchObj*)selection)->move (x,y);
592 } else if (com=="setHeading")
594 if (api.checkParamCount(1))
596 s=api.parString (ok,0);
597 if (ok) setHeading (s);
599 } else if (com=="setURL")
601 if (api.checkParamCount(1))
603 s=api.parString (ok,0);
606 } else if (com=="setVymLink")
608 if (api.checkParamCount(1))
610 s=api.parString (ok,0);
611 if (ok) setVymLink(s);
614 // Internal commands, used for undo etc.
615 else if (com==QString("undoMap"))
617 if (api.checkParamCount(1))
618 undoXML("",api.parString (ok,0));
619 } else if (com==QString("undoPart"))
621 if (api.checkParamCount(2))
623 s=api.parString (ok,0);
624 t=api.parString (ok,1);
627 } else if (com=="select")
628 if (api.checkParamCount(1))
630 s=api.parString(ok,0);
635 api.setError ("Unknown command in: "+atom);
636 cout << "ME::parse api should have error now...\n";
642 cout << "MapEditor::parseAtom: Error!\n";
643 cout << " "<<api.errorDesc()<<endl;
648 void MapEditor::finishedLineEditNoSave()
650 // This is called by finishedLineEdit or any MapEditor method,
651 // which wants to assure, that lineedits finish, before e.g. a branch is
654 // After calling LineEdit and using the clipboard, the
655 // focus is not any longer on the main widget, we
656 // have to restore it using parentWidget()->setFocus()
660 editingBO->setHeading(lineedit->text() );
662 lineedit->releaseKeyboard();
664 parentWidget()->setFocus();
665 mapCenter->reposition();
667 ensureSelectionVisible();
672 bool MapEditor::isDefault()
677 bool MapEditor::isUnsaved()
682 bool MapEditor::hasChanged()
687 void MapEditor::setChanged()
692 actionEditUndo->setEnabled (true);
693 actionFileSave->setEnabled (true);
697 void MapEditor::closeMap()
699 // Finish open lineEdits
700 if (lineedit) finishedLineEditNoSave();
702 // Unselect before disabling the toolbar actions
703 if (selection) selection->unselect();
711 void MapEditor::setFilePath(QString fname)
713 setFilePath (fname,fname);
716 void MapEditor::setFilePath(QString fname, QString destname)
725 filePath=fname; // becomes absolute path
726 fileName=fname; // gets stripped of path
727 destPath=destname; // needed for vymlinks
729 // If fname is not an absolute path, complete it
730 filePath=QDir(fname).absPath();
731 fileDir=filePath.left (1+filePath.findRev ("/"));
733 // Set short name, too. Search from behind:
734 int i=fileName.findRev("/");
735 if (i>=0) fileName=fileName.remove (0,i+1);
737 // Forget the .vym (or .xml) for name of map
738 mapName=fileName.left(fileName.findRev(".",-1,true) );
742 QString MapEditor::getFilePath()
747 QString MapEditor::getFileName()
752 QString MapEditor::getMapName()
757 QString MapEditor::getDestPath()
762 int MapEditor::load (QString fname, LoadMode lmode)
764 // Finish open lineEdits
765 if (lineedit) finishedLineEditNoSave();
771 if (selection) selection->unselect();
774 mapCenter->setMapEditor(this);
775 // (map state is set later at end of load...)
778 saveState(selection);
782 mapBuilderHandler handler;
785 // I am paranoid: file should exist anyway
786 // according to check in mainwindow.
789 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
790 tr("Couldn't open map " +fname)+".");
794 blockReposition=true;
795 QXmlInputSource source( file);
796 QXmlSimpleReader reader;
797 reader.setContentHandler( &handler );
798 reader.setErrorHandler( &handler );
799 handler.setMapEditor( this );
800 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
801 handler.setLoadMode (lmode);
803 bool ok = reader.parse( source );
804 blockReposition=false;
805 blockSaveState=false;
809 mapCenter->reposition();
819 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
820 tr( handler.errorProtocol() ) );
822 // Still return "success": the map maybe at least
823 // partially read by the parser
830 int MapEditor::save (const SaveMode &savemode)
832 // Finish open lineEdits
833 if (lineedit) finishedLineEditNoSave();
837 // The SaveMode UndoCommand is not supported here
838 if (savemode==UndoCommand) return 1;
840 // Create mapName and fileDir
841 makeSubDirs (fileDir);
845 fname=mapName+".xml";
847 // use name given by user, even if he chooses .doc
852 if (savemode==CompleteMap || selection==NULL)
853 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL);
855 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection);
857 if (!saveStringToDisk(fileDir+fname,saveFile))
864 actionFileSave->setEnabled(false);
870 void MapEditor::setZipped (bool z)
875 bool MapEditor::saveZipped ()
880 void MapEditor::print()
882 // Finish open lineEdits
883 if (lineedit) finishedLineEditNoSave();
887 printer = new QPrinter;
888 printer->setColorMode (QPrinter::Color);
889 printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName()));
892 QRect totalBBox=mapCenter->getTotalBBox();
894 // Try to set orientation automagically
895 // Note: Interpretation of generated postscript is amibiguous, if
896 // there are problems with landscape mode, see
897 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
899 if (totalBBox.width()>totalBBox.height())
900 // recommend landscape
901 printer->setOrientation (QPrinter::Landscape);
903 // recommend portrait
904 printer->setOrientation (QPrinter::Portrait);
906 if ( printer->setup(this) )
907 // returns false, if printing is canceled
909 QPainter pp(printer);
911 // Don't print the visualisation of selection
912 LinkableMapObj *oldselection=NULL;
915 oldselection=selection;
916 selection->unselect();
919 // Handle sizes of map and paper:
921 // setWindow defines which part of the canvas will be transformed
922 // setViewport defines area on paper in device coordinates (dpi)
923 // e.g. (0,50,700,700) is upper part on A4
924 // see also /usr/lib/qt3/doc/html/coordsys.html
926 QPaintDeviceMetrics metrics (printer);
928 double paperAspect = (double)metrics.width() / (double)metrics.height();
929 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
931 QRect mapRect=totalBBox;
932 QCanvasRectangle *frame=NULL;
933 QCanvasText *footerFN=NULL;
934 QCanvasText *footerDate=NULL;
935 if (printFrame || printFooter)
940 // Print frame around map
941 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
942 totalBBox.width()+20, totalBBox.height()+20);
943 frame=new QCanvasRectangle (mapRect,mapCanvas);
944 frame->setBrush (QColor(white));
945 frame->setPen (QColor(black));
949 /* TODO remove after testing
950 QCanvasLine *l=new QCanvasLine (mapCanvas);
951 l->setPoints (0,0,mapRect.width(),mapRect.height());
952 l->setPen (QPen(QColor(black), 1));
959 // Print footer below map
961 font.setPointSize(10);
962 footerFN=new QCanvasText (mapCanvas);
963 footerFN->setText ("VYM - " + fileName);
964 footerFN->setFont(font);
965 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
966 footerFN->setZ(Z_TEXT);
968 footerDate=new QCanvasText (mapCanvas);
969 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
970 footerDate->setFont(font);
971 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
972 footerDate->setZ(Z_TEXT);
975 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
978 pp.setWindow (mapRect);
981 if (mapAspect>=paperAspect)
983 // Fit horizontally to paper width
984 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
987 // Fit vertically to paper height
988 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
991 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
993 // Delete Frame and footer
999 if (frame) delete (frame);
1001 // Restore selection
1004 selection=oldselection;
1005 selection->select();
1008 // Save settings in vymrc
1009 settings.writeEntry("/vym/mainwindow/printerName",printer->printerName());
1013 QPixmap MapEditor::getPixmap()
1015 QRect mapRect=mapCenter->getTotalBBox();
1016 QPixmap pix (mapRect.size());
1019 // Don't print the visualisation of selection
1020 LinkableMapObj *oldselection=NULL;
1023 oldselection=selection;
1024 selection->unselect();
1027 pp.setWindow (mapRect);
1029 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
1032 // Restore selection
1035 selection=oldselection;
1036 selection->select();
1042 void MapEditor::exportImage(QString fn)
1044 // Finish open lineEdits
1045 if (lineedit) finishedLineEditNoSave();
1047 QPixmap pix (getPixmap());
1048 pix.save(fn, "PNG");
1051 void MapEditor::exportImage(QString fn, int item)
1053 // Finish open lineEdits
1054 if (lineedit) finishedLineEditNoSave();
1056 QPixmap pix (getPixmap());
1057 pix.save(fn, exportImageFormatMenu->text(item) );
1060 void MapEditor::exportASCII()
1062 // TODO still experimental
1064 ex.setMapCenter(mapCenter);
1066 QFileDialog *fd=new QFileDialog( this, tr("VYM - Export (ASCII)"));
1067 fd->addFilter ("TXT (*.txt)");
1068 fd->setCaption("VYM - Export (ASCII) (still experimental)");
1069 fd->setMode( QFileDialog::AnyFile );
1072 if ( fd->exec() == QDialog::Accepted )
1074 if (QFile (fd->selectedFile()).exists() )
1076 QMessageBox mb( "VYM",
1077 tr("The file %1 exists already.\nDo you want to overwrite it?").arg(fd->selectedFile()),
1078 QMessageBox::Warning,
1079 QMessageBox::Yes | QMessageBox::Default,
1080 QMessageBox::Cancel | QMessageBox::Escape,
1081 QMessageBox::NoButton );
1083 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
1084 mb.setButtonText( QMessageBox::No, tr("Cancel"));
1088 case QMessageBox::Yes:
1091 case QMessageBox::Cancel:
1092 // return, do nothing
1097 ex.setPath (fd->selectedFile() );
1102 void MapEditor::exportLaTeX()
1104 // TODO still experimental
1105 QFileDialog *fd=new QFileDialog( this, tr("VYM - Export (LaTex)"));
1106 fd->addFilter ("TEX (*.tex)");
1107 fd->setCaption("VYM - Export (LaTex) (still experimental)");
1108 fd->setMode( QFileDialog::AnyFile );
1111 if ( fd->exec() == QDialog::Accepted )
1113 if (QFile (fd->selectedFile()).exists() )
1115 QMessageBox mb( "VYM",
1116 tr("The file ") + fd->selectedFile() +
1117 tr(" exists already. Do you want to overwrite it?"),
1118 QMessageBox::Warning,
1119 QMessageBox::Yes | QMessageBox::Default,
1120 QMessageBox::Cancel | QMessageBox::Escape,
1121 QMessageBox::NoButton );
1123 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
1124 mb.setButtonText( QMessageBox::No, tr("Cancel"));
1128 case QMessageBox::Yes:
1131 case QMessageBox::Cancel:
1138 ex.setPath (fd->selectedFile() );
1139 ex.setMapCenter(mapCenter);
1144 void MapEditor::exportOOPresentation()
1146 // TODO still experimental
1148 QFileDialog *fd=new QFileDialog( this, tr("VYM - Export (Open Office 1.3.x Presentation)"));
1149 fd->addFilter ("Open Office 1.3.x presentation (*.sxi)");
1150 fd->setCaption("VYM - Export (Open Office 1.3.x presentation) (still experimental)");
1151 fd->setMode( QFileDialog::AnyFile );
1154 if ( fd->exec() == QDialog::Accepted )
1156 if (QFile (fd->selectedFile()).exists() )
1158 QMessageBox mb( "VYM",
1159 tr("The file ") + fd->selectedFile() +
1160 tr(" exists already. Do you want to overwrite it?"),
1161 QMessageBox::Warning,
1162 QMessageBox::Yes | QMessageBox::Default,
1163 QMessageBox::Cancel | QMessageBox::Escape,
1164 QMessageBox::NoButton );
1166 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
1167 mb.setButtonText( QMessageBox::No, tr("Cancel"));
1171 case QMessageBox::Yes:
1174 case QMessageBox::Cancel:
1182 //ex.setPath (fd->selectedFile() );
1183 ex.setMapCenter(mapCenter);
1184 ex.exportOOPresentation();
1190 void MapEditor::exportXML(const QString &dir)
1192 // Create subdirectories
1195 // write to directory
1196 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1199 file.setName ( dir + "/"+mapName+".xml");
1200 if ( !file.open( IO_WriteOnly ) )
1202 // This should neverever happen
1203 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1207 // Write it finally, and write in UTF8, no matter what
1208 QTextStream ts( &file );
1209 ts.setEncoding (QTextStream::UnicodeUTF8);
1213 // Now write image, too
1214 exportImage (dir+"/images/"+mapName+".png");
1217 void MapEditor::clear()
1221 selection->unselect();
1228 void MapEditor::copy()
1230 // Finish open lineEdits
1231 if (lineedit) finishedLineEditNoSave();
1235 // write to directory
1236 QString clipfile="part";
1237 QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPoint(),selection);
1240 file.setName ( clipboardDir + "/"+clipfile+".xml");
1241 if ( !file.open( IO_WriteOnly ) )
1243 // This should neverever happen
1244 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1248 // Write it finally, and write in UTF8, no matter what
1249 QTextStream ts( &file );
1250 ts.setEncoding (QTextStream::UnicodeUTF8);
1254 clipboardEmpty=false;
1259 void MapEditor::redo()
1261 // Finish open lineEdits
1262 if (lineedit) finishedLineEditNoSave();
1264 blockSaveState=true;
1266 // Find out current undo directory
1267 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
1269 // Restore variables
1270 QString undoCommand;
1271 QString undoSelection;
1272 QString redoCommand;
1273 QString redoSelection;
1275 set.readSettings(QString(bakMapDir+"/commands"));
1276 undoCommand=set.readEntry ("undoCommand");
1277 undoSelection=set.readEntry ("undoSelection");
1278 redoCommand=set.readEntry ("redoCommand");
1279 redoSelection=set.readEntry ("redoSelection");
1281 // select object before redo
1282 if (!redoSelection.isEmpty())
1283 select (redoSelection);
1285 /* TODO remove testing
1286 cout << "ME::redo() begin\n";
1287 cout << " undosTotal="<<undosTotal<<endl;
1288 cout << " undosAvail="<<undosAvail<<endl;
1289 cout << " undoNum="<<undoNum<<endl;
1290 cout << " ---------------------------"<<endl;
1291 cout << " undoCom="<<undoCommand<<endl;
1292 cout << " undoSel="<<undoSelection<<endl;
1293 cout << " ---------------------------"<<endl;
1294 cout << " redoCom="<<redoCommand<<endl;
1295 cout << " redoSel="<<redoSelection<<endl;
1296 cout << " ---------------------------"<<endl;
1298 parseAtom (undoCommand);
1299 mapCenter->reposition();
1301 //if (!redoSelection.isEmpty())
1302 // select (redoSelection);
1306 // Undo not longer available now
1307 actionEditUndo->setEnabled (false);
1309 undoNum--; if (undoNum<1) undoNum=undosTotal;
1311 blockSaveState=false;
1312 /* TODO remove testing
1313 cout << "ME::redo() end\n";
1314 cout << " undosAvail="<<undosAvail<<endl;
1315 cout << " undoNum="<<undoNum<<endl;
1316 cout << " ---------------------------"<<endl<<endl;
1320 void MapEditor::undo()
1322 // Finish open lineEdits
1323 if (lineedit) finishedLineEditNoSave();
1325 blockSaveState=true;
1327 // Find out current undo directory
1328 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
1330 // Restore variables
1331 QString undoCommand;
1332 QString undoSelection;
1333 QString redoCommand;
1334 QString redoSelection;
1336 set.readSettings(QString(bakMapDir+"/commands"));
1337 undoCommand= set.readEntry ("undoCommand");
1338 undoSelection=set.readEntry ("undoSelection");
1339 redoCommand= set.readEntry ("redoCommand");
1340 redoSelection=set.readEntry ("redoSelection");
1342 // select object before undo
1343 if (!undoSelection.isEmpty())
1344 select (undoSelection);
1347 cout << "ME::undo() begin\n";
1348 cout << " undosTotal="<<undosTotal<<endl;
1349 cout << " undosAvail="<<undosAvail<<endl;
1350 cout << " undoNum="<<undoNum<<endl;
1351 cout << " ---------------------------"<<endl;
1352 cout << " undoCom="<<undoCommand<<endl;
1353 cout << " undoSel="<<undoSelection<<endl;
1354 cout << " ---------------------------"<<endl;
1355 cout << " redoCom="<<redoCommand<<endl;
1356 cout << " redoSel="<<redoSelection<<endl;
1357 cout << " ---------------------------"<<endl;
1359 parseAtom (undoCommand);
1360 mapCenter->reposition();
1362 //if (!redoSelection.isEmpty())
1363 // select (redoSelection);
1367 // Undo not longer available now
1368 actionEditUndo->setEnabled (false);
1370 undoNum--; if (undoNum<1) undoNum=undosTotal;
1372 blockSaveState=false;
1373 /* TODO remove testing
1374 cout << "ME::undo() end\n";
1375 cout << " undosAvail="<<undosAvail<<endl;
1376 cout << " undoNum="<<undoNum<<endl;
1377 cout << " ---------------------------"<<endl<<endl;
1381 void MapEditor::undoXML(const QString &undoSel, const QString &bakMapPath)
1383 QString bakMapDir=bakMapPath.left(bakMapPath.findRev("/"));
1385 QFile file (bakMapPath);
1389 // We need to parse saved XML data
1390 mapBuilderHandler handler;
1391 QXmlInputSource source( file);
1392 QXmlSimpleReader reader;
1393 reader.setContentHandler( &handler );
1394 reader.setErrorHandler( &handler );
1395 handler.setMapEditor( this );
1396 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1397 if (undoSel.isEmpty())
1401 handler.setLoadMode (NewMap);
1405 handler.setLoadMode (ImportReplace);
1407 blockReposition=true;
1408 bool ok = reader.parse( source );
1409 blockReposition=false;
1412 // This should never ever happen
1413 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1414 tr( handler.errorProtocol() )+" in "+bakMapDir );
1418 QMessageBox::critical( 0, tr( "Critical Error" ),
1419 tr("Temporary directory %1 used for undo is gone. \n"
1420 "I will create a new one, but at the moment no undo is available.\n"
1421 "Maybe you want to reload your original data.\n\n"
1422 "Sorry for any inconveniences.").arg(bakMapDir) );
1427 void MapEditor::pasteNoSave()
1429 // Finish open lineEdits
1430 if (lineedit) finishedLineEditNoSave();
1432 load (clipboardDir+"/part.xml",ImportAdd);
1435 void MapEditor::cutNoSave()
1441 void MapEditor::paste()
1443 if (selection && (typeid(*selection) == typeid(BranchObj) ||
1444 typeid(*selection) == typeid(MapCenterObj)))
1446 saveState(selection);
1448 mapCenter->reposition();
1453 void MapEditor::cut()
1455 saveState(selection->getParObj());
1458 mapCenter->reposition();
1462 void MapEditor::move(const int &x, const int &y)
1464 // TODO no saveState, because this is only internal at undo so far
1465 if (selection) selection->move(x,y);
1466 if (typeid(*selection) == typeid(FloatImageObj))
1467 ((FloatImageObj*)selection)->setRelPos();
1470 void MapEditor::moveBranchUp()
1472 // Finish open lineEdits
1473 if (lineedit) finishedLineEditNoSave();
1477 if (typeid(*selection) == typeid(BranchObj) )
1479 bo=(BranchObj*)selection;
1480 par=(BranchObj*)(bo->getParObj());
1481 selection->unselect();
1482 selection=par->moveBranchUp (bo);
1483 selection->select();
1484 saveState("moveBranchDown ()",bo);
1485 mapCenter->reposition();
1486 ensureSelectionVisible();
1490 void MapEditor::moveBranchDown()
1492 // Finish open lineEdits
1493 if (lineedit) finishedLineEditNoSave();
1497 if (typeid(*selection) == typeid(BranchObj) )
1499 bo=(BranchObj*)selection;
1500 par=(BranchObj*)(bo->getParObj());
1501 selection->unselect();
1502 selection=par->moveBranchDown(bo);
1503 selection->select();
1504 saveState("moveBranchUp ()",bo);
1505 mapCenter->reposition();
1506 ensureSelectionVisible();
1510 void MapEditor::editHeading()
1512 // Finish open lineEdits
1513 if (lineedit) finishedLineEditNoSave();
1516 (typeid(*selection) == typeid(BranchObj) ||
1517 typeid(*selection) == typeid(MapCenterObj) ) )
1519 editingBO=(BranchObj*)selection;
1520 saveState("setHeading (\""+((BranchObj*)selection)->getHeading()+"\")",editingBO );
1522 ensureSelectionVisible();
1523 QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
1524 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1525 QString s=editingBO->getHeading();
1526 lineedit->setText(s);
1527 lineedit->setCursorPosition(1);
1528 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1529 lineedit->selectAll();
1531 lineedit->grabKeyboard();
1532 lineedit->setFocus();
1536 void MapEditor::setHeading(const QString &s)
1538 // Internal function, no saveState needed
1540 (typeid(*selection) == typeid(BranchObj) ||
1541 typeid(*selection) == typeid(MapCenterObj) ) )
1543 ((BranchObj*)selection)->setHeading(s);
1544 mapCenter->reposition();
1546 ensureSelectionVisible();
1550 void MapEditor::setURL (const QString &s)
1552 // Internal function, no saveState needed
1554 (typeid(*selection) == typeid(BranchObj) ||
1555 typeid(*selection) == typeid(MapCenterObj) ) )
1557 ((BranchObj*)selection)->setURL(s);
1558 mapCenter->reposition();
1560 ensureSelectionVisible();
1564 void MapEditor::setVymLink (const QString &s)
1566 // Internal function, no saveState needed
1568 (typeid(*selection) == typeid(BranchObj) ||
1569 typeid(*selection) == typeid(MapCenterObj) ) )
1571 ((BranchObj*)selection)->setVymLink(s);
1572 mapCenter->reposition();
1574 ensureSelectionVisible();
1578 void MapEditor::addNewBranch(int pos)
1580 // Finish open lineEdits
1581 if (lineedit) finishedLineEditNoSave();
1584 (typeid(*selection) == typeid(BranchObj) ||
1585 typeid(*selection) == typeid(MapCenterObj) ) )
1587 saveState(selection); //TODO undoCommand
1589 BranchObj* bo1 = (BranchObj*) selection;
1590 bool wasScrolled=false;
1591 BranchObj *newbo=NULL;
1594 // save scroll state. If scrolled, automatically select
1595 // new branch in order to tmp unscroll parent...
1596 wasScrolled=bo1->isScrolled();
1597 newbo=bo1->addBranch();
1600 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1604 // add above selection
1605 newbo=parbo->insertBranch(bo1->getNum());
1607 // add below selection
1608 newbo=parbo->insertBranch(bo1->getNum()+1);
1610 // This should not happen...
1615 LinkableMapObj *oldselection=selection;
1617 mapCenter->reposition();
1619 if (actionSettingsAutoedit->isOn() ||
1620 actionSettingsAutoselectHeading->isOn() )
1622 selection->unselect();
1624 selection->select();
1625 if (actionSettingsPasteNewHeading->isOn() )
1627 BranchObj *bo2= (BranchObj*)selection;
1628 bo2->setHeading("");
1630 if (actionSettingsAutoedit->isOn() )
1632 if (!actionSettingsAutoselectHeading->isOn()
1635 selection->unselect();
1636 selection=oldselection;
1637 selection->select();
1644 void MapEditor::addNewBranchHere()
1646 // Finish open lineEdits
1647 if (lineedit) finishedLineEditNoSave();
1650 (typeid(*selection) == typeid(BranchObj) ) )
1652 saveState(selection);
1654 BranchObj* bo1 = (BranchObj*) selection;
1655 bool wasScrolled=false;
1656 BranchObj *newbo=NULL;
1657 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1660 // add below selection
1661 newbo=parbo->insertBranch(bo1->getNum()+1);
1664 LinkableMapObj *oldselection=selection;
1665 ((BranchObj*)selection)->moveBranchTo (newbo,-1);
1667 mapCenter->reposition();
1669 if (actionSettingsAutoedit->isOn() ||
1670 actionSettingsAutoselectHeading->isOn() )
1672 selection->unselect();
1674 selection->select();
1675 if (actionSettingsPasteNewHeading->isOn() )
1677 BranchObj *bo2= (BranchObj*)selection;
1678 bo2->setHeading("");
1680 if (actionSettingsAutoedit->isOn() )
1682 if (!actionSettingsAutoselectHeading->isOn()
1685 selection->unselect();
1686 selection=oldselection;
1687 selection->select();
1693 void MapEditor::deleteSelection()
1695 // Finish open lineEdits
1696 if (lineedit) finishedLineEditNoSave();
1698 if (selection && typeid(*selection) ==typeid(BranchObj) )
1700 if (selection->getDepth()>1)
1701 // Normal branch, save parent with childs
1702 saveState(selection->getParObj());
1704 // Mainbranch, save whole map
1705 // TODO Better would be to insert mainbranch again at pos
1706 // But undoCommand is missing right now
1708 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1709 BranchObj* par=(BranchObj*)(bo->getParObj());
1712 par->removeBranch(bo);
1714 selection->select();
1715 ensureSelectionVisible();
1716 mapCenter->reposition();
1719 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1721 saveState(selection->getParObj());
1722 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1723 BranchObj* par=(BranchObj*)(fio->getParObj());
1726 par->removeFloatImage(fio);
1728 selection->select();
1729 ensureSelectionVisible();
1730 mapCenter->reposition();
1735 LinkableMapObj* MapEditor::getSelection()
1740 bool MapEditor::select (const QString &s)
1742 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
1744 // Finally select the found object
1747 if (selection) unselect();
1749 selection->select();
1751 ensureSelectionVisible();
1757 void MapEditor::unselect()
1761 selectionLast=selection;
1762 selection->unselect();
1767 void MapEditor::reselect()
1771 selection=selectionLast;
1772 selection->select();
1777 void MapEditor::selectNextBranch()
1779 // Increase number of branch
1782 QString s=selection->getSelectString();
1788 part=s.section(",",-1);
1790 num=part.right(part.length() - 3);
1792 s=s.left (s.length() -num.length());
1795 num=QString ("%1").arg(num.toUInt()+1);
1799 // Try to select this one
1800 if (select (s)) return;
1802 // We have no direct successor,
1803 // try to increase the parental number in order to
1804 // find a successor with same depth
1806 int d=selection->getDepth();
1811 while (!found && d>0)
1813 s=s.section (",",0,d-1);
1814 // replace substring of current depth in s with "1"
1815 part=s.section(",",-1);
1817 num=part.right(part.length() - 3);
1821 // increase number of parent
1822 num=QString ("%1").arg(num.toUInt()+1);
1823 s=s.section (",",0,d-2) + ","+ typ+num;
1826 // Special case, look at orientation
1827 if (selection->getOrientation()==OrientRightOfCenter)
1828 num=QString ("%1").arg(num.toUInt()+1);
1830 num=QString ("%1").arg(num.toUInt()-1);
1835 // pad to oldDepth, select the first branch for each depth
1836 for (i=d;i<oldDepth;i++)
1841 if ( ((BranchObj*)selection)->countBranches()>0)
1849 // try to select the freshly built string
1857 void MapEditor::selectPrevBranch()
1859 // Decrease number of branch
1862 QString s=selection->getSelectString();
1868 part=s.section(",",-1);
1870 num=part.right(part.length() - 3);
1872 s=s.left (s.length() -num.length());
1875 num=QString ("%1").arg(num.toUInt()-1);
1879 // Try to select this one
1880 if (select (s)) return;
1882 // We have no direct precessor,
1883 // try to decrease the parental number in order to
1884 // find a precessor with same depth
1886 int d=selection->getDepth();
1891 while (!found && d>0)
1893 s=s.section (",",0,d-1);
1894 // replace substring of current depth in s with "1"
1895 part=s.section(",",-1);
1897 num=part.right(part.length() - 3);
1901 // decrease number of parent
1902 num=QString ("%1").arg(num.toUInt()-1);
1903 s=s.section (",",0,d-2) + ","+ typ+num;
1906 // Special case, look at orientation
1907 if (selection->getOrientation()==OrientRightOfCenter)
1908 num=QString ("%1").arg(num.toUInt()-1);
1910 num=QString ("%1").arg(num.toUInt()+1);
1915 // pad to oldDepth, select the last branch for each depth
1916 for (i=d;i<oldDepth;i++)
1920 if ( ((BranchObj*)selection)->countBranches()>0)
1921 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)selection)->countBranches()-1 );
1928 // try to select the freshly built string
1936 void MapEditor::selectUpperBranch()
1938 // Finish open lineEdits
1939 if (lineedit) finishedLineEditNoSave();
1943 if (typeid(*selection) == typeid(BranchObj))
1945 if (selection->getOrientation()==OrientRightOfCenter)
1948 if (selection->getDepth()==1)
1956 void MapEditor::selectLowerBranch()
1958 // Finish open lineEdits
1959 if (lineedit) finishedLineEditNoSave();
1963 if (typeid(*selection) == typeid(BranchObj))
1965 if (selection->getOrientation()==OrientRightOfCenter)
1968 if (selection->getDepth()==1)
1977 void MapEditor::selectLeftBranch()
1979 // Finish open lineEdits
1980 if (lineedit) finishedLineEditNoSave();
1986 if (typeid(*selection) == typeid(MapCenterObj))
1988 par= (BranchObj*) selection;
1989 bo=par->getLastSelectedBranch();
1992 // Workaround for reselecting on left and right side
1993 if (bo->getOrientation()==OrientRightOfCenter)
1995 bo=par->getLastBranch();
2001 selection->select();
2003 ensureSelectionVisible();
2008 par=(BranchObj*)(selection->getParObj());
2009 if (selection->getOrientation()==OrientRightOfCenter)
2011 if (typeid(*selection) == typeid(BranchObj) ||
2012 typeid(*selection) == typeid(FloatImageObj))
2014 selection->unselect();
2016 selection->select();
2018 ensureSelectionVisible();
2022 if (typeid(*selection) == typeid(BranchObj) )
2024 bo=((BranchObj*)selection)->getLastSelectedBranch();
2027 selection->unselect();
2029 selection->select();
2031 ensureSelectionVisible();
2039 void MapEditor::selectRightBranch()
2041 // Finish open lineEdits
2042 if (lineedit) finishedLineEditNoSave();
2049 if (typeid(*selection) == typeid(MapCenterObj))
2051 par= (BranchObj*) selection;
2052 bo=par->getLastSelectedBranch();
2055 // Workaround for relecting on left and right side
2056 if (bo->getOrientation()==OrientLeftOfCenter)
2057 bo=par->getFirstBranch();
2062 selection->select();
2063 ensureSelectionVisible();
2068 par=(BranchObj*)(selection->getParObj());
2069 if (selection->getOrientation()==OrientLeftOfCenter)
2071 if (typeid(*selection) == typeid(BranchObj) ||
2072 typeid(*selection) == typeid(FloatImageObj))
2074 selection->unselect();
2076 selection->select();
2078 ensureSelectionVisible();
2082 if (typeid(*selection) == typeid(BranchObj) )
2084 bo=((BranchObj*)selection)->getLastSelectedBranch();
2087 selection->unselect();
2089 selection->select();
2091 ensureSelectionVisible();
2099 void MapEditor::selectFirstBranch()
2101 // Finish open lineEdits
2102 if (lineedit) finishedLineEditNoSave();
2108 if (typeid(*selection) == typeid(BranchObj))
2110 bo1= (BranchObj*) selection;
2111 par=(BranchObj*)(bo1->getParObj());
2112 bo2=par->getFirstBranch();
2116 selection->select();
2117 ensureSelectionVisible();
2124 void MapEditor::selectLastBranch()
2126 // Finish open lineEdits
2127 if (lineedit) finishedLineEditNoSave();
2133 if (typeid(*selection) == typeid(BranchObj))
2135 bo1= (BranchObj*) selection;
2136 par=(BranchObj*)(bo1->getParObj());
2137 bo2=par->getLastBranch();
2141 selection->select();
2142 ensureSelectionVisible();
2149 void MapEditor::setColor(QColor c)
2154 void MapEditor::selectBackgroundColor()
2156 // Finish open lineEdits
2157 if (lineedit) finishedLineEditNoSave();
2159 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
2160 if ( !col.isValid() ) return;
2161 setBackgroundColor( col );
2165 void MapEditor::setBackgroundColor(QColor c)
2167 mapCanvas->setBackgroundColor (c);
2170 QColor MapEditor::pickColor()
2174 if (typeid(*selection) == typeid(BranchObj) ||
2175 typeid(*selection) == typeid(MapCenterObj))
2177 BranchObj *bo=(BranchObj*)selection;
2178 actColor=bo->getColor();
2184 void MapEditor::colorItem()
2188 if (typeid(*selection) == typeid(BranchObj) ||
2189 typeid(*selection) == typeid(MapCenterObj))
2191 saveState(selection); //TODO undoCommand
2192 BranchObj *bo=(BranchObj*)selection;
2193 bo->setColor(actColor, false); // color links, color childs
2198 void MapEditor::colorBranch()
2202 if (typeid(*selection) == typeid(BranchObj) ||
2203 typeid(*selection) == typeid(MapCenterObj))
2205 saveState(selection);
2206 BranchObj *bo=(BranchObj*)selection;
2207 bo->setColor(actColor, true); // color links, color childs
2213 void MapEditor::toggleStandardFlag(QString f)
2217 saveState(selection);// TODO undoCommand
2218 ((BranchObj*)selection)->toggleStandardFlag (f,actionSettingsUseFlagGroups);
2222 void MapEditor::setViewCenter()
2224 // transform to CanvasView Coord:
2225 QPoint p=worldMatrix().map(movingCenter);
2226 center ( p.x(), p.y());
2230 BranchObj* MapEditor::findText (QString s, bool cs)
2233 { // Nothing found or new find process
2235 // nothing found, start again
2237 itFind=mapCenter->first();
2239 bool searching=true;
2240 bool foundNote=false;
2241 while (searching && !EOFind)
2245 // Searching in Note
2246 if (itFind->getNote().contains(s,cs))
2248 if (selection!=itFind)
2250 if (selection) ((BranchObj*)selection)->unselect();
2252 selection->select();
2254 ensureSelectionVisible();
2256 if (textEditor->findText(s,cs))
2262 // Searching in Heading
2263 if (searching && itFind->getHeading().contains (s,cs) )
2265 if (selection) ((BranchObj*)selection)->unselect();
2267 selection->select();
2269 ensureSelectionVisible();
2275 itFind=itFind->next();
2276 if (!itFind) EOFind=true;
2282 return (BranchObj*)selection;
2287 void MapEditor::findReset()
2288 { // Necessary if text to find changes during a find process
2293 void MapEditor::openURL()
2297 if (typeid(*selection) == typeid(BranchObj) ||
2298 typeid(*selection) == typeid(MapCenterObj))
2300 QString url=((BranchObj*)selection)->getURL();
2302 QProcess *proc = new QProcess( this );
2304 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL" ));
2305 proc->addArgument( url);
2307 if ( !proc->start() )
2309 if (mainWindow->settingsURL() )
2315 void MapEditor::editURL()
2317 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2318 typeid(*selection) == typeid(MapCenterObj)) )
2321 BranchObj *bo=(BranchObj*)selection;
2322 QString text = QInputDialog::getText(
2323 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2324 bo->getURL(), &ok, this );
2327 // user entered something and pressed OK
2328 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+text+"\")");
2335 void MapEditor::editHeading2URL()
2337 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2338 typeid(*selection) == typeid(MapCenterObj)) )
2340 BranchObj *bo=(BranchObj*)selection;
2341 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+bo->getHeading()+"\")");
2342 bo->setURL (bo->getHeading());
2347 void MapEditor::editBugzilla2URL()
2349 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2350 typeid(*selection) == typeid(MapCenterObj)) )
2352 BranchObj *bo=(BranchObj*)selection;
2353 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2354 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")");
2360 void MapEditor::editVymLink()
2362 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2363 typeid(*selection) == typeid(MapCenterObj)) )
2365 BranchObj *bo=(BranchObj*)selection;
2366 QFileDialog *fd=new QFileDialog( this,tr("VYM - Link to another map"));
2367 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2368 fd->setCaption(tr("VYM - Link to another map"));
2369 if (! bo->getVymLink().isEmpty() )
2370 fd->setSelection( bo->getVymLink() );
2374 if ( fd->exec() == QDialog::Accepted )
2376 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\""+fd->selectedFile()+"\")");
2377 bo->setVymLink (fd->selectedFile() );
2379 mapCenter->reposition();
2386 void MapEditor::deleteVymLink()
2388 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2389 typeid(*selection) == typeid(MapCenterObj)) )
2391 BranchObj *bo=(BranchObj*)selection;
2392 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\"\")");
2393 bo->setVymLink ("" );
2395 mapCenter->reposition();
2401 QString MapEditor::getVymLink()
2403 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2404 typeid(*selection) == typeid(MapCenterObj)) )
2406 return ((BranchObj*)selection)->getVymLink();
2412 void MapEditor::removeBranchHere()
2414 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2416 BranchObj* bo=(BranchObj*)selection;
2417 BranchObj* par=(BranchObj*)(bo->getParObj());
2418 if (bo->getDepth()==1)
2421 saveState(selection->getParObj()); // TODO undoCommand
2422 QString sel=selection->getSelectString();
2424 par->removeBranchHere(bo);
2425 mapCenter->reposition();
2430 void MapEditor::removeChilds()
2432 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2434 saveState(selection->getParObj());
2435 ((BranchObj*)selection)->removeChilds();
2436 mapCenter->reposition();
2440 void MapEditor::editMapInfo()
2442 ExtraInfoDialog dia;
2443 dia.setMapName (getFileName() );
2444 dia.setAuthor (mapCenter->getAuthor() );
2445 dia.setComment(mapCenter->getComment() );
2450 QCanvasItemList l=canvas()->allItems();
2451 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2453 stats+=QString ("%1 items on canvas\n").arg (i,6);
2460 bo=mapCenter->first();
2463 if (!bo->getNote().isEmpty() ) n++;
2464 f+= bo->countFloatImages();
2466 xl+=bo->countXLinks();
2469 stats+=QString ("%1 branches\n").arg (b-1,6);
2470 stats+=QString ("%1 xLinks \n").arg (xl,6);
2471 stats+=QString ("%1 notes\n").arg (n,6);
2472 stats+=QString ("%1 images\n").arg (f,6);
2473 dia.setStats (stats);
2475 // Finally show dialog
2476 if (dia.exec() == QDialog::Accepted)
2478 saveState(); //TODO undoCommand
2479 mapCenter->setAuthor (dia.getAuthor() );
2480 mapCenter->setComment (dia.getComment() );
2484 void MapEditor::updateActions()
2487 if (getLinkColorHint()==HeadingColor)
2488 actionFormatLinkColorHint->setOn(true);
2490 actionFormatLinkColorHint->setOn(false);
2495 actionFormatLinkStyleLine->setOn(true);
2498 actionFormatLinkStyleParabel->setOn(true);
2501 actionFormatLinkStylePolyLine->setOn(true);
2503 case StylePolyParabel:
2504 actionFormatLinkStylePolyParabel->setOn(true);
2510 QPixmap pix( 16, 16 );
2511 pix.fill( mapCanvas->backgroundColor() );
2512 actionFormatBackColor->setIconSet( pix );
2513 pix.fill( defLinkColor );
2514 actionFormatLinkColor->setIconSet( pix );
2516 actionEditUndo->setEnabled( mapChanged );
2517 actionFileSave->setEnabled( mapUnsaved );
2521 if ( (typeid(*selection) == typeid(BranchObj)) ||
2522 (typeid(*selection) == typeid(MapCenterObj)) )
2524 BranchObj *bo=(BranchObj*)selection;
2525 // Take care of links
2526 if (bo->countXLinks()==0)
2528 branchLinksContextMenu->clear();
2529 branchLinksContextMenu->insertItem ("No xLink available");
2530 branchLinksContextMenuDup->clear();
2531 branchLinksContextMenuDup->insertItem ("No xLink available");
2537 branchLinksContextMenu->clear();
2538 branchLinksContextMenuDup->clear();
2539 for (int i=0; i<=bo->countXLinks();i++)
2541 bot=bo->XLinkTargetAt(i);
2544 s=bot->getHeading();
2547 branchLinksContextMenu->insertItem (s);
2548 branchLinksContextMenuDup->insertItem (s);
2553 standardFlagsDefault->setEnabled (true);
2555 if ( bo->getURL().isEmpty() )
2556 actionEditOpenURL->setEnabled (false);
2558 actionEditOpenURL->setEnabled (true);
2560 if ( bo->getVymLink().isEmpty() )
2562 actionEditOpenVymLink->setEnabled (false);
2563 actionEditDeleteVymLink->setEnabled (false);
2566 actionEditOpenVymLink->setEnabled (true);
2567 actionEditDeleteVymLink->setEnabled (true);
2570 actionEditCopy->setEnabled (true);
2571 actionEditCut->setEnabled (true);
2572 if (!clipboardEmpty)
2573 actionEditPaste->setEnabled (true);
2575 actionEditPaste->setEnabled (false);
2576 for (a=actionListBranches.first();a;a=actionListBranches.next())
2577 a->setEnabled(true);
2578 actionEditDelete->setEnabled (true);
2579 actionEditToggleFloatExport->setEnabled (false);
2580 switch (selection->getFrameType())
2583 actionFormatFrameNone->setOn(true);
2586 actionFormatFrameRectangle->setOn(true);
2591 actionFormatHideLinkUnselected->setOn
2592 ( selection->getHideLinkUnselected());
2594 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2596 standardFlagsDefault->setEnabled (false);
2598 actionEditOpenURL->setEnabled (false);
2599 actionEditOpenVymLink->setEnabled (false);
2600 actionEditDeleteVymLink->setEnabled (false);
2602 actionEditCopy->setEnabled (true);
2603 actionEditCut->setEnabled (true);
2604 actionEditPaste->setEnabled (false); //FIXME
2605 for (a=actionListBranches.first();a;a=actionListBranches.next())
2606 a->setEnabled(false);
2607 actionEditDelete->setEnabled (true);
2608 actionEditToggleFloatExport->setOn
2609 ( ((FloatImageObj*)selection)->getFloatExport() );
2610 actionFormatHideLinkUnselected->setOn
2611 ( selection->getHideLinkUnselected());
2616 standardFlagsDefault->setEnabled (false);
2618 actionEditCopy->setEnabled (false);
2619 actionEditCut->setEnabled (false);
2620 actionEditPaste->setEnabled (false);
2621 for (a=actionListBranches.first();a;a=actionListBranches.next())
2622 a->setEnabled(false);
2624 actionEditOpenURL->setEnabled (false);
2625 actionEditOpenVymLink->setEnabled (false);
2626 actionEditDeleteVymLink->setEnabled (false);
2627 actionEditHeading2URL->setEnabled (false);
2628 actionEditDelete->setEnabled (false);
2629 actionEditToggleFloatExport->setEnabled (false);
2633 void MapEditor::updateNoteFlag()
2636 if ( (typeid(*selection) == typeid(BranchObj)) ||
2637 (typeid(*selection) == typeid(MapCenterObj)) )
2638 ((BranchObj*)selection)->updateNoteFlag();
2641 void MapEditor::setLinkStyle (LinkStyle ls)
2645 saveState(); // TODO undoCommand
2647 bo=mapCenter->first();
2651 bo->setLinkStyle(bo->getDefLinkStyle());
2654 mapCenter->reposition();
2657 LinkStyle MapEditor::getLinkStyle ()
2662 void MapEditor::setLinkColor(QColor c)
2668 void MapEditor::setLinkColorHint()
2670 // called from setLinkColorHint(lch) or at end of parse
2672 bo=mapCenter->first();
2680 void MapEditor::setLinkColorHint(LinkColorHint lch)
2686 void MapEditor::toggleLinkColorHint()
2688 if (linkcolorhint==HeadingColor)
2689 linkcolorhint=DefaultColor;
2691 linkcolorhint=HeadingColor;
2693 bo=mapCenter->first();
2701 LinkColorHint MapEditor::getLinkColorHint()
2703 return linkcolorhint;
2706 QColor MapEditor::getDefLinkColor()
2708 return defLinkColor;
2711 void MapEditor::setDefXLinkColor(QColor col)
2716 QColor MapEditor::getDefXLinkColor()
2718 return defXLinkColor;
2721 void MapEditor::setDefXLinkWidth (int w)
2726 int MapEditor::getDefXLinkWidth()
2728 return defXLinkWidth;
2731 void MapEditor::selectLinkColor()
2733 // Finish open lineEdits
2734 if (lineedit) finishedLineEditNoSave();
2736 QColor col = QColorDialog::getColor( defLinkColor, this );
2737 if ( !col.isValid() ) return;
2738 setLinkColor( col );
2739 saveState(); //TODO undoCommand
2743 void MapEditor::toggleScroll()
2745 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2747 BranchObj *bo=((BranchObj*)selection);
2748 if (bo->countBranches()==0) return;
2749 if (bo->getDepth()==0) return;
2750 saveState(selection);
2757 void MapEditor::unScrollAll()
2760 bo=mapCenter->first();
2763 if (bo->isScrolled()) bo->toggleScroll();
2768 void MapEditor::loadFloatImage ()
2771 (typeid(*selection) == typeid(BranchObj)) ||
2772 (typeid(*selection) == typeid(MapCenterObj)) )
2774 BranchObj *bo=((BranchObj*)selection);
2776 QFileDialog *fd=new QFileDialog( this,tr("vym - load image"));
2777 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2778 ImagePreview *p =new ImagePreview (fd);
2779 fd->setContentsPreviewEnabled( TRUE );
2780 fd->setContentsPreview( p, p );
2781 fd->setPreviewMode( QFileDialog::Contents );
2782 fd->setCaption(tr("vym - Load image"));
2783 fd->setDir (lastImageDir);
2787 if ( fd->exec() == QDialog::Accepted )
2789 saveState(selection);
2790 QString fn=fd->selectedFile();
2791 lastImageDir=fn.left(fn.findRev ("/"));
2792 bo->addFloatImage();
2793 // TODO check if load was successful
2794 bo->getLastFloatImage()->load(fn);
2795 bo->getLastFloatImage()->setOriginalFilename(fn);
2796 mapCenter->reposition();
2803 void MapEditor::saveFloatImage (int item)
2806 (typeid(*selection) == typeid(FloatImageObj)) )
2808 FloatImageObj *fio=((FloatImageObj*)selection);
2809 const char* fmt = saveImageFormatMenu->text(item);
2811 QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
2812 fd->addFilter ("PNG (*.png)");
2813 fd->addFilter ("BMP (*.bmp)");
2814 fd->addFilter ("XBM (*.xbm)");
2815 fd->addFilter ("JPG (*.jpg)");
2816 fd->addFilter ("XPM (*.xpm)");
2817 fd->addFilter ("GIF (*.gif)");
2818 fd->addFilter ("PNM (*.pnm)");
2819 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2820 fd->setCaption(tr("vym - Save image as %1").arg(fmt));
2821 fd->setMode( QFileDialog::AnyFile );
2822 fd->setSelection (fio->getOriginalFilename());
2826 if ( fd->exec() == QDialog::Accepted )
2828 if (QFile (fd->selectedFile()).exists() )
2830 QMessageBox mb( "VYM",
2831 tr("The file %1 exists already.\n"
2832 "Do you want to overwrite it?").arg(fd->selectedFile()),
2833 QMessageBox::Warning,
2834 QMessageBox::Yes | QMessageBox::Default,
2835 QMessageBox::Cancel | QMessageBox::Escape,
2836 QMessageBox::QMessageBox::NoButton );
2838 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2839 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2842 case QMessageBox::Yes:
2845 case QMessageBox::Cancel:
2851 fio->save (fd->selectedFile(),fmt);
2856 void MapEditor::toggleFloatExport()
2859 (typeid(*selection) == typeid(FloatImageObj))||
2860 (typeid(*selection) == typeid(FloatObj)) )
2862 FloatImageObj *fio=((FloatImageObj*)selection);
2863 fio->setFloatExport (actionEditToggleFloatExport->isOn() );
2867 void MapEditor::setFrame(const FrameType &t)
2870 (typeid(*selection) == typeid(BranchObj)) ||
2871 (typeid(*selection) == typeid(MapCenterObj)) )
2873 selection->setFrameType (t);
2874 mapCenter->reposition();
2875 selection->updateLink();
2879 void MapEditor::setHideLinkUnselected (bool b)
2882 (typeid(*selection) == typeid(BranchObj)) ||
2883 (typeid(*selection) == typeid(MapCenterObj)) ||
2884 (typeid(*selection) == typeid(FloatImageObj)) )
2885 selection->setHideLinkUnselected(b);
2888 void MapEditor::importDir(BranchObj *dst, QDir d)
2891 (typeid(*selection) == typeid(BranchObj)) ||
2892 (typeid(*selection) == typeid(MapCenterObj)) )
2896 // Traverse directories
2897 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2898 const QFileInfoList *dirlist = d.entryInfoList();
2899 QFileInfoListIterator itdir( *dirlist );
2902 while ( (fi = itdir.current()) != 0 )
2904 if (fi->fileName() != "." && fi->fileName() != ".." )
2907 bo=dst->getLastBranch();
2908 bo->setHeading (fi->fileName() );
2909 bo->setColor (QColor("blue"),false);
2911 if ( !d.cd(fi->fileName()) )
2912 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi->fileName()));
2915 // Recursively add subdirs
2923 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
2924 const QFileInfoList *filelist = d.entryInfoList();
2925 QFileInfoListIterator itfile( *filelist );
2927 while ( (fi = itfile.current()) != 0 )
2930 bo=dst->getLastBranch();
2931 bo->setHeading (fi->fileName() );
2932 bo->setColor (QColor("black"),false);
2933 if (fi->fileName().right(4) == ".vym" )
2934 bo->setVymLink (fi->filePath());
2941 void MapEditor::importDir()
2944 (typeid(*selection) == typeid(BranchObj)) ||
2945 (typeid(*selection) == typeid(MapCenterObj)) )
2947 QFileDialog *fd=new QFileDialog( this,tr("VYM - Choose directory structur to import"));
2948 fd->setMode (QFileDialog::DirectoryOnly);
2949 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2950 fd->setCaption(tr("VYM - Choose directory structur to import"));
2954 if ( fd->exec() == QDialog::Accepted )
2956 BranchObj *bo=((BranchObj*)selection);
2957 importDir (bo,QDir(fd->selectedFile()) );
2958 mapCenter->reposition();
2965 void MapEditor::followXLink(int i)
2968 (typeid(*selection) == typeid(BranchObj)) ||
2969 (typeid(*selection) == typeid(MapCenterObj)) )
2971 BranchObj *bo=((BranchObj*)selection)->XLinkTargetAt(i);
2974 selection->unselect();
2976 selection->select();
2977 ensureSelectionVisible();
2982 void MapEditor::editXLink(int i)
2985 (typeid(*selection) == typeid(BranchObj)) ||
2986 (typeid(*selection) == typeid(MapCenterObj)) )
2988 XLinkObj *xlo=((BranchObj*)selection)->XLinkAt(i);
2991 EditXLinkDialog dia;
2993 dia.setSelection(selection);
2994 if (dia.exec() == QDialog::Accepted)
2996 if (dia.useSettingsGlobal() )
2998 setDefXLinkColor (xlo->getColor() );
2999 setDefXLinkWidth (xlo->getWidth() );
3001 if (dia.deleteXLink())
3002 ((BranchObj*)selection)->deleteXLinkAt(i);
3003 saveState(); //TODO undoCommand
3009 void MapEditor::testFunction()
3011 cout << "MapEditor::testFunction() called\n";
3012 load (clipboardDir+"/part.xml",ImportAdd);
3015 void MapEditor::ensureSelectionVisible()
3019 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
3021 if (selection->getOrientation() == OrientLeftOfCenter)
3022 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
3024 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
3025 ensureVisible (p.x(), p.y() );
3030 void MapEditor::updateViewCenter()
3032 // Update movingCenter, so that we can zoom comfortably later
3033 QRect rc = QRect( contentsX(), contentsY(),
3034 visibleWidth(), visibleHeight() );
3035 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
3036 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
3037 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
3040 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
3042 // Lineedits are already closed by preceding
3043 // mouseEvent, we don't need to close here.
3045 QPoint p = inverseWorldMatrix().map(e->pos());
3046 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3049 { // MapObj was found
3050 if (selection != lmo)
3052 // select the MapObj
3053 if (selection) selection->unselect();
3055 selection->select();
3061 if (typeid(*selection)==typeid(BranchObj) ||
3062 typeid(*selection)==typeid(MapCenterObj) )
3064 // Context Menu on branch or mapcenter
3066 branchContextMenu->popup(e->globalPos() );
3068 if (typeid(*selection)==typeid(FloatImageObj))
3070 // Context Menu on floatimage
3072 floatimageContextMenu->popup(e->globalPos() );
3076 { // No MapObj found, we are on the Canvas itself
3077 // Context Menu on Canvas
3079 canvasContextMenu->popup(e->globalPos() );
3083 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
3085 // Finish open lineEdits
3086 if (lineedit) finishedLineEditNoSave();
3088 QPoint p = inverseWorldMatrix().map(e->pos());
3089 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3091 // Special case: CTRL is pressed
3092 if (e->state() & QMouseEvent::ControlButton)
3094 if (actionModModeColor->isOn())
3096 if (e->state() & QMouseEvent::ControlButton)
3099 setCursor (pickColorCursor);
3103 if (actionModModeLink->isOn())
3105 BranchObj *bo_begin=NULL;
3107 bo_begin=(BranchObj*)(lmo);
3110 ((typeid(*selection) == typeid(BranchObj)) ||
3111 (typeid(*selection) == typeid(MapCenterObj))) )
3112 bo_begin=(BranchObj*)selection;
3116 linkingObj_src=bo_begin;
3117 tmpXLink=new XLinkObj (mapCanvas);
3118 tmpXLink->setBegin (bo_begin);
3119 tmpXLink->setEnd (p);
3120 tmpXLink->setColor(defXLinkColor);
3121 tmpXLink->setWidth(defXLinkWidth);
3122 tmpXLink->updateXLink();
3123 tmpXLink->setVisibility (true);
3130 { // MapObj was found
3131 if (selection != lmo)
3133 // select the MapObj
3134 if (selection) selection->unselect();
3136 selection->select();
3141 // Check, if systemFlag clicked
3142 if (typeid(*selection)==typeid(BranchObj) ||
3143 typeid(*selection)==typeid(MapCenterObj) )
3145 QString foname=((BranchObj*)selection)->getSystemFlagName(p);
3146 if (!foname.isEmpty())
3148 // Do not move, if systemFlag clicked
3152 if (foname=="vymLink")
3154 mainWindow->editOpenVymLink();
3155 // tabWidget may change, better return now
3156 // before segfaulting...
3160 mainWindow->windowToggleNoteEditor();
3164 // Left Button Move Branches
3165 if (e->button() == QMouseEvent::LeftButton )
3167 movingObj_start.setX( p.x() - selection->x() );
3168 movingObj_start.setY( p.y() - selection->y() );
3169 movingObj_orgPos.setX (lmo->x() );
3170 movingObj_orgPos.setY (lmo->y() );
3172 // If modMode==copy, then we want to "move" the _new_ object around
3173 // then we need the offset from p to the _old_ selection, because of tmp
3174 if (actionModModeCopy->isOn() &&
3175 e->state() & QMouseEvent::ControlButton)
3177 if (typeid(*selection)==typeid(BranchObj) )
3180 mapCenter->addBranch ((BranchObj*)selection);
3182 selection=mapCenter->getLastBranch();
3183 selection->select();
3184 mapCenter->reposition();
3187 movingObj=selection;
3189 // Middle Button Toggle Scroll
3190 // (On Mac OS X this won't work, but we still have
3191 // a button in the toolbar)
3192 if (e->button() == QMouseEvent::MidButton )
3196 { // No MapObj found, we are on the Canvas itself
3197 // Left Button move Pos of CanvasView
3198 if (e->button() == QMouseEvent::LeftButton )
3200 movingObj=NULL; // move Content not Obj
3201 movingObj_start=e->globalPos();
3202 movingCont_start=QPoint (contentsX(), contentsY() );
3203 movingVec=QPoint(0,0);
3204 setCursor(handOpenCursor);
3209 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3211 QPoint p = inverseWorldMatrix().map(e->pos());
3213 // Move the selected MapObj
3214 if ( selection && movingObj)
3216 // To avoid jumping of the CanvasView, only
3217 // ensureSelectionVisible, if not tmp linked
3218 if (!selection->hasParObjTmp())
3219 ensureSelectionVisible ();
3221 // Now move the selection, but add relative position
3222 // (movingObj_start) where selection was chosen with
3223 // mousepointer. (This avoids flickering resp. jumping
3224 // of selection back to absPos)
3226 LinkableMapObj *lmosel;
3227 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3229 // Check if we could link
3230 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3233 if (typeid(*selection) == typeid(FloatImageObj))
3235 FloatObj *fo=(FloatObj*)selection;
3236 saveState("move "+qpointToString(movingObj_orgPos),fo->getSelectString() );
3237 if (fo->getLinkStyle()==StyleUndef)
3239 fo->setLinkStyle(fo->getDefLinkStyle());
3240 fo->setLinkColor(fo->getParObj()->getLinkColor());
3242 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3246 // Relink float to new mapcenter or branch, if shift is pressed
3247 // Only relink, if selection really has a new parent
3248 if ( (e->state() & QMouseEvent::ShiftButton) && lmo &&
3249 ( (typeid(*lmo)==typeid(BranchObj)) ||
3250 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3251 ( lmo != fo->getParObj())
3254 if (typeid(*fo) == typeid(FloatImageObj))
3257 FloatImageObj *fio=(FloatImageObj*)(fo);
3258 ((BranchObj*)(lmo))->addFloatImage (fio);
3260 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3261 fio=((BranchObj*)(lmo))->getLastFloatImage();
3264 selection=(LinkableMapObj*)(fio);
3265 selection->select();
3266 movingObj=(MapObj*)(fio);
3267 // setLinkStyle calls updateLink, only set it once
3268 if (fio->getLinkStyle()!=fio->getDefLinkStyle() )
3269 fio->setLinkStyle (fio->getDefLinkStyle());
3271 // TODO if (typeid(*selection) == typeid(FloatTextObj))
3273 } else // selection != a FloatObj
3275 if (lmosel->getDepth()==0)
3277 if (e->state() == (LeftButton | !ShiftButton))
3278 // If mapCenter is moved, move all the rest by default, too.
3279 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3281 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3284 if (lmosel->getDepth()==1)
3286 // depth==1, mainbranch
3287 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3291 if (lmosel->getOrientation() == OrientLeftOfCenter)
3292 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3293 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3294 p.y()-movingObj_start.y() );
3296 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3298 // reposition subbranch
3299 lmosel->reposition();
3300 //ensureSelectionVisible();
3302 if (lmo && (lmo!=selection) &&
3303 (typeid(*lmo) == typeid(BranchObj) ||
3304 (typeid(*lmo) == typeid(MapCenterObj) )
3307 if (e->state() & QMouseEvent::ControlButton)
3309 // Special case: CTRL to link below lmo
3310 lmosel->setParObjTmp (lmo,p,+1);
3312 else if (e->state() & QMouseEvent::ShiftButton)
3313 lmosel->setParObjTmp (lmo,p,-1);
3315 lmosel->setParObjTmp (lmo,p,0);
3318 lmosel->unsetParObjTmp();
3320 if (lmo &&(lmo==selection))
3321 // Could link to myself (happens sometimes...)
3322 lmosel->unsetParObjTmp();
3324 // no Obj under selection, go back to original Parent
3325 lmosel->unsetParObjTmp();
3330 } // no FloatImageObj
3334 } // selection && moving_obj
3336 // Draw a link from one branch to another
3339 tmpXLink->setEnd (p);
3340 tmpXLink->updateXLink();
3344 if (!movingObj && !pickingColor &&!drawingLink)
3346 QPoint p=e->globalPos();
3347 movingVec.setX(-p.x() + movingObj_start.x() );
3348 movingVec.setY(-p.y() + movingObj_start.y() );
3349 setContentsPos( movingCont_start.x() + movingVec.x(),
3350 movingCont_start.y() + movingVec.y());
3357 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3359 LinkableMapObj *dst;
3360 // Have we been picking color?
3364 setCursor (ArrowCursor);
3365 // Check if we are over another branch
3366 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3367 if (dst && selection)
3369 if (e->state() & QMouseEvent::ShiftButton)
3371 ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor(),false);
3372 ((BranchObj*)selection)->setLinkColor ();
3376 ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor(),true);
3377 ((BranchObj*)selection)->setLinkColor ();
3383 // Have we been drawing a link?
3387 // Check if we are over another branch
3388 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3389 if (dst && selection)
3391 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3392 tmpXLink->updateXLink();
3393 tmpXLink->activate();
3394 saveState(); //TODO undoCommand
3403 // Have we been moving something?
3404 if ( selection && movingObj )
3406 // Check if we are over another branch, but ignore
3407 // any found LMOs, which are FloatObjs
3408 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3409 ((LinkableMapObj*)selection) );
3412 (typeid(*dst)!=typeid(BranchObj)&&typeid(*dst)!=typeid(MapCenterObj)))
3415 // Now check, if we have been moving a branch
3416 if (typeid(*selection) == typeid(BranchObj) )
3418 // save the position in case we link to mapcenter
3419 QPoint savePos=QPoint (selection->x(),selection->y() );
3421 // Reset the temporary drawn link to the original one
3422 ((LinkableMapObj*)selection)->unsetParObjTmp();
3428 BranchObj* bs=((BranchObj*)selection);
3429 QString undoCom="linkBranchToPos (\""+
3430 (bs->getParObj())->getSelectString()+
3432 QString("%1").arg(bs->getNum())+
3434 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+
3436 // TODO we also could check, if dest and src are on same branch,
3437 // then it would be sufficient to saveState of this branch
3439 // Modifiers allow to insert above/below dst
3440 if (e->state() & QMouseEvent::ShiftButton)
3442 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum());
3444 if (e->state() & QMouseEvent::ControlButton)
3446 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum()+1);
3449 bs->moveBranchTo ((BranchObj*)(dst),-1);
3450 if (dst->getDepth()==0)
3453 saveState (undoCom,bs->getSelectString() );
3455 if (selection->getDepth()==1)
3456 // If we have moved mainbranch only save endposition
3457 saveState("move "+qpointToString(movingObj_orgPos), selection->getSelectString() );
3459 // Draw the original link, before selection was moved around
3460 mapCenter->reposition();
3462 // Finally resize canvas, if needed
3467 // maybe we moved View: set old cursor
3468 setCursor (ArrowCursor);
3472 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3474 // Finish open lineEdits
3475 if (lineedit) finishedLineEditNoSave();
3477 if (e->button() == QMouseEvent::LeftButton )
3479 QPoint p = inverseWorldMatrix().map(e->pos());
3480 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3481 if (lmo) { // MapObj was found
3482 // First select the MapObj than edit heading
3483 if (selection) selection->unselect();
3485 selection->select();
3486 saveState(selection);
3492 void MapEditor::resizeEvent (QResizeEvent* e)
3494 QCanvasView::resizeEvent( e );
3498 void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3501 // for (unsigned int i=0;event->format(i);i++) // Debug mime type
3502 // cerr << event->format(i) << endl;
3505 (typeid(*selection) == typeid(BranchObj)) ||
3506 (typeid(*selection) == typeid(MapCenterObj))) {
3508 // If QImageDrag can decode mime type
3509 if (QImageDrag::canDecode(event)) {
3514 // If image are dragged from firefox
3515 if (event->provides("application/x-moz-file-promise-url") &&
3516 event->provides("application/x-moz-nativeimage")) {
3517 event->accept(true);
3521 // If QUriDrag can decode mime type
3522 if (QUriDrag::canDecode(event)) {
3527 // If Uri are dragged from firefox
3528 if (event->provides("_NETSCAPE_URL")){
3533 // If QTextDrag can decode mime type
3534 if (QTextDrag::canDecode(event)) {
3543 bool isUnicode16(const QByteArray &d)
3545 // TODO: make more precise check for unicode 16.
3546 // Guess unicode16 if any of second bytes are zero
3547 unsigned int length = max(0,d.size()-2)/2;
3548 for (unsigned int i = 0; i<length ; i++)
3549 if (d.at(i*2+1)==0) return true;
3553 void MapEditor::contentsDropEvent(QDropEvent *event)
3556 (typeid(*selection) == typeid(BranchObj)) ||
3557 (typeid(*selection) == typeid(MapCenterObj)))
3562 if (event->provides("image/png"))
3565 if (QImageDrag::decode(event, pix))
3573 } else if (event->provides("application/x-moz-file-promise-url") &&
3574 event->provides("application/x-moz-nativeimage"))
3576 // Contains url to the img src in unicode16
3577 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3578 QString url = QString((const QChar*)d.data(),d.size()/2);
3582 } else if (event->provides ("text/uri-list"))
3583 { // Uris provided e.g. by konqueror
3584 QUriDrag::decode (event,uris);
3585 } else if (event->provides ("_NETSCAPE_URL"))
3586 { // Uris provided by Mozilla
3587 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
3590 } else if (event->provides("text/html")) {
3592 // Handels text mime types
3593 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
3594 QByteArray d = event->encodedData("text/html");
3597 text = QString((const QChar*)d.data(),d.size()/2);
3601 textEditor->setText(text);
3605 } else if (event->provides("text/plain")) {
3606 QByteArray d = event->encodedData("text/plain");
3609 text = QString((const QChar*)d.data(),d.size()/2);
3613 textEditor->setText(text);
3625 for (const char* u=uris.first(); u; u=uris.next())
3627 bo=((BranchObj*)selection)->addBranch();
3630 s=QUriDrag::uriToLocalFile(u);
3632 QString file = QDir::convertSeparators(s);
3633 heading = QFileInfo(file).baseName();
3635 if (file.endsWith(".vym", false))
3636 bo->setVymLink(file);
3645 bo->setHeading(heading);
3655 saveState(); //TODO undo Command
3656 mapCenter->reposition();
3663 void MapEditor::addFloatImage(const QPixmap &img)
3666 (typeid(*selection) == typeid(BranchObj)) ||
3667 (typeid(*selection) == typeid(MapCenterObj)) )
3669 BranchObj *bo=((BranchObj*)selection);
3670 saveState(selection);
3671 //QString fn=fd->selectedFile();
3672 //lastImageDir=fn.left(fn.findRev ("/"));
3673 bo->addFloatImage();
3674 // FIXME check if load was successful
3675 bo->getLastFloatImage()->load(img);
3676 //bo->getLastFloatImage()->setOriginalFilename(fn);
3677 mapCenter->reposition();
3684 void MapEditor::imageDataFetched(const QByteArray &a, QNetworkOperation */*nop*/)
3686 if (!imageBuffer) imageBuffer = new QBuffer();
3687 if (!imageBuffer->isOpen()) {
3688 imageBuffer->open(IO_WriteOnly | IO_Append);
3690 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
3694 void MapEditor::imageDataFinished(QNetworkOperation *nop)
3696 if (nop->state()==QNetworkProtocol::StDone) {
3697 QPixmap img(imageBuffer->buffer());
3702 imageBuffer->close();
3704 imageBuffer->close();
3711 void MapEditor::fetchImage(const QString &url)
3714 urlOperator->stop();
3715 disconnect(urlOperator);
3719 urlOperator = new QUrlOperator(url);
3720 connect(urlOperator, SIGNAL(finished(QNetworkOperation *)),
3721 this, SLOT(imageDataFinished(QNetworkOperation*)));
3723 connect(urlOperator, SIGNAL(data(const QByteArray &, QNetworkOperation *)),
3724 this, SLOT(imageDataFetched(const QByteArray &, QNetworkOperation *)));