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 *actionEditOpenURLTab;
63 extern QAction *actionEditURL;
64 extern QAction *actionEditHeading2URL;
65 extern QAction *actionEditBugzilla2URL;
66 extern QAction *actionEditFATE2URL;
67 extern QAction *actionEditOpenVymLink;
68 extern QAction *actionEditVymLink;
69 extern QAction *actionEditDeleteVymLink;
70 extern QAction *actionEditToggleHideExport;
71 extern QAction *actionEditHeading;
72 extern QAction *actionEditDelete;
73 extern QAction *actionEditAddBranch;
74 extern QAction *actionEditAddBranchAbove;
75 extern QAction *actionEditAddBranchBelow;
76 extern QAction *actionEditRemoveBranchHere;
77 extern QAction *actionEditRemoveChilds;
78 extern QAction *actionEditImportAdd;
79 extern QAction *actionEditImportReplace;
80 extern QAction *actionEditSaveBranch;
81 extern QAction *actionEditSelectFirst;
82 extern QAction *actionEditSelectLast;
83 extern QAction *actionEditLoadImage;
85 extern QAction* actionFormatPickColor;
86 extern QAction* actionFormatColorBranch;
87 extern QAction* actionFormatColorSubtree;
88 extern QAction *actionFormatLinkColorHint;
89 extern QAction *actionFormatBackColor;
90 extern QAction *actionFormatLinkColor;
92 extern QActionGroup* actionGroupModModes;
93 extern QAction* actionModModeColor;
94 extern QAction* actionModModeLink;
95 extern QAction* actionModModeCopy;
97 extern QActionGroup *actionGroupFormatFrameTypes;
98 extern QAction *actionFormatFrameNone;
99 extern QAction *actionFormatFrameRectangle;
101 extern QActionGroup *actionGroupFormatLinkStyles;
102 extern QAction *actionFormatIncludeImagesVer;
103 extern QAction *actionFormatIncludeImagesHor;
104 extern QAction *actionFormatHideLinkUnselected;
105 extern QAction *actionFormatLinkStyleLine;
106 extern QAction *actionFormatLinkStyleParabel;
107 extern QAction *actionFormatLinkStylePolyLine;
108 extern QAction *actionFormatLinkStylePolyParabel;
110 extern QAction *actionViewToggleNoteEditor;
112 extern QAction *actionSettingsAutoedit;
113 extern QAction *actionSettingsAutoselectHeading;
114 extern QAction *actionSettingsAutoselectText;
115 extern QAction *actionSettingsPasteNewHeading;
116 extern QAction *actionSettingsUseFlagGroups;
118 extern QPopupMenu *branchContextMenu;
119 extern QPopupMenu *branchLinksContextMenu;
120 extern QPopupMenu *branchLinksContextMenuDup;
121 extern QPopupMenu *floatimageContextMenu;
122 extern QPopupMenu *saveImageFormatMenu;
123 extern QPopupMenu *exportImageFormatMenu;
124 extern QPopupMenu *canvasContextMenu;
126 extern Settings settings;
128 extern QString iconPath;
130 int MapEditor::mapNum=0; // make instance
132 ///////////////////////////////////////////////////////////////////////
133 ///////////////////////////////////////////////////////////////////////
134 MapEditor::MapEditor(
135 QWidget* parent, bool interactive, const char* name, WFlags f) :
136 QCanvasView(parent,name,f), urlOperator(0), imageBuffer(0)
138 //cout << "Constructor ME "<<this<<endl;
141 viewport()->setAcceptDrops(true);
143 mapCanvas = new QCanvas(1000,800);
144 mapCanvas->setAdvancePeriod(30);
145 mapCanvas->setBackgroundColor (white);
147 setCanvas (mapCanvas);
149 // Always show scroll bars (automatic would flicker sometimes)
150 setVScrollBarMode ( QScrollView::AlwaysOn );
151 setHScrollBarMode ( QScrollView::AlwaysOn );
153 mapCenter = new MapCenterObj(mapCanvas);
154 mapCenter->setVisibility (true);
155 mapCenter->setMapEditor (this);
156 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
157 mapCenter->move(mapCanvas->width()/2-mapCenter->width()/2,mapCanvas->height()/2-mapCenter->height()/2);
161 lineedit = new QLineEdit(this, "lineedit" );
162 connect( lineedit, SIGNAL( returnPressed() ), SLOT( finishedLineEditNoSave() ) );
165 actColor=black; setColor (actColor);
166 defLinkColor=QColor (0,0,255);
167 defXLinkColor=QColor (180,180,180);
168 linkcolorhint=DefaultColor;
169 linkstyle=StylePolyParabel;
171 // Create bitmap cursors, patform dependant
172 #if defined(Q_OS_MACX)
173 handOpenCursor=QCursor ( QPixmap(iconPath+"cursorhandopen16.png") );
174 // set hot spot to tip of picker
175 pickColorCursor=QCursor ( QPixmap (iconPath+"cursorcolorpicker16.png"), 1,15 );
177 handOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen16.png"));
178 // set hot spot to tip of picker
179 pickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 );
192 defXLinkColor=QColor (230,230,230);
203 undosTotal=settings.readNumEntry("/vym/mapeditor/undoLevels",50);
207 // Initialize find routine
214 blockReposition=false;
215 blockSaveState=false;
219 isInteractive=interactive;
221 // Create temporary files
224 // Initially set movingCentre
227 mapCenter->reposition(); // for positioning heading
230 MapEditor::~MapEditor()
232 if (imageBuffer) delete imageBuffer;
238 //cout <<"Destructor MapEditor\n";
241 //settings.writeEntry( "/vym/mapeditor/editmode/autoselect", );
245 QColor MapEditor::color()
250 QColor MapEditor::backgroundColor()
252 return mapCanvas->backgroundColor();
255 MapCenterObj* MapEditor::getMapCenter()
260 QCanvas* MapEditor::getCanvas()
265 void MapEditor::adjustCanvasSize()
267 // To adjust the canvas to map, viewport size and position, we have to
268 // do some coordinate magic...
270 // Get rectangle of (scroll-)view.
271 // We want to be in canvas coords, so
272 // we map. Important if view is zoomed...
273 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
274 visibleWidth(), visibleHeight()) );
276 // Now we need the bounding box of view AND map to calc the correct canvas size.
277 // Why? Because if the map itself is moved out of view, the view has to be enlarged
278 // to avoid jumping aroung...
279 QRect map=mapCenter->getTotalBBox();
281 // right edge - left edge
282 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
283 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
286 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
287 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
290 // move the map on canvas (in order to not move it on screen) this is neccessary
291 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
292 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
293 // to scroll to an empty area of canvas to the left.
294 // b) if topleft corner of map left of or above topleft of canvas
298 if (cw > mapCanvas->width() )
300 if (map.x()<0) dx=-map.x();
302 if (cw < mapCanvas->width() )
303 dx=-min (view.x(),map.x());
304 if (ch > mapCanvas->height() )
306 if (map.y()<0) dy=-map.y();
308 if (ch < mapCanvas->height() )
310 dy=-min (view.y(),map.y());
312 // We really have to resize now. Let's go...
313 mapCanvas->resize (cw,ch);
314 if ( (dx!=0) || (dy!=0) )
316 mapCenter->moveAllBy(dx,dy);
317 mapCenter->reposition();
319 // scroll the view (in order to not move map on screen)
325 bool MapEditor::isRepositionBlocked()
327 return blockReposition;
330 void MapEditor::makeTmpDirs()
332 // Create unique temporary directories
333 tmpMapDir=tmpVymDir+QString("/mapeditor-%1").arg(mapNum);
335 d.mkdir (tmpMapDir,true);
338 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSelection)
340 // tmpdir temporary directory to which data will be written
341 // prefix mapname, which will be appended to images etc.
342 // writeflags Only write flags for "real" save of map, not undo
343 // offset offset of bbox of whole map in canvas.
344 // Needed for XML export
360 ls="StylePolyParabel";
364 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
366 if (linkcolorhint==HeadingColor)
367 colhint=attribut("linkColorHint","HeadingColor");
369 QString mapAttr=attribut("version",__VYM_VERSION);
371 mapAttr+= attribut("author",mapCenter->getAuthor()) +
372 attribut("comment",mapCenter->getComment()) +
373 attribut("date",mapCenter->getDate()) +
374 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
375 attribut("linkStyle", ls ) +
376 attribut("linkColor", defLinkColor.name() ) +
377 attribut("defXLinkColor", defXLinkColor.name() ) +
378 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
380 s+=beginElement("vymmap",mapAttr);
383 // Find the used flags while traversing the tree
384 standardFlagsDefault->resetUsedCounter();
386 // Reset the counters before saving
387 FloatImageObj (mapCanvas).resetSaveCounter();
389 // Build xml recursivly
391 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
394 if ( typeid(*saveSelection) == typeid(BranchObj) )
395 s+=((BranchObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
396 else if ( typeid(*saveSelection) == typeid(FloatImageObj) )
397 s+=((FloatImageObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
399 else if (selection && typeid(*selection)==typeid(BranchObj))
400 // This is used if selected branch is saved from mainwindow
401 s+=((BranchObj*)selection)->saveToDir(tmpdir,prefix,offset);
404 // Save local settings
405 s+=settings.getXMLData (destPath);
408 if (selection && !saveSelection )
409 s+=valueElement("select",selection->getSelectString());
412 s+=endElement("vymmap");
415 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
419 void MapEditor::saveState()
422 saveState (CompleteMap,"",NULL,"",NULL);
425 void MapEditor::saveState(LinkableMapObj *undoSel)
427 // save the given part of the map
428 saveState (PartOfMap,"",undoSel,"",NULL);
431 void MapEditor::saveState(const QString &uc, const QString &rc)
433 // selection does not change during action,
434 // so just save commands for undo and redo
435 LinkableMapObj *unsel;
440 saveState (UndoCommand,uc,unsel,rc,unsel);
443 void MapEditor::saveState(const QString & uncom, LinkableMapObj *unsel)
445 saveState (UndoCommand,uncom,unsel,"FIXME-redoCom",NULL);
448 void MapEditor::saveState(const SaveMode &savemode, const QString &undoCom, LinkableMapObj *undoSel, const QString &redoCom, LinkableMapObj *redoSel)
452 if (blockSaveState) return;
454 /* TODO remove after testing
455 cout << "ME::saveState() begin\n"<<endl;
456 cout << " undosTotal="<<undosTotal<<endl;
457 cout << " undosAvail="<<undosAvail<<endl;
458 cout << " undoNum="<<undoNum<<endl;
459 cout << " ---------------------------"<<endl;
463 // Find out current undo directory
464 if (undosAvail<undosTotal) undosAvail++;
466 if (undoNum>undosTotal) undoNum=1;
469 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
470 QString bakMapPath=QDir::convertSeparators(bakMapDir+"/map.xml");
472 // Create bakMapDir if not available
475 makeSubDirs (bakMapDir);
477 // Save current selection
478 QString redoSelection="";
480 redoSelection=redoSel->getSelectString();
482 // Save the object, which should be undone
483 QString undoSelection="";
485 undoSelection=undoSel->getSelectString();
487 // Save depending on how much needs to be saved
488 QString undoCommand="";
489 if (savemode==UndoCommand)
494 else if (savemode==PartOfMap && undoSel)
496 undoCommand="undoPart (\""+ undoSelection+"\",\""+bakMapPath+"\")";
497 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),undoSel);
500 undoCommand="undoMap (\""+bakMapPath+"\")";
501 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),NULL);
504 if (!backupXML.isEmpty())
505 // Write XML Data to disk
506 saveStringToDisk (QString(bakMapPath),backupXML);
509 set.setEntry (QString("undoCommand"),undoCommand);
510 set.setEntry (QString("undoSelection"),undoSelection);
511 set.setEntry (QString("redoCommand"),redoCom);
512 set.setEntry (QString("redoSelection"),redoSelection);
513 set.writeSettings(QString(bakMapDir+"/commands"));
515 /* TODO remove after testing
516 cout << " into="<< bakMapDir<<endl;
517 cout << " undosAvail="<<undosAvail<<endl;
518 cout << " undoNum="<<undoNum<<endl;
519 cout << " ---------------------------"<<endl;
520 cout << " undoCom="<<undoCommand<<endl;
521 cout << " undoSel="<<undoSelection<<endl;
522 cout << " ---------------------------"<<endl;
523 cout << " redoCom="<<redoCom<<endl;
524 cout << " redoSel="<<redoSelection<<endl;
525 cout << " ---------------------------"<<endl<<endl;
529 void MapEditor::parseAtom(const QString &atom)
536 // Split string s into command and parameters
537 api.parseCommand (atom);
538 QString com=api.command();
541 if (com=="moveBranchUp")
543 else if (com=="moveBranchDown")
545 else if (com=="move")
547 if (api.checkParamCount(2) && selection )
557 else if (com=="linkBranchToPos")
559 if (selection && typeid(*selection) == typeid(BranchObj) )
561 if (api.checkParamCount(4))
563 s=api.parString(ok,0);
564 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
567 if (typeid(*dst) == typeid(BranchObj) )
569 // Get number in parent
572 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),x);
573 } else if (typeid(*dst) == typeid(MapCenterObj) )
575 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),-1);
576 // Get coordinates of mainbranch
581 if (ok) ((BranchObj*)selection)->move (x,y);
587 } else if (com=="setHeading")
589 if (api.checkParamCount(1))
591 s=api.parString (ok,0);
592 if (ok) setHeading (s);
594 } else if (com=="setURL")
596 if (api.checkParamCount(1))
598 s=api.parString (ok,0);
601 } else if (com=="setVymLink")
603 if (api.checkParamCount(1))
605 s=api.parString (ok,0);
606 if (ok) setVymLink(s);
609 // Internal commands, used for undo etc.
610 else if (com==QString("undoMap"))
612 if (api.checkParamCount(1))
613 undoXML("",api.parString (ok,0));
614 } else if (com==QString("undoPart"))
616 if (api.checkParamCount(2))
618 s=api.parString (ok,0);
619 t=api.parString (ok,1);
622 } else if (com=="select")
623 if (api.checkParamCount(1))
625 s=api.parString(ok,0);
630 api.setError ("Unknown command in: "+atom);
631 cout << "ME::parse api should have error now...\n";
637 cout << "MapEditor::parseAtom: Error!\n";
638 cout << " "<<api.errorDesc()<<endl;
643 void MapEditor::finishedLineEditNoSave()
645 // This is called by finishedLineEdit or any MapEditor method,
646 // which wants to assure, that lineedits finish, before e.g. a branch is
649 // After calling LineEdit and using the clipboard, the
650 // focus is not any longer on the main widget, we
651 // have to restore it using parentWidget()->setFocus()
655 editingBO->setHeading(lineedit->text() );
657 lineedit->releaseKeyboard();
659 parentWidget()->setFocus();
660 mapCenter->reposition();
662 ensureSelectionVisible();
667 bool MapEditor::isDefault()
672 bool MapEditor::isUnsaved()
677 bool MapEditor::hasChanged()
682 void MapEditor::setChanged()
687 actionEditUndo->setEnabled (true);
688 actionFileSave->setEnabled (true);
692 void MapEditor::closeMap()
694 // Finish open lineEdits
695 if (lineedit) finishedLineEditNoSave();
697 // Unselect before disabling the toolbar actions
698 if (selection) selection->unselect();
706 void MapEditor::setFilePath(QString fname)
708 setFilePath (fname,fname);
711 void MapEditor::setFilePath(QString fname, QString destname)
713 if (fname.isEmpty() || fname=="")
720 filePath=fname; // becomes absolute path
721 fileName=fname; // gets stripped of path
722 destPath=destname; // needed for vymlinks
724 // If fname is not an absolute path, complete it
725 filePath=QDir(fname).absPath();
726 fileDir=filePath.left (1+filePath.findRev ("/"));
728 // Set short name, too. Search from behind:
729 int i=fileName.findRev("/");
730 if (i>=0) fileName=fileName.remove (0,i+1);
732 // Forget the .vym (or .xml) for name of map
733 mapName=fileName.left(fileName.findRev(".",-1,true) );
737 QString MapEditor::getFilePath()
742 QString MapEditor::getFileName()
747 QString MapEditor::getMapName()
752 QString MapEditor::getDestPath()
757 ErrorCode MapEditor::load (QString fname, LoadMode lmode)
759 // Finish open lineEdits
760 if (lineedit) finishedLineEditNoSave();
762 ErrorCode err=success;
766 if (selection) selection->unselect();
769 mapCenter->setMapEditor(this);
770 // (map state is set later at end of load...)
773 saveState(selection);
777 mapBuilderHandler handler;
780 // I am paranoid: file should exist anyway
781 // according to check in mainwindow.
784 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
785 tr("Couldn't open map " +fname)+".");
789 blockReposition=true;
790 QXmlInputSource source( file);
791 QXmlSimpleReader reader;
792 reader.setContentHandler( &handler );
793 reader.setErrorHandler( &handler );
794 handler.setMapEditor( this );
795 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
796 handler.setInputFile (file.name());
797 handler.setLoadMode (lmode);
799 bool ok = reader.parse( source );
800 blockReposition=false;
801 blockSaveState=false;
805 mapCenter->reposition();
815 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
816 tr( handler.errorProtocol() ) );
818 // Still return "success": the map maybe at least
819 // partially read by the parser
826 int MapEditor::save (const SaveMode &savemode)
828 // Finish open lineEdits
829 if (lineedit) finishedLineEditNoSave();
833 // The SaveMode UndoCommand is not supported here
834 if (savemode==UndoCommand) return 1;
836 // Create mapName and fileDir
837 makeSubDirs (fileDir);
841 fname=mapName+".xml";
843 // use name given by user, even if he chooses .doc
848 if (savemode==CompleteMap || selection==NULL)
849 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL);
851 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection);
853 if (!saveStringToDisk(fileDir+fname,saveFile))
860 actionFileSave->setEnabled(false);
866 void MapEditor::setZipped (bool z)
871 bool MapEditor::saveZipped ()
876 void MapEditor::print()
878 // Finish open lineEdits
879 if (lineedit) finishedLineEditNoSave();
883 printer = new QPrinter;
884 printer->setColorMode (QPrinter::Color);
885 printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName()));
888 QRect totalBBox=mapCenter->getTotalBBox();
890 // Try to set orientation automagically
891 // Note: Interpretation of generated postscript is amibiguous, if
892 // there are problems with landscape mode, see
893 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
895 if (totalBBox.width()>totalBBox.height())
896 // recommend landscape
897 printer->setOrientation (QPrinter::Landscape);
899 // recommend portrait
900 printer->setOrientation (QPrinter::Portrait);
902 if ( printer->setup(this) )
903 // returns false, if printing is canceled
905 QPainter pp(printer);
907 // Don't print the visualisation of selection
908 LinkableMapObj *oldselection=NULL;
911 oldselection=selection;
912 selection->unselect();
915 // Handle sizes of map and paper:
917 // setWindow defines which part of the canvas will be transformed
918 // setViewport defines area on paper in device coordinates (dpi)
919 // e.g. (0,50,700,700) is upper part on A4
920 // see also /usr/lib/qt3/doc/html/coordsys.html
922 QPaintDeviceMetrics metrics (printer);
924 double paperAspect = (double)metrics.width() / (double)metrics.height();
925 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
927 QRect mapRect=totalBBox;
928 QCanvasRectangle *frame=NULL;
929 QCanvasText *footerFN=NULL;
930 QCanvasText *footerDate=NULL;
931 if (printFrame || printFooter)
936 // Print frame around map
937 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
938 totalBBox.width()+20, totalBBox.height()+20);
939 frame=new QCanvasRectangle (mapRect,mapCanvas);
940 frame->setBrush (QColor(white));
941 frame->setPen (QColor(black));
945 /* TODO remove after testing
946 QCanvasLine *l=new QCanvasLine (mapCanvas);
947 l->setPoints (0,0,mapRect.width(),mapRect.height());
948 l->setPen (QPen(QColor(black), 1));
955 // Print footer below map
957 font.setPointSize(10);
958 footerFN=new QCanvasText (mapCanvas);
959 footerFN->setText ("VYM - " + fileName);
960 footerFN->setFont(font);
961 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
962 footerFN->setZ(Z_TEXT);
964 footerDate=new QCanvasText (mapCanvas);
965 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
966 footerDate->setFont(font);
967 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
968 footerDate->setZ(Z_TEXT);
971 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
974 pp.setWindow (mapRect);
977 if (mapAspect>=paperAspect)
979 // Fit horizontally to paper width
980 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
983 // Fit vertically to paper height
984 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
987 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
989 // Delete Frame and footer
995 if (frame) delete (frame);
1000 selection=oldselection;
1001 selection->select();
1004 // Save settings in vymrc
1005 settings.writeEntry("/vym/mainwindow/printerName",printer->printerName());
1009 QPixmap MapEditor::getPixmap()
1011 QRect mapRect=mapCenter->getTotalBBox();
1012 QPixmap pix (mapRect.size());
1015 // Don't print the visualisation of selection
1016 LinkableMapObj *oldselection=NULL;
1019 oldselection=selection;
1020 selection->unselect();
1023 pp.setWindow (mapRect);
1025 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
1028 // Restore selection
1031 selection=oldselection;
1032 selection->select();
1038 void MapEditor::setHideTmpMode (HideTmpMode mode)
1041 mapCenter->setHideTmp (hidemode);
1042 mapCenter->reposition();
1047 HideTmpMode MapEditor::getHideTmpMode()
1052 void MapEditor::exportImage(QString fn)
1054 // Finish open lineEdits
1055 if (lineedit) finishedLineEditNoSave();
1057 setExportMode (true);
1058 QPixmap pix (getPixmap());
1059 pix.save(fn, "PNG");
1060 setExportMode (false);
1063 void MapEditor::setExportMode (bool b)
1065 // should be called before and after exports
1066 // depending on the settings
1067 if (b && settings.readEntry("/vym/export/useHideExport","yes"))
1068 setHideTmpMode (HideExport);
1070 setHideTmpMode (HideNone);
1073 void MapEditor::exportImage(QString fn, int item)
1075 // Finish open lineEdits
1076 if (lineedit) finishedLineEditNoSave();
1078 setExportMode (true);
1079 QPixmap pix (getPixmap());
1080 pix.save(fn, exportImageFormatMenu->text(item) );
1081 setExportMode (false);
1084 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
1088 ex.setMapCenter(mapCenter);
1089 if (ex.setConfigFile(cf))
1091 setExportMode (true);
1092 ex.exportPresentation();
1093 setExportMode (false);
1099 void MapEditor::exportXML(const QString &dir)
1101 // Hide stuff during export, if settings want this
1102 setExportMode (true);
1104 // Create subdirectories
1107 // write to directory
1108 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1111 file.setName ( dir + "/"+mapName+".xml");
1112 if ( !file.open( IO_WriteOnly ) )
1114 // This should neverever happen
1115 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1119 // Write it finally, and write in UTF8, no matter what
1120 QTextStream ts( &file );
1121 ts.setEncoding (QTextStream::UnicodeUTF8);
1125 // Now write image, too
1126 exportImage (dir+"/images/"+mapName+".png");
1128 setExportMode (false);
1131 void MapEditor::clear()
1135 selection->unselect();
1142 void MapEditor::copy()
1144 // Finish open lineEdits
1145 if (lineedit) finishedLineEditNoSave();
1149 // write to directory
1150 QString clipfile="part";
1151 QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPoint(),selection);
1154 file.setName ( clipboardDir + "/"+clipfile+".xml");
1155 if ( !file.open( IO_WriteOnly ) )
1157 // This should neverever happen
1158 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1162 // Write it finally, and write in UTF8, no matter what
1163 QTextStream ts( &file );
1164 ts.setEncoding (QTextStream::UnicodeUTF8);
1168 clipboardEmpty=false;
1173 void MapEditor::redo()
1175 // Finish open lineEdits
1176 if (lineedit) finishedLineEditNoSave();
1178 blockSaveState=true;
1180 // Find out current undo directory
1181 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
1183 // Restore variables
1184 QString undoCommand;
1185 QString undoSelection;
1186 QString redoCommand;
1187 QString redoSelection;
1189 set.readSettings(QString(bakMapDir+"/commands"));
1190 undoCommand=set.readEntry ("undoCommand");
1191 undoSelection=set.readEntry ("undoSelection");
1192 redoCommand=set.readEntry ("redoCommand");
1193 redoSelection=set.readEntry ("redoSelection");
1195 // select object before redo
1196 if (!redoSelection.isEmpty())
1197 select (redoSelection);
1199 /* TODO remove testing
1200 cout << "ME::redo() begin\n";
1201 cout << " undosTotal="<<undosTotal<<endl;
1202 cout << " undosAvail="<<undosAvail<<endl;
1203 cout << " undoNum="<<undoNum<<endl;
1204 cout << " ---------------------------"<<endl;
1205 cout << " undoCom="<<undoCommand<<endl;
1206 cout << " undoSel="<<undoSelection<<endl;
1207 cout << " ---------------------------"<<endl;
1208 cout << " redoCom="<<redoCommand<<endl;
1209 cout << " redoSel="<<redoSelection<<endl;
1210 cout << " ---------------------------"<<endl;
1212 parseAtom (undoCommand);
1213 mapCenter->reposition();
1215 //if (!redoSelection.isEmpty())
1216 // select (redoSelection);
1220 // Undo not longer available now
1221 actionEditUndo->setEnabled (false);
1223 undoNum--; if (undoNum<1) undoNum=undosTotal;
1225 blockSaveState=false;
1226 /* TODO remove testing
1227 cout << "ME::redo() end\n";
1228 cout << " undosAvail="<<undosAvail<<endl;
1229 cout << " undoNum="<<undoNum<<endl;
1230 cout << " ---------------------------"<<endl<<endl;
1234 void MapEditor::undo()
1236 // Finish open lineEdits
1237 if (lineedit) finishedLineEditNoSave();
1239 blockSaveState=true;
1241 // Find out current undo directory
1242 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
1244 // Restore variables
1245 QString undoCommand;
1246 QString undoSelection;
1247 QString redoCommand;
1248 QString redoSelection;
1250 set.readSettings(QString(bakMapDir+"/commands"));
1251 undoCommand= set.readEntry ("undoCommand");
1252 undoSelection=set.readEntry ("undoSelection");
1253 redoCommand= set.readEntry ("redoCommand");
1254 redoSelection=set.readEntry ("redoSelection");
1256 // select object before undo
1257 if (!undoSelection.isEmpty())
1258 select (undoSelection);
1261 cout << "ME::undo() begin\n";
1262 cout << " undosTotal="<<undosTotal<<endl;
1263 cout << " undosAvail="<<undosAvail<<endl;
1264 cout << " undoNum="<<undoNum<<endl;
1265 cout << " ---------------------------"<<endl;
1266 cout << " undoCom="<<undoCommand<<endl;
1267 cout << " undoSel="<<undoSelection<<endl;
1268 cout << " ---------------------------"<<endl;
1269 cout << " redoCom="<<redoCommand<<endl;
1270 cout << " redoSel="<<redoSelection<<endl;
1271 cout << " ---------------------------"<<endl;
1273 parseAtom (undoCommand);
1274 mapCenter->reposition();
1276 //if (!redoSelection.isEmpty())
1277 // select (redoSelection);
1281 // Undo not longer available now
1282 actionEditUndo->setEnabled (false);
1284 undoNum--; if (undoNum<1) undoNum=undosTotal;
1286 blockSaveState=false;
1287 /* TODO remove testing
1288 cout << "ME::undo() end\n";
1289 cout << " undosAvail="<<undosAvail<<endl;
1290 cout << " undoNum="<<undoNum<<endl;
1291 cout << " ---------------------------"<<endl<<endl;
1295 void MapEditor::undoXML(const QString &undoSel, const QString &bakMapPath)
1297 QString bakMapDir=bakMapPath.left(bakMapPath.findRev("/"));
1299 QFile file (bakMapPath);
1303 // We need to parse saved XML data
1304 mapBuilderHandler handler;
1305 QXmlInputSource source( file);
1306 QXmlSimpleReader reader;
1307 reader.setContentHandler( &handler );
1308 reader.setErrorHandler( &handler );
1309 handler.setMapEditor( this );
1310 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1311 if (undoSel.isEmpty())
1315 handler.setLoadMode (NewMap);
1319 handler.setLoadMode (ImportReplace);
1321 blockReposition=true;
1322 bool ok = reader.parse( source );
1323 blockReposition=false;
1326 // This should never ever happen
1327 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1328 tr( handler.errorProtocol() )+" in "+bakMapDir );
1332 QMessageBox::critical( 0, tr( "Critical Error" ),
1333 tr("Temporary directory %1 used for undo is gone. \n"
1334 "I will create a new one, but at the moment no undo is available.\n"
1335 "Maybe you want to reload your original data.\n\n"
1336 "Sorry for any inconveniences.").arg(bakMapDir) );
1341 void MapEditor::pasteNoSave()
1343 // Finish open lineEdits
1344 if (lineedit) finishedLineEditNoSave();
1346 load (clipboardDir+"/part.xml",ImportAdd);
1349 void MapEditor::cutNoSave()
1355 void MapEditor::paste()
1357 if (selection && (typeid(*selection) == typeid(BranchObj) ||
1358 typeid(*selection) == typeid(MapCenterObj)))
1360 saveState(selection);
1362 mapCenter->reposition();
1367 void MapEditor::cut()
1369 saveState(selection->getParObj());
1372 mapCenter->reposition();
1376 void MapEditor::move(const int &x, const int &y)
1378 // TODO no saveState, because this is only internal at undo so far
1379 if (selection) selection->move(x,y);
1380 if (typeid(*selection) == typeid(FloatImageObj))
1381 ((FloatImageObj*)selection)->setRelPos();
1384 void MapEditor::moveBranchUp()
1386 // Finish open lineEdits
1387 if (lineedit) finishedLineEditNoSave();
1391 if (typeid(*selection) == typeid(BranchObj) )
1393 bo=(BranchObj*)selection;
1394 par=(BranchObj*)(bo->getParObj());
1395 selection->unselect();
1396 selection=par->moveBranchUp (bo);
1397 selection->select();
1398 saveState("moveBranchDown ()",bo);
1399 mapCenter->reposition();
1400 ensureSelectionVisible();
1404 void MapEditor::moveBranchDown()
1406 // Finish open lineEdits
1407 if (lineedit) finishedLineEditNoSave();
1411 if (typeid(*selection) == typeid(BranchObj) )
1413 bo=(BranchObj*)selection;
1414 par=(BranchObj*)(bo->getParObj());
1415 selection->unselect();
1416 selection=par->moveBranchDown(bo);
1417 selection->select();
1418 saveState("moveBranchUp ()",bo);
1419 mapCenter->reposition();
1420 ensureSelectionVisible();
1424 void MapEditor::editHeading()
1426 // Finish open lineEdits
1427 if (lineedit) finishedLineEditNoSave();
1430 (typeid(*selection) == typeid(BranchObj) ||
1431 typeid(*selection) == typeid(MapCenterObj) ) )
1433 editingBO=(BranchObj*)selection;
1434 saveState("setHeading (\""+((BranchObj*)selection)->getHeading()+"\")",editingBO );
1436 ensureSelectionVisible();
1437 QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
1438 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1439 QString s=editingBO->getHeading();
1440 lineedit->setText(s);
1441 lineedit->setCursorPosition(1);
1442 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1443 lineedit->selectAll();
1445 lineedit->grabKeyboard();
1446 lineedit->setFocus();
1450 void MapEditor::setHeading(const QString &s)
1452 // Internal function, no saveState needed
1454 (typeid(*selection) == typeid(BranchObj) ||
1455 typeid(*selection) == typeid(MapCenterObj) ) )
1457 ((BranchObj*)selection)->setHeading(s);
1458 mapCenter->reposition();
1460 ensureSelectionVisible();
1464 void MapEditor::setURL (const QString &s)
1466 // Internal function, no saveState needed
1468 (typeid(*selection) == typeid(BranchObj) ||
1469 typeid(*selection) == typeid(MapCenterObj) ) )
1471 ((BranchObj*)selection)->setURL(s);
1472 mapCenter->reposition();
1474 ensureSelectionVisible();
1478 void MapEditor::setVymLink (const QString &s)
1480 // Internal function, no saveState needed
1482 (typeid(*selection) == typeid(BranchObj) ||
1483 typeid(*selection) == typeid(MapCenterObj) ) )
1485 ((BranchObj*)selection)->setVymLink(s);
1486 mapCenter->reposition();
1488 ensureSelectionVisible();
1492 void MapEditor::addNewBranch(int pos)
1494 // Finish open lineEdits
1495 if (lineedit) finishedLineEditNoSave();
1498 (typeid(*selection) == typeid(BranchObj) ||
1499 typeid(*selection) == typeid(MapCenterObj) ) )
1501 saveState(selection); //TODO undoCommand
1503 BranchObj* bo1 = (BranchObj*) selection;
1504 bool wasScrolled=false;
1505 BranchObj *newbo=NULL;
1508 // save scroll state. If scrolled, automatically select
1509 // new branch in order to tmp unscroll parent...
1510 wasScrolled=bo1->isScrolled();
1511 newbo=bo1->addBranch();
1514 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1518 // add above selection
1519 newbo=parbo->insertBranch(bo1->getNum());
1521 // add below selection
1522 newbo=parbo->insertBranch(bo1->getNum()+1);
1524 // This should not happen...
1529 LinkableMapObj *oldselection=selection;
1531 mapCenter->reposition();
1533 if (actionSettingsAutoedit->isOn() ||
1534 actionSettingsAutoselectHeading->isOn() )
1536 selection->unselect();
1538 selection->select();
1539 if (actionSettingsPasteNewHeading->isOn() )
1541 BranchObj *bo2= (BranchObj*)selection;
1542 bo2->setHeading("");
1544 if (actionSettingsAutoedit->isOn() )
1546 if (!actionSettingsAutoselectHeading->isOn()
1549 selection->unselect();
1550 selection=oldselection;
1551 selection->select();
1558 void MapEditor::addNewBranchHere()
1560 // Finish open lineEdits
1561 if (lineedit) finishedLineEditNoSave();
1564 (typeid(*selection) == typeid(BranchObj) ) )
1566 saveState(selection);
1568 BranchObj* bo1 = (BranchObj*) selection;
1569 bool wasScrolled=false;
1570 BranchObj *newbo=NULL;
1571 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1574 // add below selection
1575 newbo=parbo->insertBranch(bo1->getNum()+1);
1578 LinkableMapObj *oldselection=selection;
1579 ((BranchObj*)selection)->moveBranchTo (newbo,-1);
1581 mapCenter->reposition();
1583 if (actionSettingsAutoedit->isOn() ||
1584 actionSettingsAutoselectHeading->isOn() )
1586 selection->unselect();
1588 selection->select();
1589 if (actionSettingsPasteNewHeading->isOn() )
1591 BranchObj *bo2= (BranchObj*)selection;
1592 bo2->setHeading("");
1594 if (actionSettingsAutoedit->isOn() )
1596 if (!actionSettingsAutoselectHeading->isOn()
1599 selection->unselect();
1600 selection=oldselection;
1601 selection->select();
1607 void MapEditor::deleteSelection()
1609 // Finish open lineEdits
1610 if (lineedit) finishedLineEditNoSave();
1612 if (selection && typeid(*selection) ==typeid(BranchObj) )
1614 if (selection->getDepth()>1)
1615 // Normal branch, save parent with childs
1616 saveState(selection->getParObj());
1618 // Mainbranch, save whole map
1619 // TODO Better would be to insert mainbranch again at pos
1620 // But undoCommand is missing right now
1622 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1623 BranchObj* par=(BranchObj*)(bo->getParObj());
1626 par->removeBranch(bo);
1628 selection->select();
1629 ensureSelectionVisible();
1630 mapCenter->reposition();
1633 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1635 saveState(selection->getParObj());
1636 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1637 BranchObj* par=(BranchObj*)(fio->getParObj());
1640 par->removeFloatImage(fio);
1642 selection->select();
1643 ensureSelectionVisible();
1644 mapCenter->reposition();
1649 LinkableMapObj* MapEditor::getSelection()
1654 void MapEditor::unselect()
1658 selectionLast=selection;
1659 selection->unselect();
1664 void MapEditor::reselect()
1668 selection=selectionLast;
1669 selection->select();
1674 bool MapEditor::select (const QString &s)
1676 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
1678 // Finally select the found object
1681 if (selection) unselect();
1683 selection->select();
1685 ensureSelectionVisible();
1691 void MapEditor::select (LinkableMapObj *lmo)
1693 if (lmo && selection != lmo)
1695 // select the MapObj
1696 if (selection) selection->unselect();
1698 selection->select();
1705 void MapEditor::selectNextBranch()
1707 // Increase number of branch
1710 QString s=selection->getSelectString();
1716 part=s.section(",",-1);
1718 num=part.right(part.length() - 3);
1720 s=s.left (s.length() -num.length());
1723 num=QString ("%1").arg(num.toUInt()+1);
1727 // Try to select this one
1728 if (select (s)) return;
1730 // We have no direct successor,
1731 // try to increase the parental number in order to
1732 // find a successor with same depth
1734 int d=selection->getDepth();
1739 while (!found && d>0)
1741 s=s.section (",",0,d-1);
1742 // replace substring of current depth in s with "1"
1743 part=s.section(",",-1);
1745 num=part.right(part.length() - 3);
1749 // increase number of parent
1750 num=QString ("%1").arg(num.toUInt()+1);
1751 s=s.section (",",0,d-2) + ","+ typ+num;
1754 // Special case, look at orientation
1755 if (selection->getOrientation()==OrientRightOfCenter)
1756 num=QString ("%1").arg(num.toUInt()+1);
1758 num=QString ("%1").arg(num.toUInt()-1);
1763 // pad to oldDepth, select the first branch for each depth
1764 for (i=d;i<oldDepth;i++)
1769 if ( ((BranchObj*)selection)->countBranches()>0)
1777 // try to select the freshly built string
1785 void MapEditor::selectPrevBranch()
1787 // Decrease number of branch
1790 QString s=selection->getSelectString();
1796 part=s.section(",",-1);
1798 num=part.right(part.length() - 3);
1800 s=s.left (s.length() -num.length());
1803 num=QString ("%1").arg(num.toUInt()-1);
1807 // Try to select this one
1808 if (select (s)) return;
1810 // We have no direct precessor,
1811 // try to decrease the parental number in order to
1812 // find a precessor with same depth
1814 int d=selection->getDepth();
1819 while (!found && d>0)
1821 s=s.section (",",0,d-1);
1822 // replace substring of current depth in s with "1"
1823 part=s.section(",",-1);
1825 num=part.right(part.length() - 3);
1829 // decrease number of parent
1830 num=QString ("%1").arg(num.toUInt()-1);
1831 s=s.section (",",0,d-2) + ","+ typ+num;
1834 // Special case, look at orientation
1835 if (selection->getOrientation()==OrientRightOfCenter)
1836 num=QString ("%1").arg(num.toUInt()-1);
1838 num=QString ("%1").arg(num.toUInt()+1);
1843 // pad to oldDepth, select the last branch for each depth
1844 for (i=d;i<oldDepth;i++)
1848 if ( ((BranchObj*)selection)->countBranches()>0)
1849 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)selection)->countBranches()-1 );
1856 // try to select the freshly built string
1864 void MapEditor::selectUpperBranch()
1866 // Finish open lineEdits
1867 if (lineedit) finishedLineEditNoSave();
1871 if (typeid(*selection) == typeid(BranchObj))
1873 if (selection->getOrientation()==OrientRightOfCenter)
1876 if (selection->getDepth()==1)
1884 void MapEditor::selectLowerBranch()
1886 // Finish open lineEdits
1887 if (lineedit) finishedLineEditNoSave();
1891 if (typeid(*selection) == typeid(BranchObj))
1893 if (selection->getOrientation()==OrientRightOfCenter)
1896 if (selection->getDepth()==1)
1905 void MapEditor::selectLeftBranch()
1907 // Finish open lineEdits
1908 if (lineedit) finishedLineEditNoSave();
1914 if (typeid(*selection) == typeid(MapCenterObj))
1916 par= (BranchObj*) selection;
1917 bo=par->getLastSelectedBranch();
1920 // Workaround for reselecting on left and right side
1921 if (bo->getOrientation()==OrientRightOfCenter)
1923 bo=par->getLastBranch();
1929 selection->select();
1931 ensureSelectionVisible();
1936 par=(BranchObj*)(selection->getParObj());
1937 if (selection->getOrientation()==OrientRightOfCenter)
1939 if (typeid(*selection) == typeid(BranchObj) ||
1940 typeid(*selection) == typeid(FloatImageObj))
1942 selection->unselect();
1944 selection->select();
1946 ensureSelectionVisible();
1950 if (typeid(*selection) == typeid(BranchObj) )
1952 bo=((BranchObj*)selection)->getLastSelectedBranch();
1955 selection->unselect();
1957 selection->select();
1959 ensureSelectionVisible();
1967 void MapEditor::selectRightBranch()
1969 // Finish open lineEdits
1970 if (lineedit) finishedLineEditNoSave();
1977 if (typeid(*selection) == typeid(MapCenterObj))
1979 par= (BranchObj*) selection;
1980 bo=par->getLastSelectedBranch();
1983 // Workaround for relecting on left and right side
1984 if (bo->getOrientation()==OrientLeftOfCenter)
1985 bo=par->getFirstBranch();
1990 selection->select();
1991 ensureSelectionVisible();
1996 par=(BranchObj*)(selection->getParObj());
1997 if (selection->getOrientation()==OrientLeftOfCenter)
1999 if (typeid(*selection) == typeid(BranchObj) ||
2000 typeid(*selection) == typeid(FloatImageObj))
2002 selection->unselect();
2004 selection->select();
2006 ensureSelectionVisible();
2010 if (typeid(*selection) == typeid(BranchObj) )
2012 bo=((BranchObj*)selection)->getLastSelectedBranch();
2015 selection->unselect();
2017 selection->select();
2019 ensureSelectionVisible();
2027 void MapEditor::selectFirstBranch()
2029 // Finish open lineEdits
2030 if (lineedit) finishedLineEditNoSave();
2036 if (typeid(*selection) == typeid(BranchObj))
2038 bo1= (BranchObj*) selection;
2039 par=(BranchObj*)(bo1->getParObj());
2040 bo2=par->getFirstBranch();
2044 selection->select();
2045 ensureSelectionVisible();
2052 void MapEditor::selectLastBranch()
2054 // Finish open lineEdits
2055 if (lineedit) finishedLineEditNoSave();
2061 if (typeid(*selection) == typeid(BranchObj))
2063 bo1= (BranchObj*) selection;
2064 par=(BranchObj*)(bo1->getParObj());
2065 bo2=par->getLastBranch();
2069 selection->select();
2070 ensureSelectionVisible();
2077 void MapEditor::setColor(QColor c)
2082 void MapEditor::selectBackgroundColor()
2084 // Finish open lineEdits
2085 if (lineedit) finishedLineEditNoSave();
2087 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
2088 if ( !col.isValid() ) return;
2089 setBackgroundColor( col );
2093 void MapEditor::setBackgroundColor(QColor c)
2095 mapCanvas->setBackgroundColor (c);
2098 QColor MapEditor::pickColor()
2102 if (typeid(*selection) == typeid(BranchObj) ||
2103 typeid(*selection) == typeid(MapCenterObj))
2105 BranchObj *bo=(BranchObj*)selection;
2106 actColor=bo->getColor();
2112 void MapEditor::colorItem()
2116 if (typeid(*selection) == typeid(BranchObj) ||
2117 typeid(*selection) == typeid(MapCenterObj))
2119 saveState(selection); //TODO undoCommand
2120 BranchObj *bo=(BranchObj*)selection;
2121 bo->setColor(actColor); // color branch
2126 void MapEditor::colorBranch()
2130 if (typeid(*selection) == typeid(BranchObj) ||
2131 typeid(*selection) == typeid(MapCenterObj))
2133 saveState(selection); //TODO undoCommand
2134 BranchObj *bo=(BranchObj*)selection;
2135 bo->setColorChilds(actColor); // color links, color childs
2141 void MapEditor::toggleStandardFlag(QString f)
2145 saveState(selection);// TODO undoCommand
2146 ((BranchObj*)selection)->toggleStandardFlag (f,actionSettingsUseFlagGroups);
2151 void MapEditor::setViewCenter()
2153 // transform to CanvasView Coord:
2154 QPoint p=worldMatrix().map(movingCenter);
2155 center ( p.x(), p.y());
2159 BranchObj* MapEditor::findText (QString s, bool cs)
2162 { // Nothing found or new find process
2164 // nothing found, start again
2166 itFind=mapCenter->first();
2168 bool searching=true;
2169 bool foundNote=false;
2170 while (searching && !EOFind)
2174 // Searching in Note
2175 if (itFind->getNote().contains(s,cs))
2177 if (selection!=itFind)
2179 if (selection) ((BranchObj*)selection)->unselect();
2181 selection->select();
2183 ensureSelectionVisible();
2185 if (textEditor->findText(s,cs))
2191 // Searching in Heading
2192 if (searching && itFind->getHeading().contains (s,cs) )
2194 if (selection) ((BranchObj*)selection)->unselect();
2196 selection->select();
2198 ensureSelectionVisible();
2204 itFind=itFind->next();
2205 if (!itFind) EOFind=true;
2211 return (BranchObj*)selection;
2216 void MapEditor::findReset()
2217 { // Necessary if text to find changes during a find process
2222 void MapEditor::editURL()
2224 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2225 typeid(*selection) == typeid(MapCenterObj)) )
2228 BranchObj *bo=(BranchObj*)selection;
2229 QString text = QInputDialog::getText(
2230 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2231 bo->getURL(), &ok, this );
2234 // user entered something and pressed OK
2235 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+text+"\")");
2242 QString MapEditor::getURL()
2244 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2245 typeid(*selection) == typeid(MapCenterObj)) )
2246 return ((BranchObj*)selection)->getURL();
2251 void MapEditor::editHeading2URL()
2253 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2254 typeid(*selection) == typeid(MapCenterObj)) )
2256 BranchObj *bo=(BranchObj*)selection;
2257 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+bo->getHeading()+"\")");
2258 bo->setURL (bo->getHeading());
2263 void MapEditor::editBugzilla2URL()
2265 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2266 typeid(*selection) == typeid(MapCenterObj)) )
2268 BranchObj *bo=(BranchObj*)selection;
2269 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2270 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")");
2276 void MapEditor::editFATE2URL()
2278 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2279 typeid(*selection) == typeid(MapCenterObj)) )
2281 BranchObj *bo=(BranchObj*)selection;
2282 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2283 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")");
2289 void MapEditor::editVymLink()
2291 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2292 typeid(*selection) == typeid(MapCenterObj)) )
2294 BranchObj *bo=(BranchObj*)selection;
2295 QFileDialog *fd=new QFileDialog( this,__VYM " - " +tr("Link to another map"));
2296 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2297 fd->setCaption(__VYM " - " +tr("Link to another map"));
2298 if (! bo->getVymLink().isEmpty() )
2299 fd->setSelection( bo->getVymLink() );
2303 if ( fd->exec() == QDialog::Accepted )
2305 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\""+fd->selectedFile()+"\")");
2306 bo->setVymLink (fd->selectedFile() );
2308 mapCenter->reposition();
2315 void MapEditor::deleteVymLink()
2317 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2318 typeid(*selection) == typeid(MapCenterObj)) )
2320 BranchObj *bo=(BranchObj*)selection;
2321 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\"\")");
2322 bo->setVymLink ("" );
2324 mapCenter->reposition();
2330 void MapEditor::setHideExport()
2332 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2333 typeid(*selection) == typeid(MapCenterObj)) ||
2334 (typeid(*selection)==typeid(FloatImageObj))
2337 saveState(); //TODO undoCommand
2338 OrnamentedObj *oo=(OrnamentedObj*)selection;
2339 oo->setHideInExport(actionEditToggleHideExport->isOn());
2341 mapCenter->reposition();
2347 void MapEditor::toggleHideExport()
2349 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2350 typeid(*selection) == typeid(MapCenterObj)) ||
2351 (typeid(*selection)==typeid(FloatImageObj))
2354 saveState(); //TODO undoCommand
2355 OrnamentedObj *oo=(OrnamentedObj*)selection;
2356 if (oo->hideInExport())
2357 oo->setHideInExport(false);
2359 oo->setHideInExport(true);
2360 actionEditToggleHideExport->setOn (oo->hideInExport());
2362 mapCenter->reposition();
2368 QString MapEditor::getVymLink()
2370 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2371 typeid(*selection) == typeid(MapCenterObj)) )
2373 return ((BranchObj*)selection)->getVymLink();
2379 void MapEditor::removeBranchHere()
2381 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2383 BranchObj* bo=(BranchObj*)selection;
2384 BranchObj* par=(BranchObj*)(bo->getParObj());
2385 if (bo->getDepth()==1)
2388 saveState(selection->getParObj()); // TODO undoCommand
2389 QString sel=selection->getSelectString();
2391 par->removeBranchHere(bo);
2392 mapCenter->reposition();
2397 void MapEditor::removeChilds()
2399 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2401 saveState(selection->getParObj());
2402 ((BranchObj*)selection)->removeChilds();
2403 mapCenter->reposition();
2407 void MapEditor::editMapInfo()
2409 ExtraInfoDialog dia;
2410 dia.setMapName (getFileName() );
2411 dia.setAuthor (mapCenter->getAuthor() );
2412 dia.setComment(mapCenter->getComment() );
2417 QCanvasItemList l=canvas()->allItems();
2418 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2420 stats+=QString ("%1 items on canvas\n").arg (i,6);
2427 bo=mapCenter->first();
2430 if (!bo->getNote().isEmpty() ) n++;
2431 f+= bo->countFloatImages();
2433 xl+=bo->countXLinks();
2436 stats+=QString ("%1 branches\n").arg (b-1,6);
2437 stats+=QString ("%1 xLinks \n").arg (xl,6);
2438 stats+=QString ("%1 notes\n").arg (n,6);
2439 stats+=QString ("%1 images\n").arg (f,6);
2440 dia.setStats (stats);
2442 // Finally show dialog
2443 if (dia.exec() == QDialog::Accepted)
2445 saveState(); //TODO undoCommand
2446 mapCenter->setAuthor (dia.getAuthor() );
2447 mapCenter->setComment (dia.getComment() );
2451 void MapEditor::updateActions()
2454 if (getLinkColorHint()==HeadingColor)
2455 actionFormatLinkColorHint->setOn(true);
2457 actionFormatLinkColorHint->setOn(false);
2462 actionFormatLinkStyleLine->setOn(true);
2465 actionFormatLinkStyleParabel->setOn(true);
2468 actionFormatLinkStylePolyLine->setOn(true);
2470 case StylePolyParabel:
2471 actionFormatLinkStylePolyParabel->setOn(true);
2477 QPixmap pix( 16, 16 );
2478 pix.fill( mapCanvas->backgroundColor() );
2479 actionFormatBackColor->setIconSet( pix );
2480 pix.fill( defLinkColor );
2481 actionFormatLinkColor->setIconSet( pix );
2483 actionEditUndo->setEnabled( mapChanged );
2484 actionFileSave->setEnabled( mapUnsaved );
2488 if ( (typeid(*selection) == typeid(BranchObj)) ||
2489 (typeid(*selection) == typeid(MapCenterObj)) )
2491 BranchObj *bo=(BranchObj*)selection;
2492 // Take care of links
2493 if (bo->countXLinks()==0)
2495 branchLinksContextMenu->clear();
2496 branchLinksContextMenu->insertItem ("No xLink available");
2497 branchLinksContextMenuDup->clear();
2498 branchLinksContextMenuDup->insertItem ("No xLink available");
2504 branchLinksContextMenu->clear();
2505 branchLinksContextMenuDup->clear();
2506 for (int i=0; i<=bo->countXLinks();i++)
2508 bot=bo->XLinkTargetAt(i);
2511 s=bot->getHeading();
2514 branchLinksContextMenu->insertItem (s);
2515 branchLinksContextMenuDup->insertItem (s);
2520 standardFlagsDefault->setEnabled (true);
2522 actionEditToggleScroll->setEnabled (true);
2523 if ( bo->isScrolled() )
2524 actionEditToggleScroll->setOn(true);
2526 actionEditToggleScroll->setOn(false);
2528 if ( bo->getURL().isEmpty() )
2530 actionEditOpenURL->setEnabled (false);
2531 actionEditOpenURLTab->setEnabled (false);
2535 actionEditOpenURL->setEnabled (true);
2536 actionEditOpenURLTab->setEnabled (true);
2538 if ( bo->getVymLink().isEmpty() )
2540 actionEditOpenVymLink->setEnabled (false);
2541 actionEditDeleteVymLink->setEnabled (false);
2544 actionEditOpenVymLink->setEnabled (true);
2545 actionEditDeleteVymLink->setEnabled (true);
2547 actionEditToggleHideExport->setEnabled (true);
2548 actionEditToggleHideExport->setOn (bo->hideInExport() );
2550 actionEditCopy->setEnabled (true);
2551 actionEditCut->setEnabled (true);
2552 if (!clipboardEmpty)
2553 actionEditPaste->setEnabled (true);
2555 actionEditPaste->setEnabled (false);
2556 for (a=actionListBranches.first();a;a=actionListBranches.next())
2557 a->setEnabled(true);
2558 actionEditDelete->setEnabled (true);
2559 switch (selection->getFrameType())
2562 actionFormatFrameNone->setOn(true);
2565 actionFormatFrameRectangle->setOn(true);
2570 actionFormatIncludeImagesVer->setOn
2571 ( ((BranchObj*)selection)->getIncludeImagesVer());
2572 actionFormatIncludeImagesHor->setOn
2573 ( ((BranchObj*)selection)->getIncludeImagesHor());
2574 actionFormatHideLinkUnselected->setOn
2575 (selection->getHideLinkUnselected());
2577 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2579 FloatObj *fo=(FloatImageObj*)selection;
2580 standardFlagsDefault->setEnabled (false);
2582 actionEditOpenURL->setEnabled (false);
2583 actionEditOpenVymLink->setEnabled (false);
2584 actionEditDeleteVymLink->setEnabled (false);
2585 actionEditToggleHideExport->setEnabled (true);
2586 actionEditToggleHideExport->setOn (fo->hideInExport() );
2589 actionEditCopy->setEnabled (true);
2590 actionEditCut->setEnabled (true);
2591 actionEditPaste->setEnabled (false);
2592 for (a=actionListBranches.first();a;a=actionListBranches.next())
2593 a->setEnabled(false);
2594 actionEditDelete->setEnabled (true);
2595 actionFormatHideLinkUnselected->setOn
2596 ( selection->getHideLinkUnselected());
2601 standardFlagsDefault->setEnabled (false);
2603 actionEditCopy->setEnabled (false);
2604 actionEditCut->setEnabled (false);
2605 actionEditPaste->setEnabled (false);
2606 for (a=actionListBranches.first();a;a=actionListBranches.next())
2607 a->setEnabled(false);
2609 actionEditToggleScroll->setEnabled (true);
2610 actionEditOpenURL->setEnabled (false);
2611 actionEditOpenVymLink->setEnabled (false);
2612 actionEditDeleteVymLink->setEnabled (false);
2613 actionEditHeading2URL->setEnabled (false);
2614 actionEditDelete->setEnabled (false);
2618 void MapEditor::updateNoteFlag()
2621 if ( (typeid(*selection) == typeid(BranchObj)) ||
2622 (typeid(*selection) == typeid(MapCenterObj)) )
2623 ((BranchObj*)selection)->updateNoteFlag();
2626 void MapEditor::setLinkStyle (LinkStyle ls)
2630 saveState(); // TODO undoCommand
2632 bo=mapCenter->first();
2636 bo->setLinkStyle(bo->getDefLinkStyle());
2639 mapCenter->reposition();
2642 LinkStyle MapEditor::getLinkStyle ()
2647 void MapEditor::setLinkColor(QColor c)
2653 void MapEditor::setLinkColorHint()
2655 // called from setLinkColorHint(lch) or at end of parse
2657 bo=mapCenter->first();
2665 void MapEditor::setLinkColorHint(LinkColorHint lch)
2671 void MapEditor::toggleLinkColorHint()
2673 if (linkcolorhint==HeadingColor)
2674 linkcolorhint=DefaultColor;
2676 linkcolorhint=HeadingColor;
2678 bo=mapCenter->first();
2686 LinkColorHint MapEditor::getLinkColorHint()
2688 return linkcolorhint;
2691 QColor MapEditor::getDefLinkColor()
2693 return defLinkColor;
2696 void MapEditor::setDefXLinkColor(QColor col)
2701 QColor MapEditor::getDefXLinkColor()
2703 return defXLinkColor;
2706 void MapEditor::setDefXLinkWidth (int w)
2711 int MapEditor::getDefXLinkWidth()
2713 return defXLinkWidth;
2716 void MapEditor::selectLinkColor()
2718 // Finish open lineEdits
2719 if (lineedit) finishedLineEditNoSave();
2721 QColor col = QColorDialog::getColor( defLinkColor, this );
2722 if ( !col.isValid() ) return;
2723 setLinkColor( col );
2724 saveState(); //TODO undoCommand
2728 void MapEditor::toggleScroll()
2730 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2732 BranchObj *bo=((BranchObj*)selection);
2733 if (bo->countBranches()==0) return;
2734 if (bo->getDepth()==0) return;
2735 saveState(selection);
2742 void MapEditor::unScrollAll()
2745 bo=mapCenter->first();
2748 if (bo->isScrolled()) bo->toggleScroll();
2753 void MapEditor::loadFloatImage ()
2756 (typeid(*selection) == typeid(BranchObj)) ||
2757 (typeid(*selection) == typeid(MapCenterObj)) )
2759 BranchObj *bo=((BranchObj*)selection);
2761 QFileDialog *fd=new QFileDialog( this);
2762 fd->setMode (QFileDialog::ExistingFiles);
2763 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2764 ImagePreview *p =new ImagePreview (fd);
2765 fd->setContentsPreviewEnabled( TRUE );
2766 fd->setContentsPreview( p, p );
2767 fd->setPreviewMode( QFileDialog::Contents );
2768 fd->setCaption(__VYM " - " +tr("Load image"));
2769 fd->setDir (lastImageDir);
2773 if ( fd->exec() == QDialog::Accepted )
2775 saveState(selection);
2776 lastImageDir=fn.left(fn.findRev ("/"));
2777 QStringList flist = fd->selectedFiles();
2778 QStringList::Iterator it = flist.begin();
2779 while( it != flist.end() )
2782 bo->addFloatImage();
2783 // TODO check if load was successful
2784 bo->getLastFloatImage()->load(*it);
2785 bo->getLastFloatImage()->setOriginalFilename(fn);
2789 mapCenter->reposition();
2798 void MapEditor::saveFloatImage (int item)
2801 (typeid(*selection) == typeid(FloatImageObj)) )
2803 FloatImageObj *fio=((FloatImageObj*)selection);
2804 const char* fmt = saveImageFormatMenu->text(item);
2806 QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
2807 fd->addFilter ("PNG (*.png)");
2808 fd->addFilter ("BMP (*.bmp)");
2809 fd->addFilter ("XBM (*.xbm)");
2810 fd->addFilter ("JPG (*.jpg)");
2811 fd->addFilter ("XPM (*.xpm)");
2812 fd->addFilter ("GIF (*.gif)");
2813 fd->addFilter ("PNM (*.pnm)");
2814 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2815 fd->setCaption(__VYM " - " +tr("Save image as %1").arg(fmt));
2816 fd->setMode( QFileDialog::AnyFile );
2817 fd->setSelection (fio->getOriginalFilename());
2821 if ( fd->exec() == QDialog::Accepted )
2823 if (QFile (fd->selectedFile()).exists() )
2825 QMessageBox mb( __VYM,
2826 tr("The file %1 exists already.\n"
2827 "Do you want to overwrite it?").arg(fd->selectedFile()),
2828 QMessageBox::Warning,
2829 QMessageBox::Yes | QMessageBox::Default,
2830 QMessageBox::Cancel | QMessageBox::Escape,
2831 QMessageBox::QMessageBox::NoButton );
2833 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2834 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2837 case QMessageBox::Yes:
2840 case QMessageBox::Cancel:
2846 fio->save (fd->selectedFile(),fmt);
2851 void MapEditor::setFrame(const FrameType &t)
2854 (typeid(*selection) == typeid(BranchObj)) ||
2855 (typeid(*selection) == typeid(MapCenterObj)) )
2857 selection->setFrameType (t);
2858 mapCenter->reposition();
2859 selection->updateLink();
2863 void MapEditor::setIncludeImagesVer(bool b)
2866 (typeid(*selection) == typeid(BranchObj)) ||
2867 (typeid(*selection) == typeid(MapCenterObj)) )
2868 ((BranchObj*)selection)->setIncludeImagesVer(b);
2869 mapCenter->reposition();
2872 void MapEditor::setIncludeImagesHor(bool b)
2875 (typeid(*selection) == typeid(BranchObj)) ||
2876 (typeid(*selection) == typeid(MapCenterObj)) )
2877 ((BranchObj*)selection)->setIncludeImagesHor(b);
2878 mapCenter->reposition();
2881 void MapEditor::setHideLinkUnselected (bool b)
2884 (typeid(*selection) == typeid(BranchObj)) ||
2885 (typeid(*selection) == typeid(MapCenterObj)) ||
2886 (typeid(*selection) == typeid(FloatImageObj)) )
2887 selection->setHideLinkUnselected(b);
2890 void MapEditor::importDir(BranchObj *dst, QDir d)
2893 (typeid(*selection) == typeid(BranchObj)) ||
2894 (typeid(*selection) == typeid(MapCenterObj)) )
2898 // Traverse directories
2899 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2900 const QFileInfoList *dirlist = d.entryInfoList();
2901 QFileInfoListIterator itdir( *dirlist );
2904 while ( (fi = itdir.current()) != 0 )
2906 if (fi->fileName() != "." && fi->fileName() != ".." )
2909 bo=dst->getLastBranch();
2910 bo->setHeading (fi->fileName() );
2911 bo->setColor (QColor("blue"));
2913 if ( !d.cd(fi->fileName()) )
2914 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi->fileName()));
2917 // Recursively add subdirs
2925 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
2926 const QFileInfoList *filelist = d.entryInfoList();
2927 QFileInfoListIterator itfile( *filelist );
2929 while ( (fi = itfile.current()) != 0 )
2932 bo=dst->getLastBranch();
2933 bo->setHeading (fi->fileName() );
2934 bo->setColor (QColor("black"));
2935 if (fi->fileName().right(4) == ".vym" )
2936 bo->setVymLink (fi->filePath());
2943 void MapEditor::importDir()
2946 (typeid(*selection) == typeid(BranchObj)) ||
2947 (typeid(*selection) == typeid(MapCenterObj)) )
2949 QFileDialog *fd=new QFileDialog( this,__VYM " - " +tr("Choose directory structure to import"));
2950 fd->setMode (QFileDialog::DirectoryOnly);
2951 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2952 fd->setCaption(__VYM " - " +tr("Choose directory structure to import"));
2956 if ( fd->exec() == QDialog::Accepted )
2958 BranchObj *bo=((BranchObj*)selection);
2959 importDir (bo,QDir(fd->selectedFile()) );
2960 mapCenter->reposition();
2967 void MapEditor::followXLink(int i)
2970 (typeid(*selection) == typeid(BranchObj)) ||
2971 (typeid(*selection) == typeid(MapCenterObj)) )
2973 BranchObj *bo=((BranchObj*)selection)->XLinkTargetAt(i);
2976 selection->unselect();
2978 selection->select();
2979 ensureSelectionVisible();
2984 void MapEditor::editXLink(int i)
2987 (typeid(*selection) == typeid(BranchObj)) ||
2988 (typeid(*selection) == typeid(MapCenterObj)) )
2990 XLinkObj *xlo=((BranchObj*)selection)->XLinkAt(i);
2993 EditXLinkDialog dia;
2995 dia.setSelection(selection);
2996 if (dia.exec() == QDialog::Accepted)
2998 if (dia.useSettingsGlobal() )
3000 setDefXLinkColor (xlo->getColor() );
3001 setDefXLinkWidth (xlo->getWidth() );
3003 if (dia.deleteXLink())
3004 ((BranchObj*)selection)->deleteXLinkAt(i);
3005 saveState(); //TODO undoCommand
3011 void MapEditor::testFunction()
3013 cout << "MapEditor::testFunction() called\n";
3015 if (hidemode==HideNone)
3017 setHideTmpMode (HideExport);
3018 mapCenter->calcBBoxSizeWithChilds();
3019 QRect totalBBox=mapCenter->getTotalBBox();
3020 QRect mapRect=totalBBox;
3021 QCanvasRectangle *frame=NULL;
3023 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
3025 mapRect.setRect (totalBBox.x(), totalBBox.y(),
3026 totalBBox.width(), totalBBox.height());
3027 frame=new QCanvasRectangle (mapRect,mapCanvas);
3028 frame->setBrush (QColor(white));
3029 frame->setPen (QColor(black));
3035 setHideTmpMode (HideNone);
3037 cout <<" hidemode="<<hidemode<<endl;
3040 void MapEditor::ensureSelectionVisible()
3044 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
3046 if (selection->getOrientation() == OrientLeftOfCenter)
3047 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
3049 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
3050 ensureVisible (p.x(), p.y() );
3055 void MapEditor::updateViewCenter()
3057 // Update movingCenter, so that we can zoom comfortably later
3058 QRect rc = QRect( contentsX(), contentsY(),
3059 visibleWidth(), visibleHeight() );
3060 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
3061 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
3062 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
3065 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
3067 // Lineedits are already closed by preceding
3068 // mouseEvent, we don't need to close here.
3070 QPoint p = inverseWorldMatrix().map(e->pos());
3071 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3074 { // MapObj was found
3075 if (selection != lmo)
3077 // select the MapObj
3078 if (selection) selection->unselect();
3080 selection->select();
3086 if (typeid(*selection)==typeid(BranchObj) ||
3087 typeid(*selection)==typeid(MapCenterObj) )
3089 // Context Menu on branch or mapcenter
3091 branchContextMenu->popup(e->globalPos() );
3093 if (typeid(*selection)==typeid(FloatImageObj))
3095 // Context Menu on floatimage
3097 floatimageContextMenu->popup(e->globalPos() );
3101 { // No MapObj found, we are on the Canvas itself
3102 // Context Menu on Canvas
3104 canvasContextMenu->popup(e->globalPos() );
3108 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
3110 // Finish open lineEdits
3111 if (lineedit) finishedLineEditNoSave();
3113 QPoint p = inverseWorldMatrix().map(e->pos());
3114 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3116 //Take care of clickdesystem flags _or_ modifier modes
3118 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
3119 typeid(*lmo)==typeid(MapCenterObj) ))
3121 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
3122 if (!foname.isEmpty())
3124 // systemFlag clicked
3128 if (e->state() & QMouseEvent::ControlButton)
3129 mainWindow->editOpenURLTab();
3131 mainWindow->editOpenURL();
3133 else if (foname=="vymLink")
3135 mainWindow->editOpenVymLink();
3136 // tabWidget may change, better return now
3137 // before segfaulting...
3138 } else if (foname=="note")
3139 mainWindow->windowToggleNoteEditor();
3140 else if (foname=="hideInExport")
3145 // No system flag clicked, take care of modmodes
3147 // Special case: CTRL is pressed
3148 if (e->state() & QMouseEvent::ControlButton)
3150 if (actionModModeColor->isOn())
3153 setCursor (pickColorCursor);
3156 if (actionModModeLink->isOn())
3158 BranchObj *bo_begin=NULL;
3160 bo_begin=(BranchObj*)(lmo);
3163 ((typeid(*selection) == typeid(BranchObj)) ||
3164 (typeid(*selection) == typeid(MapCenterObj))) )
3165 bo_begin=(BranchObj*)selection;
3169 linkingObj_src=bo_begin;
3170 tmpXLink=new XLinkObj (mapCanvas);
3171 tmpXLink->setBegin (bo_begin);
3172 tmpXLink->setEnd (p);
3173 tmpXLink->setColor(defXLinkColor);
3174 tmpXLink->setWidth(defXLinkWidth);
3175 tmpXLink->updateXLink();
3176 tmpXLink->setVisibility (true);
3184 // Left Button Move Branches
3185 if (e->button() == QMouseEvent::LeftButton )
3187 movingObj_start.setX( p.x() - selection->x() );
3188 movingObj_start.setY( p.y() - selection->y() );
3189 movingObj_orgPos.setX (lmo->x() );
3190 movingObj_orgPos.setY (lmo->y() );
3192 // If modMode==copy, then we want to "move" the _new_ object around
3193 // then we need the offset from p to the _old_ selection, because of tmp
3194 if (actionModModeCopy->isOn() &&
3195 e->state() & QMouseEvent::ControlButton)
3197 if (typeid(*selection)==typeid(BranchObj) )
3200 mapCenter->addBranch ((BranchObj*)selection);
3202 selection=mapCenter->getLastBranch();
3203 selection->select();
3204 mapCenter->reposition();
3207 movingObj=selection;
3209 // Middle Button Toggle Scroll
3210 // (On Mac OS X this won't work, but we still have
3211 // a button in the toolbar)
3212 if (e->button() == QMouseEvent::MidButton )
3216 { // No MapObj found, we are on the Canvas itself
3217 // Left Button move Pos of CanvasView
3218 if (e->button() == QMouseEvent::LeftButton )
3220 movingObj=NULL; // move Content not Obj
3221 movingObj_start=e->globalPos();
3222 movingCont_start=QPoint (contentsX(), contentsY() );
3223 movingVec=QPoint(0,0);
3224 setCursor(handOpenCursor);
3229 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3231 QPoint p = inverseWorldMatrix().map(e->pos());
3233 // Move the selected MapObj
3234 if ( selection && movingObj)
3236 // To avoid jumping of the CanvasView, only
3237 // ensureSelectionVisible, if not tmp linked
3238 if (!selection->hasParObjTmp())
3239 ensureSelectionVisible ();
3241 // Now move the selection, but add relative position
3242 // (movingObj_start) where selection was chosen with
3243 // mousepointer. (This avoids flickering resp. jumping
3244 // of selection back to absPos)
3246 LinkableMapObj *lmosel;
3247 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3249 // Check if we could link
3250 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3253 if (typeid(*selection) == typeid(FloatImageObj))
3255 FloatObj *fo=(FloatObj*)selection;
3256 saveState("move "+qpointToString(movingObj_orgPos),fo->getSelectString() );
3257 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3261 // Relink float to new mapcenter or branch, if shift is pressed
3262 // Only relink, if selection really has a new parent
3263 if ( (e->state() & QMouseEvent::ShiftButton) && lmo &&
3264 ( (typeid(*lmo)==typeid(BranchObj)) ||
3265 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3266 ( lmo != fo->getParObj())
3269 if (typeid(*fo) == typeid(FloatImageObj))
3272 FloatImageObj *fio=(FloatImageObj*)(fo);
3273 ((BranchObj*)(lmo))->addFloatImage (fio);
3275 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3276 fio=((BranchObj*)(lmo))->getLastFloatImage();
3279 selection=(LinkableMapObj*)(fio);
3280 selection->select();
3281 movingObj=(MapObj*)(fio);
3284 } else // selection != a FloatObj
3286 if (lmosel->getDepth()==0)
3288 if (e->state() == (LeftButton | !ShiftButton))
3289 // If mapCenter is moved, move all the rest by default, too.
3290 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3292 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3295 if (lmosel->getDepth()==1)
3297 // depth==1, mainbranch
3298 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3302 if (lmosel->getOrientation() == OrientLeftOfCenter)
3303 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3304 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3305 p.y()-movingObj_start.y() +lmosel->getTopPad() );
3307 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
3309 // reposition subbranch
3310 lmosel->reposition();
3311 //ensureSelectionVisible();
3313 if (lmo && (lmo!=selection) &&
3314 (typeid(*lmo) == typeid(BranchObj) ||
3315 (typeid(*lmo) == typeid(MapCenterObj) )
3318 if (e->state() & QMouseEvent::ControlButton)
3320 // Special case: CTRL to link below lmo
3321 lmosel->setParObjTmp (lmo,p,+1);
3323 else if (e->state() & QMouseEvent::ShiftButton)
3324 lmosel->setParObjTmp (lmo,p,-1);
3326 lmosel->setParObjTmp (lmo,p,0);
3329 lmosel->unsetParObjTmp();
3330 /* FIXME not needed anymore?
3331 if (lmo &&(lmo==selection))
3332 // Could link to myself (happens sometimes...)
3333 lmosel->unsetParObjTmp();
3335 // no Obj under selection, go back to original Parent
3336 lmosel->unsetParObjTmp();
3341 } // no FloatImageObj
3345 } // selection && moving_obj
3347 // Draw a link from one branch to another
3350 tmpXLink->setEnd (p);
3351 tmpXLink->updateXLink();
3355 if (!movingObj && !pickingColor &&!drawingLink)
3357 QPoint p=e->globalPos();
3358 movingVec.setX(-p.x() + movingObj_start.x() );
3359 movingVec.setY(-p.y() + movingObj_start.y() );
3360 setContentsPos( movingCont_start.x() + movingVec.x(),
3361 movingCont_start.y() + movingVec.y());
3368 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3370 LinkableMapObj *dst;
3371 // Have we been picking color?
3375 setCursor (ArrowCursor);
3376 // Check if we are over another branch
3377 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3378 if (dst && selection)
3380 if (e->state() & QMouseEvent::ShiftButton)
3382 ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor());
3383 ((BranchObj*)selection)->setLinkColor ();
3387 ((BranchObj*)selection)->setColorChilds (((BranchObj*)(dst))->getColor());
3388 ((BranchObj*)selection)->setLinkColor ();
3394 // Have we been drawing a link?
3398 // Check if we are over another branch
3399 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3400 if (dst && selection)
3402 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3403 tmpXLink->updateXLink();
3404 tmpXLink->activate();
3405 saveState(); //TODO undoCommand
3414 // Have we been moving something?
3415 if ( selection && movingObj )
3417 // Moved FloatObj? Maybe we need to reposition
3418 if(typeid(*selection)==typeid (FloatImageObj))
3420 selection->getParObj()->requestReposition();
3421 mapCenter->reposition();
3424 // Check if we are over another branch, but ignore
3425 // any found LMOs, which are FloatObjs
3426 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3427 ((LinkableMapObj*)selection) );
3430 (typeid(*dst)!=typeid(BranchObj)&&typeid(*dst)!=typeid(MapCenterObj)))
3433 // Now check, if we have been moving a branch
3434 if (typeid(*selection) == typeid(BranchObj) )
3436 // save the position in case we link to mapcenter
3437 QPoint savePos=QPoint (selection->x(),selection->y() );
3439 // Reset the temporary drawn link to the original one
3440 ((LinkableMapObj*)selection)->unsetParObjTmp();
3446 BranchObj* bs=((BranchObj*)selection);
3447 QString undoCom="linkBranchToPos (\""+
3448 (bs->getParObj())->getSelectString()+
3450 QString("%1").arg(bs->getNum())+
3452 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+
3454 // TODO we also could check, if dest and src are on same branch,
3455 // then it would be sufficient to saveState of this branch
3457 // Modifiers allow to insert above/below dst
3458 if (e->state() & QMouseEvent::ShiftButton)
3460 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum());
3462 if (e->state() & QMouseEvent::ControlButton)
3464 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum()+1);
3467 bs->moveBranchTo ((BranchObj*)(dst),-1);
3468 if (dst->getDepth()==0)
3471 saveState (undoCom,bs->getSelectString() );
3473 if (selection->getDepth()==1)
3474 // If we have moved mainbranch only save endposition
3475 saveState("move "+qpointToString(movingObj_orgPos), selection->getSelectString() );
3477 // Draw the original link, before selection was moved around
3478 mapCenter->reposition();
3480 // Finally resize canvas, if needed
3485 // maybe we moved View: set old cursor
3486 setCursor (ArrowCursor);
3490 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3492 // Finish open lineEdits
3493 if (lineedit) finishedLineEditNoSave();
3495 if (e->button() == QMouseEvent::LeftButton )
3497 QPoint p = inverseWorldMatrix().map(e->pos());
3498 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3499 if (lmo) { // MapObj was found
3500 // First select the MapObj than edit heading
3501 if (selection) selection->unselect();
3503 selection->select();
3504 saveState(selection);
3510 void MapEditor::resizeEvent (QResizeEvent* e)
3512 QCanvasView::resizeEvent( e );
3516 void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3519 // for (unsigned int i=0;event->format(i);i++) // Debug mime type
3520 // cerr << event->format(i) << endl;
3523 (typeid(*selection) == typeid(BranchObj)) ||
3524 (typeid(*selection) == typeid(MapCenterObj))) {
3526 // If QImageDrag can decode mime type
3527 if (QImageDrag::canDecode(event)) {
3532 // If image are dragged from firefox
3533 if (event->provides("application/x-moz-file-promise-url") &&
3534 event->provides("application/x-moz-nativeimage")) {
3535 event->accept(true);
3539 // If QUriDrag can decode mime type
3540 if (QUriDrag::canDecode(event)) {
3545 // If Uri are dragged from firefox
3546 if (event->provides("_NETSCAPE_URL")){
3551 // If QTextDrag can decode mime type
3552 if (QTextDrag::canDecode(event)) {
3561 bool isUnicode16(const QByteArray &d)
3563 // TODO: make more precise check for unicode 16.
3564 // Guess unicode16 if any of second bytes are zero
3565 unsigned int length = max(0,d.size()-2)/2;
3566 for (unsigned int i = 0; i<length ; i++)
3567 if (d.at(i*2+1)==0) return true;
3571 void MapEditor::contentsDropEvent(QDropEvent *event)
3574 (typeid(*selection) == typeid(BranchObj)) ||
3575 (typeid(*selection) == typeid(MapCenterObj)))
3580 if (event->provides("image/png"))
3583 if (QImageDrag::decode(event, pix))
3591 } else if (event->provides("application/x-moz-file-promise-url") &&
3592 event->provides("application/x-moz-nativeimage"))
3594 // Contains url to the img src in unicode16
3595 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3596 QString url = QString((const QChar*)d.data(),d.size()/2);
3600 } else if (event->provides ("text/uri-list"))
3601 { // Uris provided e.g. by konqueror
3602 QUriDrag::decode (event,uris);
3603 } else if (event->provides ("_NETSCAPE_URL"))
3604 { // Uris provided by Mozilla
3605 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
3608 } else if (event->provides("text/html")) {
3610 // Handels text mime types
3611 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
3612 QByteArray d = event->encodedData("text/html");
3615 text = QString((const QChar*)d.data(),d.size()/2);
3619 textEditor->setText(text);
3623 } else if (event->provides("text/plain")) {
3624 QByteArray d = event->encodedData("text/plain");
3627 text = QString((const QChar*)d.data(),d.size()/2);
3631 textEditor->setText(text);
3643 for (const char* u=uris.first(); u; u=uris.next())
3645 bo=((BranchObj*)selection)->addBranch();
3648 s=QUriDrag::uriToLocalFile(u);
3650 QString file = QDir::convertSeparators(s);
3651 heading = QFileInfo(file).baseName();
3653 if (file.endsWith(".vym", false))
3654 bo->setVymLink(file);
3663 bo->setHeading(heading);
3673 saveState(); //TODO undo Command
3674 mapCenter->reposition();
3681 void MapEditor::addFloatImage(const QPixmap &img)
3684 (typeid(*selection) == typeid(BranchObj)) ||
3685 (typeid(*selection) == typeid(MapCenterObj)) )
3687 BranchObj *bo=((BranchObj*)selection);
3688 saveState(selection);
3689 //QString fn=fd->selectedFile();
3690 //lastImageDir=fn.left(fn.findRev ("/"));
3691 bo->addFloatImage();
3692 // FIXME check if load was successful
3693 bo->getLastFloatImage()->load(img);
3694 //bo->getLastFloatImage()->setOriginalFilename(fn);
3695 mapCenter->reposition();
3702 void MapEditor::imageDataFetched(const QByteArray &a, QNetworkOperation */*nop*/)
3704 if (!imageBuffer) imageBuffer = new QBuffer();
3705 if (!imageBuffer->isOpen()) {
3706 imageBuffer->open(IO_WriteOnly | IO_Append);
3708 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
3712 void MapEditor::imageDataFinished(QNetworkOperation *nop)
3714 if (nop->state()==QNetworkProtocol::StDone) {
3715 QPixmap img(imageBuffer->buffer());
3720 imageBuffer->close();
3722 imageBuffer->close();
3729 void MapEditor::fetchImage(const QString &url)
3732 urlOperator->stop();
3733 disconnect(urlOperator);
3737 urlOperator = new QUrlOperator(url);
3738 connect(urlOperator, SIGNAL(finished(QNetworkOperation *)),
3739 this, SLOT(imageDataFinished(QNetworkOperation*)));
3741 connect(urlOperator, SIGNAL(data(const QByteArray &, QNetworkOperation *)),
3742 this, SLOT(imageDataFetched(const QByteArray &, QNetworkOperation *)));