hideLinkInExport for Branches (Floats still missing). Floats are now OrnamentedObj.
3 #include <qstatusbar.h>
4 #include <qmessagebox.h>
5 #include <qapplication.h>
7 #include <qpopupmenu.h>
9 #include <qpaintdevicemetrics.h>
11 #include <qfiledialog.h>
14 #include <qcolordialog.h>
17 #include <qinputdialog.h>
18 #include <qdragobject.h>
19 #include <qurloperator.h>
20 #include <qnetworkprotocol.h>
30 #include "editxlinkdialog.h"
32 #include "extrainfodialog.h"
34 #include "linkablemapobj.h"
35 #include "mainwindow.h"
38 #include "texteditor.h"
42 extern TextEditor *textEditor;
43 extern int statusbarTime;
44 extern Main *mainWindow;
45 extern QString tmpVymDir;
46 extern QString clipboardDir;
47 extern bool clipboardEmpty;
48 extern FlagRowObj *systemFlagsDefault;
49 extern FlagRowObj *standardFlagsDefault;
51 extern QPtrList <QAction> actionListBranches;
53 extern QAction *actionFileSave;
54 extern QAction *actionEditUndo;
55 extern QAction *actionEditCopy;
56 extern QAction *actionEditCut;
57 extern QAction *actionEditPaste;
58 extern QAction *actionEditMoveUp;
59 extern QAction *actionEditMoveDown;
60 extern QAction *actionEditToggleScroll;
61 extern QAction *actionEditOpenURL;
62 extern QAction *actionEditURL;
63 extern QAction *actionEditHeading2URL;
64 extern QAction *actionEditBugzilla2URL;
65 extern QAction *actionEditFATE2URL;
66 extern QAction *actionEditOpenVymLink;
67 extern QAction *actionEditVymLink;
68 extern QAction *actionEditDeleteVymLink;
69 extern QAction *actionEditHeading;
70 extern QAction *actionEditDelete;
71 extern QAction *actionEditAddBranch;
72 extern QAction *actionEditAddBranchAbove;
73 extern QAction *actionEditAddBranchBelow;
74 extern QAction *actionEditRemoveBranchHere;
75 extern QAction *actionEditRemoveChilds;
76 extern QAction *actionEditImportAdd;
77 extern QAction *actionEditImportReplace;
78 extern QAction *actionEditSaveBranch;
79 extern QAction *actionEditSelectFirst;
80 extern QAction *actionEditSelectLast;
81 extern QAction *actionEditLoadImage;
82 extern QAction *actionEditToggleFloatExport;
84 extern QAction* actionFormatPickColor;
85 extern QAction* actionFormatColorBranch;
86 extern QAction* actionFormatColorSubtree;
87 extern QAction *actionFormatLinkColorHint;
88 extern QAction *actionFormatBackColor;
89 extern QAction *actionFormatLinkColor;
91 extern QActionGroup* actionGroupModModes;
92 extern QAction* actionModModeColor;
93 extern QAction* actionModModeLink;
94 extern QAction* actionModModeCopy;
96 extern QActionGroup *actionGroupFormatFrameTypes;
97 extern QAction *actionFormatFrameNone;
98 extern QAction *actionFormatFrameRectangle;
100 extern QActionGroup *actionGroupFormatLinkStyles;
101 extern QAction *actionFormatIncludeImagesVer;
102 extern QAction *actionFormatIncludeImagesHor;
103 extern QAction *actionFormatHideLinkUnselected;
104 extern QAction *actionFormatLinkStyleLine;
105 extern QAction *actionFormatLinkStyleParabel;
106 extern QAction *actionFormatLinkStylePolyLine;
107 extern QAction *actionFormatLinkStylePolyParabel;
109 extern QAction *actionViewToggleNoteEditor;
111 extern QAction *actionSettingsAutoedit;
112 extern QAction *actionSettingsAutoselectHeading;
113 extern QAction *actionSettingsAutoselectText;
114 extern QAction *actionSettingsPasteNewHeading;
115 extern QAction *actionSettingsUseFlagGroups;
117 extern QPopupMenu *branchContextMenu;
118 extern QPopupMenu *branchLinksContextMenu;
119 extern QPopupMenu *branchLinksContextMenuDup;
120 extern QPopupMenu *floatimageContextMenu;
121 extern QPopupMenu *saveImageFormatMenu;
122 extern QPopupMenu *exportImageFormatMenu;
123 extern QPopupMenu *canvasContextMenu;
125 extern Settings settings;
127 int MapEditor::mapNum=0; // make instance
129 ///////////////////////////////////////////////////////////////////////
130 ///////////////////////////////////////////////////////////////////////
131 MapEditor::MapEditor(
132 QWidget* parent, bool interactive, const char* name, WFlags f) :
133 QCanvasView(parent,name,f), urlOperator(0), imageBuffer(0)
135 //cout << "Constructor ME "<<this<<endl;
138 viewport()->setAcceptDrops(true);
140 mapCanvas = new QCanvas(1000,800);
141 mapCanvas->setAdvancePeriod(30);
142 mapCanvas->setBackgroundColor (white);
144 setCanvas (mapCanvas);
146 // Always show scroll bars (automatic would flicker sometimes)
147 setVScrollBarMode ( QScrollView::AlwaysOn );
148 setHScrollBarMode ( QScrollView::AlwaysOn );
150 mapCenter = new MapCenterObj(mapCanvas);
151 mapCenter->setVisibility (true);
152 mapCenter->setMapEditor (this);
153 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
154 mapCenter->move(mapCanvas->width()/2-mapCenter->width()/2,mapCanvas->height()/2-mapCenter->height()/2);
158 lineedit = new QLineEdit(this, "lineedit" );
159 connect( lineedit, SIGNAL( returnPressed() ), SLOT( finishedLineEditNoSave() ) );
162 actColor=black; setColor (actColor);
163 defLinkColor=QColor (0,0,255);
164 defXLinkColor=QColor (180,180,180);
165 linkcolorhint=DefaultColor;
166 linkstyle=StylePolyParabel;
168 // Create bitmap cursors, patform dependant
169 #if defined(Q_OS_MACX)
170 #include "icons/cursorhandopen16.xpm"
171 #include "icons/cursorcolorpicker16.xpm"
172 QBitmap cb( 16, 16, chandopen, TRUE );
173 QBitmap cm( 16, 16, chandopenmask, TRUE );
174 handOpenCursor=QCursor ( cb, cm );
175 // set hot spot to tip of picker
176 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 1,15 );
178 #include "icons/cursorhandopen.xpm"
179 #include "icons/cursorcolorpicker.xpm"
181 QBitmap cb( 32, 32, chandopen, TRUE );
182 QBitmap cm( 32, 32, chandopenmask, TRUE );
183 handOpenCursor=QCursor ( cb, cm );
184 // set hot spot to tip of picker
185 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 5,27 );
198 defXLinkColor=QColor (230,230,230);
209 undosTotal=settings.readNumEntry("/vym/mapeditor/undoLevels",50);
213 // Initialize find routine
220 blockReposition=false;
221 blockSaveState=false;
222 isInteractive=interactive;
224 // Create temporary files
227 // Initially set movingCentre
230 mapCenter->reposition(); // for positioning heading
233 MapEditor::~MapEditor()
235 if (imageBuffer) delete imageBuffer;
241 //cout <<"Destructor MapEditor\n";
244 //settings.writeEntry( "/vym/mapeditor/editmode/autoselect", );
248 QColor MapEditor::color()
253 QColor MapEditor::backgroundColor()
255 return mapCanvas->backgroundColor();
258 MapCenterObj* MapEditor::getMapCenter()
263 QCanvas* MapEditor::getCanvas()
268 void MapEditor::adjustCanvasSize()
270 // To adjust the canvas to map, viewport size and position, we have to
271 // do some coordinate magic...
273 // Get rectangle of (scroll-)view.
274 // We want to be in canvas coords, so
275 // we map. Important if view is zoomed...
276 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
277 visibleWidth(), visibleHeight()) );
279 // Now we need the bounding box of view AND map to calc the correct canvas size.
280 // Why? Because if the map itself is moved out of view, the view has to be enlarged
281 // to avoid jumping aroung...
282 QRect map=mapCenter->getTotalBBox();
284 // right edge - left edge
285 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
286 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
289 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
290 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
293 // move the map on canvas (in order to not move it on screen) this is neccessary
294 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
295 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
296 // to scroll to an empty area of canvas to the left.
297 // b) if topleft corner of map left of or above topleft of canvas
301 if (cw > mapCanvas->width() )
303 if (map.x()<0) dx=-map.x();
305 if (cw < mapCanvas->width() )
306 dx=-min (view.x(),map.x());
307 if (ch > mapCanvas->height() )
309 if (map.y()<0) dy=-map.y();
311 if (ch < mapCanvas->height() )
313 dy=-min (view.y(),map.y());
315 // We really have to resize now. Let's go...
316 mapCanvas->resize (cw,ch);
317 if ( (dx!=0) || (dy!=0) )
319 mapCenter->moveAllBy(dx,dy);
320 mapCenter->reposition();
322 // scroll the view (in order to not move map on screen)
328 bool MapEditor::isRepositionBlocked()
330 return blockReposition;
333 void MapEditor::makeTmpDirs()
335 // Create unique temporary directories
336 tmpMapDir=tmpVymDir+QString("/mapeditor-%1").arg(mapNum);
338 d.mkdir (tmpMapDir,true);
341 void MapEditor::delTmpDirs()
343 removeDir (QDir(tmpMapDir));
346 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSelection)
348 // tmpdir temporary directory to which data will be written
349 // prefix mapname, which will be appended to images etc.
350 // writeflags Only write flags for "real" save of map, not undo
351 // offset offset of bbox of whole map in canvas.
352 // Needed for XML export
368 ls="StylePolyParabel";
372 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
374 if (linkcolorhint==HeadingColor)
375 colhint=attribut("linkColorHint","HeadingColor");
377 QString mapAttr=attribut("version",__VYM_VERSION);
379 mapAttr+= attribut("author",mapCenter->getAuthor()) +
380 attribut("comment",mapCenter->getComment()) +
381 attribut("date",mapCenter->getDate()) +
382 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
383 attribut("linkStyle", ls ) +
384 attribut("linkColor", defLinkColor.name() ) +
385 attribut("defXLinkColor", defXLinkColor.name() ) +
386 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
388 s+=beginElement("vymmap",mapAttr);
391 // Find the used flags while traversing the tree
392 standardFlagsDefault->resetUsedCounter();
394 // Reset the counters before saving
395 FloatImageObj (mapCanvas).resetSaveCounter();
397 // Build xml recursivly
399 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
402 if ( typeid(*saveSelection) == typeid(BranchObj) )
403 s+=((BranchObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
404 else if ( typeid(*saveSelection) == typeid(FloatImageObj) )
405 s+=((FloatImageObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
407 else if (selection && typeid(*selection)==typeid(BranchObj))
408 // This is used if selected branch is saved from mainwindow
409 s+=((BranchObj*)selection)->saveToDir(tmpdir,prefix,offset);
412 // Save local settings
413 s+=settings.getXMLData (destPath);
416 if (selection && !saveSelection )
417 s+=valueElement("select",selection->getSelectString());
420 s+=endElement("vymmap");
423 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
427 void MapEditor::saveState()
430 saveState (CompleteMap,"",NULL,"",NULL);
433 void MapEditor::saveState(LinkableMapObj *undoSel)
435 // save the given part of the map
436 saveState (PartOfMap,"",undoSel,"",NULL);
439 void MapEditor::saveState(const QString &uc, const QString &rc)
441 // selection does not change during action,
442 // so just save commands for undo and redo
443 LinkableMapObj *unsel;
448 saveState (UndoCommand,uc,unsel,rc,unsel);
451 void MapEditor::saveState(const QString & uncom, LinkableMapObj *unsel)
453 saveState (UndoCommand,uncom,unsel,"FIXME-redoCom",NULL);
456 void MapEditor::saveState(const SaveMode &savemode, const QString &undoCom, LinkableMapObj *undoSel, const QString &redoCom, LinkableMapObj *redoSel)
460 if (blockSaveState) return;
462 /* TODO remove after testing
463 cout << "ME::saveState() begin\n"<<endl;
464 cout << " undosTotal="<<undosTotal<<endl;
465 cout << " undosAvail="<<undosAvail<<endl;
466 cout << " undoNum="<<undoNum<<endl;
467 cout << " ---------------------------"<<endl;
471 // Find out current undo directory
472 if (undosAvail<undosTotal) undosAvail++;
474 if (undoNum>undosTotal) undoNum=1;
477 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
478 QString bakMapPath=QDir::convertSeparators(bakMapDir+"/map.xml");
480 // Create bakMapDir if not available
483 makeSubDirs (bakMapDir);
485 // Save current selection
486 QString redoSelection="";
488 redoSelection=redoSel->getSelectString();
490 // Save the object, which should be undone
491 QString undoSelection="";
493 undoSelection=undoSel->getSelectString();
495 // Save depending on how much needs to be saved
496 QString undoCommand="";
497 if (savemode==UndoCommand)
502 else if (savemode==PartOfMap && undoSel)
504 undoCommand="undoPart (\""+ undoSelection+"\",\""+bakMapPath+"\")";
505 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),undoSel);
508 undoCommand="undoMap (\""+bakMapPath+"\")";
509 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),NULL);
512 if (!backupXML.isEmpty())
513 // Write XML Data to disk
514 saveStringToDisk (QString(bakMapPath),backupXML);
517 set.setEntry (QString("undoCommand"),undoCommand);
518 set.setEntry (QString("undoSelection"),undoSelection);
519 set.setEntry (QString("redoCommand"),redoCom);
520 set.setEntry (QString("redoSelection"),redoSelection);
521 set.writeSettings(QString(bakMapDir+"/commands"));
523 /* TODO remove after testing
524 cout << " into="<< bakMapDir<<endl;
525 cout << " undosAvail="<<undosAvail<<endl;
526 cout << " undoNum="<<undoNum<<endl;
527 cout << " ---------------------------"<<endl;
528 cout << " undoCom="<<undoCommand<<endl;
529 cout << " undoSel="<<undoSelection<<endl;
530 cout << " ---------------------------"<<endl;
531 cout << " redoCom="<<redoCom<<endl;
532 cout << " redoSel="<<redoSelection<<endl;
533 cout << " ---------------------------"<<endl<<endl;
537 void MapEditor::parseAtom(const QString &atom)
544 // Split string s into command and parameters
545 api.parseCommand (atom);
546 QString com=api.command();
549 if (com=="moveBranchUp")
551 else if (com=="moveBranchDown")
553 else if (com=="move")
555 if (api.checkParamCount(2) && selection )
565 else if (com=="linkBranchToPos")
567 if (selection && typeid(*selection) == typeid(BranchObj) )
569 if (api.checkParamCount(4))
571 s=api.parString(ok,0);
572 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
575 if (typeid(*dst) == typeid(BranchObj) )
577 // Get number in parent
580 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),x);
581 } else if (typeid(*dst) == typeid(MapCenterObj) )
583 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),-1);
584 // Get coordinates of mainbranch
589 if (ok) ((BranchObj*)selection)->move (x,y);
595 } else if (com=="setHeading")
597 if (api.checkParamCount(1))
599 s=api.parString (ok,0);
600 if (ok) setHeading (s);
602 } else if (com=="setURL")
604 if (api.checkParamCount(1))
606 s=api.parString (ok,0);
609 } else if (com=="setVymLink")
611 if (api.checkParamCount(1))
613 s=api.parString (ok,0);
614 if (ok) setVymLink(s);
617 // Internal commands, used for undo etc.
618 else if (com==QString("undoMap"))
620 if (api.checkParamCount(1))
621 undoXML("",api.parString (ok,0));
622 } else if (com==QString("undoPart"))
624 if (api.checkParamCount(2))
626 s=api.parString (ok,0);
627 t=api.parString (ok,1);
630 } else if (com=="select")
631 if (api.checkParamCount(1))
633 s=api.parString(ok,0);
638 api.setError ("Unknown command in: "+atom);
639 cout << "ME::parse api should have error now...\n";
645 cout << "MapEditor::parseAtom: Error!\n";
646 cout << " "<<api.errorDesc()<<endl;
651 void MapEditor::finishedLineEditNoSave()
653 // This is called by finishedLineEdit or any MapEditor method,
654 // which wants to assure, that lineedits finish, before e.g. a branch is
657 // After calling LineEdit and using the clipboard, the
658 // focus is not any longer on the main widget, we
659 // have to restore it using parentWidget()->setFocus()
663 editingBO->setHeading(lineedit->text() );
665 lineedit->releaseKeyboard();
667 parentWidget()->setFocus();
668 mapCenter->reposition();
670 ensureSelectionVisible();
675 bool MapEditor::isDefault()
680 bool MapEditor::isUnsaved()
685 bool MapEditor::hasChanged()
690 void MapEditor::setChanged()
695 actionEditUndo->setEnabled (true);
696 actionFileSave->setEnabled (true);
700 void MapEditor::closeMap()
702 // Finish open lineEdits
703 if (lineedit) finishedLineEditNoSave();
705 // Unselect before disabling the toolbar actions
706 if (selection) selection->unselect();
714 void MapEditor::setFilePath(QString fname)
716 setFilePath (fname,fname);
719 void MapEditor::setFilePath(QString fname, QString destname)
721 if (fname.isEmpty() || fname=="")
728 filePath=fname; // becomes absolute path
729 fileName=fname; // gets stripped of path
730 destPath=destname; // needed for vymlinks
732 // If fname is not an absolute path, complete it
733 filePath=QDir(fname).absPath();
734 fileDir=filePath.left (1+filePath.findRev ("/"));
736 // Set short name, too. Search from behind:
737 int i=fileName.findRev("/");
738 if (i>=0) fileName=fileName.remove (0,i+1);
740 // Forget the .vym (or .xml) for name of map
741 mapName=fileName.left(fileName.findRev(".",-1,true) );
745 QString MapEditor::getFilePath()
750 QString MapEditor::getFileName()
755 QString MapEditor::getMapName()
760 QString MapEditor::getDestPath()
765 ErrorCode MapEditor::load (QString fname, LoadMode lmode)
767 // Finish open lineEdits
768 if (lineedit) finishedLineEditNoSave();
770 ErrorCode err=success;
774 if (selection) selection->unselect();
777 mapCenter->setMapEditor(this);
778 // (map state is set later at end of load...)
781 saveState(selection);
785 mapBuilderHandler handler;
788 // I am paranoid: file should exist anyway
789 // according to check in mainwindow.
792 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
793 tr("Couldn't open map " +fname)+".");
797 blockReposition=true;
798 QXmlInputSource source( file);
799 QXmlSimpleReader reader;
800 reader.setContentHandler( &handler );
801 reader.setErrorHandler( &handler );
802 handler.setMapEditor( this );
803 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
804 handler.setLoadMode (lmode);
806 bool ok = reader.parse( source );
807 blockReposition=false;
808 blockSaveState=false;
812 mapCenter->reposition();
822 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
823 tr( handler.errorProtocol() ) );
825 // Still return "success": the map maybe at least
826 // partially read by the parser
833 int MapEditor::save (const SaveMode &savemode)
835 // Finish open lineEdits
836 if (lineedit) finishedLineEditNoSave();
840 // The SaveMode UndoCommand is not supported here
841 if (savemode==UndoCommand) return 1;
843 // Create mapName and fileDir
844 makeSubDirs (fileDir);
848 fname=mapName+".xml";
850 // use name given by user, even if he chooses .doc
855 if (savemode==CompleteMap || selection==NULL)
856 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL);
858 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection);
860 if (!saveStringToDisk(fileDir+fname,saveFile))
867 actionFileSave->setEnabled(false);
873 void MapEditor::setZipped (bool z)
878 bool MapEditor::saveZipped ()
883 void MapEditor::print()
885 // Finish open lineEdits
886 if (lineedit) finishedLineEditNoSave();
890 printer = new QPrinter;
891 printer->setColorMode (QPrinter::Color);
892 printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName()));
895 QRect totalBBox=mapCenter->getTotalBBox();
897 // Try to set orientation automagically
898 // Note: Interpretation of generated postscript is amibiguous, if
899 // there are problems with landscape mode, see
900 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
902 if (totalBBox.width()>totalBBox.height())
903 // recommend landscape
904 printer->setOrientation (QPrinter::Landscape);
906 // recommend portrait
907 printer->setOrientation (QPrinter::Portrait);
909 if ( printer->setup(this) )
910 // returns false, if printing is canceled
912 QPainter pp(printer);
914 // Don't print the visualisation of selection
915 LinkableMapObj *oldselection=NULL;
918 oldselection=selection;
919 selection->unselect();
922 // Handle sizes of map and paper:
924 // setWindow defines which part of the canvas will be transformed
925 // setViewport defines area on paper in device coordinates (dpi)
926 // e.g. (0,50,700,700) is upper part on A4
927 // see also /usr/lib/qt3/doc/html/coordsys.html
929 QPaintDeviceMetrics metrics (printer);
931 double paperAspect = (double)metrics.width() / (double)metrics.height();
932 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
934 QRect mapRect=totalBBox;
935 QCanvasRectangle *frame=NULL;
936 QCanvasText *footerFN=NULL;
937 QCanvasText *footerDate=NULL;
938 if (printFrame || printFooter)
943 // Print frame around map
944 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
945 totalBBox.width()+20, totalBBox.height()+20);
946 frame=new QCanvasRectangle (mapRect,mapCanvas);
947 frame->setBrush (QColor(white));
948 frame->setPen (QColor(black));
952 /* TODO remove after testing
953 QCanvasLine *l=new QCanvasLine (mapCanvas);
954 l->setPoints (0,0,mapRect.width(),mapRect.height());
955 l->setPen (QPen(QColor(black), 1));
962 // Print footer below map
964 font.setPointSize(10);
965 footerFN=new QCanvasText (mapCanvas);
966 footerFN->setText ("VYM - " + fileName);
967 footerFN->setFont(font);
968 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
969 footerFN->setZ(Z_TEXT);
971 footerDate=new QCanvasText (mapCanvas);
972 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
973 footerDate->setFont(font);
974 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
975 footerDate->setZ(Z_TEXT);
978 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
981 pp.setWindow (mapRect);
984 if (mapAspect>=paperAspect)
986 // Fit horizontally to paper width
987 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
990 // Fit vertically to paper height
991 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
994 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
996 // Delete Frame and footer
1000 delete (footerDate);
1002 if (frame) delete (frame);
1004 // Restore selection
1007 selection=oldselection;
1008 selection->select();
1011 // Save settings in vymrc
1012 settings.writeEntry("/vym/mainwindow/printerName",printer->printerName());
1016 QPixmap MapEditor::getPixmap()
1018 QRect mapRect=mapCenter->getTotalBBox();
1019 QPixmap pix (mapRect.size());
1022 // Don't print the visualisation of selection
1023 LinkableMapObj *oldselection=NULL;
1026 oldselection=selection;
1027 selection->unselect();
1030 pp.setWindow (mapRect);
1032 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
1035 // Restore selection
1038 selection=oldselection;
1039 selection->select();
1045 void MapEditor::exportImage(QString fn)
1047 // Finish open lineEdits
1048 if (lineedit) finishedLineEditNoSave();
1050 QPixmap pix (getPixmap());
1051 pix.save(fn, "PNG");
1054 void MapEditor::exportImage(QString fn, int item)
1056 // Finish open lineEdits
1057 if (lineedit) finishedLineEditNoSave();
1059 QPixmap pix (getPixmap());
1060 pix.save(fn, exportImageFormatMenu->text(item) );
1063 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
1067 ex.setMapCenter(mapCenter);
1068 if (ex.setConfigFile(cf)) ex.exportPresentation();
1073 void MapEditor::exportXML(const QString &dir)
1075 // Create subdirectories
1078 // write to directory
1079 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1082 file.setName ( dir + "/"+mapName+".xml");
1083 if ( !file.open( IO_WriteOnly ) )
1085 // This should neverever happen
1086 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1090 // Write it finally, and write in UTF8, no matter what
1091 QTextStream ts( &file );
1092 ts.setEncoding (QTextStream::UnicodeUTF8);
1096 // Now write image, too
1097 exportImage (dir+"/images/"+mapName+".png");
1100 void MapEditor::clear()
1104 selection->unselect();
1111 void MapEditor::copy()
1113 // Finish open lineEdits
1114 if (lineedit) finishedLineEditNoSave();
1118 // write to directory
1119 QString clipfile="part";
1120 QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPoint(),selection);
1123 file.setName ( clipboardDir + "/"+clipfile+".xml");
1124 if ( !file.open( IO_WriteOnly ) )
1126 // This should neverever happen
1127 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1131 // Write it finally, and write in UTF8, no matter what
1132 QTextStream ts( &file );
1133 ts.setEncoding (QTextStream::UnicodeUTF8);
1137 clipboardEmpty=false;
1142 void MapEditor::redo()
1144 // Finish open lineEdits
1145 if (lineedit) finishedLineEditNoSave();
1147 blockSaveState=true;
1149 // Find out current undo directory
1150 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
1152 // Restore variables
1153 QString undoCommand;
1154 QString undoSelection;
1155 QString redoCommand;
1156 QString redoSelection;
1158 set.readSettings(QString(bakMapDir+"/commands"));
1159 undoCommand=set.readEntry ("undoCommand");
1160 undoSelection=set.readEntry ("undoSelection");
1161 redoCommand=set.readEntry ("redoCommand");
1162 redoSelection=set.readEntry ("redoSelection");
1164 // select object before redo
1165 if (!redoSelection.isEmpty())
1166 select (redoSelection);
1168 /* TODO remove testing
1169 cout << "ME::redo() begin\n";
1170 cout << " undosTotal="<<undosTotal<<endl;
1171 cout << " undosAvail="<<undosAvail<<endl;
1172 cout << " undoNum="<<undoNum<<endl;
1173 cout << " ---------------------------"<<endl;
1174 cout << " undoCom="<<undoCommand<<endl;
1175 cout << " undoSel="<<undoSelection<<endl;
1176 cout << " ---------------------------"<<endl;
1177 cout << " redoCom="<<redoCommand<<endl;
1178 cout << " redoSel="<<redoSelection<<endl;
1179 cout << " ---------------------------"<<endl;
1181 parseAtom (undoCommand);
1182 mapCenter->reposition();
1184 //if (!redoSelection.isEmpty())
1185 // select (redoSelection);
1189 // Undo not longer available now
1190 actionEditUndo->setEnabled (false);
1192 undoNum--; if (undoNum<1) undoNum=undosTotal;
1194 blockSaveState=false;
1195 /* TODO remove testing
1196 cout << "ME::redo() end\n";
1197 cout << " undosAvail="<<undosAvail<<endl;
1198 cout << " undoNum="<<undoNum<<endl;
1199 cout << " ---------------------------"<<endl<<endl;
1203 void MapEditor::undo()
1205 // Finish open lineEdits
1206 if (lineedit) finishedLineEditNoSave();
1208 blockSaveState=true;
1210 // Find out current undo directory
1211 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
1213 // Restore variables
1214 QString undoCommand;
1215 QString undoSelection;
1216 QString redoCommand;
1217 QString redoSelection;
1219 set.readSettings(QString(bakMapDir+"/commands"));
1220 undoCommand= set.readEntry ("undoCommand");
1221 undoSelection=set.readEntry ("undoSelection");
1222 redoCommand= set.readEntry ("redoCommand");
1223 redoSelection=set.readEntry ("redoSelection");
1225 // select object before undo
1226 if (!undoSelection.isEmpty())
1227 select (undoSelection);
1230 cout << "ME::undo() begin\n";
1231 cout << " undosTotal="<<undosTotal<<endl;
1232 cout << " undosAvail="<<undosAvail<<endl;
1233 cout << " undoNum="<<undoNum<<endl;
1234 cout << " ---------------------------"<<endl;
1235 cout << " undoCom="<<undoCommand<<endl;
1236 cout << " undoSel="<<undoSelection<<endl;
1237 cout << " ---------------------------"<<endl;
1238 cout << " redoCom="<<redoCommand<<endl;
1239 cout << " redoSel="<<redoSelection<<endl;
1240 cout << " ---------------------------"<<endl;
1242 parseAtom (undoCommand);
1243 mapCenter->reposition();
1245 //if (!redoSelection.isEmpty())
1246 // select (redoSelection);
1250 // Undo not longer available now
1251 actionEditUndo->setEnabled (false);
1253 undoNum--; if (undoNum<1) undoNum=undosTotal;
1255 blockSaveState=false;
1256 /* TODO remove testing
1257 cout << "ME::undo() end\n";
1258 cout << " undosAvail="<<undosAvail<<endl;
1259 cout << " undoNum="<<undoNum<<endl;
1260 cout << " ---------------------------"<<endl<<endl;
1264 void MapEditor::undoXML(const QString &undoSel, const QString &bakMapPath)
1266 QString bakMapDir=bakMapPath.left(bakMapPath.findRev("/"));
1268 QFile file (bakMapPath);
1272 // We need to parse saved XML data
1273 mapBuilderHandler handler;
1274 QXmlInputSource source( file);
1275 QXmlSimpleReader reader;
1276 reader.setContentHandler( &handler );
1277 reader.setErrorHandler( &handler );
1278 handler.setMapEditor( this );
1279 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1280 if (undoSel.isEmpty())
1284 handler.setLoadMode (NewMap);
1288 handler.setLoadMode (ImportReplace);
1290 blockReposition=true;
1291 bool ok = reader.parse( source );
1292 blockReposition=false;
1295 // This should never ever happen
1296 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1297 tr( handler.errorProtocol() )+" in "+bakMapDir );
1301 QMessageBox::critical( 0, tr( "Critical Error" ),
1302 tr("Temporary directory %1 used for undo is gone. \n"
1303 "I will create a new one, but at the moment no undo is available.\n"
1304 "Maybe you want to reload your original data.\n\n"
1305 "Sorry for any inconveniences.").arg(bakMapDir) );
1310 void MapEditor::pasteNoSave()
1312 // Finish open lineEdits
1313 if (lineedit) finishedLineEditNoSave();
1315 load (clipboardDir+"/part.xml",ImportAdd);
1318 void MapEditor::cutNoSave()
1324 void MapEditor::paste()
1326 if (selection && (typeid(*selection) == typeid(BranchObj) ||
1327 typeid(*selection) == typeid(MapCenterObj)))
1329 saveState(selection);
1331 mapCenter->reposition();
1336 void MapEditor::cut()
1338 saveState(selection->getParObj());
1341 mapCenter->reposition();
1345 void MapEditor::move(const int &x, const int &y)
1347 // TODO no saveState, because this is only internal at undo so far
1348 if (selection) selection->move(x,y);
1349 if (typeid(*selection) == typeid(FloatImageObj))
1350 ((FloatImageObj*)selection)->setRelPos();
1353 void MapEditor::moveBranchUp()
1355 // Finish open lineEdits
1356 if (lineedit) finishedLineEditNoSave();
1360 if (typeid(*selection) == typeid(BranchObj) )
1362 bo=(BranchObj*)selection;
1363 par=(BranchObj*)(bo->getParObj());
1364 selection->unselect();
1365 selection=par->moveBranchUp (bo);
1366 selection->select();
1367 saveState("moveBranchDown ()",bo);
1368 mapCenter->reposition();
1369 ensureSelectionVisible();
1373 void MapEditor::moveBranchDown()
1375 // Finish open lineEdits
1376 if (lineedit) finishedLineEditNoSave();
1380 if (typeid(*selection) == typeid(BranchObj) )
1382 bo=(BranchObj*)selection;
1383 par=(BranchObj*)(bo->getParObj());
1384 selection->unselect();
1385 selection=par->moveBranchDown(bo);
1386 selection->select();
1387 saveState("moveBranchUp ()",bo);
1388 mapCenter->reposition();
1389 ensureSelectionVisible();
1393 void MapEditor::editHeading()
1395 // Finish open lineEdits
1396 if (lineedit) finishedLineEditNoSave();
1399 (typeid(*selection) == typeid(BranchObj) ||
1400 typeid(*selection) == typeid(MapCenterObj) ) )
1402 editingBO=(BranchObj*)selection;
1403 saveState("setHeading (\""+((BranchObj*)selection)->getHeading()+"\")",editingBO );
1405 ensureSelectionVisible();
1406 QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
1407 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1408 QString s=editingBO->getHeading();
1409 lineedit->setText(s);
1410 lineedit->setCursorPosition(1);
1411 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1412 lineedit->selectAll();
1414 lineedit->grabKeyboard();
1415 lineedit->setFocus();
1419 void MapEditor::setHeading(const QString &s)
1421 // Internal function, no saveState needed
1423 (typeid(*selection) == typeid(BranchObj) ||
1424 typeid(*selection) == typeid(MapCenterObj) ) )
1426 ((BranchObj*)selection)->setHeading(s);
1427 mapCenter->reposition();
1429 ensureSelectionVisible();
1433 void MapEditor::setURL (const QString &s)
1435 // Internal function, no saveState needed
1437 (typeid(*selection) == typeid(BranchObj) ||
1438 typeid(*selection) == typeid(MapCenterObj) ) )
1440 ((BranchObj*)selection)->setURL(s);
1441 mapCenter->reposition();
1443 ensureSelectionVisible();
1447 void MapEditor::setVymLink (const QString &s)
1449 // Internal function, no saveState needed
1451 (typeid(*selection) == typeid(BranchObj) ||
1452 typeid(*selection) == typeid(MapCenterObj) ) )
1454 ((BranchObj*)selection)->setVymLink(s);
1455 mapCenter->reposition();
1457 ensureSelectionVisible();
1461 void MapEditor::addNewBranch(int pos)
1463 // Finish open lineEdits
1464 if (lineedit) finishedLineEditNoSave();
1467 (typeid(*selection) == typeid(BranchObj) ||
1468 typeid(*selection) == typeid(MapCenterObj) ) )
1470 saveState(selection); //TODO undoCommand
1472 BranchObj* bo1 = (BranchObj*) selection;
1473 bool wasScrolled=false;
1474 BranchObj *newbo=NULL;
1477 // save scroll state. If scrolled, automatically select
1478 // new branch in order to tmp unscroll parent...
1479 wasScrolled=bo1->isScrolled();
1480 newbo=bo1->addBranch();
1483 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1487 // add above selection
1488 newbo=parbo->insertBranch(bo1->getNum());
1490 // add below selection
1491 newbo=parbo->insertBranch(bo1->getNum()+1);
1493 // This should not happen...
1498 LinkableMapObj *oldselection=selection;
1500 mapCenter->reposition();
1502 if (actionSettingsAutoedit->isOn() ||
1503 actionSettingsAutoselectHeading->isOn() )
1505 selection->unselect();
1507 selection->select();
1508 if (actionSettingsPasteNewHeading->isOn() )
1510 BranchObj *bo2= (BranchObj*)selection;
1511 bo2->setHeading("");
1513 if (actionSettingsAutoedit->isOn() )
1515 if (!actionSettingsAutoselectHeading->isOn()
1518 selection->unselect();
1519 selection=oldselection;
1520 selection->select();
1527 void MapEditor::addNewBranchHere()
1529 // Finish open lineEdits
1530 if (lineedit) finishedLineEditNoSave();
1533 (typeid(*selection) == typeid(BranchObj) ) )
1535 saveState(selection);
1537 BranchObj* bo1 = (BranchObj*) selection;
1538 bool wasScrolled=false;
1539 BranchObj *newbo=NULL;
1540 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1543 // add below selection
1544 newbo=parbo->insertBranch(bo1->getNum()+1);
1547 LinkableMapObj *oldselection=selection;
1548 ((BranchObj*)selection)->moveBranchTo (newbo,-1);
1550 mapCenter->reposition();
1552 if (actionSettingsAutoedit->isOn() ||
1553 actionSettingsAutoselectHeading->isOn() )
1555 selection->unselect();
1557 selection->select();
1558 if (actionSettingsPasteNewHeading->isOn() )
1560 BranchObj *bo2= (BranchObj*)selection;
1561 bo2->setHeading("");
1563 if (actionSettingsAutoedit->isOn() )
1565 if (!actionSettingsAutoselectHeading->isOn()
1568 selection->unselect();
1569 selection=oldselection;
1570 selection->select();
1576 void MapEditor::deleteSelection()
1578 // Finish open lineEdits
1579 if (lineedit) finishedLineEditNoSave();
1581 if (selection && typeid(*selection) ==typeid(BranchObj) )
1583 if (selection->getDepth()>1)
1584 // Normal branch, save parent with childs
1585 saveState(selection->getParObj());
1587 // Mainbranch, save whole map
1588 // TODO Better would be to insert mainbranch again at pos
1589 // But undoCommand is missing right now
1591 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1592 BranchObj* par=(BranchObj*)(bo->getParObj());
1595 par->removeBranch(bo);
1597 selection->select();
1598 ensureSelectionVisible();
1599 mapCenter->reposition();
1602 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1604 saveState(selection->getParObj());
1605 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1606 BranchObj* par=(BranchObj*)(fio->getParObj());
1609 par->removeFloatImage(fio);
1611 selection->select();
1612 ensureSelectionVisible();
1613 mapCenter->reposition();
1618 LinkableMapObj* MapEditor::getSelection()
1623 bool MapEditor::select (const QString &s)
1625 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
1627 // Finally select the found object
1630 if (selection) unselect();
1632 selection->select();
1634 ensureSelectionVisible();
1640 void MapEditor::unselect()
1644 selectionLast=selection;
1645 selection->unselect();
1650 void MapEditor::reselect()
1654 selection=selectionLast;
1655 selection->select();
1660 void MapEditor::selectNextBranch()
1662 // Increase number of branch
1665 QString s=selection->getSelectString();
1671 part=s.section(",",-1);
1673 num=part.right(part.length() - 3);
1675 s=s.left (s.length() -num.length());
1678 num=QString ("%1").arg(num.toUInt()+1);
1682 // Try to select this one
1683 if (select (s)) return;
1685 // We have no direct successor,
1686 // try to increase the parental number in order to
1687 // find a successor with same depth
1689 int d=selection->getDepth();
1694 while (!found && d>0)
1696 s=s.section (",",0,d-1);
1697 // replace substring of current depth in s with "1"
1698 part=s.section(",",-1);
1700 num=part.right(part.length() - 3);
1704 // increase number of parent
1705 num=QString ("%1").arg(num.toUInt()+1);
1706 s=s.section (",",0,d-2) + ","+ typ+num;
1709 // Special case, look at orientation
1710 if (selection->getOrientation()==OrientRightOfCenter)
1711 num=QString ("%1").arg(num.toUInt()+1);
1713 num=QString ("%1").arg(num.toUInt()-1);
1718 // pad to oldDepth, select the first branch for each depth
1719 for (i=d;i<oldDepth;i++)
1724 if ( ((BranchObj*)selection)->countBranches()>0)
1732 // try to select the freshly built string
1740 void MapEditor::selectPrevBranch()
1742 // Decrease number of branch
1745 QString s=selection->getSelectString();
1751 part=s.section(",",-1);
1753 num=part.right(part.length() - 3);
1755 s=s.left (s.length() -num.length());
1758 num=QString ("%1").arg(num.toUInt()-1);
1762 // Try to select this one
1763 if (select (s)) return;
1765 // We have no direct precessor,
1766 // try to decrease the parental number in order to
1767 // find a precessor with same depth
1769 int d=selection->getDepth();
1774 while (!found && d>0)
1776 s=s.section (",",0,d-1);
1777 // replace substring of current depth in s with "1"
1778 part=s.section(",",-1);
1780 num=part.right(part.length() - 3);
1784 // decrease number of parent
1785 num=QString ("%1").arg(num.toUInt()-1);
1786 s=s.section (",",0,d-2) + ","+ typ+num;
1789 // Special case, look at orientation
1790 if (selection->getOrientation()==OrientRightOfCenter)
1791 num=QString ("%1").arg(num.toUInt()-1);
1793 num=QString ("%1").arg(num.toUInt()+1);
1798 // pad to oldDepth, select the last branch for each depth
1799 for (i=d;i<oldDepth;i++)
1803 if ( ((BranchObj*)selection)->countBranches()>0)
1804 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)selection)->countBranches()-1 );
1811 // try to select the freshly built string
1819 void MapEditor::selectUpperBranch()
1821 // Finish open lineEdits
1822 if (lineedit) finishedLineEditNoSave();
1826 if (typeid(*selection) == typeid(BranchObj))
1828 if (selection->getOrientation()==OrientRightOfCenter)
1831 if (selection->getDepth()==1)
1839 void MapEditor::selectLowerBranch()
1841 // Finish open lineEdits
1842 if (lineedit) finishedLineEditNoSave();
1846 if (typeid(*selection) == typeid(BranchObj))
1848 if (selection->getOrientation()==OrientRightOfCenter)
1851 if (selection->getDepth()==1)
1860 void MapEditor::selectLeftBranch()
1862 // Finish open lineEdits
1863 if (lineedit) finishedLineEditNoSave();
1869 if (typeid(*selection) == typeid(MapCenterObj))
1871 par= (BranchObj*) selection;
1872 bo=par->getLastSelectedBranch();
1875 // Workaround for reselecting on left and right side
1876 if (bo->getOrientation()==OrientRightOfCenter)
1878 bo=par->getLastBranch();
1884 selection->select();
1886 ensureSelectionVisible();
1891 par=(BranchObj*)(selection->getParObj());
1892 if (selection->getOrientation()==OrientRightOfCenter)
1894 if (typeid(*selection) == typeid(BranchObj) ||
1895 typeid(*selection) == typeid(FloatImageObj))
1897 selection->unselect();
1899 selection->select();
1901 ensureSelectionVisible();
1905 if (typeid(*selection) == typeid(BranchObj) )
1907 bo=((BranchObj*)selection)->getLastSelectedBranch();
1910 selection->unselect();
1912 selection->select();
1914 ensureSelectionVisible();
1922 void MapEditor::selectRightBranch()
1924 // Finish open lineEdits
1925 if (lineedit) finishedLineEditNoSave();
1932 if (typeid(*selection) == typeid(MapCenterObj))
1934 par= (BranchObj*) selection;
1935 bo=par->getLastSelectedBranch();
1938 // Workaround for relecting on left and right side
1939 if (bo->getOrientation()==OrientLeftOfCenter)
1940 bo=par->getFirstBranch();
1945 selection->select();
1946 ensureSelectionVisible();
1951 par=(BranchObj*)(selection->getParObj());
1952 if (selection->getOrientation()==OrientLeftOfCenter)
1954 if (typeid(*selection) == typeid(BranchObj) ||
1955 typeid(*selection) == typeid(FloatImageObj))
1957 selection->unselect();
1959 selection->select();
1961 ensureSelectionVisible();
1965 if (typeid(*selection) == typeid(BranchObj) )
1967 bo=((BranchObj*)selection)->getLastSelectedBranch();
1970 selection->unselect();
1972 selection->select();
1974 ensureSelectionVisible();
1982 void MapEditor::selectFirstBranch()
1984 // Finish open lineEdits
1985 if (lineedit) finishedLineEditNoSave();
1991 if (typeid(*selection) == typeid(BranchObj))
1993 bo1= (BranchObj*) selection;
1994 par=(BranchObj*)(bo1->getParObj());
1995 bo2=par->getFirstBranch();
1999 selection->select();
2000 ensureSelectionVisible();
2007 void MapEditor::selectLastBranch()
2009 // Finish open lineEdits
2010 if (lineedit) finishedLineEditNoSave();
2016 if (typeid(*selection) == typeid(BranchObj))
2018 bo1= (BranchObj*) selection;
2019 par=(BranchObj*)(bo1->getParObj());
2020 bo2=par->getLastBranch();
2024 selection->select();
2025 ensureSelectionVisible();
2032 void MapEditor::setColor(QColor c)
2037 void MapEditor::selectBackgroundColor()
2039 // Finish open lineEdits
2040 if (lineedit) finishedLineEditNoSave();
2042 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
2043 if ( !col.isValid() ) return;
2044 setBackgroundColor( col );
2048 void MapEditor::setBackgroundColor(QColor c)
2050 mapCanvas->setBackgroundColor (c);
2053 QColor MapEditor::pickColor()
2057 if (typeid(*selection) == typeid(BranchObj) ||
2058 typeid(*selection) == typeid(MapCenterObj))
2060 BranchObj *bo=(BranchObj*)selection;
2061 actColor=bo->getColor();
2067 void MapEditor::colorItem()
2071 if (typeid(*selection) == typeid(BranchObj) ||
2072 typeid(*selection) == typeid(MapCenterObj))
2074 saveState(selection); //TODO undoCommand
2075 BranchObj *bo=(BranchObj*)selection;
2076 bo->setColor(actColor, false); // color links, color childs
2081 void MapEditor::colorBranch()
2085 if (typeid(*selection) == typeid(BranchObj) ||
2086 typeid(*selection) == typeid(MapCenterObj))
2088 saveState(selection); //TODO undoCommand
2089 BranchObj *bo=(BranchObj*)selection;
2090 bo->setColor(actColor, true); // color links, color childs
2096 void MapEditor::toggleStandardFlag(QString f)
2100 saveState(selection);// TODO undoCommand
2101 ((BranchObj*)selection)->toggleStandardFlag (f,actionSettingsUseFlagGroups);
2106 void MapEditor::setViewCenter()
2108 // transform to CanvasView Coord:
2109 QPoint p=worldMatrix().map(movingCenter);
2110 center ( p.x(), p.y());
2114 BranchObj* MapEditor::findText (QString s, bool cs)
2117 { // Nothing found or new find process
2119 // nothing found, start again
2121 itFind=mapCenter->first();
2123 bool searching=true;
2124 bool foundNote=false;
2125 while (searching && !EOFind)
2129 // Searching in Note
2130 if (itFind->getNote().contains(s,cs))
2132 if (selection!=itFind)
2134 if (selection) ((BranchObj*)selection)->unselect();
2136 selection->select();
2138 ensureSelectionVisible();
2140 if (textEditor->findText(s,cs))
2146 // Searching in Heading
2147 if (searching && itFind->getHeading().contains (s,cs) )
2149 if (selection) ((BranchObj*)selection)->unselect();
2151 selection->select();
2153 ensureSelectionVisible();
2159 itFind=itFind->next();
2160 if (!itFind) EOFind=true;
2166 return (BranchObj*)selection;
2171 void MapEditor::findReset()
2172 { // Necessary if text to find changes during a find process
2177 void MapEditor::openURL()
2181 if (typeid(*selection) == typeid(BranchObj) ||
2182 typeid(*selection) == typeid(MapCenterObj))
2184 QString url=((BranchObj*)selection)->getURL();
2186 QProcess *proc = new QProcess( this );
2188 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL" ));
2189 proc->addArgument( url);
2191 if ( !proc->start() )
2193 if (mainWindow->settingsURL() )
2199 void MapEditor::editURL()
2201 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2202 typeid(*selection) == typeid(MapCenterObj)) )
2205 BranchObj *bo=(BranchObj*)selection;
2206 QString text = QInputDialog::getText(
2207 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2208 bo->getURL(), &ok, this );
2211 // user entered something and pressed OK
2212 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+text+"\")");
2219 void MapEditor::editHeading2URL()
2221 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2222 typeid(*selection) == typeid(MapCenterObj)) )
2224 BranchObj *bo=(BranchObj*)selection;
2225 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+bo->getHeading()+"\")");
2226 bo->setURL (bo->getHeading());
2231 void MapEditor::editBugzilla2URL()
2233 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2234 typeid(*selection) == typeid(MapCenterObj)) )
2236 BranchObj *bo=(BranchObj*)selection;
2237 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2238 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")");
2244 void MapEditor::editFATE2URL()
2246 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2247 typeid(*selection) == typeid(MapCenterObj)) )
2249 BranchObj *bo=(BranchObj*)selection;
2250 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2251 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")");
2257 void MapEditor::editVymLink()
2259 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2260 typeid(*selection) == typeid(MapCenterObj)) )
2262 BranchObj *bo=(BranchObj*)selection;
2263 QFileDialog *fd=new QFileDialog( this,__VYM " - " +tr("Link to another map"));
2264 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2265 fd->setCaption(__VYM " - " +tr("Link to another map"));
2266 if (! bo->getVymLink().isEmpty() )
2267 fd->setSelection( bo->getVymLink() );
2271 if ( fd->exec() == QDialog::Accepted )
2273 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\""+fd->selectedFile()+"\")");
2274 bo->setVymLink (fd->selectedFile() );
2276 mapCenter->reposition();
2283 void MapEditor::deleteVymLink()
2285 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2286 typeid(*selection) == typeid(MapCenterObj)) )
2288 BranchObj *bo=(BranchObj*)selection;
2289 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\"\")");
2290 bo->setVymLink ("" );
2292 mapCenter->reposition();
2298 QString MapEditor::getVymLink()
2300 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2301 typeid(*selection) == typeid(MapCenterObj)) )
2303 return ((BranchObj*)selection)->getVymLink();
2309 void MapEditor::removeBranchHere()
2311 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2313 BranchObj* bo=(BranchObj*)selection;
2314 BranchObj* par=(BranchObj*)(bo->getParObj());
2315 if (bo->getDepth()==1)
2318 saveState(selection->getParObj()); // TODO undoCommand
2319 QString sel=selection->getSelectString();
2321 par->removeBranchHere(bo);
2322 mapCenter->reposition();
2327 void MapEditor::removeChilds()
2329 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2331 saveState(selection->getParObj());
2332 ((BranchObj*)selection)->removeChilds();
2333 mapCenter->reposition();
2337 void MapEditor::editMapInfo()
2339 ExtraInfoDialog dia;
2340 dia.setMapName (getFileName() );
2341 dia.setAuthor (mapCenter->getAuthor() );
2342 dia.setComment(mapCenter->getComment() );
2347 QCanvasItemList l=canvas()->allItems();
2348 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2350 stats+=QString ("%1 items on canvas\n").arg (i,6);
2357 bo=mapCenter->first();
2360 if (!bo->getNote().isEmpty() ) n++;
2361 f+= bo->countFloatImages();
2363 xl+=bo->countXLinks();
2366 stats+=QString ("%1 branches\n").arg (b-1,6);
2367 stats+=QString ("%1 xLinks \n").arg (xl,6);
2368 stats+=QString ("%1 notes\n").arg (n,6);
2369 stats+=QString ("%1 images\n").arg (f,6);
2370 dia.setStats (stats);
2372 // Finally show dialog
2373 if (dia.exec() == QDialog::Accepted)
2375 saveState(); //TODO undoCommand
2376 mapCenter->setAuthor (dia.getAuthor() );
2377 mapCenter->setComment (dia.getComment() );
2381 void MapEditor::updateActions()
2384 if (getLinkColorHint()==HeadingColor)
2385 actionFormatLinkColorHint->setOn(true);
2387 actionFormatLinkColorHint->setOn(false);
2392 actionFormatLinkStyleLine->setOn(true);
2395 actionFormatLinkStyleParabel->setOn(true);
2398 actionFormatLinkStylePolyLine->setOn(true);
2400 case StylePolyParabel:
2401 actionFormatLinkStylePolyParabel->setOn(true);
2407 QPixmap pix( 16, 16 );
2408 pix.fill( mapCanvas->backgroundColor() );
2409 actionFormatBackColor->setIconSet( pix );
2410 pix.fill( defLinkColor );
2411 actionFormatLinkColor->setIconSet( pix );
2413 actionEditUndo->setEnabled( mapChanged );
2414 actionFileSave->setEnabled( mapUnsaved );
2418 if ( (typeid(*selection) == typeid(BranchObj)) ||
2419 (typeid(*selection) == typeid(MapCenterObj)) )
2421 BranchObj *bo=(BranchObj*)selection;
2422 // Take care of links
2423 if (bo->countXLinks()==0)
2425 branchLinksContextMenu->clear();
2426 branchLinksContextMenu->insertItem ("No xLink available");
2427 branchLinksContextMenuDup->clear();
2428 branchLinksContextMenuDup->insertItem ("No xLink available");
2434 branchLinksContextMenu->clear();
2435 branchLinksContextMenuDup->clear();
2436 for (int i=0; i<=bo->countXLinks();i++)
2438 bot=bo->XLinkTargetAt(i);
2441 s=bot->getHeading();
2444 branchLinksContextMenu->insertItem (s);
2445 branchLinksContextMenuDup->insertItem (s);
2450 standardFlagsDefault->setEnabled (true);
2452 if ( bo->getURL().isEmpty() )
2453 actionEditOpenURL->setEnabled (false);
2455 actionEditOpenURL->setEnabled (true);
2457 if ( bo->getVymLink().isEmpty() )
2459 actionEditOpenVymLink->setEnabled (false);
2460 actionEditDeleteVymLink->setEnabled (false);
2463 actionEditOpenVymLink->setEnabled (true);
2464 actionEditDeleteVymLink->setEnabled (true);
2467 actionEditCopy->setEnabled (true);
2468 actionEditCut->setEnabled (true);
2469 if (!clipboardEmpty)
2470 actionEditPaste->setEnabled (true);
2472 actionEditPaste->setEnabled (false);
2473 for (a=actionListBranches.first();a;a=actionListBranches.next())
2474 a->setEnabled(true);
2475 actionEditDelete->setEnabled (true);
2476 actionEditToggleFloatExport->setEnabled (false);
2477 switch (selection->getFrameType())
2480 actionFormatFrameNone->setOn(true);
2483 actionFormatFrameRectangle->setOn(true);
2488 actionFormatIncludeImagesVer->setOn
2489 ( ((BranchObj*)selection)->getIncludeImagesVer());
2490 actionFormatIncludeImagesHor->setOn
2491 ( ((BranchObj*)selection)->getIncludeImagesHor());
2492 actionFormatHideLinkUnselected->setOn
2493 (selection->getHideLinkUnselected());
2495 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2497 standardFlagsDefault->setEnabled (false);
2499 actionEditOpenURL->setEnabled (false);
2500 actionEditOpenVymLink->setEnabled (false);
2501 actionEditDeleteVymLink->setEnabled (false);
2503 actionEditCopy->setEnabled (true);
2504 actionEditCut->setEnabled (true);
2505 actionEditPaste->setEnabled (false); //FIXME
2506 for (a=actionListBranches.first();a;a=actionListBranches.next())
2507 a->setEnabled(false);
2508 actionEditDelete->setEnabled (true);
2509 actionEditToggleFloatExport->setOn
2510 ( ((FloatImageObj*)selection)->getFloatExport() );
2511 actionFormatHideLinkUnselected->setOn
2512 ( selection->getHideLinkUnselected());
2517 standardFlagsDefault->setEnabled (false);
2519 actionEditCopy->setEnabled (false);
2520 actionEditCut->setEnabled (false);
2521 actionEditPaste->setEnabled (false);
2522 for (a=actionListBranches.first();a;a=actionListBranches.next())
2523 a->setEnabled(false);
2525 actionEditOpenURL->setEnabled (false);
2526 actionEditOpenVymLink->setEnabled (false);
2527 actionEditDeleteVymLink->setEnabled (false);
2528 actionEditHeading2URL->setEnabled (false);
2529 actionEditDelete->setEnabled (false);
2530 actionEditToggleFloatExport->setEnabled (false);
2534 void MapEditor::updateNoteFlag()
2537 if ( (typeid(*selection) == typeid(BranchObj)) ||
2538 (typeid(*selection) == typeid(MapCenterObj)) )
2539 ((BranchObj*)selection)->updateNoteFlag();
2542 void MapEditor::setLinkStyle (LinkStyle ls)
2546 saveState(); // TODO undoCommand
2548 bo=mapCenter->first();
2552 bo->setLinkStyle(bo->getDefLinkStyle());
2555 mapCenter->reposition();
2558 LinkStyle MapEditor::getLinkStyle ()
2563 void MapEditor::setLinkColor(QColor c)
2569 void MapEditor::setLinkColorHint()
2571 // called from setLinkColorHint(lch) or at end of parse
2573 bo=mapCenter->first();
2581 void MapEditor::setLinkColorHint(LinkColorHint lch)
2587 void MapEditor::toggleLinkColorHint()
2589 if (linkcolorhint==HeadingColor)
2590 linkcolorhint=DefaultColor;
2592 linkcolorhint=HeadingColor;
2594 bo=mapCenter->first();
2602 LinkColorHint MapEditor::getLinkColorHint()
2604 return linkcolorhint;
2607 QColor MapEditor::getDefLinkColor()
2609 return defLinkColor;
2612 void MapEditor::setDefXLinkColor(QColor col)
2617 QColor MapEditor::getDefXLinkColor()
2619 return defXLinkColor;
2622 void MapEditor::setDefXLinkWidth (int w)
2627 int MapEditor::getDefXLinkWidth()
2629 return defXLinkWidth;
2632 void MapEditor::selectLinkColor()
2634 // Finish open lineEdits
2635 if (lineedit) finishedLineEditNoSave();
2637 QColor col = QColorDialog::getColor( defLinkColor, this );
2638 if ( !col.isValid() ) return;
2639 setLinkColor( col );
2640 saveState(); //TODO undoCommand
2644 void MapEditor::toggleScroll()
2646 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2648 BranchObj *bo=((BranchObj*)selection);
2649 if (bo->countBranches()==0) return;
2650 if (bo->getDepth()==0) return;
2651 saveState(selection);
2658 void MapEditor::unScrollAll()
2661 bo=mapCenter->first();
2664 if (bo->isScrolled()) bo->toggleScroll();
2669 void MapEditor::loadFloatImage ()
2672 (typeid(*selection) == typeid(BranchObj)) ||
2673 (typeid(*selection) == typeid(MapCenterObj)) )
2675 BranchObj *bo=((BranchObj*)selection);
2677 QFileDialog *fd=new QFileDialog( this);
2678 fd->setMode (QFileDialog::ExistingFiles);
2679 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2680 ImagePreview *p =new ImagePreview (fd);
2681 fd->setContentsPreviewEnabled( TRUE );
2682 fd->setContentsPreview( p, p );
2683 fd->setPreviewMode( QFileDialog::Contents );
2684 fd->setCaption(__VYM " - " +tr("Load image"));
2685 fd->setDir (lastImageDir);
2689 if ( fd->exec() == QDialog::Accepted )
2691 saveState(selection);
2692 lastImageDir=fn.left(fn.findRev ("/"));
2693 QStringList flist = fd->selectedFiles();
2694 QStringList::Iterator it = flist.begin();
2695 while( it != flist.end() )
2698 bo->addFloatImage();
2699 // TODO check if load was successful
2700 bo->getLastFloatImage()->load(*it);
2701 bo->getLastFloatImage()->setOriginalFilename(fn);
2705 mapCenter->reposition();
2714 void MapEditor::saveFloatImage (int item)
2717 (typeid(*selection) == typeid(FloatImageObj)) )
2719 FloatImageObj *fio=((FloatImageObj*)selection);
2720 const char* fmt = saveImageFormatMenu->text(item);
2722 QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
2723 fd->addFilter ("PNG (*.png)");
2724 fd->addFilter ("BMP (*.bmp)");
2725 fd->addFilter ("XBM (*.xbm)");
2726 fd->addFilter ("JPG (*.jpg)");
2727 fd->addFilter ("XPM (*.xpm)");
2728 fd->addFilter ("GIF (*.gif)");
2729 fd->addFilter ("PNM (*.pnm)");
2730 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2731 fd->setCaption(__VYM " - " +tr("Save image as %1").arg(fmt));
2732 fd->setMode( QFileDialog::AnyFile );
2733 fd->setSelection (fio->getOriginalFilename());
2737 if ( fd->exec() == QDialog::Accepted )
2739 if (QFile (fd->selectedFile()).exists() )
2741 QMessageBox mb( __VYM,
2742 tr("The file %1 exists already.\n"
2743 "Do you want to overwrite it?").arg(fd->selectedFile()),
2744 QMessageBox::Warning,
2745 QMessageBox::Yes | QMessageBox::Default,
2746 QMessageBox::Cancel | QMessageBox::Escape,
2747 QMessageBox::QMessageBox::NoButton );
2749 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2750 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2753 case QMessageBox::Yes:
2756 case QMessageBox::Cancel:
2762 fio->save (fd->selectedFile(),fmt);
2767 void MapEditor::toggleFloatExport()
2770 (typeid(*selection) == typeid(FloatImageObj))||
2771 (typeid(*selection) == typeid(FloatObj)) )
2773 FloatImageObj *fio=((FloatImageObj*)selection);
2774 fio->setFloatExport (actionEditToggleFloatExport->isOn() );
2778 void MapEditor::setFrame(const FrameType &t)
2781 (typeid(*selection) == typeid(BranchObj)) ||
2782 (typeid(*selection) == typeid(MapCenterObj)) )
2784 selection->setFrameType (t);
2785 mapCenter->reposition();
2786 selection->updateLink();
2790 void MapEditor::setIncludeImagesVer(bool b)
2793 (typeid(*selection) == typeid(BranchObj)) ||
2794 (typeid(*selection) == typeid(MapCenterObj)) )
2795 ((BranchObj*)selection)->setIncludeImagesVer(b);
2796 mapCenter->reposition();
2799 void MapEditor::setIncludeImagesHor(bool b)
2802 (typeid(*selection) == typeid(BranchObj)) ||
2803 (typeid(*selection) == typeid(MapCenterObj)) )
2804 ((BranchObj*)selection)->setIncludeImagesHor(b);
2805 mapCenter->reposition();
2808 void MapEditor::setHideLinkUnselected (bool b)
2811 (typeid(*selection) == typeid(BranchObj)) ||
2812 (typeid(*selection) == typeid(MapCenterObj)) ||
2813 (typeid(*selection) == typeid(FloatImageObj)) )
2814 selection->setHideLinkUnselected(b);
2817 void MapEditor::importDir(BranchObj *dst, QDir d)
2820 (typeid(*selection) == typeid(BranchObj)) ||
2821 (typeid(*selection) == typeid(MapCenterObj)) )
2825 // Traverse directories
2826 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2827 const QFileInfoList *dirlist = d.entryInfoList();
2828 QFileInfoListIterator itdir( *dirlist );
2831 while ( (fi = itdir.current()) != 0 )
2833 if (fi->fileName() != "." && fi->fileName() != ".." )
2836 bo=dst->getLastBranch();
2837 bo->setHeading (fi->fileName() );
2838 bo->setColor (QColor("blue"),false);
2840 if ( !d.cd(fi->fileName()) )
2841 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi->fileName()));
2844 // Recursively add subdirs
2852 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
2853 const QFileInfoList *filelist = d.entryInfoList();
2854 QFileInfoListIterator itfile( *filelist );
2856 while ( (fi = itfile.current()) != 0 )
2859 bo=dst->getLastBranch();
2860 bo->setHeading (fi->fileName() );
2861 bo->setColor (QColor("black"),false);
2862 if (fi->fileName().right(4) == ".vym" )
2863 bo->setVymLink (fi->filePath());
2870 void MapEditor::importDir()
2873 (typeid(*selection) == typeid(BranchObj)) ||
2874 (typeid(*selection) == typeid(MapCenterObj)) )
2876 QFileDialog *fd=new QFileDialog( this,__VYM " - " +tr("Choose directory structure to import"));
2877 fd->setMode (QFileDialog::DirectoryOnly);
2878 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2879 fd->setCaption(__VYM " - " +tr("Choose directory structure to import"));
2883 if ( fd->exec() == QDialog::Accepted )
2885 BranchObj *bo=((BranchObj*)selection);
2886 importDir (bo,QDir(fd->selectedFile()) );
2887 mapCenter->reposition();
2894 void MapEditor::followXLink(int i)
2897 (typeid(*selection) == typeid(BranchObj)) ||
2898 (typeid(*selection) == typeid(MapCenterObj)) )
2900 BranchObj *bo=((BranchObj*)selection)->XLinkTargetAt(i);
2903 selection->unselect();
2905 selection->select();
2906 ensureSelectionVisible();
2911 void MapEditor::editXLink(int i)
2914 (typeid(*selection) == typeid(BranchObj)) ||
2915 (typeid(*selection) == typeid(MapCenterObj)) )
2917 XLinkObj *xlo=((BranchObj*)selection)->XLinkAt(i);
2920 EditXLinkDialog dia;
2922 dia.setSelection(selection);
2923 if (dia.exec() == QDialog::Accepted)
2925 if (dia.useSettingsGlobal() )
2927 setDefXLinkColor (xlo->getColor() );
2928 setDefXLinkWidth (xlo->getWidth() );
2930 if (dia.deleteXLink())
2931 ((BranchObj*)selection)->deleteXLinkAt(i);
2932 saveState(); //TODO undoCommand
2938 void MapEditor::testFunction()
2940 cout << "MapEditor::testFunction() called\n";
2944 if (selection && (typeid(*selection) == typeid(BranchObj)))
2946 cout << "Note:\n"<<((BranchObj*)selection)->getNoteOpenDoc()<<endl;
2951 void MapEditor::ensureSelectionVisible()
2955 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
2957 if (selection->getOrientation() == OrientLeftOfCenter)
2958 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
2960 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
2961 ensureVisible (p.x(), p.y() );
2966 void MapEditor::updateViewCenter()
2968 // Update movingCenter, so that we can zoom comfortably later
2969 QRect rc = QRect( contentsX(), contentsY(),
2970 visibleWidth(), visibleHeight() );
2971 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
2972 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
2973 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
2976 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
2978 // Lineedits are already closed by preceding
2979 // mouseEvent, we don't need to close here.
2981 QPoint p = inverseWorldMatrix().map(e->pos());
2982 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
2985 { // MapObj was found
2986 if (selection != lmo)
2988 // select the MapObj
2989 if (selection) selection->unselect();
2991 selection->select();
2997 if (typeid(*selection)==typeid(BranchObj) ||
2998 typeid(*selection)==typeid(MapCenterObj) )
3000 // Context Menu on branch or mapcenter
3002 branchContextMenu->popup(e->globalPos() );
3004 if (typeid(*selection)==typeid(FloatImageObj))
3006 // Context Menu on floatimage
3008 floatimageContextMenu->popup(e->globalPos() );
3012 { // No MapObj found, we are on the Canvas itself
3013 // Context Menu on Canvas
3015 canvasContextMenu->popup(e->globalPos() );
3019 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
3021 // Finish open lineEdits
3022 if (lineedit) finishedLineEditNoSave();
3024 QPoint p = inverseWorldMatrix().map(e->pos());
3025 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3027 // Special case: CTRL is pressed
3028 if (e->state() & QMouseEvent::ControlButton)
3030 if (actionModModeColor->isOn())
3032 if (e->state() & QMouseEvent::ControlButton)
3035 setCursor (pickColorCursor);
3039 if (actionModModeLink->isOn())
3041 BranchObj *bo_begin=NULL;
3043 bo_begin=(BranchObj*)(lmo);
3046 ((typeid(*selection) == typeid(BranchObj)) ||
3047 (typeid(*selection) == typeid(MapCenterObj))) )
3048 bo_begin=(BranchObj*)selection;
3052 linkingObj_src=bo_begin;
3053 tmpXLink=new XLinkObj (mapCanvas);
3054 tmpXLink->setBegin (bo_begin);
3055 tmpXLink->setEnd (p);
3056 tmpXLink->setColor(defXLinkColor);
3057 tmpXLink->setWidth(defXLinkWidth);
3058 tmpXLink->updateXLink();
3059 tmpXLink->setVisibility (true);
3066 { // MapObj was found
3067 if (selection != lmo)
3069 // select the MapObj
3070 if (selection) selection->unselect();
3072 selection->select();
3077 // Check, if systemFlag clicked
3078 if (typeid(*selection)==typeid(BranchObj) ||
3079 typeid(*selection)==typeid(MapCenterObj) )
3081 QString foname=((BranchObj*)selection)->getSystemFlagName(p);
3082 if (!foname.isEmpty())
3084 // Do not move, if systemFlag clicked
3088 if (foname=="vymLink")
3090 mainWindow->editOpenVymLink();
3091 // tabWidget may change, better return now
3092 // before segfaulting...
3096 mainWindow->windowToggleNoteEditor();
3100 // Left Button Move Branches
3101 if (e->button() == QMouseEvent::LeftButton )
3103 movingObj_start.setX( p.x() - selection->x() );
3104 movingObj_start.setY( p.y() - selection->y() );
3105 movingObj_orgPos.setX (lmo->x() );
3106 movingObj_orgPos.setY (lmo->y() );
3108 // If modMode==copy, then we want to "move" the _new_ object around
3109 // then we need the offset from p to the _old_ selection, because of tmp
3110 if (actionModModeCopy->isOn() &&
3111 e->state() & QMouseEvent::ControlButton)
3113 if (typeid(*selection)==typeid(BranchObj) )
3116 mapCenter->addBranch ((BranchObj*)selection);
3118 selection=mapCenter->getLastBranch();
3119 selection->select();
3120 mapCenter->reposition();
3123 movingObj=selection;
3125 // Middle Button Toggle Scroll
3126 // (On Mac OS X this won't work, but we still have
3127 // a button in the toolbar)
3128 if (e->button() == QMouseEvent::MidButton )
3132 { // No MapObj found, we are on the Canvas itself
3133 // Left Button move Pos of CanvasView
3134 if (e->button() == QMouseEvent::LeftButton )
3136 movingObj=NULL; // move Content not Obj
3137 movingObj_start=e->globalPos();
3138 movingCont_start=QPoint (contentsX(), contentsY() );
3139 movingVec=QPoint(0,0);
3140 setCursor(handOpenCursor);
3145 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3147 QPoint p = inverseWorldMatrix().map(e->pos());
3149 // Move the selected MapObj
3150 if ( selection && movingObj)
3152 // To avoid jumping of the CanvasView, only
3153 // ensureSelectionVisible, if not tmp linked
3154 if (!selection->hasParObjTmp())
3155 ensureSelectionVisible ();
3157 // Now move the selection, but add relative position
3158 // (movingObj_start) where selection was chosen with
3159 // mousepointer. (This avoids flickering resp. jumping
3160 // of selection back to absPos)
3162 LinkableMapObj *lmosel;
3163 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3165 // Check if we could link
3166 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3169 if (typeid(*selection) == typeid(FloatImageObj))
3171 FloatObj *fo=(FloatObj*)selection;
3172 saveState("move "+qpointToString(movingObj_orgPos),fo->getSelectString() );
3173 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3177 // Relink float to new mapcenter or branch, if shift is pressed
3178 // Only relink, if selection really has a new parent
3179 if ( (e->state() & QMouseEvent::ShiftButton) && lmo &&
3180 ( (typeid(*lmo)==typeid(BranchObj)) ||
3181 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3182 ( lmo != fo->getParObj())
3185 if (typeid(*fo) == typeid(FloatImageObj))
3188 FloatImageObj *fio=(FloatImageObj*)(fo);
3189 ((BranchObj*)(lmo))->addFloatImage (fio);
3191 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3192 fio=((BranchObj*)(lmo))->getLastFloatImage();
3195 selection=(LinkableMapObj*)(fio);
3196 selection->select();
3197 movingObj=(MapObj*)(fio);
3200 } else // selection != a FloatObj
3202 if (lmosel->getDepth()==0)
3204 if (e->state() == (LeftButton | !ShiftButton))
3205 // If mapCenter is moved, move all the rest by default, too.
3206 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3208 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3211 if (lmosel->getDepth()==1)
3213 // depth==1, mainbranch
3214 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3218 if (lmosel->getOrientation() == OrientLeftOfCenter)
3219 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3220 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3221 p.y()-movingObj_start.y() +lmosel->getTopPad() );
3223 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
3225 // reposition subbranch
3226 lmosel->reposition();
3227 //ensureSelectionVisible();
3229 if (lmo && (lmo!=selection) &&
3230 (typeid(*lmo) == typeid(BranchObj) ||
3231 (typeid(*lmo) == typeid(MapCenterObj) )
3234 if (e->state() & QMouseEvent::ControlButton)
3236 // Special case: CTRL to link below lmo
3237 lmosel->setParObjTmp (lmo,p,+1);
3239 else if (e->state() & QMouseEvent::ShiftButton)
3240 lmosel->setParObjTmp (lmo,p,-1);
3242 lmosel->setParObjTmp (lmo,p,0);
3245 lmosel->unsetParObjTmp();
3246 /* FIXME not needed anymore?
3247 if (lmo &&(lmo==selection))
3248 // Could link to myself (happens sometimes...)
3249 lmosel->unsetParObjTmp();
3251 // no Obj under selection, go back to original Parent
3252 lmosel->unsetParObjTmp();
3257 } // no FloatImageObj
3261 } // selection && moving_obj
3263 // Draw a link from one branch to another
3266 tmpXLink->setEnd (p);
3267 tmpXLink->updateXLink();
3271 if (!movingObj && !pickingColor &&!drawingLink)
3273 QPoint p=e->globalPos();
3274 movingVec.setX(-p.x() + movingObj_start.x() );
3275 movingVec.setY(-p.y() + movingObj_start.y() );
3276 setContentsPos( movingCont_start.x() + movingVec.x(),
3277 movingCont_start.y() + movingVec.y());
3284 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3286 LinkableMapObj *dst;
3287 // Have we been picking color?
3291 setCursor (ArrowCursor);
3292 // Check if we are over another branch
3293 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3294 if (dst && selection)
3296 if (e->state() & QMouseEvent::ShiftButton)
3298 ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor(),false);
3299 ((BranchObj*)selection)->setLinkColor ();
3303 ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor(),true);
3304 ((BranchObj*)selection)->setLinkColor ();
3310 // Have we been drawing a link?
3314 // Check if we are over another branch
3315 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3316 if (dst && selection)
3318 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3319 tmpXLink->updateXLink();
3320 tmpXLink->activate();
3321 saveState(); //TODO undoCommand
3330 // Have we been moving something?
3331 if ( selection && movingObj )
3333 // Moved FloatObj? Maybe we need to reposition
3334 if(typeid(*selection)==typeid (FloatImageObj))
3336 selection->getParObj()->requestReposition();
3337 mapCenter->reposition();
3340 // Check if we are over another branch, but ignore
3341 // any found LMOs, which are FloatObjs
3342 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3343 ((LinkableMapObj*)selection) );
3346 (typeid(*dst)!=typeid(BranchObj)&&typeid(*dst)!=typeid(MapCenterObj)))
3349 // Now check, if we have been moving a branch
3350 if (typeid(*selection) == typeid(BranchObj) )
3352 // save the position in case we link to mapcenter
3353 QPoint savePos=QPoint (selection->x(),selection->y() );
3355 // Reset the temporary drawn link to the original one
3356 ((LinkableMapObj*)selection)->unsetParObjTmp();
3362 BranchObj* bs=((BranchObj*)selection);
3363 QString undoCom="linkBranchToPos (\""+
3364 (bs->getParObj())->getSelectString()+
3366 QString("%1").arg(bs->getNum())+
3368 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+
3370 // TODO we also could check, if dest and src are on same branch,
3371 // then it would be sufficient to saveState of this branch
3373 // Modifiers allow to insert above/below dst
3374 if (e->state() & QMouseEvent::ShiftButton)
3376 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum());
3378 if (e->state() & QMouseEvent::ControlButton)
3380 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum()+1);
3383 bs->moveBranchTo ((BranchObj*)(dst),-1);
3384 if (dst->getDepth()==0)
3387 saveState (undoCom,bs->getSelectString() );
3389 if (selection->getDepth()==1)
3390 // If we have moved mainbranch only save endposition
3391 saveState("move "+qpointToString(movingObj_orgPos), selection->getSelectString() );
3393 // Draw the original link, before selection was moved around
3394 mapCenter->reposition();
3396 // Finally resize canvas, if needed
3401 // maybe we moved View: set old cursor
3402 setCursor (ArrowCursor);
3406 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3408 // Finish open lineEdits
3409 if (lineedit) finishedLineEditNoSave();
3411 if (e->button() == QMouseEvent::LeftButton )
3413 QPoint p = inverseWorldMatrix().map(e->pos());
3414 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3415 if (lmo) { // MapObj was found
3416 // First select the MapObj than edit heading
3417 if (selection) selection->unselect();
3419 selection->select();
3420 saveState(selection);
3426 void MapEditor::resizeEvent (QResizeEvent* e)
3428 QCanvasView::resizeEvent( e );
3432 void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3435 // for (unsigned int i=0;event->format(i);i++) // Debug mime type
3436 // cerr << event->format(i) << endl;
3439 (typeid(*selection) == typeid(BranchObj)) ||
3440 (typeid(*selection) == typeid(MapCenterObj))) {
3442 // If QImageDrag can decode mime type
3443 if (QImageDrag::canDecode(event)) {
3448 // If image are dragged from firefox
3449 if (event->provides("application/x-moz-file-promise-url") &&
3450 event->provides("application/x-moz-nativeimage")) {
3451 event->accept(true);
3455 // If QUriDrag can decode mime type
3456 if (QUriDrag::canDecode(event)) {
3461 // If Uri are dragged from firefox
3462 if (event->provides("_NETSCAPE_URL")){
3467 // If QTextDrag can decode mime type
3468 if (QTextDrag::canDecode(event)) {
3477 bool isUnicode16(const QByteArray &d)
3479 // TODO: make more precise check for unicode 16.
3480 // Guess unicode16 if any of second bytes are zero
3481 unsigned int length = max(0,d.size()-2)/2;
3482 for (unsigned int i = 0; i<length ; i++)
3483 if (d.at(i*2+1)==0) return true;
3487 void MapEditor::contentsDropEvent(QDropEvent *event)
3490 (typeid(*selection) == typeid(BranchObj)) ||
3491 (typeid(*selection) == typeid(MapCenterObj)))
3496 if (event->provides("image/png"))
3499 if (QImageDrag::decode(event, pix))
3507 } else if (event->provides("application/x-moz-file-promise-url") &&
3508 event->provides("application/x-moz-nativeimage"))
3510 // Contains url to the img src in unicode16
3511 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3512 QString url = QString((const QChar*)d.data(),d.size()/2);
3516 } else if (event->provides ("text/uri-list"))
3517 { // Uris provided e.g. by konqueror
3518 QUriDrag::decode (event,uris);
3519 } else if (event->provides ("_NETSCAPE_URL"))
3520 { // Uris provided by Mozilla
3521 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
3524 } else if (event->provides("text/html")) {
3526 // Handels text mime types
3527 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
3528 QByteArray d = event->encodedData("text/html");
3531 text = QString((const QChar*)d.data(),d.size()/2);
3535 textEditor->setText(text);
3539 } else if (event->provides("text/plain")) {
3540 QByteArray d = event->encodedData("text/plain");
3543 text = QString((const QChar*)d.data(),d.size()/2);
3547 textEditor->setText(text);
3559 for (const char* u=uris.first(); u; u=uris.next())
3561 bo=((BranchObj*)selection)->addBranch();
3564 s=QUriDrag::uriToLocalFile(u);
3566 QString file = QDir::convertSeparators(s);
3567 heading = QFileInfo(file).baseName();
3569 if (file.endsWith(".vym", false))
3570 bo->setVymLink(file);
3579 bo->setHeading(heading);
3589 saveState(); //TODO undo Command
3590 mapCenter->reposition();
3597 void MapEditor::addFloatImage(const QPixmap &img)
3600 (typeid(*selection) == typeid(BranchObj)) ||
3601 (typeid(*selection) == typeid(MapCenterObj)) )
3603 BranchObj *bo=((BranchObj*)selection);
3604 saveState(selection);
3605 //QString fn=fd->selectedFile();
3606 //lastImageDir=fn.left(fn.findRev ("/"));
3607 bo->addFloatImage();
3608 // FIXME check if load was successful
3609 bo->getLastFloatImage()->load(img);
3610 //bo->getLastFloatImage()->setOriginalFilename(fn);
3611 mapCenter->reposition();
3618 void MapEditor::imageDataFetched(const QByteArray &a, QNetworkOperation */*nop*/)
3620 if (!imageBuffer) imageBuffer = new QBuffer();
3621 if (!imageBuffer->isOpen()) {
3622 imageBuffer->open(IO_WriteOnly | IO_Append);
3624 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
3628 void MapEditor::imageDataFinished(QNetworkOperation *nop)
3630 if (nop->state()==QNetworkProtocol::StDone) {
3631 QPixmap img(imageBuffer->buffer());
3636 imageBuffer->close();
3638 imageBuffer->close();
3645 void MapEditor::fetchImage(const QString &url)
3648 urlOperator->stop();
3649 disconnect(urlOperator);
3653 urlOperator = new QUrlOperator(url);
3654 connect(urlOperator, SIGNAL(finished(QNetworkOperation *)),
3655 this, SLOT(imageDataFinished(QNetworkOperation*)));
3657 connect(urlOperator, SIGNAL(data(const QByteArray &, QNetworkOperation *)),
3658 this, SLOT(imageDataFetched(const QByteArray &, QNetworkOperation *)));