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"
33 #include "linkablemapobj.h"
34 #include "mainwindow.h"
37 #include "texteditor.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 *actionEditFATE2URL;
65 extern QAction *actionEditOpenVymLink;
66 extern QAction *actionEditVymLink;
67 extern QAction *actionEditDeleteVymLink;
68 extern QAction *actionEditHeading;
69 extern QAction *actionEditDelete;
70 extern QAction *actionEditAddBranch;
71 extern QAction *actionEditAddBranchAbove;
72 extern QAction *actionEditAddBranchBelow;
73 extern QAction *actionEditRemoveBranchHere;
74 extern QAction *actionEditRemoveChilds;
75 extern QAction *actionEditImportAdd;
76 extern QAction *actionEditImportReplace;
77 extern QAction *actionEditSaveBranch;
78 extern QAction *actionEditSelectFirst;
79 extern QAction *actionEditSelectLast;
80 extern QAction *actionEditLoadImage;
81 extern QAction *actionEditToggleFloatExport;
83 extern QAction* actionFormatPickColor;
84 extern QAction* actionFormatColorBranch;
85 extern QAction* actionFormatColorSubtree;
86 extern QAction *actionFormatLinkColorHint;
87 extern QAction *actionFormatBackColor;
88 extern QAction *actionFormatLinkColor;
90 extern QActionGroup* actionGroupModModes;
91 extern QAction* actionModModeColor;
92 extern QAction* actionModModeLink;
93 extern QAction* actionModModeCopy;
95 extern QActionGroup *actionGroupFormatFrameTypes;
96 extern QAction *actionFormatFrameNone;
97 extern QAction *actionFormatFrameRectangle;
99 extern QActionGroup *actionGroupFormatLinkStyles;
100 extern QAction *actionFormatIncludeImagesVer;
101 extern QAction *actionFormatIncludeImagesHor;
102 extern QAction *actionFormatHideLinkUnselected;
103 extern QAction *actionFormatLinkStyleLine;
104 extern QAction *actionFormatLinkStyleParabel;
105 extern QAction *actionFormatLinkStylePolyLine;
106 extern QAction *actionFormatLinkStylePolyParabel;
108 extern QAction *actionViewToggleNoteEditor;
110 extern QAction *actionSettingsAutoedit;
111 extern QAction *actionSettingsAutoselectHeading;
112 extern QAction *actionSettingsAutoselectText;
113 extern QAction *actionSettingsPasteNewHeading;
114 extern QAction *actionSettingsUseFlagGroups;
116 extern QPopupMenu *branchContextMenu;
117 extern QPopupMenu *branchLinksContextMenu;
118 extern QPopupMenu *branchLinksContextMenuDup;
119 extern QPopupMenu *floatimageContextMenu;
120 extern QPopupMenu *saveImageFormatMenu;
121 extern QPopupMenu *exportImageFormatMenu;
122 extern QPopupMenu *canvasContextMenu;
124 extern Settings settings;
126 int MapEditor::mapNum=0; // make instance
128 ///////////////////////////////////////////////////////////////////////
129 ///////////////////////////////////////////////////////////////////////
130 MapEditor::MapEditor(
131 QWidget* parent, bool interactive, const char* name, WFlags f) :
132 QCanvasView(parent,name,f), urlOperator(0), imageBuffer(0)
134 //cout << "Constructor ME "<<this<<endl;
137 viewport()->setAcceptDrops(true);
139 mapCanvas = new QCanvas(1000,800);
140 mapCanvas->setAdvancePeriod(30);
141 mapCanvas->setBackgroundColor (white);
143 setCanvas (mapCanvas);
145 // Always show scroll bars (automatic would flicker sometimes)
146 setVScrollBarMode ( QScrollView::AlwaysOn );
147 setHScrollBarMode ( QScrollView::AlwaysOn );
149 mapCenter = new MapCenterObj(mapCanvas);
150 mapCenter->setVisibility (true);
151 mapCenter->setMapEditor (this);
152 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
153 mapCenter->move(mapCanvas->width()/2-mapCenter->width()/2,mapCanvas->height()/2-mapCenter->height()/2);
157 lineedit = new QLineEdit(this, "lineedit" );
158 connect( lineedit, SIGNAL( returnPressed() ), SLOT( finishedLineEditNoSave() ) );
161 actColor=black; setColor (actColor);
162 defLinkColor=QColor (0,0,255);
163 defXLinkColor=QColor (180,180,180);
164 linkcolorhint=DefaultColor;
165 linkstyle=StylePolyParabel;
167 // Create bitmap cursors, patform dependant
168 #if defined(Q_OS_MACX)
169 #include "icons/cursorhandopen16.xpm"
170 #include "icons/cursorcolorpicker16.xpm"
171 QBitmap cb( 16, 16, chandopen, TRUE );
172 QBitmap cm( 16, 16, chandopenmask, TRUE );
173 handOpenCursor=QCursor ( cb, cm );
174 // set hot spot to tip of picker
175 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 1,15 );
177 #include "icons/cursorhandopen.xpm"
178 #include "icons/cursorcolorpicker.xpm"
180 QBitmap cb( 32, 32, chandopen, TRUE );
181 QBitmap cm( 32, 32, chandopenmask, TRUE );
182 handOpenCursor=QCursor ( cb, cm );
183 // set hot spot to tip of picker
184 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 5,27 );
197 defXLinkColor=QColor (230,230,230);
208 undosTotal=settings.readNumEntry("/vym/mapeditor/undoLevels",50);
212 // Initialize find routine
219 blockReposition=false;
220 blockSaveState=false;
221 isInteractive=interactive;
223 // Create temporary files
226 // Initially set movingCentre
229 mapCenter->reposition(); // for positioning heading
232 MapEditor::~MapEditor()
234 if (imageBuffer) delete imageBuffer;
240 //cout <<"Destructor MapEditor\n";
243 //settings.writeEntry( "/vym/mapeditor/editmode/autoselect", );
247 QColor MapEditor::color()
252 QColor MapEditor::backgroundColor()
254 return mapCanvas->backgroundColor();
257 MapCenterObj* MapEditor::getMapCenter()
262 QCanvas* MapEditor::getCanvas()
267 void MapEditor::adjustCanvasSize()
269 // To adjust the canvas to map, viewport size and position, we have to
270 // do some coordinate magic...
272 // Get rectangle of (scroll-)view.
273 // We want to be in canvas coords, so
274 // we map. Important if view is zoomed...
275 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
276 visibleWidth(), visibleHeight()) );
278 // Now we need the bounding box of view AND map to calc the correct canvas size.
279 // Why? Because if the map itself is moved out of view, the view has to be enlarged
280 // to avoid jumping aroung...
281 QRect map=mapCenter->getTotalBBox();
283 // right edge - left edge
284 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
285 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
288 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
289 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
292 // move the map on canvas (in order to not move it on screen) this is neccessary
293 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
294 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
295 // to scroll to an empty area of canvas to the left.
296 // b) if topleft corner of map left of or above topleft of canvas
300 if (cw > mapCanvas->width() )
302 if (map.x()<0) dx=-map.x();
304 if (cw < mapCanvas->width() )
305 dx=-min (view.x(),map.x());
306 if (ch > mapCanvas->height() )
308 if (map.y()<0) dy=-map.y();
310 if (ch < mapCanvas->height() )
312 dy=-min (view.y(),map.y());
314 // We really have to resize now. Let's go...
315 mapCanvas->resize (cw,ch);
316 if ( (dx!=0) || (dy!=0) )
318 mapCenter->moveAllBy(dx,dy);
319 mapCenter->reposition();
321 // scroll the view (in order to not move map on screen)
327 bool MapEditor::isRepositionBlocked()
329 return blockReposition;
332 void MapEditor::makeTmpDirs()
334 // Create unique temporary directories
335 tmpMapDir=tmpVymDir+QString("/mapeditor-%1").arg(mapNum);
337 d.mkdir (tmpMapDir,true);
340 void MapEditor::delTmpDirs()
342 removeDir (QDir(tmpMapDir));
345 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSelection)
347 // tmpdir temporary directory to which data will be written
348 // prefix mapname, which will be appended to images etc.
349 // writeflags Only write flags for "real" save of map, not undo
350 // offset offset of bbox of whole map in canvas.
351 // Needed for XML export
367 ls="StylePolyParabel";
371 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
373 if (linkcolorhint==HeadingColor)
374 colhint=attribut("linkColorHint","HeadingColor");
376 QString mapAttr=attribut("version",__VYM_VERSION);
378 mapAttr+= attribut("author",mapCenter->getAuthor()) +
379 attribut("comment",mapCenter->getComment()) +
380 attribut("date",mapCenter->getDate()) +
381 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
382 attribut("linkStyle", ls ) +
383 attribut("linkColor", defLinkColor.name() ) +
384 attribut("defXLinkColor", defXLinkColor.name() ) +
385 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
387 s+=beginElement("vymmap",mapAttr);
390 // Find the used flags while traversing the tree
391 standardFlagsDefault->resetUsedCounter();
393 // Reset the counters before saving
394 FloatImageObj (mapCanvas).resetSaveCounter();
396 // Build xml recursivly
398 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
401 if ( typeid(*saveSelection) == typeid(BranchObj) )
402 s+=((BranchObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
403 else if ( typeid(*saveSelection) == typeid(FloatImageObj) )
404 s+=((FloatImageObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
406 else if (selection && typeid(*selection)==typeid(BranchObj))
407 // This is used if selected branch is saved from mainwindow
408 s+=((BranchObj*)selection)->saveToDir(tmpdir,prefix,offset);
411 // Save local settings
412 s+=settings.getXMLData (destPath);
415 if (selection && !saveSelection )
416 s+=valueElement("select",selection->getSelectString());
419 s+=endElement("vymmap");
422 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
426 void MapEditor::saveState()
429 saveState (CompleteMap,"",NULL,"",NULL);
432 void MapEditor::saveState(LinkableMapObj *undoSel)
434 // save the given part of the map
435 saveState (PartOfMap,"",undoSel,"",NULL);
438 void MapEditor::saveState(const QString &uc, const QString &rc)
440 // selection does not change during action,
441 // so just save commands for undo and redo
442 LinkableMapObj *unsel;
447 saveState (UndoCommand,uc,unsel,rc,unsel);
450 void MapEditor::saveState(const QString & uncom, LinkableMapObj *unsel)
452 saveState (UndoCommand,uncom,unsel,"FIXME-redoCom",NULL);
455 void MapEditor::saveState(const SaveMode &savemode, const QString &undoCom, LinkableMapObj *undoSel, const QString &redoCom, LinkableMapObj *redoSel)
459 if (blockSaveState) return;
461 /* TODO remove after testing
462 cout << "ME::saveState() begin\n"<<endl;
463 cout << " undosTotal="<<undosTotal<<endl;
464 cout << " undosAvail="<<undosAvail<<endl;
465 cout << " undoNum="<<undoNum<<endl;
466 cout << " ---------------------------"<<endl;
470 // Find out current undo directory
471 if (undosAvail<undosTotal) undosAvail++;
473 if (undoNum>undosTotal) undoNum=1;
476 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
477 QString bakMapPath=QDir::convertSeparators(bakMapDir+"/map.xml");
479 // Create bakMapDir if not available
482 makeSubDirs (bakMapDir);
484 // Save current selection
485 QString redoSelection="";
487 redoSelection=redoSel->getSelectString();
489 // Save the object, which should be undone
490 QString undoSelection="";
492 undoSelection=undoSel->getSelectString();
494 // Save depending on how much needs to be saved
495 QString undoCommand="";
496 if (savemode==UndoCommand)
501 else if (savemode==PartOfMap && undoSel)
503 undoCommand="undoPart (\""+ undoSelection+"\",\""+bakMapPath+"\")";
504 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),undoSel);
507 undoCommand="undoMap (\""+bakMapPath+"\")";
508 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),NULL);
511 if (!backupXML.isEmpty())
512 // Write XML Data to disk
513 saveStringToDisk (QString(bakMapPath),backupXML);
516 set.setEntry (QString("undoCommand"),undoCommand);
517 set.setEntry (QString("undoSelection"),undoSelection);
518 set.setEntry (QString("redoCommand"),redoCom);
519 set.setEntry (QString("redoSelection"),redoSelection);
520 set.writeSettings(QString(bakMapDir+"/commands"));
522 /* TODO remove after testing
523 cout << " into="<< bakMapDir<<endl;
524 cout << " undosAvail="<<undosAvail<<endl;
525 cout << " undoNum="<<undoNum<<endl;
526 cout << " ---------------------------"<<endl;
527 cout << " undoCom="<<undoCommand<<endl;
528 cout << " undoSel="<<undoSelection<<endl;
529 cout << " ---------------------------"<<endl;
530 cout << " redoCom="<<redoCom<<endl;
531 cout << " redoSel="<<redoSelection<<endl;
532 cout << " ---------------------------"<<endl<<endl;
536 void MapEditor::parseAtom(const QString &atom)
543 // Split string s into command and parameters
544 api.parseCommand (atom);
545 QString com=api.command();
548 if (com=="moveBranchUp")
550 else if (com=="moveBranchDown")
552 else if (com=="move")
554 if (api.checkParamCount(2) && selection )
564 else if (com=="linkBranchToPos")
566 if (selection && typeid(*selection) == typeid(BranchObj) )
568 if (api.checkParamCount(4))
570 s=api.parString(ok,0);
571 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
574 if (typeid(*dst) == typeid(BranchObj) )
576 // Get number in parent
579 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),x);
580 } else if (typeid(*dst) == typeid(MapCenterObj) )
582 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),-1);
583 // Get coordinates of mainbranch
588 if (ok) ((BranchObj*)selection)->move (x,y);
594 } else if (com=="setHeading")
596 if (api.checkParamCount(1))
598 s=api.parString (ok,0);
599 if (ok) setHeading (s);
601 } else if (com=="setURL")
603 if (api.checkParamCount(1))
605 s=api.parString (ok,0);
608 } else if (com=="setVymLink")
610 if (api.checkParamCount(1))
612 s=api.parString (ok,0);
613 if (ok) setVymLink(s);
616 // Internal commands, used for undo etc.
617 else if (com==QString("undoMap"))
619 if (api.checkParamCount(1))
620 undoXML("",api.parString (ok,0));
621 } else if (com==QString("undoPart"))
623 if (api.checkParamCount(2))
625 s=api.parString (ok,0);
626 t=api.parString (ok,1);
629 } else if (com=="select")
630 if (api.checkParamCount(1))
632 s=api.parString(ok,0);
637 api.setError ("Unknown command in: "+atom);
638 cout << "ME::parse api should have error now...\n";
644 cout << "MapEditor::parseAtom: Error!\n";
645 cout << " "<<api.errorDesc()<<endl;
650 void MapEditor::finishedLineEditNoSave()
652 // This is called by finishedLineEdit or any MapEditor method,
653 // which wants to assure, that lineedits finish, before e.g. a branch is
656 // After calling LineEdit and using the clipboard, the
657 // focus is not any longer on the main widget, we
658 // have to restore it using parentWidget()->setFocus()
662 editingBO->setHeading(lineedit->text() );
664 lineedit->releaseKeyboard();
666 parentWidget()->setFocus();
667 mapCenter->reposition();
669 ensureSelectionVisible();
674 bool MapEditor::isDefault()
679 bool MapEditor::isUnsaved()
684 bool MapEditor::hasChanged()
689 void MapEditor::setChanged()
694 actionEditUndo->setEnabled (true);
695 actionFileSave->setEnabled (true);
699 void MapEditor::closeMap()
701 // Finish open lineEdits
702 if (lineedit) finishedLineEditNoSave();
704 // Unselect before disabling the toolbar actions
705 if (selection) selection->unselect();
713 void MapEditor::setFilePath(QString fname)
715 setFilePath (fname,fname);
718 void MapEditor::setFilePath(QString fname, QString destname)
727 filePath=fname; // becomes absolute path
728 fileName=fname; // gets stripped of path
729 destPath=destname; // needed for vymlinks
731 // If fname is not an absolute path, complete it
732 filePath=QDir(fname).absPath();
733 fileDir=filePath.left (1+filePath.findRev ("/"));
735 // Set short name, too. Search from behind:
736 int i=fileName.findRev("/");
737 if (i>=0) fileName=fileName.remove (0,i+1);
739 // Forget the .vym (or .xml) for name of map
740 mapName=fileName.left(fileName.findRev(".",-1,true) );
744 QString MapEditor::getFilePath()
749 QString MapEditor::getFileName()
754 QString MapEditor::getMapName()
759 QString MapEditor::getDestPath()
764 int MapEditor::load (QString fname, LoadMode lmode)
766 // Finish open lineEdits
767 if (lineedit) finishedLineEditNoSave();
773 if (selection) selection->unselect();
776 mapCenter->setMapEditor(this);
777 // (map state is set later at end of load...)
780 saveState(selection);
784 mapBuilderHandler handler;
787 // I am paranoid: file should exist anyway
788 // according to check in mainwindow.
791 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
792 tr("Couldn't open map " +fname)+".");
796 blockReposition=true;
797 QXmlInputSource source( file);
798 QXmlSimpleReader reader;
799 reader.setContentHandler( &handler );
800 reader.setErrorHandler( &handler );
801 handler.setMapEditor( this );
802 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
803 handler.setLoadMode (lmode);
805 bool ok = reader.parse( source );
806 blockReposition=false;
807 blockSaveState=false;
811 mapCenter->reposition();
821 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
822 tr( handler.errorProtocol() ) );
824 // Still return "success": the map maybe at least
825 // partially read by the parser
832 int MapEditor::save (const SaveMode &savemode)
834 // Finish open lineEdits
835 if (lineedit) finishedLineEditNoSave();
839 // The SaveMode UndoCommand is not supported here
840 if (savemode==UndoCommand) return 1;
842 // Create mapName and fileDir
843 makeSubDirs (fileDir);
847 fname=mapName+".xml";
849 // use name given by user, even if he chooses .doc
854 if (savemode==CompleteMap || selection==NULL)
855 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL);
857 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection);
859 if (!saveStringToDisk(fileDir+fname,saveFile))
866 actionFileSave->setEnabled(false);
872 void MapEditor::setZipped (bool z)
877 bool MapEditor::saveZipped ()
882 void MapEditor::print()
884 // Finish open lineEdits
885 if (lineedit) finishedLineEditNoSave();
889 printer = new QPrinter;
890 printer->setColorMode (QPrinter::Color);
891 printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName()));
894 QRect totalBBox=mapCenter->getTotalBBox();
896 // Try to set orientation automagically
897 // Note: Interpretation of generated postscript is amibiguous, if
898 // there are problems with landscape mode, see
899 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
901 if (totalBBox.width()>totalBBox.height())
902 // recommend landscape
903 printer->setOrientation (QPrinter::Landscape);
905 // recommend portrait
906 printer->setOrientation (QPrinter::Portrait);
908 if ( printer->setup(this) )
909 // returns false, if printing is canceled
911 QPainter pp(printer);
913 // Don't print the visualisation of selection
914 LinkableMapObj *oldselection=NULL;
917 oldselection=selection;
918 selection->unselect();
921 // Handle sizes of map and paper:
923 // setWindow defines which part of the canvas will be transformed
924 // setViewport defines area on paper in device coordinates (dpi)
925 // e.g. (0,50,700,700) is upper part on A4
926 // see also /usr/lib/qt3/doc/html/coordsys.html
928 QPaintDeviceMetrics metrics (printer);
930 double paperAspect = (double)metrics.width() / (double)metrics.height();
931 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
933 QRect mapRect=totalBBox;
934 QCanvasRectangle *frame=NULL;
935 QCanvasText *footerFN=NULL;
936 QCanvasText *footerDate=NULL;
937 if (printFrame || printFooter)
942 // Print frame around map
943 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
944 totalBBox.width()+20, totalBBox.height()+20);
945 frame=new QCanvasRectangle (mapRect,mapCanvas);
946 frame->setBrush (QColor(white));
947 frame->setPen (QColor(black));
951 /* TODO remove after testing
952 QCanvasLine *l=new QCanvasLine (mapCanvas);
953 l->setPoints (0,0,mapRect.width(),mapRect.height());
954 l->setPen (QPen(QColor(black), 1));
961 // Print footer below map
963 font.setPointSize(10);
964 footerFN=new QCanvasText (mapCanvas);
965 footerFN->setText ("VYM - " + fileName);
966 footerFN->setFont(font);
967 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
968 footerFN->setZ(Z_TEXT);
970 footerDate=new QCanvasText (mapCanvas);
971 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
972 footerDate->setFont(font);
973 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
974 footerDate->setZ(Z_TEXT);
977 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
980 pp.setWindow (mapRect);
983 if (mapAspect>=paperAspect)
985 // Fit horizontally to paper width
986 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
989 // Fit vertically to paper height
990 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
993 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
995 // Delete Frame and footer
1001 if (frame) delete (frame);
1003 // Restore selection
1006 selection=oldselection;
1007 selection->select();
1010 // Save settings in vymrc
1011 settings.writeEntry("/vym/mainwindow/printerName",printer->printerName());
1015 QPixmap MapEditor::getPixmap()
1017 QRect mapRect=mapCenter->getTotalBBox();
1018 QPixmap pix (mapRect.size());
1021 // Don't print the visualisation of selection
1022 LinkableMapObj *oldselection=NULL;
1025 oldselection=selection;
1026 selection->unselect();
1029 pp.setWindow (mapRect);
1031 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
1034 // Restore selection
1037 selection=oldselection;
1038 selection->select();
1044 void MapEditor::exportImage(QString fn)
1046 // Finish open lineEdits
1047 if (lineedit) finishedLineEditNoSave();
1049 QPixmap pix (getPixmap());
1050 pix.save(fn, "PNG");
1053 void MapEditor::exportImage(QString fn, int item)
1055 // Finish open lineEdits
1056 if (lineedit) finishedLineEditNoSave();
1058 QPixmap pix (getPixmap());
1059 pix.save(fn, exportImageFormatMenu->text(item) );
1062 void MapEditor::exportASCII()
1064 // TODO still experimental
1066 ex.setMapCenter(mapCenter);
1068 QFileDialog *fd=new QFileDialog( this, __VYM " - " +tr("Export (ASCII)"));
1069 fd->addFilter ("TXT (*.txt)");
1070 fd->setCaption(__VYM " -" +tr("Export (ASCII) (still experimental)"));
1071 fd->setMode( QFileDialog::AnyFile );
1074 if ( fd->exec() == QDialog::Accepted )
1076 if (QFile (fd->selectedFile()).exists() )
1078 QMessageBox mb( __VYM,
1079 tr("The file %1 exists already.\nDo you want to overwrite it?").arg(fd->selectedFile()),
1080 QMessageBox::Warning,
1081 QMessageBox::Yes | QMessageBox::Default,
1082 QMessageBox::Cancel | QMessageBox::Escape,
1083 QMessageBox::NoButton );
1085 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
1086 mb.setButtonText( QMessageBox::No, tr("Cancel"));
1090 case QMessageBox::Yes:
1093 case QMessageBox::Cancel:
1094 // return, do nothing
1099 ex.setPath (fd->selectedFile() );
1104 void MapEditor::exportLaTeX()
1106 // TODO still experimental
1107 QFileDialog *fd=new QFileDialog( this, __VYM " - " +tr("Export (LaTex)"));
1108 fd->addFilter ("TEX (*.tex)");
1109 fd->setCaption(__VYM " - " + tr("Export (LaTex) (still experimental)"));
1110 fd->setMode( QFileDialog::AnyFile );
1113 if ( fd->exec() == QDialog::Accepted )
1115 if (QFile (fd->selectedFile()).exists() )
1117 QMessageBox mb( "VYM",
1118 tr("The file ") + fd->selectedFile() +
1119 tr(" exists already. Do you want to overwrite it?"),
1120 QMessageBox::Warning,
1121 QMessageBox::Yes | QMessageBox::Default,
1122 QMessageBox::Cancel | QMessageBox::Escape,
1123 QMessageBox::NoButton );
1125 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
1126 mb.setButtonText( QMessageBox::No, tr("Cancel"));
1130 case QMessageBox::Yes:
1133 case QMessageBox::Cancel:
1140 ex.setPath (fd->selectedFile() );
1141 ex.setMapCenter(mapCenter);
1146 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
1150 ex.setConfigFile(cf);
1151 ex.setMapCenter(mapCenter);
1152 ex.exportPresentation();
1157 void MapEditor::exportXML(const QString &dir)
1159 // Create subdirectories
1162 // write to directory
1163 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1166 file.setName ( dir + "/"+mapName+".xml");
1167 if ( !file.open( IO_WriteOnly ) )
1169 // This should neverever happen
1170 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1174 // Write it finally, and write in UTF8, no matter what
1175 QTextStream ts( &file );
1176 ts.setEncoding (QTextStream::UnicodeUTF8);
1180 // Now write image, too
1181 exportImage (dir+"/images/"+mapName+".png");
1184 void MapEditor::clear()
1188 selection->unselect();
1195 void MapEditor::copy()
1197 // Finish open lineEdits
1198 if (lineedit) finishedLineEditNoSave();
1202 // write to directory
1203 QString clipfile="part";
1204 QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPoint(),selection);
1207 file.setName ( clipboardDir + "/"+clipfile+".xml");
1208 if ( !file.open( IO_WriteOnly ) )
1210 // This should neverever happen
1211 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1215 // Write it finally, and write in UTF8, no matter what
1216 QTextStream ts( &file );
1217 ts.setEncoding (QTextStream::UnicodeUTF8);
1221 clipboardEmpty=false;
1226 void MapEditor::redo()
1228 // Finish open lineEdits
1229 if (lineedit) finishedLineEditNoSave();
1231 blockSaveState=true;
1233 // Find out current undo directory
1234 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
1236 // Restore variables
1237 QString undoCommand;
1238 QString undoSelection;
1239 QString redoCommand;
1240 QString redoSelection;
1242 set.readSettings(QString(bakMapDir+"/commands"));
1243 undoCommand=set.readEntry ("undoCommand");
1244 undoSelection=set.readEntry ("undoSelection");
1245 redoCommand=set.readEntry ("redoCommand");
1246 redoSelection=set.readEntry ("redoSelection");
1248 // select object before redo
1249 if (!redoSelection.isEmpty())
1250 select (redoSelection);
1252 /* TODO remove testing
1253 cout << "ME::redo() begin\n";
1254 cout << " undosTotal="<<undosTotal<<endl;
1255 cout << " undosAvail="<<undosAvail<<endl;
1256 cout << " undoNum="<<undoNum<<endl;
1257 cout << " ---------------------------"<<endl;
1258 cout << " undoCom="<<undoCommand<<endl;
1259 cout << " undoSel="<<undoSelection<<endl;
1260 cout << " ---------------------------"<<endl;
1261 cout << " redoCom="<<redoCommand<<endl;
1262 cout << " redoSel="<<redoSelection<<endl;
1263 cout << " ---------------------------"<<endl;
1265 parseAtom (undoCommand);
1266 mapCenter->reposition();
1268 //if (!redoSelection.isEmpty())
1269 // select (redoSelection);
1273 // Undo not longer available now
1274 actionEditUndo->setEnabled (false);
1276 undoNum--; if (undoNum<1) undoNum=undosTotal;
1278 blockSaveState=false;
1279 /* TODO remove testing
1280 cout << "ME::redo() end\n";
1281 cout << " undosAvail="<<undosAvail<<endl;
1282 cout << " undoNum="<<undoNum<<endl;
1283 cout << " ---------------------------"<<endl<<endl;
1287 void MapEditor::undo()
1289 // Finish open lineEdits
1290 if (lineedit) finishedLineEditNoSave();
1292 blockSaveState=true;
1294 // Find out current undo directory
1295 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
1297 // Restore variables
1298 QString undoCommand;
1299 QString undoSelection;
1300 QString redoCommand;
1301 QString redoSelection;
1303 set.readSettings(QString(bakMapDir+"/commands"));
1304 undoCommand= set.readEntry ("undoCommand");
1305 undoSelection=set.readEntry ("undoSelection");
1306 redoCommand= set.readEntry ("redoCommand");
1307 redoSelection=set.readEntry ("redoSelection");
1309 // select object before undo
1310 if (!undoSelection.isEmpty())
1311 select (undoSelection);
1314 cout << "ME::undo() begin\n";
1315 cout << " undosTotal="<<undosTotal<<endl;
1316 cout << " undosAvail="<<undosAvail<<endl;
1317 cout << " undoNum="<<undoNum<<endl;
1318 cout << " ---------------------------"<<endl;
1319 cout << " undoCom="<<undoCommand<<endl;
1320 cout << " undoSel="<<undoSelection<<endl;
1321 cout << " ---------------------------"<<endl;
1322 cout << " redoCom="<<redoCommand<<endl;
1323 cout << " redoSel="<<redoSelection<<endl;
1324 cout << " ---------------------------"<<endl;
1326 parseAtom (undoCommand);
1327 mapCenter->reposition();
1329 //if (!redoSelection.isEmpty())
1330 // select (redoSelection);
1334 // Undo not longer available now
1335 actionEditUndo->setEnabled (false);
1337 undoNum--; if (undoNum<1) undoNum=undosTotal;
1339 blockSaveState=false;
1340 /* TODO remove testing
1341 cout << "ME::undo() end\n";
1342 cout << " undosAvail="<<undosAvail<<endl;
1343 cout << " undoNum="<<undoNum<<endl;
1344 cout << " ---------------------------"<<endl<<endl;
1348 void MapEditor::undoXML(const QString &undoSel, const QString &bakMapPath)
1350 QString bakMapDir=bakMapPath.left(bakMapPath.findRev("/"));
1352 QFile file (bakMapPath);
1356 // We need to parse saved XML data
1357 mapBuilderHandler handler;
1358 QXmlInputSource source( file);
1359 QXmlSimpleReader reader;
1360 reader.setContentHandler( &handler );
1361 reader.setErrorHandler( &handler );
1362 handler.setMapEditor( this );
1363 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1364 if (undoSel.isEmpty())
1368 handler.setLoadMode (NewMap);
1372 handler.setLoadMode (ImportReplace);
1374 blockReposition=true;
1375 bool ok = reader.parse( source );
1376 blockReposition=false;
1379 // This should never ever happen
1380 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1381 tr( handler.errorProtocol() )+" in "+bakMapDir );
1385 QMessageBox::critical( 0, tr( "Critical Error" ),
1386 tr("Temporary directory %1 used for undo is gone. \n"
1387 "I will create a new one, but at the moment no undo is available.\n"
1388 "Maybe you want to reload your original data.\n\n"
1389 "Sorry for any inconveniences.").arg(bakMapDir) );
1394 void MapEditor::pasteNoSave()
1396 // Finish open lineEdits
1397 if (lineedit) finishedLineEditNoSave();
1399 load (clipboardDir+"/part.xml",ImportAdd);
1402 void MapEditor::cutNoSave()
1408 void MapEditor::paste()
1410 if (selection && (typeid(*selection) == typeid(BranchObj) ||
1411 typeid(*selection) == typeid(MapCenterObj)))
1413 saveState(selection);
1415 mapCenter->reposition();
1420 void MapEditor::cut()
1422 saveState(selection->getParObj());
1425 mapCenter->reposition();
1429 void MapEditor::move(const int &x, const int &y)
1431 // TODO no saveState, because this is only internal at undo so far
1432 if (selection) selection->move(x,y);
1433 if (typeid(*selection) == typeid(FloatImageObj))
1434 ((FloatImageObj*)selection)->setRelPos();
1437 void MapEditor::moveBranchUp()
1439 // Finish open lineEdits
1440 if (lineedit) finishedLineEditNoSave();
1444 if (typeid(*selection) == typeid(BranchObj) )
1446 bo=(BranchObj*)selection;
1447 par=(BranchObj*)(bo->getParObj());
1448 selection->unselect();
1449 selection=par->moveBranchUp (bo);
1450 selection->select();
1451 saveState("moveBranchDown ()",bo);
1452 mapCenter->reposition();
1453 ensureSelectionVisible();
1457 void MapEditor::moveBranchDown()
1459 // Finish open lineEdits
1460 if (lineedit) finishedLineEditNoSave();
1464 if (typeid(*selection) == typeid(BranchObj) )
1466 bo=(BranchObj*)selection;
1467 par=(BranchObj*)(bo->getParObj());
1468 selection->unselect();
1469 selection=par->moveBranchDown(bo);
1470 selection->select();
1471 saveState("moveBranchUp ()",bo);
1472 mapCenter->reposition();
1473 ensureSelectionVisible();
1477 void MapEditor::editHeading()
1479 // Finish open lineEdits
1480 if (lineedit) finishedLineEditNoSave();
1483 (typeid(*selection) == typeid(BranchObj) ||
1484 typeid(*selection) == typeid(MapCenterObj) ) )
1486 editingBO=(BranchObj*)selection;
1487 saveState("setHeading (\""+((BranchObj*)selection)->getHeading()+"\")",editingBO );
1489 ensureSelectionVisible();
1490 QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
1491 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1492 QString s=editingBO->getHeading();
1493 lineedit->setText(s);
1494 lineedit->setCursorPosition(1);
1495 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1496 lineedit->selectAll();
1498 lineedit->grabKeyboard();
1499 lineedit->setFocus();
1503 void MapEditor::setHeading(const QString &s)
1505 // Internal function, no saveState needed
1507 (typeid(*selection) == typeid(BranchObj) ||
1508 typeid(*selection) == typeid(MapCenterObj) ) )
1510 ((BranchObj*)selection)->setHeading(s);
1511 mapCenter->reposition();
1513 ensureSelectionVisible();
1517 void MapEditor::setURL (const QString &s)
1519 // Internal function, no saveState needed
1521 (typeid(*selection) == typeid(BranchObj) ||
1522 typeid(*selection) == typeid(MapCenterObj) ) )
1524 ((BranchObj*)selection)->setURL(s);
1525 mapCenter->reposition();
1527 ensureSelectionVisible();
1531 void MapEditor::setVymLink (const QString &s)
1533 // Internal function, no saveState needed
1535 (typeid(*selection) == typeid(BranchObj) ||
1536 typeid(*selection) == typeid(MapCenterObj) ) )
1538 ((BranchObj*)selection)->setVymLink(s);
1539 mapCenter->reposition();
1541 ensureSelectionVisible();
1545 void MapEditor::addNewBranch(int pos)
1547 // Finish open lineEdits
1548 if (lineedit) finishedLineEditNoSave();
1551 (typeid(*selection) == typeid(BranchObj) ||
1552 typeid(*selection) == typeid(MapCenterObj) ) )
1554 saveState(selection); //TODO undoCommand
1556 BranchObj* bo1 = (BranchObj*) selection;
1557 bool wasScrolled=false;
1558 BranchObj *newbo=NULL;
1561 // save scroll state. If scrolled, automatically select
1562 // new branch in order to tmp unscroll parent...
1563 wasScrolled=bo1->isScrolled();
1564 newbo=bo1->addBranch();
1567 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1571 // add above selection
1572 newbo=parbo->insertBranch(bo1->getNum());
1574 // add below selection
1575 newbo=parbo->insertBranch(bo1->getNum()+1);
1577 // This should not happen...
1582 LinkableMapObj *oldselection=selection;
1584 mapCenter->reposition();
1586 if (actionSettingsAutoedit->isOn() ||
1587 actionSettingsAutoselectHeading->isOn() )
1589 selection->unselect();
1591 selection->select();
1592 if (actionSettingsPasteNewHeading->isOn() )
1594 BranchObj *bo2= (BranchObj*)selection;
1595 bo2->setHeading("");
1597 if (actionSettingsAutoedit->isOn() )
1599 if (!actionSettingsAutoselectHeading->isOn()
1602 selection->unselect();
1603 selection=oldselection;
1604 selection->select();
1611 void MapEditor::addNewBranchHere()
1613 // Finish open lineEdits
1614 if (lineedit) finishedLineEditNoSave();
1617 (typeid(*selection) == typeid(BranchObj) ) )
1619 saveState(selection);
1621 BranchObj* bo1 = (BranchObj*) selection;
1622 bool wasScrolled=false;
1623 BranchObj *newbo=NULL;
1624 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1627 // add below selection
1628 newbo=parbo->insertBranch(bo1->getNum()+1);
1631 LinkableMapObj *oldselection=selection;
1632 ((BranchObj*)selection)->moveBranchTo (newbo,-1);
1634 mapCenter->reposition();
1636 if (actionSettingsAutoedit->isOn() ||
1637 actionSettingsAutoselectHeading->isOn() )
1639 selection->unselect();
1641 selection->select();
1642 if (actionSettingsPasteNewHeading->isOn() )
1644 BranchObj *bo2= (BranchObj*)selection;
1645 bo2->setHeading("");
1647 if (actionSettingsAutoedit->isOn() )
1649 if (!actionSettingsAutoselectHeading->isOn()
1652 selection->unselect();
1653 selection=oldselection;
1654 selection->select();
1660 void MapEditor::deleteSelection()
1662 // Finish open lineEdits
1663 if (lineedit) finishedLineEditNoSave();
1665 if (selection && typeid(*selection) ==typeid(BranchObj) )
1667 if (selection->getDepth()>1)
1668 // Normal branch, save parent with childs
1669 saveState(selection->getParObj());
1671 // Mainbranch, save whole map
1672 // TODO Better would be to insert mainbranch again at pos
1673 // But undoCommand is missing right now
1675 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1676 BranchObj* par=(BranchObj*)(bo->getParObj());
1679 par->removeBranch(bo);
1681 selection->select();
1682 ensureSelectionVisible();
1683 mapCenter->reposition();
1686 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1688 saveState(selection->getParObj());
1689 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1690 BranchObj* par=(BranchObj*)(fio->getParObj());
1693 par->removeFloatImage(fio);
1695 selection->select();
1696 ensureSelectionVisible();
1697 mapCenter->reposition();
1702 LinkableMapObj* MapEditor::getSelection()
1707 bool MapEditor::select (const QString &s)
1709 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
1711 // Finally select the found object
1714 if (selection) unselect();
1716 selection->select();
1718 ensureSelectionVisible();
1724 void MapEditor::unselect()
1728 selectionLast=selection;
1729 selection->unselect();
1734 void MapEditor::reselect()
1738 selection=selectionLast;
1739 selection->select();
1744 void MapEditor::selectNextBranch()
1746 // Increase number of branch
1749 QString s=selection->getSelectString();
1755 part=s.section(",",-1);
1757 num=part.right(part.length() - 3);
1759 s=s.left (s.length() -num.length());
1762 num=QString ("%1").arg(num.toUInt()+1);
1766 // Try to select this one
1767 if (select (s)) return;
1769 // We have no direct successor,
1770 // try to increase the parental number in order to
1771 // find a successor with same depth
1773 int d=selection->getDepth();
1778 while (!found && d>0)
1780 s=s.section (",",0,d-1);
1781 // replace substring of current depth in s with "1"
1782 part=s.section(",",-1);
1784 num=part.right(part.length() - 3);
1788 // increase number of parent
1789 num=QString ("%1").arg(num.toUInt()+1);
1790 s=s.section (",",0,d-2) + ","+ typ+num;
1793 // Special case, look at orientation
1794 if (selection->getOrientation()==OrientRightOfCenter)
1795 num=QString ("%1").arg(num.toUInt()+1);
1797 num=QString ("%1").arg(num.toUInt()-1);
1802 // pad to oldDepth, select the first branch for each depth
1803 for (i=d;i<oldDepth;i++)
1808 if ( ((BranchObj*)selection)->countBranches()>0)
1816 // try to select the freshly built string
1824 void MapEditor::selectPrevBranch()
1826 // Decrease number of branch
1829 QString s=selection->getSelectString();
1835 part=s.section(",",-1);
1837 num=part.right(part.length() - 3);
1839 s=s.left (s.length() -num.length());
1842 num=QString ("%1").arg(num.toUInt()-1);
1846 // Try to select this one
1847 if (select (s)) return;
1849 // We have no direct precessor,
1850 // try to decrease the parental number in order to
1851 // find a precessor with same depth
1853 int d=selection->getDepth();
1858 while (!found && d>0)
1860 s=s.section (",",0,d-1);
1861 // replace substring of current depth in s with "1"
1862 part=s.section(",",-1);
1864 num=part.right(part.length() - 3);
1868 // decrease number of parent
1869 num=QString ("%1").arg(num.toUInt()-1);
1870 s=s.section (",",0,d-2) + ","+ typ+num;
1873 // Special case, look at orientation
1874 if (selection->getOrientation()==OrientRightOfCenter)
1875 num=QString ("%1").arg(num.toUInt()-1);
1877 num=QString ("%1").arg(num.toUInt()+1);
1882 // pad to oldDepth, select the last branch for each depth
1883 for (i=d;i<oldDepth;i++)
1887 if ( ((BranchObj*)selection)->countBranches()>0)
1888 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)selection)->countBranches()-1 );
1895 // try to select the freshly built string
1903 void MapEditor::selectUpperBranch()
1905 // Finish open lineEdits
1906 if (lineedit) finishedLineEditNoSave();
1910 if (typeid(*selection) == typeid(BranchObj))
1912 if (selection->getOrientation()==OrientRightOfCenter)
1915 if (selection->getDepth()==1)
1923 void MapEditor::selectLowerBranch()
1925 // Finish open lineEdits
1926 if (lineedit) finishedLineEditNoSave();
1930 if (typeid(*selection) == typeid(BranchObj))
1932 if (selection->getOrientation()==OrientRightOfCenter)
1935 if (selection->getDepth()==1)
1944 void MapEditor::selectLeftBranch()
1946 // Finish open lineEdits
1947 if (lineedit) finishedLineEditNoSave();
1953 if (typeid(*selection) == typeid(MapCenterObj))
1955 par= (BranchObj*) selection;
1956 bo=par->getLastSelectedBranch();
1959 // Workaround for reselecting on left and right side
1960 if (bo->getOrientation()==OrientRightOfCenter)
1962 bo=par->getLastBranch();
1968 selection->select();
1970 ensureSelectionVisible();
1975 par=(BranchObj*)(selection->getParObj());
1976 if (selection->getOrientation()==OrientRightOfCenter)
1978 if (typeid(*selection) == typeid(BranchObj) ||
1979 typeid(*selection) == typeid(FloatImageObj))
1981 selection->unselect();
1983 selection->select();
1985 ensureSelectionVisible();
1989 if (typeid(*selection) == typeid(BranchObj) )
1991 bo=((BranchObj*)selection)->getLastSelectedBranch();
1994 selection->unselect();
1996 selection->select();
1998 ensureSelectionVisible();
2006 void MapEditor::selectRightBranch()
2008 // Finish open lineEdits
2009 if (lineedit) finishedLineEditNoSave();
2016 if (typeid(*selection) == typeid(MapCenterObj))
2018 par= (BranchObj*) selection;
2019 bo=par->getLastSelectedBranch();
2022 // Workaround for relecting on left and right side
2023 if (bo->getOrientation()==OrientLeftOfCenter)
2024 bo=par->getFirstBranch();
2029 selection->select();
2030 ensureSelectionVisible();
2035 par=(BranchObj*)(selection->getParObj());
2036 if (selection->getOrientation()==OrientLeftOfCenter)
2038 if (typeid(*selection) == typeid(BranchObj) ||
2039 typeid(*selection) == typeid(FloatImageObj))
2041 selection->unselect();
2043 selection->select();
2045 ensureSelectionVisible();
2049 if (typeid(*selection) == typeid(BranchObj) )
2051 bo=((BranchObj*)selection)->getLastSelectedBranch();
2054 selection->unselect();
2056 selection->select();
2058 ensureSelectionVisible();
2066 void MapEditor::selectFirstBranch()
2068 // Finish open lineEdits
2069 if (lineedit) finishedLineEditNoSave();
2075 if (typeid(*selection) == typeid(BranchObj))
2077 bo1= (BranchObj*) selection;
2078 par=(BranchObj*)(bo1->getParObj());
2079 bo2=par->getFirstBranch();
2083 selection->select();
2084 ensureSelectionVisible();
2091 void MapEditor::selectLastBranch()
2093 // Finish open lineEdits
2094 if (lineedit) finishedLineEditNoSave();
2100 if (typeid(*selection) == typeid(BranchObj))
2102 bo1= (BranchObj*) selection;
2103 par=(BranchObj*)(bo1->getParObj());
2104 bo2=par->getLastBranch();
2108 selection->select();
2109 ensureSelectionVisible();
2116 void MapEditor::setColor(QColor c)
2121 void MapEditor::selectBackgroundColor()
2123 // Finish open lineEdits
2124 if (lineedit) finishedLineEditNoSave();
2126 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
2127 if ( !col.isValid() ) return;
2128 setBackgroundColor( col );
2132 void MapEditor::setBackgroundColor(QColor c)
2134 mapCanvas->setBackgroundColor (c);
2137 QColor MapEditor::pickColor()
2141 if (typeid(*selection) == typeid(BranchObj) ||
2142 typeid(*selection) == typeid(MapCenterObj))
2144 BranchObj *bo=(BranchObj*)selection;
2145 actColor=bo->getColor();
2151 void MapEditor::colorItem()
2155 if (typeid(*selection) == typeid(BranchObj) ||
2156 typeid(*selection) == typeid(MapCenterObj))
2158 saveState(selection); //TODO undoCommand
2159 BranchObj *bo=(BranchObj*)selection;
2160 bo->setColor(actColor, false); // color links, color childs
2165 void MapEditor::colorBranch()
2169 if (typeid(*selection) == typeid(BranchObj) ||
2170 typeid(*selection) == typeid(MapCenterObj))
2172 saveState(selection); //TODO undoCommand
2173 BranchObj *bo=(BranchObj*)selection;
2174 bo->setColor(actColor, true); // color links, color childs
2180 void MapEditor::toggleStandardFlag(QString f)
2184 saveState(selection);// TODO undoCommand
2185 ((BranchObj*)selection)->toggleStandardFlag (f,actionSettingsUseFlagGroups);
2189 void MapEditor::setViewCenter()
2191 // transform to CanvasView Coord:
2192 QPoint p=worldMatrix().map(movingCenter);
2193 center ( p.x(), p.y());
2197 BranchObj* MapEditor::findText (QString s, bool cs)
2200 { // Nothing found or new find process
2202 // nothing found, start again
2204 itFind=mapCenter->first();
2206 bool searching=true;
2207 bool foundNote=false;
2208 while (searching && !EOFind)
2212 // Searching in Note
2213 if (itFind->getNote().contains(s,cs))
2215 if (selection!=itFind)
2217 if (selection) ((BranchObj*)selection)->unselect();
2219 selection->select();
2221 ensureSelectionVisible();
2223 if (textEditor->findText(s,cs))
2229 // Searching in Heading
2230 if (searching && itFind->getHeading().contains (s,cs) )
2232 if (selection) ((BranchObj*)selection)->unselect();
2234 selection->select();
2236 ensureSelectionVisible();
2242 itFind=itFind->next();
2243 if (!itFind) EOFind=true;
2249 return (BranchObj*)selection;
2254 void MapEditor::findReset()
2255 { // Necessary if text to find changes during a find process
2260 void MapEditor::openURL()
2264 if (typeid(*selection) == typeid(BranchObj) ||
2265 typeid(*selection) == typeid(MapCenterObj))
2267 QString url=((BranchObj*)selection)->getURL();
2269 QProcess *proc = new QProcess( this );
2271 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL" ));
2272 proc->addArgument( url);
2274 if ( !proc->start() )
2276 if (mainWindow->settingsURL() )
2282 void MapEditor::editURL()
2284 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2285 typeid(*selection) == typeid(MapCenterObj)) )
2288 BranchObj *bo=(BranchObj*)selection;
2289 QString text = QInputDialog::getText(
2290 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2291 bo->getURL(), &ok, this );
2294 // user entered something and pressed OK
2295 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+text+"\")");
2302 void MapEditor::editHeading2URL()
2304 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2305 typeid(*selection) == typeid(MapCenterObj)) )
2307 BranchObj *bo=(BranchObj*)selection;
2308 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+bo->getHeading()+"\")");
2309 bo->setURL (bo->getHeading());
2314 void MapEditor::editBugzilla2URL()
2316 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2317 typeid(*selection) == typeid(MapCenterObj)) )
2319 BranchObj *bo=(BranchObj*)selection;
2320 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2321 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")");
2327 void MapEditor::editFATE2URL()
2329 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2330 typeid(*selection) == typeid(MapCenterObj)) )
2332 BranchObj *bo=(BranchObj*)selection;
2333 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2334 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")");
2340 void MapEditor::editVymLink()
2342 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2343 typeid(*selection) == typeid(MapCenterObj)) )
2345 BranchObj *bo=(BranchObj*)selection;
2346 QFileDialog *fd=new QFileDialog( this,__VYM " - " +tr("Link to another map"));
2347 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2348 fd->setCaption(__VYM " - " +tr("Link to another map"));
2349 if (! bo->getVymLink().isEmpty() )
2350 fd->setSelection( bo->getVymLink() );
2354 if ( fd->exec() == QDialog::Accepted )
2356 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\""+fd->selectedFile()+"\")");
2357 bo->setVymLink (fd->selectedFile() );
2359 mapCenter->reposition();
2366 void MapEditor::deleteVymLink()
2368 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2369 typeid(*selection) == typeid(MapCenterObj)) )
2371 BranchObj *bo=(BranchObj*)selection;
2372 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\"\")");
2373 bo->setVymLink ("" );
2375 mapCenter->reposition();
2381 QString MapEditor::getVymLink()
2383 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2384 typeid(*selection) == typeid(MapCenterObj)) )
2386 return ((BranchObj*)selection)->getVymLink();
2392 void MapEditor::removeBranchHere()
2394 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2396 BranchObj* bo=(BranchObj*)selection;
2397 BranchObj* par=(BranchObj*)(bo->getParObj());
2398 if (bo->getDepth()==1)
2401 saveState(selection->getParObj()); // TODO undoCommand
2402 QString sel=selection->getSelectString();
2404 par->removeBranchHere(bo);
2405 mapCenter->reposition();
2410 void MapEditor::removeChilds()
2412 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2414 saveState(selection->getParObj());
2415 ((BranchObj*)selection)->removeChilds();
2416 mapCenter->reposition();
2420 void MapEditor::editMapInfo()
2422 ExtraInfoDialog dia;
2423 dia.setMapName (getFileName() );
2424 dia.setAuthor (mapCenter->getAuthor() );
2425 dia.setComment(mapCenter->getComment() );
2430 QCanvasItemList l=canvas()->allItems();
2431 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2433 stats+=QString ("%1 items on canvas\n").arg (i,6);
2440 bo=mapCenter->first();
2443 if (!bo->getNote().isEmpty() ) n++;
2444 f+= bo->countFloatImages();
2446 xl+=bo->countXLinks();
2449 stats+=QString ("%1 branches\n").arg (b-1,6);
2450 stats+=QString ("%1 xLinks \n").arg (xl,6);
2451 stats+=QString ("%1 notes\n").arg (n,6);
2452 stats+=QString ("%1 images\n").arg (f,6);
2453 dia.setStats (stats);
2455 // Finally show dialog
2456 if (dia.exec() == QDialog::Accepted)
2458 saveState(); //TODO undoCommand
2459 mapCenter->setAuthor (dia.getAuthor() );
2460 mapCenter->setComment (dia.getComment() );
2464 void MapEditor::updateActions()
2467 if (getLinkColorHint()==HeadingColor)
2468 actionFormatLinkColorHint->setOn(true);
2470 actionFormatLinkColorHint->setOn(false);
2475 actionFormatLinkStyleLine->setOn(true);
2478 actionFormatLinkStyleParabel->setOn(true);
2481 actionFormatLinkStylePolyLine->setOn(true);
2483 case StylePolyParabel:
2484 actionFormatLinkStylePolyParabel->setOn(true);
2490 QPixmap pix( 16, 16 );
2491 pix.fill( mapCanvas->backgroundColor() );
2492 actionFormatBackColor->setIconSet( pix );
2493 pix.fill( defLinkColor );
2494 actionFormatLinkColor->setIconSet( pix );
2496 actionEditUndo->setEnabled( mapChanged );
2497 actionFileSave->setEnabled( mapUnsaved );
2501 if ( (typeid(*selection) == typeid(BranchObj)) ||
2502 (typeid(*selection) == typeid(MapCenterObj)) )
2504 BranchObj *bo=(BranchObj*)selection;
2505 // Take care of links
2506 if (bo->countXLinks()==0)
2508 branchLinksContextMenu->clear();
2509 branchLinksContextMenu->insertItem ("No xLink available");
2510 branchLinksContextMenuDup->clear();
2511 branchLinksContextMenuDup->insertItem ("No xLink available");
2517 branchLinksContextMenu->clear();
2518 branchLinksContextMenuDup->clear();
2519 for (int i=0; i<=bo->countXLinks();i++)
2521 bot=bo->XLinkTargetAt(i);
2524 s=bot->getHeading();
2527 branchLinksContextMenu->insertItem (s);
2528 branchLinksContextMenuDup->insertItem (s);
2533 standardFlagsDefault->setEnabled (true);
2535 if ( bo->getURL().isEmpty() )
2536 actionEditOpenURL->setEnabled (false);
2538 actionEditOpenURL->setEnabled (true);
2540 if ( bo->getVymLink().isEmpty() )
2542 actionEditOpenVymLink->setEnabled (false);
2543 actionEditDeleteVymLink->setEnabled (false);
2546 actionEditOpenVymLink->setEnabled (true);
2547 actionEditDeleteVymLink->setEnabled (true);
2550 actionEditCopy->setEnabled (true);
2551 actionEditCut->setEnabled (true);
2552 if (!clipboardEmpty)
2553 actionEditPaste->setEnabled (true);
2555 actionEditPaste->setEnabled (false);
2556 for (a=actionListBranches.first();a;a=actionListBranches.next())
2557 a->setEnabled(true);
2558 actionEditDelete->setEnabled (true);
2559 actionEditToggleFloatExport->setEnabled (false);
2560 switch (selection->getFrameType())
2563 actionFormatFrameNone->setOn(true);
2566 actionFormatFrameRectangle->setOn(true);
2571 actionFormatIncludeImagesVer->setOn
2572 ( ((BranchObj*)selection)->getIncludeImagesVer());
2573 actionFormatIncludeImagesHor->setOn
2574 ( ((BranchObj*)selection)->getIncludeImagesHor());
2575 actionFormatHideLinkUnselected->setOn
2576 (selection->getHideLinkUnselected());
2578 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2580 standardFlagsDefault->setEnabled (false);
2582 actionEditOpenURL->setEnabled (false);
2583 actionEditOpenVymLink->setEnabled (false);
2584 actionEditDeleteVymLink->setEnabled (false);
2586 actionEditCopy->setEnabled (true);
2587 actionEditCut->setEnabled (true);
2588 actionEditPaste->setEnabled (false); //FIXME
2589 for (a=actionListBranches.first();a;a=actionListBranches.next())
2590 a->setEnabled(false);
2591 actionEditDelete->setEnabled (true);
2592 actionEditToggleFloatExport->setOn
2593 ( ((FloatImageObj*)selection)->getFloatExport() );
2594 actionFormatHideLinkUnselected->setOn
2595 ( selection->getHideLinkUnselected());
2600 standardFlagsDefault->setEnabled (false);
2602 actionEditCopy->setEnabled (false);
2603 actionEditCut->setEnabled (false);
2604 actionEditPaste->setEnabled (false);
2605 for (a=actionListBranches.first();a;a=actionListBranches.next())
2606 a->setEnabled(false);
2608 actionEditOpenURL->setEnabled (false);
2609 actionEditOpenVymLink->setEnabled (false);
2610 actionEditDeleteVymLink->setEnabled (false);
2611 actionEditHeading2URL->setEnabled (false);
2612 actionEditDelete->setEnabled (false);
2613 actionEditToggleFloatExport->setEnabled (false);
2617 void MapEditor::updateNoteFlag()
2620 if ( (typeid(*selection) == typeid(BranchObj)) ||
2621 (typeid(*selection) == typeid(MapCenterObj)) )
2622 ((BranchObj*)selection)->updateNoteFlag();
2625 void MapEditor::setLinkStyle (LinkStyle ls)
2629 saveState(); // TODO undoCommand
2631 bo=mapCenter->first();
2635 bo->setLinkStyle(bo->getDefLinkStyle());
2638 mapCenter->reposition();
2641 LinkStyle MapEditor::getLinkStyle ()
2646 void MapEditor::setLinkColor(QColor c)
2652 void MapEditor::setLinkColorHint()
2654 // called from setLinkColorHint(lch) or at end of parse
2656 bo=mapCenter->first();
2664 void MapEditor::setLinkColorHint(LinkColorHint lch)
2670 void MapEditor::toggleLinkColorHint()
2672 if (linkcolorhint==HeadingColor)
2673 linkcolorhint=DefaultColor;
2675 linkcolorhint=HeadingColor;
2677 bo=mapCenter->first();
2685 LinkColorHint MapEditor::getLinkColorHint()
2687 return linkcolorhint;
2690 QColor MapEditor::getDefLinkColor()
2692 return defLinkColor;
2695 void MapEditor::setDefXLinkColor(QColor col)
2700 QColor MapEditor::getDefXLinkColor()
2702 return defXLinkColor;
2705 void MapEditor::setDefXLinkWidth (int w)
2710 int MapEditor::getDefXLinkWidth()
2712 return defXLinkWidth;
2715 void MapEditor::selectLinkColor()
2717 // Finish open lineEdits
2718 if (lineedit) finishedLineEditNoSave();
2720 QColor col = QColorDialog::getColor( defLinkColor, this );
2721 if ( !col.isValid() ) return;
2722 setLinkColor( col );
2723 saveState(); //TODO undoCommand
2727 void MapEditor::toggleScroll()
2729 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2731 BranchObj *bo=((BranchObj*)selection);
2732 if (bo->countBranches()==0) return;
2733 if (bo->getDepth()==0) return;
2734 saveState(selection);
2741 void MapEditor::unScrollAll()
2744 bo=mapCenter->first();
2747 if (bo->isScrolled()) bo->toggleScroll();
2752 void MapEditor::loadFloatImage ()
2755 (typeid(*selection) == typeid(BranchObj)) ||
2756 (typeid(*selection) == typeid(MapCenterObj)) )
2758 BranchObj *bo=((BranchObj*)selection);
2760 QFileDialog *fd=new QFileDialog( this,QString ("vym - ")+tr("Load image"));
2761 fd->setMode (QFileDialog::ExistingFiles);
2762 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2763 ImagePreview *p =new ImagePreview (fd);
2764 fd->setContentsPreviewEnabled( TRUE );
2765 fd->setContentsPreview( p, p );
2766 fd->setPreviewMode( QFileDialog::Contents );
2767 fd->setCaption(__VYM " - " +tr("Load image"));
2768 fd->setDir (lastImageDir);
2772 if ( fd->exec() == QDialog::Accepted )
2774 saveState(selection);
2775 lastImageDir=fn.left(fn.findRev ("/"));
2776 QStringList flist = fd->selectedFiles();
2777 QStringList::Iterator it = flist.begin();
2778 while( it != flist.end() )
2781 bo->addFloatImage();
2782 // TODO check if load was successful
2783 bo->getLastFloatImage()->load(*it);
2784 bo->getLastFloatImage()->setOriginalFilename(fn);
2788 mapCenter->reposition();
2795 void MapEditor::saveFloatImage (int item)
2798 (typeid(*selection) == typeid(FloatImageObj)) )
2800 FloatImageObj *fio=((FloatImageObj*)selection);
2801 const char* fmt = saveImageFormatMenu->text(item);
2803 QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
2804 fd->addFilter ("PNG (*.png)");
2805 fd->addFilter ("BMP (*.bmp)");
2806 fd->addFilter ("XBM (*.xbm)");
2807 fd->addFilter ("JPG (*.jpg)");
2808 fd->addFilter ("XPM (*.xpm)");
2809 fd->addFilter ("GIF (*.gif)");
2810 fd->addFilter ("PNM (*.pnm)");
2811 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2812 fd->setCaption(__VYM " - " +tr("Save image as %1").arg(fmt));
2813 fd->setMode( QFileDialog::AnyFile );
2814 fd->setSelection (fio->getOriginalFilename());
2818 if ( fd->exec() == QDialog::Accepted )
2820 if (QFile (fd->selectedFile()).exists() )
2822 QMessageBox mb( __VYM,
2823 tr("The file %1 exists already.\n"
2824 "Do you want to overwrite it?").arg(fd->selectedFile()),
2825 QMessageBox::Warning,
2826 QMessageBox::Yes | QMessageBox::Default,
2827 QMessageBox::Cancel | QMessageBox::Escape,
2828 QMessageBox::QMessageBox::NoButton );
2830 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2831 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2834 case QMessageBox::Yes:
2837 case QMessageBox::Cancel:
2843 fio->save (fd->selectedFile(),fmt);
2848 void MapEditor::toggleFloatExport()
2851 (typeid(*selection) == typeid(FloatImageObj))||
2852 (typeid(*selection) == typeid(FloatObj)) )
2854 FloatImageObj *fio=((FloatImageObj*)selection);
2855 fio->setFloatExport (actionEditToggleFloatExport->isOn() );
2859 void MapEditor::setFrame(const FrameType &t)
2862 (typeid(*selection) == typeid(BranchObj)) ||
2863 (typeid(*selection) == typeid(MapCenterObj)) )
2865 selection->setFrameType (t);
2866 mapCenter->reposition();
2867 selection->updateLink();
2871 void MapEditor::setIncludeImagesVer(bool b)
2874 (typeid(*selection) == typeid(BranchObj)) ||
2875 (typeid(*selection) == typeid(MapCenterObj)) )
2876 ((BranchObj*)selection)->setIncludeImagesVer(b);
2877 mapCenter->reposition();
2880 void MapEditor::setIncludeImagesHor(bool b)
2883 (typeid(*selection) == typeid(BranchObj)) ||
2884 (typeid(*selection) == typeid(MapCenterObj)) )
2885 ((BranchObj*)selection)->setIncludeImagesHor(b);
2886 mapCenter->reposition();
2889 void MapEditor::setHideLinkUnselected (bool b)
2892 (typeid(*selection) == typeid(BranchObj)) ||
2893 (typeid(*selection) == typeid(MapCenterObj)) ||
2894 (typeid(*selection) == typeid(FloatImageObj)) )
2895 selection->setHideLinkUnselected(b);
2898 void MapEditor::importDir(BranchObj *dst, QDir d)
2901 (typeid(*selection) == typeid(BranchObj)) ||
2902 (typeid(*selection) == typeid(MapCenterObj)) )
2906 // Traverse directories
2907 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2908 const QFileInfoList *dirlist = d.entryInfoList();
2909 QFileInfoListIterator itdir( *dirlist );
2912 while ( (fi = itdir.current()) != 0 )
2914 if (fi->fileName() != "." && fi->fileName() != ".." )
2917 bo=dst->getLastBranch();
2918 bo->setHeading (fi->fileName() );
2919 bo->setColor (QColor("blue"),false);
2921 if ( !d.cd(fi->fileName()) )
2922 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi->fileName()));
2925 // Recursively add subdirs
2933 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
2934 const QFileInfoList *filelist = d.entryInfoList();
2935 QFileInfoListIterator itfile( *filelist );
2937 while ( (fi = itfile.current()) != 0 )
2940 bo=dst->getLastBranch();
2941 bo->setHeading (fi->fileName() );
2942 bo->setColor (QColor("black"),false);
2943 if (fi->fileName().right(4) == ".vym" )
2944 bo->setVymLink (fi->filePath());
2951 void MapEditor::importDir()
2954 (typeid(*selection) == typeid(BranchObj)) ||
2955 (typeid(*selection) == typeid(MapCenterObj)) )
2957 QFileDialog *fd=new QFileDialog( this,__VYM " - " +tr("Choose directory structure to import"));
2958 fd->setMode (QFileDialog::DirectoryOnly);
2959 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2960 fd->setCaption(__VYM " - " +tr("Choose directory structure to import"));
2964 if ( fd->exec() == QDialog::Accepted )
2966 BranchObj *bo=((BranchObj*)selection);
2967 importDir (bo,QDir(fd->selectedFile()) );
2968 mapCenter->reposition();
2975 void MapEditor::followXLink(int i)
2978 (typeid(*selection) == typeid(BranchObj)) ||
2979 (typeid(*selection) == typeid(MapCenterObj)) )
2981 BranchObj *bo=((BranchObj*)selection)->XLinkTargetAt(i);
2984 selection->unselect();
2986 selection->select();
2987 ensureSelectionVisible();
2992 void MapEditor::editXLink(int i)
2995 (typeid(*selection) == typeid(BranchObj)) ||
2996 (typeid(*selection) == typeid(MapCenterObj)) )
2998 XLinkObj *xlo=((BranchObj*)selection)->XLinkAt(i);
3001 EditXLinkDialog dia;
3003 dia.setSelection(selection);
3004 if (dia.exec() == QDialog::Accepted)
3006 if (dia.useSettingsGlobal() )
3008 setDefXLinkColor (xlo->getColor() );
3009 setDefXLinkWidth (xlo->getWidth() );
3011 if (dia.deleteXLink())
3012 ((BranchObj*)selection)->deleteXLinkAt(i);
3013 saveState(); //TODO undoCommand
3019 void MapEditor::testFunction()
3021 cout << "MapEditor::testFunction() called\n";
3022 if (selection && (typeid(*selection) == typeid(BranchObj)))
3024 cout << "Note:\n"<<((BranchObj*)selection)->getNoteOpenDoc()<<endl;
3028 void MapEditor::ensureSelectionVisible()
3032 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
3034 if (selection->getOrientation() == OrientLeftOfCenter)
3035 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
3037 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
3038 ensureVisible (p.x(), p.y() );
3043 void MapEditor::updateViewCenter()
3045 // Update movingCenter, so that we can zoom comfortably later
3046 QRect rc = QRect( contentsX(), contentsY(),
3047 visibleWidth(), visibleHeight() );
3048 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
3049 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
3050 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
3053 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
3055 // Lineedits are already closed by preceding
3056 // mouseEvent, we don't need to close here.
3058 QPoint p = inverseWorldMatrix().map(e->pos());
3059 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3062 { // MapObj was found
3063 if (selection != lmo)
3065 // select the MapObj
3066 if (selection) selection->unselect();
3068 selection->select();
3074 if (typeid(*selection)==typeid(BranchObj) ||
3075 typeid(*selection)==typeid(MapCenterObj) )
3077 // Context Menu on branch or mapcenter
3079 branchContextMenu->popup(e->globalPos() );
3081 if (typeid(*selection)==typeid(FloatImageObj))
3083 // Context Menu on floatimage
3085 floatimageContextMenu->popup(e->globalPos() );
3089 { // No MapObj found, we are on the Canvas itself
3090 // Context Menu on Canvas
3092 canvasContextMenu->popup(e->globalPos() );
3096 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
3098 // Finish open lineEdits
3099 if (lineedit) finishedLineEditNoSave();
3101 QPoint p = inverseWorldMatrix().map(e->pos());
3102 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3104 // Special case: CTRL is pressed
3105 if (e->state() & QMouseEvent::ControlButton)
3107 if (actionModModeColor->isOn())
3109 if (e->state() & QMouseEvent::ControlButton)
3112 setCursor (pickColorCursor);
3116 if (actionModModeLink->isOn())
3118 BranchObj *bo_begin=NULL;
3120 bo_begin=(BranchObj*)(lmo);
3123 ((typeid(*selection) == typeid(BranchObj)) ||
3124 (typeid(*selection) == typeid(MapCenterObj))) )
3125 bo_begin=(BranchObj*)selection;
3129 linkingObj_src=bo_begin;
3130 tmpXLink=new XLinkObj (mapCanvas);
3131 tmpXLink->setBegin (bo_begin);
3132 tmpXLink->setEnd (p);
3133 tmpXLink->setColor(defXLinkColor);
3134 tmpXLink->setWidth(defXLinkWidth);
3135 tmpXLink->updateXLink();
3136 tmpXLink->setVisibility (true);
3143 { // MapObj was found
3144 if (selection != lmo)
3146 // select the MapObj
3147 if (selection) selection->unselect();
3149 selection->select();
3154 // Check, if systemFlag clicked
3155 if (typeid(*selection)==typeid(BranchObj) ||
3156 typeid(*selection)==typeid(MapCenterObj) )
3158 QString foname=((BranchObj*)selection)->getSystemFlagName(p);
3159 if (!foname.isEmpty())
3161 // Do not move, if systemFlag clicked
3165 if (foname=="vymLink")
3167 mainWindow->editOpenVymLink();
3168 // tabWidget may change, better return now
3169 // before segfaulting...
3173 mainWindow->windowToggleNoteEditor();
3177 // Left Button Move Branches
3178 if (e->button() == QMouseEvent::LeftButton )
3180 movingObj_start.setX( p.x() - selection->x() );
3181 movingObj_start.setY( p.y() - selection->y() );
3182 movingObj_orgPos.setX (lmo->x() );
3183 movingObj_orgPos.setY (lmo->y() );
3185 // If modMode==copy, then we want to "move" the _new_ object around
3186 // then we need the offset from p to the _old_ selection, because of tmp
3187 if (actionModModeCopy->isOn() &&
3188 e->state() & QMouseEvent::ControlButton)
3190 if (typeid(*selection)==typeid(BranchObj) )
3193 mapCenter->addBranch ((BranchObj*)selection);
3195 selection=mapCenter->getLastBranch();
3196 selection->select();
3197 mapCenter->reposition();
3200 movingObj=selection;
3202 // Middle Button Toggle Scroll
3203 // (On Mac OS X this won't work, but we still have
3204 // a button in the toolbar)
3205 if (e->button() == QMouseEvent::MidButton )
3209 { // No MapObj found, we are on the Canvas itself
3210 // Left Button move Pos of CanvasView
3211 if (e->button() == QMouseEvent::LeftButton )
3213 movingObj=NULL; // move Content not Obj
3214 movingObj_start=e->globalPos();
3215 movingCont_start=QPoint (contentsX(), contentsY() );
3216 movingVec=QPoint(0,0);
3217 setCursor(handOpenCursor);
3222 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3224 QPoint p = inverseWorldMatrix().map(e->pos());
3226 // Move the selected MapObj
3227 if ( selection && movingObj)
3229 // To avoid jumping of the CanvasView, only
3230 // ensureSelectionVisible, if not tmp linked
3231 if (!selection->hasParObjTmp())
3232 ensureSelectionVisible ();
3234 // Now move the selection, but add relative position
3235 // (movingObj_start) where selection was chosen with
3236 // mousepointer. (This avoids flickering resp. jumping
3237 // of selection back to absPos)
3239 LinkableMapObj *lmosel;
3240 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3242 // Check if we could link
3243 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3246 if (typeid(*selection) == typeid(FloatImageObj))
3248 FloatObj *fo=(FloatObj*)selection;
3249 saveState("move "+qpointToString(movingObj_orgPos),fo->getSelectString() );
3250 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3254 // Relink float to new mapcenter or branch, if shift is pressed
3255 // Only relink, if selection really has a new parent
3256 if ( (e->state() & QMouseEvent::ShiftButton) && lmo &&
3257 ( (typeid(*lmo)==typeid(BranchObj)) ||
3258 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3259 ( lmo != fo->getParObj())
3262 if (typeid(*fo) == typeid(FloatImageObj))
3265 FloatImageObj *fio=(FloatImageObj*)(fo);
3266 ((BranchObj*)(lmo))->addFloatImage (fio);
3268 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3269 fio=((BranchObj*)(lmo))->getLastFloatImage();
3272 selection=(LinkableMapObj*)(fio);
3273 selection->select();
3274 movingObj=(MapObj*)(fio);
3277 } else // selection != a FloatObj
3279 if (lmosel->getDepth()==0)
3281 if (e->state() == (LeftButton | !ShiftButton))
3282 // If mapCenter is moved, move all the rest by default, too.
3283 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3285 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3288 if (lmosel->getDepth()==1)
3290 // depth==1, mainbranch
3291 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3295 if (lmosel->getOrientation() == OrientLeftOfCenter)
3296 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3297 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3298 p.y()-movingObj_start.y() +lmosel->getTopPad() );
3300 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
3302 // reposition subbranch
3303 lmosel->reposition();
3304 //ensureSelectionVisible();
3306 if (lmo && (lmo!=selection) &&
3307 (typeid(*lmo) == typeid(BranchObj) ||
3308 (typeid(*lmo) == typeid(MapCenterObj) )
3311 if (e->state() & QMouseEvent::ControlButton)
3313 // Special case: CTRL to link below lmo
3314 lmosel->setParObjTmp (lmo,p,+1);
3316 else if (e->state() & QMouseEvent::ShiftButton)
3317 lmosel->setParObjTmp (lmo,p,-1);
3319 lmosel->setParObjTmp (lmo,p,0);
3322 lmosel->unsetParObjTmp();
3323 /* FIXME not needed anymore?
3324 if (lmo &&(lmo==selection))
3325 // Could link to myself (happens sometimes...)
3326 lmosel->unsetParObjTmp();
3328 // no Obj under selection, go back to original Parent
3329 lmosel->unsetParObjTmp();
3334 } // no FloatImageObj
3338 } // selection && moving_obj
3340 // Draw a link from one branch to another
3343 tmpXLink->setEnd (p);
3344 tmpXLink->updateXLink();
3348 if (!movingObj && !pickingColor &&!drawingLink)
3350 QPoint p=e->globalPos();
3351 movingVec.setX(-p.x() + movingObj_start.x() );
3352 movingVec.setY(-p.y() + movingObj_start.y() );
3353 setContentsPos( movingCont_start.x() + movingVec.x(),
3354 movingCont_start.y() + movingVec.y());
3361 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3363 LinkableMapObj *dst;
3364 // Have we been picking color?
3368 setCursor (ArrowCursor);
3369 // Check if we are over another branch
3370 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3371 if (dst && selection)
3373 if (e->state() & QMouseEvent::ShiftButton)
3375 ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor(),false);
3376 ((BranchObj*)selection)->setLinkColor ();
3380 ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor(),true);
3381 ((BranchObj*)selection)->setLinkColor ();
3387 // Have we been drawing a link?
3391 // Check if we are over another branch
3392 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3393 if (dst && selection)
3395 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3396 tmpXLink->updateXLink();
3397 tmpXLink->activate();
3398 saveState(); //TODO undoCommand
3407 // Have we been moving something?
3408 if ( selection && movingObj )
3410 // Moved FloatObj? Maybe we need to reposition
3411 if(typeid(*selection)==typeid (FloatImageObj))
3413 selection->getParObj()->requestReposition();
3414 mapCenter->reposition();
3417 // Check if we are over another branch, but ignore
3418 // any found LMOs, which are FloatObjs
3419 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3420 ((LinkableMapObj*)selection) );
3423 (typeid(*dst)!=typeid(BranchObj)&&typeid(*dst)!=typeid(MapCenterObj)))
3426 // Now check, if we have been moving a branch
3427 if (typeid(*selection) == typeid(BranchObj) )
3429 // save the position in case we link to mapcenter
3430 QPoint savePos=QPoint (selection->x(),selection->y() );
3432 // Reset the temporary drawn link to the original one
3433 ((LinkableMapObj*)selection)->unsetParObjTmp();
3439 BranchObj* bs=((BranchObj*)selection);
3440 QString undoCom="linkBranchToPos (\""+
3441 (bs->getParObj())->getSelectString()+
3443 QString("%1").arg(bs->getNum())+
3445 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+
3447 // TODO we also could check, if dest and src are on same branch,
3448 // then it would be sufficient to saveState of this branch
3450 // Modifiers allow to insert above/below dst
3451 if (e->state() & QMouseEvent::ShiftButton)
3453 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum());
3455 if (e->state() & QMouseEvent::ControlButton)
3457 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum()+1);
3460 bs->moveBranchTo ((BranchObj*)(dst),-1);
3461 if (dst->getDepth()==0)
3464 saveState (undoCom,bs->getSelectString() );
3466 if (selection->getDepth()==1)
3467 // If we have moved mainbranch only save endposition
3468 saveState("move "+qpointToString(movingObj_orgPos), selection->getSelectString() );
3470 // Draw the original link, before selection was moved around
3471 mapCenter->reposition();
3473 // Finally resize canvas, if needed
3478 // maybe we moved View: set old cursor
3479 setCursor (ArrowCursor);
3483 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3485 // Finish open lineEdits
3486 if (lineedit) finishedLineEditNoSave();
3488 if (e->button() == QMouseEvent::LeftButton )
3490 QPoint p = inverseWorldMatrix().map(e->pos());
3491 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3492 if (lmo) { // MapObj was found
3493 // First select the MapObj than edit heading
3494 if (selection) selection->unselect();
3496 selection->select();
3497 saveState(selection);
3503 void MapEditor::resizeEvent (QResizeEvent* e)
3505 QCanvasView::resizeEvent( e );
3509 void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3512 // for (unsigned int i=0;event->format(i);i++) // Debug mime type
3513 // cerr << event->format(i) << endl;
3516 (typeid(*selection) == typeid(BranchObj)) ||
3517 (typeid(*selection) == typeid(MapCenterObj))) {
3519 // If QImageDrag can decode mime type
3520 if (QImageDrag::canDecode(event)) {
3525 // If image are dragged from firefox
3526 if (event->provides("application/x-moz-file-promise-url") &&
3527 event->provides("application/x-moz-nativeimage")) {
3528 event->accept(true);
3532 // If QUriDrag can decode mime type
3533 if (QUriDrag::canDecode(event)) {
3538 // If Uri are dragged from firefox
3539 if (event->provides("_NETSCAPE_URL")){
3544 // If QTextDrag can decode mime type
3545 if (QTextDrag::canDecode(event)) {
3554 bool isUnicode16(const QByteArray &d)
3556 // TODO: make more precise check for unicode 16.
3557 // Guess unicode16 if any of second bytes are zero
3558 unsigned int length = max(0,d.size()-2)/2;
3559 for (unsigned int i = 0; i<length ; i++)
3560 if (d.at(i*2+1)==0) return true;
3564 void MapEditor::contentsDropEvent(QDropEvent *event)
3567 (typeid(*selection) == typeid(BranchObj)) ||
3568 (typeid(*selection) == typeid(MapCenterObj)))
3573 if (event->provides("image/png"))
3576 if (QImageDrag::decode(event, pix))
3584 } else if (event->provides("application/x-moz-file-promise-url") &&
3585 event->provides("application/x-moz-nativeimage"))
3587 // Contains url to the img src in unicode16
3588 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3589 QString url = QString((const QChar*)d.data(),d.size()/2);
3593 } else if (event->provides ("text/uri-list"))
3594 { // Uris provided e.g. by konqueror
3595 QUriDrag::decode (event,uris);
3596 } else if (event->provides ("_NETSCAPE_URL"))
3597 { // Uris provided by Mozilla
3598 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
3601 } else if (event->provides("text/html")) {
3603 // Handels text mime types
3604 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
3605 QByteArray d = event->encodedData("text/html");
3608 text = QString((const QChar*)d.data(),d.size()/2);
3612 textEditor->setText(text);
3616 } else if (event->provides("text/plain")) {
3617 QByteArray d = event->encodedData("text/plain");
3620 text = QString((const QChar*)d.data(),d.size()/2);
3624 textEditor->setText(text);
3636 for (const char* u=uris.first(); u; u=uris.next())
3638 bo=((BranchObj*)selection)->addBranch();
3641 s=QUriDrag::uriToLocalFile(u);
3643 QString file = QDir::convertSeparators(s);
3644 heading = QFileInfo(file).baseName();
3646 if (file.endsWith(".vym", false))
3647 bo->setVymLink(file);
3656 bo->setHeading(heading);
3666 saveState(); //TODO undo Command
3667 mapCenter->reposition();
3674 void MapEditor::addFloatImage(const QPixmap &img)
3677 (typeid(*selection) == typeid(BranchObj)) ||
3678 (typeid(*selection) == typeid(MapCenterObj)) )
3680 BranchObj *bo=((BranchObj*)selection);
3681 saveState(selection);
3682 //QString fn=fd->selectedFile();
3683 //lastImageDir=fn.left(fn.findRev ("/"));
3684 bo->addFloatImage();
3685 // FIXME check if load was successful
3686 bo->getLastFloatImage()->load(img);
3687 //bo->getLastFloatImage()->setOriginalFilename(fn);
3688 mapCenter->reposition();
3695 void MapEditor::imageDataFetched(const QByteArray &a, QNetworkOperation */*nop*/)
3697 if (!imageBuffer) imageBuffer = new QBuffer();
3698 if (!imageBuffer->isOpen()) {
3699 imageBuffer->open(IO_WriteOnly | IO_Append);
3701 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
3705 void MapEditor::imageDataFinished(QNetworkOperation *nop)
3707 if (nop->state()==QNetworkProtocol::StDone) {
3708 QPixmap img(imageBuffer->buffer());
3713 imageBuffer->close();
3715 imageBuffer->close();
3722 void MapEditor::fetchImage(const QString &url)
3725 urlOperator->stop();
3726 disconnect(urlOperator);
3730 urlOperator = new QUrlOperator(url);
3731 connect(urlOperator, SIGNAL(finished(QNetworkOperation *)),
3732 this, SLOT(imageDataFinished(QNetworkOperation*)));
3734 connect(urlOperator, SIGNAL(data(const QByteArray &, QNetworkOperation *)),
3735 this, SLOT(imageDataFetched(const QByteArray &, QNetworkOperation *)));