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)
720 if (fname.isEmpty() || fname=="")
727 filePath=fname; // becomes absolute path
728 fileName=fname; // gets stripped of path
729 destPath=destname; // needed for vymlinks
731 // If fname is not an absolute path, complete it
732 filePath=QDir(fname).absPath();
733 fileDir=filePath.left (1+filePath.findRev ("/"));
735 // Set short name, too. Search from behind:
736 int i=fileName.findRev("/");
737 if (i>=0) fileName=fileName.remove (0,i+1);
739 // Forget the .vym (or .xml) for name of map
740 mapName=fileName.left(fileName.findRev(".",-1,true) );
744 QString MapEditor::getFilePath()
749 QString MapEditor::getFileName()
754 QString MapEditor::getMapName()
759 QString MapEditor::getDestPath()
764 ErrorCode MapEditor::load (QString fname, LoadMode lmode)
766 // Finish open lineEdits
767 if (lineedit) finishedLineEditNoSave();
769 ErrorCode err=success;
773 if (selection) selection->unselect();
776 mapCenter->setMapEditor(this);
777 // (map state is set later at end of load...)
780 saveState(selection);
784 mapBuilderHandler handler;
787 // I am paranoid: file should exist anyway
788 // according to check in mainwindow.
791 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
792 tr("Couldn't open map " +fname)+".");
796 blockReposition=true;
797 QXmlInputSource source( file);
798 QXmlSimpleReader reader;
799 reader.setContentHandler( &handler );
800 reader.setErrorHandler( &handler );
801 handler.setMapEditor( this );
802 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
803 handler.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 as ASCII"));
1069 fd->addFilter ("TXT (*.txt)");
1070 fd->setCaption(__VYM " -" +tr("Export as ASCII")+" "+tr("(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.setFile(fd->selectedFile() );
1104 void MapEditor::exportLaTeX()
1106 // TODO still experimental
1107 QFileDialog *fd=new QFileDialog( this, __VYM " - " +tr("Export as LaTeX"));
1108 fd->addFilter ("TEX (*.tex)");
1109 fd->setCaption(__VYM " - " + tr("Export as LaTeX")+" "+tr("(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 %1\nexists already. Do you want to overwrite it?").arg(fd->selectedFile()),
1119 QMessageBox::Warning,
1120 QMessageBox::Yes | QMessageBox::Default,
1121 QMessageBox::Cancel | QMessageBox::Escape,
1122 QMessageBox::NoButton );
1124 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
1125 mb.setButtonText( QMessageBox::No, tr("Cancel"));
1129 case QMessageBox::Yes:
1132 case QMessageBox::Cancel:
1139 ex.setFile (fd->selectedFile() );
1140 ex.setMapCenter(mapCenter);
1145 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
1149 ex.setMapCenter(mapCenter);
1150 if (ex.setConfigFile(cf)) ex.exportPresentation();
1155 void MapEditor::exportXML(const QString &dir)
1157 // Create subdirectories
1160 // write to directory
1161 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1164 file.setName ( dir + "/"+mapName+".xml");
1165 if ( !file.open( IO_WriteOnly ) )
1167 // This should neverever happen
1168 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1172 // Write it finally, and write in UTF8, no matter what
1173 QTextStream ts( &file );
1174 ts.setEncoding (QTextStream::UnicodeUTF8);
1178 // Now write image, too
1179 exportImage (dir+"/images/"+mapName+".png");
1182 void MapEditor::clear()
1186 selection->unselect();
1193 void MapEditor::copy()
1195 // Finish open lineEdits
1196 if (lineedit) finishedLineEditNoSave();
1200 // write to directory
1201 QString clipfile="part";
1202 QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPoint(),selection);
1205 file.setName ( clipboardDir + "/"+clipfile+".xml");
1206 if ( !file.open( IO_WriteOnly ) )
1208 // This should neverever happen
1209 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1213 // Write it finally, and write in UTF8, no matter what
1214 QTextStream ts( &file );
1215 ts.setEncoding (QTextStream::UnicodeUTF8);
1219 clipboardEmpty=false;
1224 void MapEditor::redo()
1226 // Finish open lineEdits
1227 if (lineedit) finishedLineEditNoSave();
1229 blockSaveState=true;
1231 // Find out current undo directory
1232 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
1234 // Restore variables
1235 QString undoCommand;
1236 QString undoSelection;
1237 QString redoCommand;
1238 QString redoSelection;
1240 set.readSettings(QString(bakMapDir+"/commands"));
1241 undoCommand=set.readEntry ("undoCommand");
1242 undoSelection=set.readEntry ("undoSelection");
1243 redoCommand=set.readEntry ("redoCommand");
1244 redoSelection=set.readEntry ("redoSelection");
1246 // select object before redo
1247 if (!redoSelection.isEmpty())
1248 select (redoSelection);
1250 /* TODO remove testing
1251 cout << "ME::redo() begin\n";
1252 cout << " undosTotal="<<undosTotal<<endl;
1253 cout << " undosAvail="<<undosAvail<<endl;
1254 cout << " undoNum="<<undoNum<<endl;
1255 cout << " ---------------------------"<<endl;
1256 cout << " undoCom="<<undoCommand<<endl;
1257 cout << " undoSel="<<undoSelection<<endl;
1258 cout << " ---------------------------"<<endl;
1259 cout << " redoCom="<<redoCommand<<endl;
1260 cout << " redoSel="<<redoSelection<<endl;
1261 cout << " ---------------------------"<<endl;
1263 parseAtom (undoCommand);
1264 mapCenter->reposition();
1266 //if (!redoSelection.isEmpty())
1267 // select (redoSelection);
1271 // Undo not longer available now
1272 actionEditUndo->setEnabled (false);
1274 undoNum--; if (undoNum<1) undoNum=undosTotal;
1276 blockSaveState=false;
1277 /* TODO remove testing
1278 cout << "ME::redo() end\n";
1279 cout << " undosAvail="<<undosAvail<<endl;
1280 cout << " undoNum="<<undoNum<<endl;
1281 cout << " ---------------------------"<<endl<<endl;
1285 void MapEditor::undo()
1287 // Finish open lineEdits
1288 if (lineedit) finishedLineEditNoSave();
1290 blockSaveState=true;
1292 // Find out current undo directory
1293 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
1295 // Restore variables
1296 QString undoCommand;
1297 QString undoSelection;
1298 QString redoCommand;
1299 QString redoSelection;
1301 set.readSettings(QString(bakMapDir+"/commands"));
1302 undoCommand= set.readEntry ("undoCommand");
1303 undoSelection=set.readEntry ("undoSelection");
1304 redoCommand= set.readEntry ("redoCommand");
1305 redoSelection=set.readEntry ("redoSelection");
1307 // select object before undo
1308 if (!undoSelection.isEmpty())
1309 select (undoSelection);
1312 cout << "ME::undo() begin\n";
1313 cout << " undosTotal="<<undosTotal<<endl;
1314 cout << " undosAvail="<<undosAvail<<endl;
1315 cout << " undoNum="<<undoNum<<endl;
1316 cout << " ---------------------------"<<endl;
1317 cout << " undoCom="<<undoCommand<<endl;
1318 cout << " undoSel="<<undoSelection<<endl;
1319 cout << " ---------------------------"<<endl;
1320 cout << " redoCom="<<redoCommand<<endl;
1321 cout << " redoSel="<<redoSelection<<endl;
1322 cout << " ---------------------------"<<endl;
1324 parseAtom (undoCommand);
1325 mapCenter->reposition();
1327 //if (!redoSelection.isEmpty())
1328 // select (redoSelection);
1332 // Undo not longer available now
1333 actionEditUndo->setEnabled (false);
1335 undoNum--; if (undoNum<1) undoNum=undosTotal;
1337 blockSaveState=false;
1338 /* TODO remove testing
1339 cout << "ME::undo() end\n";
1340 cout << " undosAvail="<<undosAvail<<endl;
1341 cout << " undoNum="<<undoNum<<endl;
1342 cout << " ---------------------------"<<endl<<endl;
1346 void MapEditor::undoXML(const QString &undoSel, const QString &bakMapPath)
1348 QString bakMapDir=bakMapPath.left(bakMapPath.findRev("/"));
1350 QFile file (bakMapPath);
1354 // We need to parse saved XML data
1355 mapBuilderHandler handler;
1356 QXmlInputSource source( file);
1357 QXmlSimpleReader reader;
1358 reader.setContentHandler( &handler );
1359 reader.setErrorHandler( &handler );
1360 handler.setMapEditor( this );
1361 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1362 if (undoSel.isEmpty())
1366 handler.setLoadMode (NewMap);
1370 handler.setLoadMode (ImportReplace);
1372 blockReposition=true;
1373 bool ok = reader.parse( source );
1374 blockReposition=false;
1377 // This should never ever happen
1378 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1379 tr( handler.errorProtocol() )+" in "+bakMapDir );
1383 QMessageBox::critical( 0, tr( "Critical Error" ),
1384 tr("Temporary directory %1 used for undo is gone. \n"
1385 "I will create a new one, but at the moment no undo is available.\n"
1386 "Maybe you want to reload your original data.\n\n"
1387 "Sorry for any inconveniences.").arg(bakMapDir) );
1392 void MapEditor::pasteNoSave()
1394 // Finish open lineEdits
1395 if (lineedit) finishedLineEditNoSave();
1397 load (clipboardDir+"/part.xml",ImportAdd);
1400 void MapEditor::cutNoSave()
1406 void MapEditor::paste()
1408 if (selection && (typeid(*selection) == typeid(BranchObj) ||
1409 typeid(*selection) == typeid(MapCenterObj)))
1411 saveState(selection);
1413 mapCenter->reposition();
1418 void MapEditor::cut()
1420 saveState(selection->getParObj());
1423 mapCenter->reposition();
1427 void MapEditor::move(const int &x, const int &y)
1429 // TODO no saveState, because this is only internal at undo so far
1430 if (selection) selection->move(x,y);
1431 if (typeid(*selection) == typeid(FloatImageObj))
1432 ((FloatImageObj*)selection)->setRelPos();
1435 void MapEditor::moveBranchUp()
1437 // Finish open lineEdits
1438 if (lineedit) finishedLineEditNoSave();
1442 if (typeid(*selection) == typeid(BranchObj) )
1444 bo=(BranchObj*)selection;
1445 par=(BranchObj*)(bo->getParObj());
1446 selection->unselect();
1447 selection=par->moveBranchUp (bo);
1448 selection->select();
1449 saveState("moveBranchDown ()",bo);
1450 mapCenter->reposition();
1451 ensureSelectionVisible();
1455 void MapEditor::moveBranchDown()
1457 // Finish open lineEdits
1458 if (lineedit) finishedLineEditNoSave();
1462 if (typeid(*selection) == typeid(BranchObj) )
1464 bo=(BranchObj*)selection;
1465 par=(BranchObj*)(bo->getParObj());
1466 selection->unselect();
1467 selection=par->moveBranchDown(bo);
1468 selection->select();
1469 saveState("moveBranchUp ()",bo);
1470 mapCenter->reposition();
1471 ensureSelectionVisible();
1475 void MapEditor::editHeading()
1477 // Finish open lineEdits
1478 if (lineedit) finishedLineEditNoSave();
1481 (typeid(*selection) == typeid(BranchObj) ||
1482 typeid(*selection) == typeid(MapCenterObj) ) )
1484 editingBO=(BranchObj*)selection;
1485 saveState("setHeading (\""+((BranchObj*)selection)->getHeading()+"\")",editingBO );
1487 ensureSelectionVisible();
1488 QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
1489 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1490 QString s=editingBO->getHeading();
1491 lineedit->setText(s);
1492 lineedit->setCursorPosition(1);
1493 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1494 lineedit->selectAll();
1496 lineedit->grabKeyboard();
1497 lineedit->setFocus();
1501 void MapEditor::setHeading(const QString &s)
1503 // Internal function, no saveState needed
1505 (typeid(*selection) == typeid(BranchObj) ||
1506 typeid(*selection) == typeid(MapCenterObj) ) )
1508 ((BranchObj*)selection)->setHeading(s);
1509 mapCenter->reposition();
1511 ensureSelectionVisible();
1515 void MapEditor::setURL (const QString &s)
1517 // Internal function, no saveState needed
1519 (typeid(*selection) == typeid(BranchObj) ||
1520 typeid(*selection) == typeid(MapCenterObj) ) )
1522 ((BranchObj*)selection)->setURL(s);
1523 mapCenter->reposition();
1525 ensureSelectionVisible();
1529 void MapEditor::setVymLink (const QString &s)
1531 // Internal function, no saveState needed
1533 (typeid(*selection) == typeid(BranchObj) ||
1534 typeid(*selection) == typeid(MapCenterObj) ) )
1536 ((BranchObj*)selection)->setVymLink(s);
1537 mapCenter->reposition();
1539 ensureSelectionVisible();
1543 void MapEditor::addNewBranch(int pos)
1545 // Finish open lineEdits
1546 if (lineedit) finishedLineEditNoSave();
1549 (typeid(*selection) == typeid(BranchObj) ||
1550 typeid(*selection) == typeid(MapCenterObj) ) )
1552 saveState(selection); //TODO undoCommand
1554 BranchObj* bo1 = (BranchObj*) selection;
1555 bool wasScrolled=false;
1556 BranchObj *newbo=NULL;
1559 // save scroll state. If scrolled, automatically select
1560 // new branch in order to tmp unscroll parent...
1561 wasScrolled=bo1->isScrolled();
1562 newbo=bo1->addBranch();
1565 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1569 // add above selection
1570 newbo=parbo->insertBranch(bo1->getNum());
1572 // add below selection
1573 newbo=parbo->insertBranch(bo1->getNum()+1);
1575 // This should not happen...
1580 LinkableMapObj *oldselection=selection;
1582 mapCenter->reposition();
1584 if (actionSettingsAutoedit->isOn() ||
1585 actionSettingsAutoselectHeading->isOn() )
1587 selection->unselect();
1589 selection->select();
1590 if (actionSettingsPasteNewHeading->isOn() )
1592 BranchObj *bo2= (BranchObj*)selection;
1593 bo2->setHeading("");
1595 if (actionSettingsAutoedit->isOn() )
1597 if (!actionSettingsAutoselectHeading->isOn()
1600 selection->unselect();
1601 selection=oldselection;
1602 selection->select();
1609 void MapEditor::addNewBranchHere()
1611 // Finish open lineEdits
1612 if (lineedit) finishedLineEditNoSave();
1615 (typeid(*selection) == typeid(BranchObj) ) )
1617 saveState(selection);
1619 BranchObj* bo1 = (BranchObj*) selection;
1620 bool wasScrolled=false;
1621 BranchObj *newbo=NULL;
1622 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1625 // add below selection
1626 newbo=parbo->insertBranch(bo1->getNum()+1);
1629 LinkableMapObj *oldselection=selection;
1630 ((BranchObj*)selection)->moveBranchTo (newbo,-1);
1632 mapCenter->reposition();
1634 if (actionSettingsAutoedit->isOn() ||
1635 actionSettingsAutoselectHeading->isOn() )
1637 selection->unselect();
1639 selection->select();
1640 if (actionSettingsPasteNewHeading->isOn() )
1642 BranchObj *bo2= (BranchObj*)selection;
1643 bo2->setHeading("");
1645 if (actionSettingsAutoedit->isOn() )
1647 if (!actionSettingsAutoselectHeading->isOn()
1650 selection->unselect();
1651 selection=oldselection;
1652 selection->select();
1658 void MapEditor::deleteSelection()
1660 // Finish open lineEdits
1661 if (lineedit) finishedLineEditNoSave();
1663 if (selection && typeid(*selection) ==typeid(BranchObj) )
1665 if (selection->getDepth()>1)
1666 // Normal branch, save parent with childs
1667 saveState(selection->getParObj());
1669 // Mainbranch, save whole map
1670 // TODO Better would be to insert mainbranch again at pos
1671 // But undoCommand is missing right now
1673 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1674 BranchObj* par=(BranchObj*)(bo->getParObj());
1677 par->removeBranch(bo);
1679 selection->select();
1680 ensureSelectionVisible();
1681 mapCenter->reposition();
1684 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1686 saveState(selection->getParObj());
1687 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1688 BranchObj* par=(BranchObj*)(fio->getParObj());
1691 par->removeFloatImage(fio);
1693 selection->select();
1694 ensureSelectionVisible();
1695 mapCenter->reposition();
1700 LinkableMapObj* MapEditor::getSelection()
1705 bool MapEditor::select (const QString &s)
1707 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
1709 // Finally select the found object
1712 if (selection) unselect();
1714 selection->select();
1716 ensureSelectionVisible();
1722 void MapEditor::unselect()
1726 selectionLast=selection;
1727 selection->unselect();
1732 void MapEditor::reselect()
1736 selection=selectionLast;
1737 selection->select();
1742 void MapEditor::selectNextBranch()
1744 // Increase number of branch
1747 QString s=selection->getSelectString();
1753 part=s.section(",",-1);
1755 num=part.right(part.length() - 3);
1757 s=s.left (s.length() -num.length());
1760 num=QString ("%1").arg(num.toUInt()+1);
1764 // Try to select this one
1765 if (select (s)) return;
1767 // We have no direct successor,
1768 // try to increase the parental number in order to
1769 // find a successor with same depth
1771 int d=selection->getDepth();
1776 while (!found && d>0)
1778 s=s.section (",",0,d-1);
1779 // replace substring of current depth in s with "1"
1780 part=s.section(",",-1);
1782 num=part.right(part.length() - 3);
1786 // increase number of parent
1787 num=QString ("%1").arg(num.toUInt()+1);
1788 s=s.section (",",0,d-2) + ","+ typ+num;
1791 // Special case, look at orientation
1792 if (selection->getOrientation()==OrientRightOfCenter)
1793 num=QString ("%1").arg(num.toUInt()+1);
1795 num=QString ("%1").arg(num.toUInt()-1);
1800 // pad to oldDepth, select the first branch for each depth
1801 for (i=d;i<oldDepth;i++)
1806 if ( ((BranchObj*)selection)->countBranches()>0)
1814 // try to select the freshly built string
1822 void MapEditor::selectPrevBranch()
1824 // Decrease number of branch
1827 QString s=selection->getSelectString();
1833 part=s.section(",",-1);
1835 num=part.right(part.length() - 3);
1837 s=s.left (s.length() -num.length());
1840 num=QString ("%1").arg(num.toUInt()-1);
1844 // Try to select this one
1845 if (select (s)) return;
1847 // We have no direct precessor,
1848 // try to decrease the parental number in order to
1849 // find a precessor with same depth
1851 int d=selection->getDepth();
1856 while (!found && d>0)
1858 s=s.section (",",0,d-1);
1859 // replace substring of current depth in s with "1"
1860 part=s.section(",",-1);
1862 num=part.right(part.length() - 3);
1866 // decrease number of parent
1867 num=QString ("%1").arg(num.toUInt()-1);
1868 s=s.section (",",0,d-2) + ","+ typ+num;
1871 // Special case, look at orientation
1872 if (selection->getOrientation()==OrientRightOfCenter)
1873 num=QString ("%1").arg(num.toUInt()-1);
1875 num=QString ("%1").arg(num.toUInt()+1);
1880 // pad to oldDepth, select the last branch for each depth
1881 for (i=d;i<oldDepth;i++)
1885 if ( ((BranchObj*)selection)->countBranches()>0)
1886 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)selection)->countBranches()-1 );
1893 // try to select the freshly built string
1901 void MapEditor::selectUpperBranch()
1903 // Finish open lineEdits
1904 if (lineedit) finishedLineEditNoSave();
1908 if (typeid(*selection) == typeid(BranchObj))
1910 if (selection->getOrientation()==OrientRightOfCenter)
1913 if (selection->getDepth()==1)
1921 void MapEditor::selectLowerBranch()
1923 // Finish open lineEdits
1924 if (lineedit) finishedLineEditNoSave();
1928 if (typeid(*selection) == typeid(BranchObj))
1930 if (selection->getOrientation()==OrientRightOfCenter)
1933 if (selection->getDepth()==1)
1942 void MapEditor::selectLeftBranch()
1944 // Finish open lineEdits
1945 if (lineedit) finishedLineEditNoSave();
1951 if (typeid(*selection) == typeid(MapCenterObj))
1953 par= (BranchObj*) selection;
1954 bo=par->getLastSelectedBranch();
1957 // Workaround for reselecting on left and right side
1958 if (bo->getOrientation()==OrientRightOfCenter)
1960 bo=par->getLastBranch();
1966 selection->select();
1968 ensureSelectionVisible();
1973 par=(BranchObj*)(selection->getParObj());
1974 if (selection->getOrientation()==OrientRightOfCenter)
1976 if (typeid(*selection) == typeid(BranchObj) ||
1977 typeid(*selection) == typeid(FloatImageObj))
1979 selection->unselect();
1981 selection->select();
1983 ensureSelectionVisible();
1987 if (typeid(*selection) == typeid(BranchObj) )
1989 bo=((BranchObj*)selection)->getLastSelectedBranch();
1992 selection->unselect();
1994 selection->select();
1996 ensureSelectionVisible();
2004 void MapEditor::selectRightBranch()
2006 // Finish open lineEdits
2007 if (lineedit) finishedLineEditNoSave();
2014 if (typeid(*selection) == typeid(MapCenterObj))
2016 par= (BranchObj*) selection;
2017 bo=par->getLastSelectedBranch();
2020 // Workaround for relecting on left and right side
2021 if (bo->getOrientation()==OrientLeftOfCenter)
2022 bo=par->getFirstBranch();
2027 selection->select();
2028 ensureSelectionVisible();
2033 par=(BranchObj*)(selection->getParObj());
2034 if (selection->getOrientation()==OrientLeftOfCenter)
2036 if (typeid(*selection) == typeid(BranchObj) ||
2037 typeid(*selection) == typeid(FloatImageObj))
2039 selection->unselect();
2041 selection->select();
2043 ensureSelectionVisible();
2047 if (typeid(*selection) == typeid(BranchObj) )
2049 bo=((BranchObj*)selection)->getLastSelectedBranch();
2052 selection->unselect();
2054 selection->select();
2056 ensureSelectionVisible();
2064 void MapEditor::selectFirstBranch()
2066 // Finish open lineEdits
2067 if (lineedit) finishedLineEditNoSave();
2073 if (typeid(*selection) == typeid(BranchObj))
2075 bo1= (BranchObj*) selection;
2076 par=(BranchObj*)(bo1->getParObj());
2077 bo2=par->getFirstBranch();
2081 selection->select();
2082 ensureSelectionVisible();
2089 void MapEditor::selectLastBranch()
2091 // Finish open lineEdits
2092 if (lineedit) finishedLineEditNoSave();
2098 if (typeid(*selection) == typeid(BranchObj))
2100 bo1= (BranchObj*) selection;
2101 par=(BranchObj*)(bo1->getParObj());
2102 bo2=par->getLastBranch();
2106 selection->select();
2107 ensureSelectionVisible();
2114 void MapEditor::setColor(QColor c)
2119 void MapEditor::selectBackgroundColor()
2121 // Finish open lineEdits
2122 if (lineedit) finishedLineEditNoSave();
2124 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
2125 if ( !col.isValid() ) return;
2126 setBackgroundColor( col );
2130 void MapEditor::setBackgroundColor(QColor c)
2132 mapCanvas->setBackgroundColor (c);
2135 QColor MapEditor::pickColor()
2139 if (typeid(*selection) == typeid(BranchObj) ||
2140 typeid(*selection) == typeid(MapCenterObj))
2142 BranchObj *bo=(BranchObj*)selection;
2143 actColor=bo->getColor();
2149 void MapEditor::colorItem()
2153 if (typeid(*selection) == typeid(BranchObj) ||
2154 typeid(*selection) == typeid(MapCenterObj))
2156 saveState(selection); //TODO undoCommand
2157 BranchObj *bo=(BranchObj*)selection;
2158 bo->setColor(actColor, false); // color links, color childs
2163 void MapEditor::colorBranch()
2167 if (typeid(*selection) == typeid(BranchObj) ||
2168 typeid(*selection) == typeid(MapCenterObj))
2170 saveState(selection); //TODO undoCommand
2171 BranchObj *bo=(BranchObj*)selection;
2172 bo->setColor(actColor, true); // color links, color childs
2178 void MapEditor::toggleStandardFlag(QString f)
2182 saveState(selection);// TODO undoCommand
2183 ((BranchObj*)selection)->toggleStandardFlag (f,actionSettingsUseFlagGroups);
2187 void MapEditor::setViewCenter()
2189 // transform to CanvasView Coord:
2190 QPoint p=worldMatrix().map(movingCenter);
2191 center ( p.x(), p.y());
2195 BranchObj* MapEditor::findText (QString s, bool cs)
2198 { // Nothing found or new find process
2200 // nothing found, start again
2202 itFind=mapCenter->first();
2204 bool searching=true;
2205 bool foundNote=false;
2206 while (searching && !EOFind)
2210 // Searching in Note
2211 if (itFind->getNote().contains(s,cs))
2213 if (selection!=itFind)
2215 if (selection) ((BranchObj*)selection)->unselect();
2217 selection->select();
2219 ensureSelectionVisible();
2221 if (textEditor->findText(s,cs))
2227 // Searching in Heading
2228 if (searching && itFind->getHeading().contains (s,cs) )
2230 if (selection) ((BranchObj*)selection)->unselect();
2232 selection->select();
2234 ensureSelectionVisible();
2240 itFind=itFind->next();
2241 if (!itFind) EOFind=true;
2247 return (BranchObj*)selection;
2252 void MapEditor::findReset()
2253 { // Necessary if text to find changes during a find process
2258 void MapEditor::openURL()
2262 if (typeid(*selection) == typeid(BranchObj) ||
2263 typeid(*selection) == typeid(MapCenterObj))
2265 QString url=((BranchObj*)selection)->getURL();
2267 QProcess *proc = new QProcess( this );
2269 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL" ));
2270 proc->addArgument( url);
2272 if ( !proc->start() )
2274 if (mainWindow->settingsURL() )
2280 void MapEditor::editURL()
2282 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2283 typeid(*selection) == typeid(MapCenterObj)) )
2286 BranchObj *bo=(BranchObj*)selection;
2287 QString text = QInputDialog::getText(
2288 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2289 bo->getURL(), &ok, this );
2292 // user entered something and pressed OK
2293 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+text+"\")");
2300 void MapEditor::editHeading2URL()
2302 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2303 typeid(*selection) == typeid(MapCenterObj)) )
2305 BranchObj *bo=(BranchObj*)selection;
2306 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+bo->getHeading()+"\")");
2307 bo->setURL (bo->getHeading());
2312 void MapEditor::editBugzilla2URL()
2314 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2315 typeid(*selection) == typeid(MapCenterObj)) )
2317 BranchObj *bo=(BranchObj*)selection;
2318 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2319 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")");
2325 void MapEditor::editFATE2URL()
2327 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2328 typeid(*selection) == typeid(MapCenterObj)) )
2330 BranchObj *bo=(BranchObj*)selection;
2331 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2332 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")");
2338 void MapEditor::editVymLink()
2340 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2341 typeid(*selection) == typeid(MapCenterObj)) )
2343 BranchObj *bo=(BranchObj*)selection;
2344 QFileDialog *fd=new QFileDialog( this,__VYM " - " +tr("Link to another map"));
2345 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2346 fd->setCaption(__VYM " - " +tr("Link to another map"));
2347 if (! bo->getVymLink().isEmpty() )
2348 fd->setSelection( bo->getVymLink() );
2352 if ( fd->exec() == QDialog::Accepted )
2354 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\""+fd->selectedFile()+"\")");
2355 bo->setVymLink (fd->selectedFile() );
2357 mapCenter->reposition();
2364 void MapEditor::deleteVymLink()
2366 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2367 typeid(*selection) == typeid(MapCenterObj)) )
2369 BranchObj *bo=(BranchObj*)selection;
2370 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\"\")");
2371 bo->setVymLink ("" );
2373 mapCenter->reposition();
2379 QString MapEditor::getVymLink()
2381 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2382 typeid(*selection) == typeid(MapCenterObj)) )
2384 return ((BranchObj*)selection)->getVymLink();
2390 void MapEditor::removeBranchHere()
2392 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2394 BranchObj* bo=(BranchObj*)selection;
2395 BranchObj* par=(BranchObj*)(bo->getParObj());
2396 if (bo->getDepth()==1)
2399 saveState(selection->getParObj()); // TODO undoCommand
2400 QString sel=selection->getSelectString();
2402 par->removeBranchHere(bo);
2403 mapCenter->reposition();
2408 void MapEditor::removeChilds()
2410 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2412 saveState(selection->getParObj());
2413 ((BranchObj*)selection)->removeChilds();
2414 mapCenter->reposition();
2418 void MapEditor::editMapInfo()
2420 ExtraInfoDialog dia;
2421 dia.setMapName (getFileName() );
2422 dia.setAuthor (mapCenter->getAuthor() );
2423 dia.setComment(mapCenter->getComment() );
2428 QCanvasItemList l=canvas()->allItems();
2429 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2431 stats+=QString ("%1 items on canvas\n").arg (i,6);
2438 bo=mapCenter->first();
2441 if (!bo->getNote().isEmpty() ) n++;
2442 f+= bo->countFloatImages();
2444 xl+=bo->countXLinks();
2447 stats+=QString ("%1 branches\n").arg (b-1,6);
2448 stats+=QString ("%1 xLinks \n").arg (xl,6);
2449 stats+=QString ("%1 notes\n").arg (n,6);
2450 stats+=QString ("%1 images\n").arg (f,6);
2451 dia.setStats (stats);
2453 // Finally show dialog
2454 if (dia.exec() == QDialog::Accepted)
2456 saveState(); //TODO undoCommand
2457 mapCenter->setAuthor (dia.getAuthor() );
2458 mapCenter->setComment (dia.getComment() );
2462 void MapEditor::updateActions()
2465 if (getLinkColorHint()==HeadingColor)
2466 actionFormatLinkColorHint->setOn(true);
2468 actionFormatLinkColorHint->setOn(false);
2473 actionFormatLinkStyleLine->setOn(true);
2476 actionFormatLinkStyleParabel->setOn(true);
2479 actionFormatLinkStylePolyLine->setOn(true);
2481 case StylePolyParabel:
2482 actionFormatLinkStylePolyParabel->setOn(true);
2488 QPixmap pix( 16, 16 );
2489 pix.fill( mapCanvas->backgroundColor() );
2490 actionFormatBackColor->setIconSet( pix );
2491 pix.fill( defLinkColor );
2492 actionFormatLinkColor->setIconSet( pix );
2494 actionEditUndo->setEnabled( mapChanged );
2495 actionFileSave->setEnabled( mapUnsaved );
2499 if ( (typeid(*selection) == typeid(BranchObj)) ||
2500 (typeid(*selection) == typeid(MapCenterObj)) )
2502 BranchObj *bo=(BranchObj*)selection;
2503 // Take care of links
2504 if (bo->countXLinks()==0)
2506 branchLinksContextMenu->clear();
2507 branchLinksContextMenu->insertItem ("No xLink available");
2508 branchLinksContextMenuDup->clear();
2509 branchLinksContextMenuDup->insertItem ("No xLink available");
2515 branchLinksContextMenu->clear();
2516 branchLinksContextMenuDup->clear();
2517 for (int i=0; i<=bo->countXLinks();i++)
2519 bot=bo->XLinkTargetAt(i);
2522 s=bot->getHeading();
2525 branchLinksContextMenu->insertItem (s);
2526 branchLinksContextMenuDup->insertItem (s);
2531 standardFlagsDefault->setEnabled (true);
2533 if ( bo->getURL().isEmpty() )
2534 actionEditOpenURL->setEnabled (false);
2536 actionEditOpenURL->setEnabled (true);
2538 if ( bo->getVymLink().isEmpty() )
2540 actionEditOpenVymLink->setEnabled (false);
2541 actionEditDeleteVymLink->setEnabled (false);
2544 actionEditOpenVymLink->setEnabled (true);
2545 actionEditDeleteVymLink->setEnabled (true);
2548 actionEditCopy->setEnabled (true);
2549 actionEditCut->setEnabled (true);
2550 if (!clipboardEmpty)
2551 actionEditPaste->setEnabled (true);
2553 actionEditPaste->setEnabled (false);
2554 for (a=actionListBranches.first();a;a=actionListBranches.next())
2555 a->setEnabled(true);
2556 actionEditDelete->setEnabled (true);
2557 actionEditToggleFloatExport->setEnabled (false);
2558 switch (selection->getFrameType())
2561 actionFormatFrameNone->setOn(true);
2564 actionFormatFrameRectangle->setOn(true);
2569 actionFormatIncludeImagesVer->setOn
2570 ( ((BranchObj*)selection)->getIncludeImagesVer());
2571 actionFormatIncludeImagesHor->setOn
2572 ( ((BranchObj*)selection)->getIncludeImagesHor());
2573 actionFormatHideLinkUnselected->setOn
2574 (selection->getHideLinkUnselected());
2576 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2578 standardFlagsDefault->setEnabled (false);
2580 actionEditOpenURL->setEnabled (false);
2581 actionEditOpenVymLink->setEnabled (false);
2582 actionEditDeleteVymLink->setEnabled (false);
2584 actionEditCopy->setEnabled (true);
2585 actionEditCut->setEnabled (true);
2586 actionEditPaste->setEnabled (false); //FIXME
2587 for (a=actionListBranches.first();a;a=actionListBranches.next())
2588 a->setEnabled(false);
2589 actionEditDelete->setEnabled (true);
2590 actionEditToggleFloatExport->setOn
2591 ( ((FloatImageObj*)selection)->getFloatExport() );
2592 actionFormatHideLinkUnselected->setOn
2593 ( selection->getHideLinkUnselected());
2598 standardFlagsDefault->setEnabled (false);
2600 actionEditCopy->setEnabled (false);
2601 actionEditCut->setEnabled (false);
2602 actionEditPaste->setEnabled (false);
2603 for (a=actionListBranches.first();a;a=actionListBranches.next())
2604 a->setEnabled(false);
2606 actionEditOpenURL->setEnabled (false);
2607 actionEditOpenVymLink->setEnabled (false);
2608 actionEditDeleteVymLink->setEnabled (false);
2609 actionEditHeading2URL->setEnabled (false);
2610 actionEditDelete->setEnabled (false);
2611 actionEditToggleFloatExport->setEnabled (false);
2615 void MapEditor::updateNoteFlag()
2618 if ( (typeid(*selection) == typeid(BranchObj)) ||
2619 (typeid(*selection) == typeid(MapCenterObj)) )
2620 ((BranchObj*)selection)->updateNoteFlag();
2623 void MapEditor::setLinkStyle (LinkStyle ls)
2627 saveState(); // TODO undoCommand
2629 bo=mapCenter->first();
2633 bo->setLinkStyle(bo->getDefLinkStyle());
2636 mapCenter->reposition();
2639 LinkStyle MapEditor::getLinkStyle ()
2644 void MapEditor::setLinkColor(QColor c)
2650 void MapEditor::setLinkColorHint()
2652 // called from setLinkColorHint(lch) or at end of parse
2654 bo=mapCenter->first();
2662 void MapEditor::setLinkColorHint(LinkColorHint lch)
2668 void MapEditor::toggleLinkColorHint()
2670 if (linkcolorhint==HeadingColor)
2671 linkcolorhint=DefaultColor;
2673 linkcolorhint=HeadingColor;
2675 bo=mapCenter->first();
2683 LinkColorHint MapEditor::getLinkColorHint()
2685 return linkcolorhint;
2688 QColor MapEditor::getDefLinkColor()
2690 return defLinkColor;
2693 void MapEditor::setDefXLinkColor(QColor col)
2698 QColor MapEditor::getDefXLinkColor()
2700 return defXLinkColor;
2703 void MapEditor::setDefXLinkWidth (int w)
2708 int MapEditor::getDefXLinkWidth()
2710 return defXLinkWidth;
2713 void MapEditor::selectLinkColor()
2715 // Finish open lineEdits
2716 if (lineedit) finishedLineEditNoSave();
2718 QColor col = QColorDialog::getColor( defLinkColor, this );
2719 if ( !col.isValid() ) return;
2720 setLinkColor( col );
2721 saveState(); //TODO undoCommand
2725 void MapEditor::toggleScroll()
2727 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2729 BranchObj *bo=((BranchObj*)selection);
2730 if (bo->countBranches()==0) return;
2731 if (bo->getDepth()==0) return;
2732 saveState(selection);
2739 void MapEditor::unScrollAll()
2742 bo=mapCenter->first();
2745 if (bo->isScrolled()) bo->toggleScroll();
2750 void MapEditor::loadFloatImage ()
2753 (typeid(*selection) == typeid(BranchObj)) ||
2754 (typeid(*selection) == typeid(MapCenterObj)) )
2756 BranchObj *bo=((BranchObj*)selection);
2758 QFileDialog *fd=new QFileDialog( this,QString ("vym - ")+tr("Load image"));
2759 fd->setMode (QFileDialog::ExistingFiles);
2760 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2761 ImagePreview *p =new ImagePreview (fd);
2762 fd->setContentsPreviewEnabled( TRUE );
2763 fd->setContentsPreview( p, p );
2764 fd->setPreviewMode( QFileDialog::Contents );
2765 fd->setCaption(__VYM " - " +tr("Load image"));
2766 fd->setDir (lastImageDir);
2770 if ( fd->exec() == QDialog::Accepted )
2772 saveState(selection);
2773 lastImageDir=fn.left(fn.findRev ("/"));
2774 QStringList flist = fd->selectedFiles();
2775 QStringList::Iterator it = flist.begin();
2776 while( it != flist.end() )
2779 bo->addFloatImage();
2780 // TODO check if load was successful
2781 bo->getLastFloatImage()->load(*it);
2782 bo->getLastFloatImage()->setOriginalFilename(fn);
2786 mapCenter->reposition();
2793 void MapEditor::saveFloatImage (int item)
2796 (typeid(*selection) == typeid(FloatImageObj)) )
2798 FloatImageObj *fio=((FloatImageObj*)selection);
2799 const char* fmt = saveImageFormatMenu->text(item);
2801 QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
2802 fd->addFilter ("PNG (*.png)");
2803 fd->addFilter ("BMP (*.bmp)");
2804 fd->addFilter ("XBM (*.xbm)");
2805 fd->addFilter ("JPG (*.jpg)");
2806 fd->addFilter ("XPM (*.xpm)");
2807 fd->addFilter ("GIF (*.gif)");
2808 fd->addFilter ("PNM (*.pnm)");
2809 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2810 fd->setCaption(__VYM " - " +tr("Save image as %1").arg(fmt));
2811 fd->setMode( QFileDialog::AnyFile );
2812 fd->setSelection (fio->getOriginalFilename());
2816 if ( fd->exec() == QDialog::Accepted )
2818 if (QFile (fd->selectedFile()).exists() )
2820 QMessageBox mb( __VYM,
2821 tr("The file %1 exists already.\n"
2822 "Do you want to overwrite it?").arg(fd->selectedFile()),
2823 QMessageBox::Warning,
2824 QMessageBox::Yes | QMessageBox::Default,
2825 QMessageBox::Cancel | QMessageBox::Escape,
2826 QMessageBox::QMessageBox::NoButton );
2828 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2829 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2832 case QMessageBox::Yes:
2835 case QMessageBox::Cancel:
2841 fio->save (fd->selectedFile(),fmt);
2846 void MapEditor::toggleFloatExport()
2849 (typeid(*selection) == typeid(FloatImageObj))||
2850 (typeid(*selection) == typeid(FloatObj)) )
2852 FloatImageObj *fio=((FloatImageObj*)selection);
2853 fio->setFloatExport (actionEditToggleFloatExport->isOn() );
2857 void MapEditor::setFrame(const FrameType &t)
2860 (typeid(*selection) == typeid(BranchObj)) ||
2861 (typeid(*selection) == typeid(MapCenterObj)) )
2863 selection->setFrameType (t);
2864 mapCenter->reposition();
2865 selection->updateLink();
2869 void MapEditor::setIncludeImagesVer(bool b)
2872 (typeid(*selection) == typeid(BranchObj)) ||
2873 (typeid(*selection) == typeid(MapCenterObj)) )
2874 ((BranchObj*)selection)->setIncludeImagesVer(b);
2875 mapCenter->reposition();
2878 void MapEditor::setIncludeImagesHor(bool b)
2881 (typeid(*selection) == typeid(BranchObj)) ||
2882 (typeid(*selection) == typeid(MapCenterObj)) )
2883 ((BranchObj*)selection)->setIncludeImagesHor(b);
2884 mapCenter->reposition();
2887 void MapEditor::setHideLinkUnselected (bool b)
2890 (typeid(*selection) == typeid(BranchObj)) ||
2891 (typeid(*selection) == typeid(MapCenterObj)) ||
2892 (typeid(*selection) == typeid(FloatImageObj)) )
2893 selection->setHideLinkUnselected(b);
2896 void MapEditor::importDir(BranchObj *dst, QDir d)
2899 (typeid(*selection) == typeid(BranchObj)) ||
2900 (typeid(*selection) == typeid(MapCenterObj)) )
2904 // Traverse directories
2905 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2906 const QFileInfoList *dirlist = d.entryInfoList();
2907 QFileInfoListIterator itdir( *dirlist );
2910 while ( (fi = itdir.current()) != 0 )
2912 if (fi->fileName() != "." && fi->fileName() != ".." )
2915 bo=dst->getLastBranch();
2916 bo->setHeading (fi->fileName() );
2917 bo->setColor (QColor("blue"),false);
2919 if ( !d.cd(fi->fileName()) )
2920 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi->fileName()));
2923 // Recursively add subdirs
2931 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
2932 const QFileInfoList *filelist = d.entryInfoList();
2933 QFileInfoListIterator itfile( *filelist );
2935 while ( (fi = itfile.current()) != 0 )
2938 bo=dst->getLastBranch();
2939 bo->setHeading (fi->fileName() );
2940 bo->setColor (QColor("black"),false);
2941 if (fi->fileName().right(4) == ".vym" )
2942 bo->setVymLink (fi->filePath());
2949 void MapEditor::importDir()
2952 (typeid(*selection) == typeid(BranchObj)) ||
2953 (typeid(*selection) == typeid(MapCenterObj)) )
2955 QFileDialog *fd=new QFileDialog( this,__VYM " - " +tr("Choose directory structure to import"));
2956 fd->setMode (QFileDialog::DirectoryOnly);
2957 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2958 fd->setCaption(__VYM " - " +tr("Choose directory structure to import"));
2962 if ( fd->exec() == QDialog::Accepted )
2964 BranchObj *bo=((BranchObj*)selection);
2965 importDir (bo,QDir(fd->selectedFile()) );
2966 mapCenter->reposition();
2973 void MapEditor::followXLink(int i)
2976 (typeid(*selection) == typeid(BranchObj)) ||
2977 (typeid(*selection) == typeid(MapCenterObj)) )
2979 BranchObj *bo=((BranchObj*)selection)->XLinkTargetAt(i);
2982 selection->unselect();
2984 selection->select();
2985 ensureSelectionVisible();
2990 void MapEditor::editXLink(int i)
2993 (typeid(*selection) == typeid(BranchObj)) ||
2994 (typeid(*selection) == typeid(MapCenterObj)) )
2996 XLinkObj *xlo=((BranchObj*)selection)->XLinkAt(i);
2999 EditXLinkDialog dia;
3001 dia.setSelection(selection);
3002 if (dia.exec() == QDialog::Accepted)
3004 if (dia.useSettingsGlobal() )
3006 setDefXLinkColor (xlo->getColor() );
3007 setDefXLinkWidth (xlo->getWidth() );
3009 if (dia.deleteXLink())
3010 ((BranchObj*)selection)->deleteXLinkAt(i);
3011 saveState(); //TODO undoCommand
3017 void MapEditor::testFunction()
3019 cout << "MapEditor::testFunction() called\n";
3022 if (selection && (typeid(*selection) == typeid(BranchObj)))
3024 cout << "Note:\n"<<((BranchObj*)selection)->getNoteOpenDoc()<<endl;
3029 void MapEditor::ensureSelectionVisible()
3033 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
3035 if (selection->getOrientation() == OrientLeftOfCenter)
3036 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
3038 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
3039 ensureVisible (p.x(), p.y() );
3044 void MapEditor::updateViewCenter()
3046 // Update movingCenter, so that we can zoom comfortably later
3047 QRect rc = QRect( contentsX(), contentsY(),
3048 visibleWidth(), visibleHeight() );
3049 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
3050 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
3051 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
3054 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
3056 // Lineedits are already closed by preceding
3057 // mouseEvent, we don't need to close here.
3059 QPoint p = inverseWorldMatrix().map(e->pos());
3060 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3063 { // MapObj was found
3064 if (selection != lmo)
3066 // select the MapObj
3067 if (selection) selection->unselect();
3069 selection->select();
3075 if (typeid(*selection)==typeid(BranchObj) ||
3076 typeid(*selection)==typeid(MapCenterObj) )
3078 // Context Menu on branch or mapcenter
3080 branchContextMenu->popup(e->globalPos() );
3082 if (typeid(*selection)==typeid(FloatImageObj))
3084 // Context Menu on floatimage
3086 floatimageContextMenu->popup(e->globalPos() );
3090 { // No MapObj found, we are on the Canvas itself
3091 // Context Menu on Canvas
3093 canvasContextMenu->popup(e->globalPos() );
3097 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
3099 // Finish open lineEdits
3100 if (lineedit) finishedLineEditNoSave();
3102 QPoint p = inverseWorldMatrix().map(e->pos());
3103 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3105 // Special case: CTRL is pressed
3106 if (e->state() & QMouseEvent::ControlButton)
3108 if (actionModModeColor->isOn())
3110 if (e->state() & QMouseEvent::ControlButton)
3113 setCursor (pickColorCursor);
3117 if (actionModModeLink->isOn())
3119 BranchObj *bo_begin=NULL;
3121 bo_begin=(BranchObj*)(lmo);
3124 ((typeid(*selection) == typeid(BranchObj)) ||
3125 (typeid(*selection) == typeid(MapCenterObj))) )
3126 bo_begin=(BranchObj*)selection;
3130 linkingObj_src=bo_begin;
3131 tmpXLink=new XLinkObj (mapCanvas);
3132 tmpXLink->setBegin (bo_begin);
3133 tmpXLink->setEnd (p);
3134 tmpXLink->setColor(defXLinkColor);
3135 tmpXLink->setWidth(defXLinkWidth);
3136 tmpXLink->updateXLink();
3137 tmpXLink->setVisibility (true);
3144 { // MapObj was found
3145 if (selection != lmo)
3147 // select the MapObj
3148 if (selection) selection->unselect();
3150 selection->select();
3155 // Check, if systemFlag clicked
3156 if (typeid(*selection)==typeid(BranchObj) ||
3157 typeid(*selection)==typeid(MapCenterObj) )
3159 QString foname=((BranchObj*)selection)->getSystemFlagName(p);
3160 if (!foname.isEmpty())
3162 // Do not move, if systemFlag clicked
3166 if (foname=="vymLink")
3168 mainWindow->editOpenVymLink();
3169 // tabWidget may change, better return now
3170 // before segfaulting...
3174 mainWindow->windowToggleNoteEditor();
3178 // Left Button Move Branches
3179 if (e->button() == QMouseEvent::LeftButton )
3181 movingObj_start.setX( p.x() - selection->x() );
3182 movingObj_start.setY( p.y() - selection->y() );
3183 movingObj_orgPos.setX (lmo->x() );
3184 movingObj_orgPos.setY (lmo->y() );
3186 // If modMode==copy, then we want to "move" the _new_ object around
3187 // then we need the offset from p to the _old_ selection, because of tmp
3188 if (actionModModeCopy->isOn() &&
3189 e->state() & QMouseEvent::ControlButton)
3191 if (typeid(*selection)==typeid(BranchObj) )
3194 mapCenter->addBranch ((BranchObj*)selection);
3196 selection=mapCenter->getLastBranch();
3197 selection->select();
3198 mapCenter->reposition();
3201 movingObj=selection;
3203 // Middle Button Toggle Scroll
3204 // (On Mac OS X this won't work, but we still have
3205 // a button in the toolbar)
3206 if (e->button() == QMouseEvent::MidButton )
3210 { // No MapObj found, we are on the Canvas itself
3211 // Left Button move Pos of CanvasView
3212 if (e->button() == QMouseEvent::LeftButton )
3214 movingObj=NULL; // move Content not Obj
3215 movingObj_start=e->globalPos();
3216 movingCont_start=QPoint (contentsX(), contentsY() );
3217 movingVec=QPoint(0,0);
3218 setCursor(handOpenCursor);
3223 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3225 QPoint p = inverseWorldMatrix().map(e->pos());
3227 // Move the selected MapObj
3228 if ( selection && movingObj)
3230 // To avoid jumping of the CanvasView, only
3231 // ensureSelectionVisible, if not tmp linked
3232 if (!selection->hasParObjTmp())
3233 ensureSelectionVisible ();
3235 // Now move the selection, but add relative position
3236 // (movingObj_start) where selection was chosen with
3237 // mousepointer. (This avoids flickering resp. jumping
3238 // of selection back to absPos)
3240 LinkableMapObj *lmosel;
3241 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3243 // Check if we could link
3244 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3247 if (typeid(*selection) == typeid(FloatImageObj))
3249 FloatObj *fo=(FloatObj*)selection;
3250 saveState("move "+qpointToString(movingObj_orgPos),fo->getSelectString() );
3251 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3255 // Relink float to new mapcenter or branch, if shift is pressed
3256 // Only relink, if selection really has a new parent
3257 if ( (e->state() & QMouseEvent::ShiftButton) && lmo &&
3258 ( (typeid(*lmo)==typeid(BranchObj)) ||
3259 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3260 ( lmo != fo->getParObj())
3263 if (typeid(*fo) == typeid(FloatImageObj))
3266 FloatImageObj *fio=(FloatImageObj*)(fo);
3267 ((BranchObj*)(lmo))->addFloatImage (fio);
3269 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3270 fio=((BranchObj*)(lmo))->getLastFloatImage();
3273 selection=(LinkableMapObj*)(fio);
3274 selection->select();
3275 movingObj=(MapObj*)(fio);
3278 } else // selection != a FloatObj
3280 if (lmosel->getDepth()==0)
3282 if (e->state() == (LeftButton | !ShiftButton))
3283 // If mapCenter is moved, move all the rest by default, too.
3284 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3286 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3289 if (lmosel->getDepth()==1)
3291 // depth==1, mainbranch
3292 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3296 if (lmosel->getOrientation() == OrientLeftOfCenter)
3297 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3298 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3299 p.y()-movingObj_start.y() +lmosel->getTopPad() );
3301 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
3303 // reposition subbranch
3304 lmosel->reposition();
3305 //ensureSelectionVisible();
3307 if (lmo && (lmo!=selection) &&
3308 (typeid(*lmo) == typeid(BranchObj) ||
3309 (typeid(*lmo) == typeid(MapCenterObj) )
3312 if (e->state() & QMouseEvent::ControlButton)
3314 // Special case: CTRL to link below lmo
3315 lmosel->setParObjTmp (lmo,p,+1);
3317 else if (e->state() & QMouseEvent::ShiftButton)
3318 lmosel->setParObjTmp (lmo,p,-1);
3320 lmosel->setParObjTmp (lmo,p,0);
3323 lmosel->unsetParObjTmp();
3324 /* FIXME not needed anymore?
3325 if (lmo &&(lmo==selection))
3326 // Could link to myself (happens sometimes...)
3327 lmosel->unsetParObjTmp();
3329 // no Obj under selection, go back to original Parent
3330 lmosel->unsetParObjTmp();
3335 } // no FloatImageObj
3339 } // selection && moving_obj
3341 // Draw a link from one branch to another
3344 tmpXLink->setEnd (p);
3345 tmpXLink->updateXLink();
3349 if (!movingObj && !pickingColor &&!drawingLink)
3351 QPoint p=e->globalPos();
3352 movingVec.setX(-p.x() + movingObj_start.x() );
3353 movingVec.setY(-p.y() + movingObj_start.y() );
3354 setContentsPos( movingCont_start.x() + movingVec.x(),
3355 movingCont_start.y() + movingVec.y());
3362 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3364 LinkableMapObj *dst;
3365 // Have we been picking color?
3369 setCursor (ArrowCursor);
3370 // Check if we are over another branch
3371 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3372 if (dst && selection)
3374 if (e->state() & QMouseEvent::ShiftButton)
3376 ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor(),false);
3377 ((BranchObj*)selection)->setLinkColor ();
3381 ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor(),true);
3382 ((BranchObj*)selection)->setLinkColor ();
3388 // Have we been drawing a link?
3392 // Check if we are over another branch
3393 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3394 if (dst && selection)
3396 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3397 tmpXLink->updateXLink();
3398 tmpXLink->activate();
3399 saveState(); //TODO undoCommand
3408 // Have we been moving something?
3409 if ( selection && movingObj )
3411 // Moved FloatObj? Maybe we need to reposition
3412 if(typeid(*selection)==typeid (FloatImageObj))
3414 selection->getParObj()->requestReposition();
3415 mapCenter->reposition();
3418 // Check if we are over another branch, but ignore
3419 // any found LMOs, which are FloatObjs
3420 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3421 ((LinkableMapObj*)selection) );
3424 (typeid(*dst)!=typeid(BranchObj)&&typeid(*dst)!=typeid(MapCenterObj)))
3427 // Now check, if we have been moving a branch
3428 if (typeid(*selection) == typeid(BranchObj) )
3430 // save the position in case we link to mapcenter
3431 QPoint savePos=QPoint (selection->x(),selection->y() );
3433 // Reset the temporary drawn link to the original one
3434 ((LinkableMapObj*)selection)->unsetParObjTmp();
3440 BranchObj* bs=((BranchObj*)selection);
3441 QString undoCom="linkBranchToPos (\""+
3442 (bs->getParObj())->getSelectString()+
3444 QString("%1").arg(bs->getNum())+
3446 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+
3448 // TODO we also could check, if dest and src are on same branch,
3449 // then it would be sufficient to saveState of this branch
3451 // Modifiers allow to insert above/below dst
3452 if (e->state() & QMouseEvent::ShiftButton)
3454 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum());
3456 if (e->state() & QMouseEvent::ControlButton)
3458 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum()+1);
3461 bs->moveBranchTo ((BranchObj*)(dst),-1);
3462 if (dst->getDepth()==0)
3465 saveState (undoCom,bs->getSelectString() );
3467 if (selection->getDepth()==1)
3468 // If we have moved mainbranch only save endposition
3469 saveState("move "+qpointToString(movingObj_orgPos), selection->getSelectString() );
3471 // Draw the original link, before selection was moved around
3472 mapCenter->reposition();
3474 // Finally resize canvas, if needed
3479 // maybe we moved View: set old cursor
3480 setCursor (ArrowCursor);
3484 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3486 // Finish open lineEdits
3487 if (lineedit) finishedLineEditNoSave();
3489 if (e->button() == QMouseEvent::LeftButton )
3491 QPoint p = inverseWorldMatrix().map(e->pos());
3492 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3493 if (lmo) { // MapObj was found
3494 // First select the MapObj than edit heading
3495 if (selection) selection->unselect();
3497 selection->select();
3498 saveState(selection);
3504 void MapEditor::resizeEvent (QResizeEvent* e)
3506 QCanvasView::resizeEvent( e );
3510 void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3513 // for (unsigned int i=0;event->format(i);i++) // Debug mime type
3514 // cerr << event->format(i) << endl;
3517 (typeid(*selection) == typeid(BranchObj)) ||
3518 (typeid(*selection) == typeid(MapCenterObj))) {
3520 // If QImageDrag can decode mime type
3521 if (QImageDrag::canDecode(event)) {
3526 // If image are dragged from firefox
3527 if (event->provides("application/x-moz-file-promise-url") &&
3528 event->provides("application/x-moz-nativeimage")) {
3529 event->accept(true);
3533 // If QUriDrag can decode mime type
3534 if (QUriDrag::canDecode(event)) {
3539 // If Uri are dragged from firefox
3540 if (event->provides("_NETSCAPE_URL")){
3545 // If QTextDrag can decode mime type
3546 if (QTextDrag::canDecode(event)) {
3555 bool isUnicode16(const QByteArray &d)
3557 // TODO: make more precise check for unicode 16.
3558 // Guess unicode16 if any of second bytes are zero
3559 unsigned int length = max(0,d.size()-2)/2;
3560 for (unsigned int i = 0; i<length ; i++)
3561 if (d.at(i*2+1)==0) return true;
3565 void MapEditor::contentsDropEvent(QDropEvent *event)
3568 (typeid(*selection) == typeid(BranchObj)) ||
3569 (typeid(*selection) == typeid(MapCenterObj)))
3574 if (event->provides("image/png"))
3577 if (QImageDrag::decode(event, pix))
3585 } else if (event->provides("application/x-moz-file-promise-url") &&
3586 event->provides("application/x-moz-nativeimage"))
3588 // Contains url to the img src in unicode16
3589 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3590 QString url = QString((const QChar*)d.data(),d.size()/2);
3594 } else if (event->provides ("text/uri-list"))
3595 { // Uris provided e.g. by konqueror
3596 QUriDrag::decode (event,uris);
3597 } else if (event->provides ("_NETSCAPE_URL"))
3598 { // Uris provided by Mozilla
3599 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
3602 } else if (event->provides("text/html")) {
3604 // Handels text mime types
3605 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
3606 QByteArray d = event->encodedData("text/html");
3609 text = QString((const QChar*)d.data(),d.size()/2);
3613 textEditor->setText(text);
3617 } else if (event->provides("text/plain")) {
3618 QByteArray d = event->encodedData("text/plain");
3621 text = QString((const QChar*)d.data(),d.size()/2);
3625 textEditor->setText(text);
3637 for (const char* u=uris.first(); u; u=uris.next())
3639 bo=((BranchObj*)selection)->addBranch();
3642 s=QUriDrag::uriToLocalFile(u);
3644 QString file = QDir::convertSeparators(s);
3645 heading = QFileInfo(file).baseName();
3647 if (file.endsWith(".vym", false))
3648 bo->setVymLink(file);
3657 bo->setHeading(heading);
3667 saveState(); //TODO undo Command
3668 mapCenter->reposition();
3675 void MapEditor::addFloatImage(const QPixmap &img)
3678 (typeid(*selection) == typeid(BranchObj)) ||
3679 (typeid(*selection) == typeid(MapCenterObj)) )
3681 BranchObj *bo=((BranchObj*)selection);
3682 saveState(selection);
3683 //QString fn=fd->selectedFile();
3684 //lastImageDir=fn.left(fn.findRev ("/"));
3685 bo->addFloatImage();
3686 // FIXME check if load was successful
3687 bo->getLastFloatImage()->load(img);
3688 //bo->getLastFloatImage()->setOriginalFilename(fn);
3689 mapCenter->reposition();
3696 void MapEditor::imageDataFetched(const QByteArray &a, QNetworkOperation */*nop*/)
3698 if (!imageBuffer) imageBuffer = new QBuffer();
3699 if (!imageBuffer->isOpen()) {
3700 imageBuffer->open(IO_WriteOnly | IO_Append);
3702 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
3706 void MapEditor::imageDataFinished(QNetworkOperation *nop)
3708 if (nop->state()==QNetworkProtocol::StDone) {
3709 QPixmap img(imageBuffer->buffer());
3714 imageBuffer->close();
3716 imageBuffer->close();
3723 void MapEditor::fetchImage(const QString &url)
3726 urlOperator->stop();
3727 disconnect(urlOperator);
3731 urlOperator = new QUrlOperator(url);
3732 connect(urlOperator, SIGNAL(finished(QNetworkOperation *)),
3733 this, SLOT(imageDataFinished(QNetworkOperation*)));
3735 connect(urlOperator, SIGNAL(data(const QByteArray &, QNetworkOperation *)),
3736 this, SLOT(imageDataFetched(const QByteArray &, QNetworkOperation *)));