3 #include <qstatusbar.h>
4 #include <qmessagebox.h>
5 #include <qapplication.h>
7 #include <q3popupmenu.h>
9 #include <q3paintdevicemetrics.h>
11 #include <q3filedialog.h>
14 #include <qcolordialog.h>
16 #include <q3process.h>
17 #include <qinputdialog.h>
18 #include <q3dragobject.h>
19 #include <q3urloperator.h>
20 #include <q3networkprotocol.h>
23 #include <QResizeEvent>
24 #include <QContextMenuEvent>
27 #include <QMouseEvent>
28 #include <QDragEnterEvent>
29 #include <QTextStream>
31 #include <QActionGroup>
41 #include "editxlinkdialog.h"
43 #include "extrainfodialog.h"
45 #include "linkablemapobj.h"
46 #include "mainwindow.h"
49 #include "texteditor.h"
50 #include "warningdialog.h"
54 extern TextEditor *textEditor;
55 extern int statusbarTime;
56 extern Main *mainWindow;
57 extern QString tmpVymDir;
58 extern QString clipboardDir;
59 extern bool clipboardEmpty;
60 extern FlagRowObj *systemFlagsDefault;
61 extern FlagRowObj *standardFlagsDefault;
63 extern Q3PtrList <QAction> actionListBranches;
65 extern QAction *actionFileSave;
66 extern QAction *actionEditUndo;
67 extern QAction *actionEditCopy;
68 extern QAction *actionEditCut;
69 extern QAction *actionEditPaste;
70 extern QAction *actionEditMoveUp;
71 extern QAction *actionEditMoveDown;
72 extern QAction *actionEditToggleScroll;
73 extern QAction *actionEditOpenURL;
74 extern QAction *actionEditOpenURLTab;
75 extern QAction *actionEditURL;
76 extern QAction *actionEditHeading2URL;
77 extern QAction *actionEditBugzilla2URL;
78 extern QAction *actionEditFATE2URL;
79 extern QAction *actionEditOpenVymLink;
80 extern QAction *actionEditVymLink;
81 extern QAction *actionEditDeleteVymLink;
82 extern QAction *actionEditToggleHideExport;
83 extern QAction *actionEditHeading;
84 extern QAction *actionEditDelete;
85 extern QAction *actionEditAddBranch;
86 extern QAction *actionEditAddBranchAbove;
87 extern QAction *actionEditAddBranchBelow;
88 extern QAction *actionEditRemoveBranchHere;
89 extern QAction *actionEditRemoveChilds;
90 extern QAction *actionEditImportAdd;
91 extern QAction *actionEditImportReplace;
92 extern QAction *actionEditSaveBranch;
93 extern QAction *actionEditSelectFirst;
94 extern QAction *actionEditSelectLast;
95 extern QAction *actionEditLoadImage;
97 extern QAction* actionFormatPickColor;
98 extern QAction* actionFormatColorBranch;
99 extern QAction* actionFormatColorSubtree;
100 extern QAction *actionFormatLinkColorHint;
101 extern QAction *actionFormatBackColor;
102 extern QAction *actionFormatLinkColor;
104 extern QActionGroup* actionGroupModModes;
105 extern QAction* actionModModeColor;
106 extern QAction* actionModModeLink;
107 extern QAction* actionModModeCopy;
109 extern QActionGroup *actionGroupFormatFrameTypes;
110 extern QAction *actionFormatFrameNone;
111 extern QAction *actionFormatFrameRectangle;
113 extern QActionGroup *actionGroupFormatLinkStyles;
114 extern QAction *actionFormatIncludeImagesVer;
115 extern QAction *actionFormatIncludeImagesHor;
116 extern QAction *actionFormatHideLinkUnselected;
117 extern QAction *actionFormatLinkStyleLine;
118 extern QAction *actionFormatLinkStyleParabel;
119 extern QAction *actionFormatLinkStylePolyLine;
120 extern QAction *actionFormatLinkStylePolyParabel;
122 extern QAction *actionViewToggleNoteEditor;
124 extern QAction *actionSettingsAutoedit;
125 extern QAction *actionSettingsAutoselectHeading;
126 extern QAction *actionSettingsAutoselectText;
127 extern QAction *actionSettingsPasteNewHeading;
128 extern QAction *actionSettingsUseFlagGroups;
130 extern Q3PopupMenu *branchContextMenu;
131 extern Q3PopupMenu *branchLinksContextMenu;
132 extern Q3PopupMenu *branchLinksContextMenuDup;
133 extern Q3PopupMenu *floatimageContextMenu;
134 extern Q3PopupMenu *saveImageFormatMenu;
135 extern Q3PopupMenu *exportImageFormatMenu;
136 extern Q3PopupMenu *canvasContextMenu;
138 extern Settings settings;
140 extern QString iconPath;
141 extern QDir vymBaseDir;
143 int MapEditor::mapNum=0; // make instance
145 ///////////////////////////////////////////////////////////////////////
146 ///////////////////////////////////////////////////////////////////////
147 MapEditor::MapEditor(
148 QWidget* parent, bool interactive, const char* name, Qt::WFlags f) :
149 Q3CanvasView(parent,name,f), urlOperator(0), imageBuffer(0)
151 //cout << "Constructor ME "<<this<<endl;
154 viewport()->setAcceptDrops(true);
156 mapCanvas = new Q3Canvas(1000,800);
157 mapCanvas->setAdvancePeriod(30);
158 mapCanvas->setBackgroundColor (Qt::white);
160 setCanvas (mapCanvas);
162 // Always show scroll bars (automatic would flicker sometimes)
163 setVScrollBarMode ( Q3ScrollView::AlwaysOn );
164 setHScrollBarMode ( Q3ScrollView::AlwaysOn );
166 mapCenter = new MapCenterObj(mapCanvas);
167 mapCenter->setVisibility (true);
168 mapCenter->setMapEditor (this);
169 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
170 mapCenter->move(mapCanvas->width()/2-mapCenter->width()/2,mapCanvas->height()/2-mapCenter->height()/2);
174 lineedit = new QLineEdit(this, "lineedit" );
175 connect( lineedit, SIGNAL( returnPressed() ), SLOT( finishedLineEdit() ) );
178 actColor=Qt::black; setColor (actColor);
179 defLinkColor=QColor (0,0,255);
180 defXLinkColor=QColor (180,180,180);
181 linkcolorhint=DefaultColor;
182 linkstyle=StylePolyParabel;
184 // Create bitmap cursors, patform dependant
185 #if defined(Q_OS_MACX)
186 handOpenCursor=QCursor ( QPixmap(iconPath+"cursorhandopen16.png") );
187 // set hot spot to tip of picker
188 pickColorCursor=QCursor ( QPixmap (iconPath+"cursorcolorpicker16.png"), 1,15 );
190 handOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen16.png"));
191 // set hot spot to tip of picker
192 pickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 );
205 defXLinkColor=QColor (230,230,230);
213 fileName=tr("unnamed");
216 undosTotal=settings.readNumEntry("/vym/mapeditor/undoLevels",50);
220 // Initialize find routine
227 blockReposition=false;
228 blockSaveState=false;
232 isInteractive=interactive;
234 // Create temporary files
237 // Initially set movingCentre
240 // For testing purposes create history window
241 historyWindow = new ShowTextDialog (this);
242 historyWindow->setCaption (fileName);
244 mapCenter->reposition(); // for positioning heading
247 MapEditor::~MapEditor()
249 if (imageBuffer) delete imageBuffer;
255 //cout <<"Destructor MapEditor\n";
258 //settings.writeEntry( "/vym/mapeditor/editmode/autoselect", );
262 QColor MapEditor::color()
267 QColor MapEditor::backgroundColor()
269 return mapCanvas->backgroundColor();
272 MapCenterObj* MapEditor::getMapCenter()
277 Q3Canvas* MapEditor::getCanvas()
282 void MapEditor::adjustCanvasSize()
284 // To adjust the canvas to map, viewport size and position, we have to
285 // do some coordinate magic...
287 // Get rectangle of (scroll-)view.
288 // We want to be in canvas coords, so
289 // we map. Important if view is zoomed...
290 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
291 visibleWidth(), visibleHeight()) );
293 // Now we need the bounding box of view AND map to calc the correct canvas size.
294 // Why? Because if the map itself is moved out of view, the view has to be enlarged
295 // to avoid jumping aroung...
296 QRect map=mapCenter->getTotalBBox();
298 // right edge - left edge
299 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
300 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
303 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
304 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
307 // move the map on canvas (in order to not move it on screen) this is neccessary
308 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
309 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
310 // to scroll to an empty area of canvas to the left.
311 // b) if topleft corner of map left of or above topleft of canvas
315 if (cw > mapCanvas->width() )
317 if (map.x()<0) dx=-map.x();
319 if (cw < mapCanvas->width() )
320 dx=-min (view.x(),map.x());
321 if (ch > mapCanvas->height() )
323 if (map.y()<0) dy=-map.y();
325 if (ch < mapCanvas->height() )
327 dy=-min (view.y(),map.y());
329 // We really have to resize now. Let's go...
330 mapCanvas->resize (cw,ch);
331 if ( (dx!=0) || (dy!=0) )
333 mapCenter->moveAllBy(dx,dy);
334 mapCenter->reposition();
335 // mapCenter->positionBBox(); // To move float
337 // scroll the view (in order to not move map on screen)
343 bool MapEditor::isRepositionBlocked()
345 return blockReposition;
348 QString MapEditor::getName (LinkableMapObj *lmo)
351 if (!lmo) return QString("Error: NULL has no name!");
353 if ((typeid(*lmo) == typeid(BranchObj) ||
354 typeid(*lmo) == typeid(MapCenterObj)))
357 s=(((BranchObj*)lmo)->getHeading());
358 if (s=="") s="unnamed";
359 return QString("branch (<font color=\"#0000ff\">%1</font>)").arg(s);
361 if ((typeid(*lmo) == typeid(FloatImageObj) ))
362 return QString ("floatimage [<font color=\"#0000ff\">%1</font>]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
363 return QString("Unknown type has no name!");
366 void MapEditor::makeTmpDirs()
368 // Create unique temporary directories
369 tmpMapDir=tmpVymDir+QString("/mapeditor-%1").arg(mapNum);
371 d.mkdir (tmpMapDir,true);
374 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSelection)
376 // tmpdir temporary directory to which data will be written
377 // prefix mapname, which will be appended to images etc.
378 // writeflags Only write flags for "real" save of map, not undo
379 // offset offset of bbox of whole map in canvas.
380 // Needed for XML export
396 ls="StylePolyParabel";
400 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
402 if (linkcolorhint==HeadingColor)
403 colhint=attribut("linkColorHint","HeadingColor");
405 QString mapAttr=attribut("version",__VYM_VERSION);
407 mapAttr+= attribut("author",mapCenter->getAuthor()) +
408 attribut("comment",mapCenter->getComment()) +
409 attribut("date",mapCenter->getDate()) +
410 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
411 attribut("linkStyle", ls ) +
412 attribut("linkColor", defLinkColor.name() ) +
413 attribut("defXLinkColor", defXLinkColor.name() ) +
414 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
416 s+=beginElement("vymmap",mapAttr);
419 // Find the used flags while traversing the tree
420 standardFlagsDefault->resetUsedCounter();
422 // Reset the counters before saving
423 FloatImageObj (mapCanvas).resetSaveCounter();
425 // Build xml recursivly
427 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
430 if ( typeid(*saveSelection) == typeid(BranchObj) )
431 s+=((BranchObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
432 else if ( typeid(*saveSelection) == typeid(FloatImageObj) )
433 s+=((FloatImageObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
435 else if (selection && typeid(*selection)==typeid(BranchObj))
436 // This is used if selected branch is saved from mainwindow
437 s+=((BranchObj*)selection)->saveToDir(tmpdir,prefix,offset);
440 // Save local settings
441 s+=settings.getXMLData (destPath);
444 if (selection && !saveSelection )
445 s+=valueElement("select",selection->getSelectString());
448 s+=endElement("vymmap");
451 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
455 void MapEditor::saveState(const QString &comment)
458 saveState (CompleteMap,"",NULL,"",NULL, comment);
461 void MapEditor::saveState(LinkableMapObj *undoSel, const QString &comment)
463 // save the given part of the map
464 saveState (PartOfMap,"",undoSel,"",NULL, comment);
467 void MapEditor::saveState(const QString &uc, const QString &rc, const QString &comment)
469 // selection does not change during action,
470 // so just save commands for undo and redo
471 LinkableMapObj *unsel;
476 saveState (UndoCommand,uc,unsel,rc,unsel, comment);
479 void MapEditor::saveState(const QString & uncom, LinkableMapObj *unsel, const QString &comment)
481 saveState (UndoCommand,uncom,unsel,"FIXME-redoCom",NULL, comment);
484 void MapEditor::saveState(const SaveMode &savemode, const QString &undoCom, LinkableMapObj *undoSel, const QString &redoCom, LinkableMapObj *redoSel, const QString &comment)
488 if (blockSaveState) return;
490 /* TODO remove after testing
491 cout << "ME::saveState() begin\n"<<endl;
492 cout << " undosTotal="<<undosTotal<<endl;
493 cout << " undosAvail="<<undosAvail<<endl;
494 cout << " undoNum="<<undoNum<<endl;
495 cout << " ---------------------------"<<endl;
498 historyWindow->append (comment);
502 // Find out current undo directory
503 if (undosAvail<undosTotal) undosAvail++;
505 if (undoNum>undosTotal) undoNum=1;
508 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
509 QString bakMapPath=QDir::convertSeparators(bakMapDir+"/map.xml");
511 // Create bakMapDir if not available
514 makeSubDirs (bakMapDir);
516 // Save current selection
517 QString redoSelection="";
519 redoSelection=redoSel->getSelectString();
521 // Save the object, which should be undone
522 QString undoSelection="";
524 undoSelection=undoSel->getSelectString();
526 // Save depending on how much needs to be saved
527 QString undoCommand="";
528 if (savemode==UndoCommand)
533 else if (savemode==PartOfMap && undoSel)
535 undoCommand="undoPart (\""+ undoSelection+"\",\""+bakMapPath+"\")";
536 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),undoSel);
539 undoCommand="undoMap (\""+bakMapPath+"\")";
540 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),NULL);
543 if (!backupXML.isEmpty())
544 // Write XML Data to disk
545 saveStringToDisk (QString(bakMapPath),backupXML);
548 set.setEntry (QString("undoCommand"),undoCommand);
549 set.setEntry (QString("undoSelection"),undoSelection);
550 set.setEntry (QString("redoCommand"),redoCom);
551 set.setEntry (QString("redoSelection"),redoSelection);
552 set.setEntry (QString("comment"),comment);
553 set.writeSettings(QString(bakMapDir+"/commands"));
555 /* TODO remove after testing
556 cout << " into="<< bakMapDir<<endl;
557 cout << " undosAvail="<<undosAvail<<endl;
558 cout << " undoNum="<<undoNum<<endl;
559 cout << " ---------------------------"<<endl;
560 cout << " comment="<<comment<<endl;
561 cout << " ---------------------------"<<endl;
562 cout << " undoCom="<<undoCommand<<endl;
563 cout << " undoSel="<<undoSelection<<endl;
564 cout << " ---------------------------"<<endl;
565 cout << " redoCom="<<redoCom<<endl;
566 cout << " redoSel="<<redoSelection<<endl;
567 cout << " ---------------------------"<<endl<<endl;
571 void MapEditor::parseAtom(const QString &atom)
578 // Split string s into command and parameters
579 api.parseCommand (atom);
580 QString com=api.command();
583 if (com=="moveBranchUp")
585 else if (com=="moveBranchDown")
587 else if (com=="move")
589 if (api.checkParamCount(2) && selection )
599 else if (com=="linkBranchToPos")
601 if (selection && typeid(*selection) == typeid(BranchObj) )
603 if (api.checkParamCount(4))
605 s=api.parString(ok,0);
606 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
609 if (typeid(*dst) == typeid(BranchObj) )
611 // Get number in parent
614 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),x);
615 } else if (typeid(*dst) == typeid(MapCenterObj) )
617 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),-1);
618 // Get coordinates of mainbranch
623 if (ok) ((BranchObj*)selection)->move (x,y);
629 } else if (com=="setHeading")
631 if (api.checkParamCount(1))
633 s=api.parString (ok,0);
634 if (ok) setHeading (s);
636 } else if (com=="setURL")
638 if (api.checkParamCount(1))
640 s=api.parString (ok,0);
643 } else if (com=="setVymLink")
645 if (api.checkParamCount(1))
647 s=api.parString (ok,0);
648 if (ok) setVymLink(s);
651 // Internal commands, used for undo etc.
652 else if (com==QString("undoMap"))
654 if (api.checkParamCount(1))
655 undoXML("",api.parString (ok,0));
656 } else if (com==QString("undoPart"))
658 if (api.checkParamCount(2))
660 s=api.parString (ok,0);
661 t=api.parString (ok,1);
664 } else if (com=="select")
665 if (api.checkParamCount(1))
667 s=api.parString(ok,0);
672 api.setError ("Unknown command in: "+atom);
673 cout << "ME::parse api should have error now...\n";
679 qWarning("MapEditor::parseAtom: Error!");
680 qWarning(api.errorDesc());
685 void MapEditor::finishedLineEdit()
687 // This is called by finishedLineEdit or any MapEditor method,
688 // which wants to assure, that lineedits finish, before e.g. a branch is
691 // After calling LineEdit and using the clipboard, the
692 // focus is not any longer on the main widget, we
693 // have to restore it using parentWidget()->setFocus()
697 saveState("setHeading (\""+editingBO->getHeading()+"\")",editingBO, QString("Set heading of %1 to \"%2\"").arg(getName(editingBO)).arg(lineedit->text()) );
698 editingBO->setHeading(lineedit->text() );
700 lineedit->releaseKeyboard();
702 parentWidget()->setFocus();
703 mapCenter->reposition();
705 ensureSelectionVisible();
709 void MapEditor::toggleHistoryWindow()
711 if (historyWindow->isVisible())
712 historyWindow->hide();
714 historyWindow->show();
718 bool MapEditor::isDefault()
723 bool MapEditor::isUnsaved()
728 bool MapEditor::hasChanged()
733 void MapEditor::setChanged()
738 actionEditUndo->setEnabled (true);
739 actionFileSave->setEnabled (true);
743 void MapEditor::closeMap()
745 // Finish open lineEdits
746 if (lineedit) finishedLineEdit();
748 // Unselect before disabling the toolbar actions
749 if (selection) selection->unselect();
757 void MapEditor::setFilePath(QString fname)
759 setFilePath (fname,fname);
762 void MapEditor::setFilePath(QString fname, QString destname)
764 if (fname.isEmpty() || fname=="")
771 filePath=fname; // becomes absolute path
772 fileName=fname; // gets stripped of path
773 destPath=destname; // needed for vymlinks
775 // If fname is not an absolute path, complete it
776 filePath=QDir(fname).absPath();
777 fileDir=filePath.left (1+filePath.findRev ("/"));
779 // Set short name, too. Search from behind:
780 int i=fileName.findRev("/");
781 if (i>=0) fileName=fileName.remove (0,i+1);
783 // Forget the .vym (or .xml) for name of map
784 mapName=fileName.left(fileName.findRev(".",-1,true) );
786 // Adjust history window
787 historyWindow->setCaption (fileName);
791 QString MapEditor::getFilePath()
796 QString MapEditor::getFileName()
801 QString MapEditor::getMapName()
806 QString MapEditor::getDestPath()
811 ErrorCode MapEditor::load (QString fname, LoadMode lmode)
813 // Finish open lineEdits
814 if (lineedit) finishedLineEdit();
816 ErrorCode err=success;
820 if (selection) selection->unselect();
823 mapCenter->setMapEditor(this);
824 // (map state is set later at end of load...)
827 saveState(selection,"Load map");
831 mapBuilderHandler handler;
834 // I am paranoid: file should exist anyway
835 // according to check in mainwindow.
838 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
839 tr("Couldn't open map " +fname)+".");
843 blockReposition=true;
844 QXmlInputSource source( file);
845 QXmlSimpleReader reader;
846 reader.setContentHandler( &handler );
847 reader.setErrorHandler( &handler );
848 handler.setMapEditor( this );
849 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
850 handler.setInputFile (file.name());
851 handler.setLoadMode (lmode);
853 bool ok = reader.parse( source );
854 blockReposition=false;
855 blockSaveState=false;
859 mapCenter->reposition();
869 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
870 tr( handler.errorProtocol() ) );
872 // Still return "success": the map maybe at least
873 // partially read by the parser
880 int MapEditor::save (const SaveMode &savemode)
882 // Finish open lineEdits
883 if (lineedit) finishedLineEdit();
887 // The SaveMode UndoCommand is not supported here
888 if (savemode==UndoCommand) return 1;
890 // Create mapName and fileDir
891 makeSubDirs (fileDir);
895 fname=mapName+".xml";
897 // use name given by user, even if he chooses .doc
902 if (savemode==CompleteMap || selection==NULL)
903 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL);
905 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection);
907 if (!saveStringToDisk(fileDir+fname,saveFile))
914 actionFileSave->setEnabled(false);
920 void MapEditor::setZipped (bool z)
925 bool MapEditor::saveZipped ()
930 void MapEditor::print()
932 // Finish open lineEdits
933 if (lineedit) finishedLineEdit();
937 printer = new QPrinter;
938 printer->setColorMode (QPrinter::Color);
939 printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName()));
942 QRect totalBBox=mapCenter->getTotalBBox();
944 // Try to set orientation automagically
945 // Note: Interpretation of generated postscript is amibiguous, if
946 // there are problems with landscape mode, see
947 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
949 if (totalBBox.width()>totalBBox.height())
950 // recommend landscape
951 printer->setOrientation (QPrinter::Landscape);
953 // recommend portrait
954 printer->setOrientation (QPrinter::Portrait);
956 if ( printer->setup(this) )
957 // returns false, if printing is canceled
959 QPainter pp(printer);
961 // Don't print the visualisation of selection
962 LinkableMapObj *oldselection=NULL;
965 oldselection=selection;
966 selection->unselect();
969 // Handle sizes of map and paper:
971 // setWindow defines which part of the canvas will be transformed
972 // setViewport defines area on paper in device coordinates (dpi)
973 // e.g. (0,50,700,700) is upper part on A4
974 // see also /usr/lib/qt3/doc/html/coordsys.html
976 Q3PaintDeviceMetrics metrics (printer);
978 double paperAspect = (double)metrics.width() / (double)metrics.height();
979 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
981 QRect mapRect=totalBBox;
982 Q3CanvasRectangle *frame=NULL;
983 Q3CanvasText *footerFN=NULL;
984 Q3CanvasText *footerDate=NULL;
985 if (printFrame || printFooter)
990 // Print frame around map
991 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
992 totalBBox.width()+20, totalBBox.height()+20);
993 frame=new Q3CanvasRectangle (mapRect,mapCanvas);
994 frame->setBrush (QColor(Qt::white));
995 frame->setPen (QColor(Qt::black));
999 /* TODO remove after testing
1000 QCanvasLine *l=new QCanvasLine (mapCanvas);
1001 l->setPoints (0,0,mapRect.width(),mapRect.height());
1002 l->setPen (QPen(QColor(black), 1));
1009 // Print footer below map
1011 font.setPointSize(10);
1012 footerFN=new Q3CanvasText (mapCanvas);
1013 footerFN->setText ("VYM - " + fileName);
1014 footerFN->setFont(font);
1015 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
1016 footerFN->setZ(Z_TEXT);
1018 footerDate=new Q3CanvasText (mapCanvas);
1019 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
1020 footerDate->setFont(font);
1021 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
1022 footerDate->setZ(Z_TEXT);
1025 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
1028 pp.setWindow (mapRect);
1031 if (mapAspect>=paperAspect)
1033 // Fit horizontally to paper width
1034 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
1037 // Fit vertically to paper height
1038 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
1041 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
1043 // Delete Frame and footer
1047 delete (footerDate);
1049 if (frame) delete (frame);
1051 // Restore selection
1054 selection=oldselection;
1055 selection->select();
1058 // Save settings in vymrc
1059 settings.writeEntry("/vym/mainwindow/printerName",printer->printerName());
1063 QPixmap MapEditor::getPixmap()
1065 QRect mapRect=mapCenter->getTotalBBox();
1066 QPixmap pix (mapRect.size());
1069 // Don't print the visualisation of selection
1070 LinkableMapObj *oldselection=NULL;
1073 oldselection=selection;
1074 selection->unselect();
1077 pp.setWindow (mapRect);
1079 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
1082 // Restore selection
1085 selection=oldselection;
1086 selection->select();
1092 void MapEditor::setHideTmpMode (HideTmpMode mode)
1095 mapCenter->setHideTmp (hidemode);
1096 mapCenter->reposition();
1101 HideTmpMode MapEditor::getHideTmpMode()
1106 void MapEditor::exportImage(QString fn)
1108 // Finish open lineEdits
1109 if (lineedit) finishedLineEdit();
1111 setExportMode (true);
1112 QPixmap pix (getPixmap());
1113 pix.save(fn, "PNG");
1114 setExportMode (false);
1117 void MapEditor::setExportMode (bool b)
1119 // should be called before and after exports
1120 // depending on the settings
1121 if (b && settings.value("/vym/export/useHideExport","yes")=="yes")
1122 setHideTmpMode (HideExport);
1124 setHideTmpMode (HideNone);
1127 void MapEditor::exportImage(QString fn, int item)
1129 // Finish open lineEdits
1130 if (lineedit) finishedLineEdit();
1132 setExportMode (true);
1133 QPixmap pix (getPixmap());
1134 pix.save(fn, exportImageFormatMenu->text(item) );
1135 setExportMode (false);
1138 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
1142 ex.setMapCenter(mapCenter);
1143 if (ex.setConfigFile(cf))
1145 setExportMode (true);
1146 ex.exportPresentation();
1147 setExportMode (false);
1153 void MapEditor::exportXML(const QString &dir)
1155 // Hide stuff during export, if settings want this
1156 setExportMode (true);
1158 // Create subdirectories
1161 // write to directory
1162 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1165 file.setName ( dir + "/"+mapName+".xml");
1166 if ( !file.open( QIODevice::WriteOnly ) )
1168 // This should neverever happen
1169 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1173 // Write it finally, and write in UTF8, no matter what
1174 QTextStream ts( &file );
1175 ts.setEncoding (QTextStream::UnicodeUTF8);
1179 // Now write image, too
1180 exportImage (dir+"/images/"+mapName+".png");
1182 setExportMode (false);
1185 void MapEditor::clear()
1189 selection->unselect();
1196 void MapEditor::copy()
1198 // Finish open lineEdits
1199 if (lineedit) finishedLineEdit();
1203 // write to directory
1204 QString clipfile="part";
1205 QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPoint(),selection);
1208 file.setName ( clipboardDir + "/"+clipfile+".xml");
1209 if ( !file.open( QIODevice::WriteOnly ) )
1211 // This should neverever happen
1212 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1216 // Write it finally, and write in UTF8, no matter what
1217 QTextStream ts( &file );
1218 ts.setEncoding (QTextStream::UnicodeUTF8);
1222 clipboardEmpty=false;
1227 void MapEditor::redo()
1229 // Finish open lineEdits
1230 if (lineedit) finishedLineEdit();
1232 blockSaveState=true;
1234 // Find out current undo directory
1235 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
1237 // Restore variables
1238 QString undoCommand;
1239 QString undoSelection;
1240 QString redoCommand;
1241 QString redoSelection;
1243 set.readSettings(QString(bakMapDir+"/commands"));
1244 undoCommand=set.readEntry ("undoCommand");
1245 undoSelection=set.readEntry ("undoSelection");
1246 redoCommand=set.readEntry ("redoCommand");
1247 redoSelection=set.readEntry ("redoSelection");
1249 // select object before redo
1250 if (!redoSelection.isEmpty())
1251 select (redoSelection);
1253 /* TODO remove testing
1254 cout << "ME::redo() begin\n";
1255 cout << " undosTotal="<<undosTotal<<endl;
1256 cout << " undosAvail="<<undosAvail<<endl;
1257 cout << " undoNum="<<undoNum<<endl;
1258 cout << " ---------------------------"<<endl;
1259 cout << " undoCom="<<undoCommand<<endl;
1260 cout << " undoSel="<<undoSelection<<endl;
1261 cout << " ---------------------------"<<endl;
1262 cout << " redoCom="<<redoCommand<<endl;
1263 cout << " redoSel="<<redoSelection<<endl;
1264 cout << " ---------------------------"<<endl;
1266 parseAtom (undoCommand);
1267 mapCenter->reposition();
1269 //if (!redoSelection.isEmpty())
1270 // select (redoSelection);
1274 // Undo not longer available now
1275 actionEditUndo->setEnabled (false);
1277 undoNum--; if (undoNum<1) undoNum=undosTotal;
1279 blockSaveState=false;
1280 /* TODO remove testing
1281 cout << "ME::redo() end\n";
1282 cout << " undosAvail="<<undosAvail<<endl;
1283 cout << " undoNum="<<undoNum<<endl;
1284 cout << " ---------------------------"<<endl<<endl;
1288 void MapEditor::undo()
1290 // Finish open lineEdits
1291 if (lineedit) finishedLineEdit();
1293 blockSaveState=true;
1295 // Find out current undo directory
1296 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
1298 // Restore variables
1299 QString undoCommand;
1300 QString undoSelection;
1301 QString redoCommand;
1302 QString redoSelection;
1304 set.readSettings(QString(bakMapDir+"/commands"));
1305 undoCommand= set.readEntry ("undoCommand");
1306 undoSelection=set.readEntry ("undoSelection");
1307 redoCommand= set.readEntry ("redoCommand");
1308 redoSelection=set.readEntry ("redoSelection");
1310 // select object before undo
1311 if (!undoSelection.isEmpty())
1312 select (undoSelection);
1315 cout << "ME::undo() begin\n";
1316 cout << " undosTotal="<<undosTotal<<endl;
1317 cout << " undosAvail="<<undosAvail<<endl;
1318 cout << " undoNum="<<undoNum<<endl;
1319 cout << " ---------------------------"<<endl;
1320 cout << " undoCom="<<undoCommand<<endl;
1321 cout << " undoSel="<<undoSelection<<endl;
1322 cout << " ---------------------------"<<endl;
1323 cout << " redoCom="<<redoCommand<<endl;
1324 cout << " redoSel="<<redoSelection<<endl;
1325 cout << " ---------------------------"<<endl;
1327 parseAtom (undoCommand);
1328 mapCenter->reposition();
1330 //if (!redoSelection.isEmpty())
1331 // select (redoSelection);
1335 // Undo not longer available now
1336 actionEditUndo->setEnabled (false);
1338 undoNum--; if (undoNum<1) undoNum=undosTotal;
1340 blockSaveState=false;
1341 /* TODO remove testing
1342 cout << "ME::undo() end\n";
1343 cout << " undosAvail="<<undosAvail<<endl;
1344 cout << " undoNum="<<undoNum<<endl;
1345 cout << " ---------------------------"<<endl<<endl;
1349 void MapEditor::undoXML(const QString &undoSel, const QString &bakMapPath)
1351 QString bakMapDir=bakMapPath.left(bakMapPath.findRev("/"));
1353 QFile file (bakMapPath);
1357 // We need to parse saved XML data
1358 mapBuilderHandler handler;
1359 QXmlInputSource source( file);
1360 QXmlSimpleReader reader;
1361 reader.setContentHandler( &handler );
1362 reader.setErrorHandler( &handler );
1363 handler.setMapEditor( this );
1364 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1365 if (undoSel.isEmpty())
1369 handler.setLoadMode (NewMap);
1373 handler.setLoadMode (ImportReplace);
1375 blockReposition=true;
1376 bool ok = reader.parse( source );
1377 blockReposition=false;
1380 // This should never ever happen
1381 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1382 tr( handler.errorProtocol() )+" in "+bakMapDir );
1386 QMessageBox::critical( 0, tr( "Critical Error" ),
1387 tr("Temporary directory %1 used for undo is gone. \n"
1388 "I will create a new one, but at the moment no undo is available.\n"
1389 "Maybe you want to reload your original data.\n\n"
1390 "Sorry for any inconveniences.").arg(bakMapDir) );
1395 void MapEditor::pasteNoSave()
1397 // Finish open lineEdits
1398 if (lineedit) finishedLineEdit();
1400 load (clipboardDir+"/part.xml",ImportAdd);
1403 void MapEditor::cutNoSave()
1409 void MapEditor::paste()
1411 if (selection && (typeid(*selection) == typeid(BranchObj) ||
1412 typeid(*selection) == typeid(MapCenterObj)))
1414 saveState(selection,QString("Paste to %1").arg( getName(selection)));
1416 mapCenter->reposition();
1421 void MapEditor::cut()
1423 saveState(selection->getParObj(),QString("Cut %1").arg(getName(selection)));
1426 mapCenter->reposition();
1430 void MapEditor::move(const int &x, const int &y)
1432 // TODO no saveState, because this is only internal at undo so far
1433 if (selection) selection->move(x,y);
1434 if (typeid(*selection) == typeid(FloatImageObj))
1435 ((FloatImageObj*)selection)->setRelPos();
1438 void MapEditor::moveBranchUp()
1440 // Finish open lineEdits
1441 if (lineedit) finishedLineEdit();
1445 if (typeid(*selection) == typeid(BranchObj) )
1447 bo=(BranchObj*)selection;
1448 if (!bo->canMoveBranchUp()) return;
1449 par=(BranchObj*)(bo->getParObj());
1450 selection->unselect();
1451 selection=par->moveBranchUp (bo);
1452 selection->select();
1453 saveState("moveBranchDown ()",bo,QString("Move up %1").arg(getName(bo)));
1454 mapCenter->reposition();
1455 ensureSelectionVisible();
1459 void MapEditor::moveBranchDown()
1461 // Finish open lineEdits
1462 if (lineedit) finishedLineEdit();
1466 if (typeid(*selection) == typeid(BranchObj) )
1468 bo=(BranchObj*)selection;
1469 if (!bo->canMoveBranchDown()) return;
1470 par=(BranchObj*)(bo->getParObj());
1471 selection->unselect();
1472 selection=par->moveBranchDown(bo);
1473 selection->select();
1474 saveState("moveBranchUp ()",bo,QString("Move down %1").arg(getName(bo)));
1475 mapCenter->reposition();
1476 ensureSelectionVisible();
1480 void MapEditor::editHeading()
1482 // Finish open lineEdits
1483 if (lineedit) finishedLineEdit();
1486 (typeid(*selection) == typeid(BranchObj) ||
1487 typeid(*selection) == typeid(MapCenterObj) ) )
1489 editingBO=(BranchObj*)selection;
1491 ensureSelectionVisible();
1492 QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
1493 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1494 QString s=editingBO->getHeading();
1495 lineedit->setText(s);
1496 lineedit->setCursorPosition(1);
1497 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1498 lineedit->selectAll();
1500 lineedit->grabKeyboard();
1501 lineedit->setFocus();
1505 void MapEditor::setHeading(const QString &s)
1507 // Internal function, no saveState needed
1509 (typeid(*selection) == typeid(BranchObj) ||
1510 typeid(*selection) == typeid(MapCenterObj) ) )
1512 ((BranchObj*)selection)->setHeading(s);
1513 mapCenter->reposition();
1515 ensureSelectionVisible();
1519 void MapEditor::setURL (const QString &s)
1521 // Internal function, no saveState needed
1523 (typeid(*selection) == typeid(BranchObj) ||
1524 typeid(*selection) == typeid(MapCenterObj) ) )
1526 ((BranchObj*)selection)->setURL(s);
1527 mapCenter->reposition();
1529 ensureSelectionVisible();
1533 void MapEditor::setVymLink (const QString &s)
1535 // Internal function, no saveState needed
1537 (typeid(*selection) == typeid(BranchObj) ||
1538 typeid(*selection) == typeid(MapCenterObj) ) )
1540 ((BranchObj*)selection)->setVymLink(s);
1541 mapCenter->reposition();
1543 ensureSelectionVisible();
1547 void MapEditor::addNewBranch(int pos)
1549 // Finish open lineEdits
1550 if (lineedit) finishedLineEdit();
1553 (typeid(*selection) == typeid(BranchObj) ||
1554 typeid(*selection) == typeid(MapCenterObj) ) )
1556 BranchObj* bo1 = (BranchObj*) selection;
1557 saveState(selection, QString("Add new branch to %1").arg(getName(bo1))); //TODO undoCommand
1559 bool wasScrolled=false;
1560 BranchObj *newbo=NULL;
1563 // save scroll state. If scrolled, automatically select
1564 // new branch in order to tmp unscroll parent...
1565 wasScrolled=bo1->isScrolled();
1566 newbo=bo1->addBranch();
1569 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1573 // add above selection
1574 newbo=parbo->insertBranch(bo1->getNum());
1576 // add below selection
1577 newbo=parbo->insertBranch(bo1->getNum()+1);
1579 // This should not happen...
1584 LinkableMapObj *oldselection=selection;
1586 mapCenter->reposition();
1588 if (actionSettingsAutoedit->isOn() ||
1589 actionSettingsAutoselectHeading->isOn() )
1591 selection->unselect();
1593 selection->select();
1594 if (actionSettingsPasteNewHeading->isOn() )
1596 BranchObj *bo2= (BranchObj*)selection;
1597 bo2->setHeading("");
1599 if (actionSettingsAutoedit->isOn() )
1601 if (!actionSettingsAutoselectHeading->isOn()
1604 selection->unselect();
1605 selection=oldselection;
1606 selection->select();
1613 void MapEditor::addNewBranchHere()
1615 // Finish open lineEdits
1616 if (lineedit) finishedLineEdit();
1619 (typeid(*selection) == typeid(BranchObj) ) )
1621 BranchObj* bo1 = (BranchObj*) selection;
1622 saveState(selection, QString("Add new branch here").arg(getName(bo1)));
1624 bool wasScrolled=false;
1625 BranchObj *newbo=NULL;
1626 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1629 // add below selection
1630 newbo=parbo->insertBranch(bo1->getNum()+1);
1633 LinkableMapObj *oldselection=selection;
1634 ((BranchObj*)selection)->moveBranchTo (newbo,-1);
1636 mapCenter->reposition();
1638 if (actionSettingsAutoedit->isOn() ||
1639 actionSettingsAutoselectHeading->isOn() )
1641 selection->unselect();
1643 selection->select();
1644 if (actionSettingsPasteNewHeading->isOn() )
1646 BranchObj *bo2= (BranchObj*)selection;
1647 bo2->setHeading("");
1649 if (actionSettingsAutoedit->isOn() )
1651 if (!actionSettingsAutoselectHeading->isOn()
1654 selection->unselect();
1655 selection=oldselection;
1656 selection->select();
1662 void MapEditor::deleteSelection()
1664 // Finish open lineEdits
1665 if (lineedit) finishedLineEdit();
1667 if (selection && typeid(*selection) ==typeid(BranchObj) )
1669 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1670 BranchObj* par=(BranchObj*)(bo->getParObj());
1672 if (selection->getDepth()>1)
1673 // Normal branch, save parent with childs
1674 saveState(par,QString("Delete %1").arg(getName(bo)));
1676 // Mainbranch, save whole map
1677 // TODO Better would be to insert mainbranch again at pos
1678 // But undoCommand is missing right now
1679 saveState(QString("Delete %1").arg(getName(bo)));
1681 par->removeBranch(bo);
1683 selection->select();
1684 ensureSelectionVisible();
1685 mapCenter->reposition();
1688 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1690 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1691 BranchObj* par=(BranchObj*)(fio->getParObj());
1692 saveState(par, QString("Delete %1").arg(getName(fio)));
1695 par->removeFloatImage(fio);
1697 selection->select();
1698 ensureSelectionVisible();
1699 mapCenter->reposition();
1704 LinkableMapObj* MapEditor::getSelection()
1709 void MapEditor::unselect()
1713 selectionLast=selection;
1714 selection->unselect();
1719 void MapEditor::reselect()
1723 selection=selectionLast;
1724 selection->select();
1729 bool MapEditor::select (const QString &s)
1731 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
1733 // Finally select the found object
1736 if (selection) unselect();
1738 selection->select();
1740 ensureSelectionVisible();
1746 void MapEditor::select (LinkableMapObj *lmo)
1748 if (lmo && selection != lmo)
1750 // select the MapObj
1751 if (selection) selection->unselect();
1753 selection->select();
1760 void MapEditor::selectNextBranch()
1762 // Increase number of branch
1765 QString s=selection->getSelectString();
1771 part=s.section(",",-1);
1773 num=part.right(part.length() - 3);
1775 s=s.left (s.length() -num.length());
1778 num=QString ("%1").arg(num.toUInt()+1);
1782 // Try to select this one
1783 if (select (s)) return;
1785 // We have no direct successor,
1786 // try to increase the parental number in order to
1787 // find a successor with same depth
1789 int d=selection->getDepth();
1794 while (!found && d>0)
1796 s=s.section (",",0,d-1);
1797 // replace substring of current depth in s with "1"
1798 part=s.section(",",-1);
1800 num=part.right(part.length() - 3);
1804 // increase number of parent
1805 num=QString ("%1").arg(num.toUInt()+1);
1806 s=s.section (",",0,d-2) + ","+ typ+num;
1809 // Special case, look at orientation
1810 if (selection->getOrientation()==OrientRightOfCenter)
1811 num=QString ("%1").arg(num.toUInt()+1);
1813 num=QString ("%1").arg(num.toUInt()-1);
1818 // pad to oldDepth, select the first branch for each depth
1819 for (i=d;i<oldDepth;i++)
1824 if ( ((BranchObj*)selection)->countBranches()>0)
1832 // try to select the freshly built string
1840 void MapEditor::selectPrevBranch()
1842 // Decrease number of branch
1845 QString s=selection->getSelectString();
1851 part=s.section(",",-1);
1853 num=part.right(part.length() - 3);
1855 s=s.left (s.length() -num.length());
1858 num=QString ("%1").arg(num.toUInt()-1);
1862 // Try to select this one
1863 if (select (s)) return;
1865 // We have no direct precessor,
1866 // try to decrease the parental number in order to
1867 // find a precessor with same depth
1869 int d=selection->getDepth();
1874 while (!found && d>0)
1876 s=s.section (",",0,d-1);
1877 // replace substring of current depth in s with "1"
1878 part=s.section(",",-1);
1880 num=part.right(part.length() - 3);
1884 // decrease number of parent
1885 num=QString ("%1").arg(num.toUInt()-1);
1886 s=s.section (",",0,d-2) + ","+ typ+num;
1889 // Special case, look at orientation
1890 if (selection->getOrientation()==OrientRightOfCenter)
1891 num=QString ("%1").arg(num.toUInt()-1);
1893 num=QString ("%1").arg(num.toUInt()+1);
1898 // pad to oldDepth, select the last branch for each depth
1899 for (i=d;i<oldDepth;i++)
1903 if ( ((BranchObj*)selection)->countBranches()>0)
1904 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)selection)->countBranches()-1 );
1911 // try to select the freshly built string
1919 void MapEditor::selectUpperBranch()
1921 // Finish open lineEdits
1922 if (lineedit) finishedLineEdit();
1926 if (typeid(*selection) == typeid(BranchObj))
1928 if (selection->getOrientation()==OrientRightOfCenter)
1931 if (selection->getDepth()==1)
1939 void MapEditor::selectLowerBranch()
1941 // Finish open lineEdits
1942 if (lineedit) finishedLineEdit();
1946 if (typeid(*selection) == typeid(BranchObj))
1948 if (selection->getOrientation()==OrientRightOfCenter)
1951 if (selection->getDepth()==1)
1960 void MapEditor::selectLeftBranch()
1962 // Finish open lineEdits
1963 if (lineedit) finishedLineEdit();
1969 if (typeid(*selection) == typeid(MapCenterObj))
1971 par= (BranchObj*) selection;
1972 bo=par->getLastSelectedBranch();
1975 // Workaround for reselecting on left and right side
1976 if (bo->getOrientation()==OrientRightOfCenter)
1978 bo=par->getLastBranch();
1984 selection->select();
1986 ensureSelectionVisible();
1991 par=(BranchObj*)(selection->getParObj());
1992 if (selection->getOrientation()==OrientRightOfCenter)
1994 if (typeid(*selection) == typeid(BranchObj) ||
1995 typeid(*selection) == typeid(FloatImageObj))
1997 selection->unselect();
1999 selection->select();
2001 ensureSelectionVisible();
2005 if (typeid(*selection) == typeid(BranchObj) )
2007 bo=((BranchObj*)selection)->getLastSelectedBranch();
2010 selection->unselect();
2012 selection->select();
2014 ensureSelectionVisible();
2022 void MapEditor::selectRightBranch()
2024 // Finish open lineEdits
2025 if (lineedit) finishedLineEdit();
2032 if (typeid(*selection) == typeid(MapCenterObj))
2034 par= (BranchObj*) selection;
2035 bo=par->getLastSelectedBranch();
2038 // Workaround for relecting on left and right side
2039 if (bo->getOrientation()==OrientLeftOfCenter)
2040 bo=par->getFirstBranch();
2045 selection->select();
2046 ensureSelectionVisible();
2051 par=(BranchObj*)(selection->getParObj());
2052 if (selection->getOrientation()==OrientLeftOfCenter)
2054 if (typeid(*selection) == typeid(BranchObj) ||
2055 typeid(*selection) == typeid(FloatImageObj))
2057 selection->unselect();
2059 selection->select();
2061 ensureSelectionVisible();
2065 if (typeid(*selection) == typeid(BranchObj) )
2067 bo=((BranchObj*)selection)->getLastSelectedBranch();
2070 selection->unselect();
2072 selection->select();
2074 ensureSelectionVisible();
2082 void MapEditor::selectFirstBranch()
2084 // Finish open lineEdits
2085 if (lineedit) finishedLineEdit();
2091 if (typeid(*selection) == typeid(BranchObj))
2093 bo1= (BranchObj*) selection;
2094 par=(BranchObj*)(bo1->getParObj());
2095 bo2=par->getFirstBranch();
2099 selection->select();
2100 ensureSelectionVisible();
2107 void MapEditor::selectLastBranch()
2109 // Finish open lineEdits
2110 if (lineedit) finishedLineEdit();
2116 if (typeid(*selection) == typeid(BranchObj))
2118 bo1= (BranchObj*) selection;
2119 par=(BranchObj*)(bo1->getParObj());
2120 bo2=par->getLastBranch();
2124 selection->select();
2125 ensureSelectionVisible();
2132 void MapEditor::setColor(QColor c)
2137 void MapEditor::selectBackgroundColor()
2139 // Finish open lineEdits
2140 if (lineedit) finishedLineEdit();
2142 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
2143 if ( !col.isValid() ) return;
2144 setBackgroundColor( col );
2145 saveState(QString("Set background color of map to %1").arg(col.name()));
2148 void MapEditor::setBackgroundColor(QColor c)
2150 mapCanvas->setBackgroundColor (c);
2153 QColor MapEditor::pickColor()
2157 if (typeid(*selection) == typeid(BranchObj) ||
2158 typeid(*selection) == typeid(MapCenterObj))
2160 BranchObj *bo=(BranchObj*)selection;
2161 actColor=bo->getColor();
2167 void MapEditor::colorItem()
2171 if (typeid(*selection) == typeid(BranchObj) ||
2172 typeid(*selection) == typeid(MapCenterObj))
2174 BranchObj *bo=(BranchObj*)selection;
2175 saveState(selection, QString("Set color of %1 to %2").arg(getName(bo)).arg(actColor.name())); //TODO undoCommand
2176 bo->setColor(actColor); // color branch
2181 void MapEditor::colorBranch()
2185 if (typeid(*selection) == typeid(BranchObj) ||
2186 typeid(*selection) == typeid(MapCenterObj))
2188 BranchObj *bo=(BranchObj*)selection;
2189 saveState(selection, QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(actColor.name())); //TODO undoCommand
2190 bo->setColorChilds(actColor); // color links, color childs
2196 void MapEditor::toggleStandardFlag(QString f)
2200 if (typeid(*selection) == typeid(BranchObj) ||
2201 typeid(*selection) == typeid(MapCenterObj))
2203 BranchObj *bo=(BranchObj*)selection;
2205 if (bo->isSetStandardFlag(f))
2209 saveState(selection, QString("%1 standard flag \"%2\" of %3").arg(s).arg(f).arg(getName(bo)));// TODO undoCommand
2210 bo->toggleStandardFlag (f,actionSettingsUseFlagGroups->isOn());
2216 void MapEditor::setViewCenter()
2218 // transform to CanvasView Coord:
2219 QPoint p=worldMatrix().map(movingCenter);
2220 center ( p.x(), p.y());
2224 BranchObj* MapEditor::findText (QString s, bool cs)
2227 { // Nothing found or new find process
2229 // nothing found, start again
2231 itFind=mapCenter->first();
2233 bool searching=true;
2234 bool foundNote=false;
2235 while (searching && !EOFind)
2239 // Searching in Note
2240 if (itFind->getNote().contains(s,cs))
2242 if (selection!=itFind)
2244 if (selection) ((BranchObj*)selection)->unselect();
2246 selection->select();
2248 ensureSelectionVisible();
2250 if (textEditor->findText(s,cs))
2256 // Searching in Heading
2257 if (searching && itFind->getHeading().contains (s,cs) )
2259 if (selection) ((BranchObj*)selection)->unselect();
2261 selection->select();
2263 ensureSelectionVisible();
2269 itFind=itFind->next();
2270 if (!itFind) EOFind=true;
2276 return (BranchObj*)selection;
2281 void MapEditor::findReset()
2282 { // Necessary if text to find changes during a find process
2287 void MapEditor::editURL()
2289 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2290 typeid(*selection) == typeid(MapCenterObj)) )
2293 BranchObj *bo=(BranchObj*)selection;
2294 QString text = QInputDialog::getText(
2295 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2296 bo->getURL(), &ok, this );
2299 // user entered something and pressed OK
2300 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+text+"\")", QString("Set URL of %1 to %21").arg(getName(bo)).arg(text));
2307 QString MapEditor::getURL()
2309 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2310 typeid(*selection) == typeid(MapCenterObj)) )
2311 return ((BranchObj*)selection)->getURL();
2316 void MapEditor::editHeading2URL()
2318 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2319 typeid(*selection) == typeid(MapCenterObj)) )
2321 BranchObj *bo=(BranchObj*)selection;
2322 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+bo->getHeading()+"\")",QString("Copy heading of %1 to URL").arg(getName(bo)));
2323 bo->setURL (bo->getHeading());
2328 void MapEditor::editBugzilla2URL()
2330 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2331 typeid(*selection) == typeid(MapCenterObj)) )
2333 BranchObj *bo=(BranchObj*)selection;
2334 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2335 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to Novell Bugzilla").arg(getName(bo)));
2341 void MapEditor::editFATE2URL()
2343 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2344 typeid(*selection) == typeid(MapCenterObj)) )
2346 BranchObj *bo=(BranchObj*)selection;
2347 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2348 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to FATE").arg(getName(bo)));
2354 void MapEditor::editVymLink()
2356 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2357 typeid(*selection) == typeid(MapCenterObj)) )
2359 BranchObj *bo=(BranchObj*)selection;
2360 Q3FileDialog *fd=new Q3FileDialog( this,__VYM " - " +tr("Link to another map"));
2361 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2362 fd->setCaption(__VYM " - " +tr("Link to another map"));
2363 if (! bo->getVymLink().isEmpty() )
2364 fd->setSelection( bo->getVymLink() );
2368 if ( fd->exec() == QDialog::Accepted )
2370 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\""+fd->selectedFile()+"\")",QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile()));
2371 bo->setVymLink (fd->selectedFile() );
2373 mapCenter->reposition();
2380 void MapEditor::deleteVymLink()
2382 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2383 typeid(*selection) == typeid(MapCenterObj)) )
2385 BranchObj *bo=(BranchObj*)selection;
2386 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\"\")",QString("Unset vymlink of %1").arg(getName(bo)));
2387 bo->setVymLink ("" );
2389 mapCenter->reposition();
2395 void MapEditor::toggleHideExport()
2397 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2398 typeid(*selection) == typeid(MapCenterObj)) ||
2399 (typeid(*selection)==typeid(FloatImageObj))
2402 OrnamentedObj *oo=(OrnamentedObj*)selection;
2404 if (oo->hideInExport())
2406 oo->setHideInExport(false);
2411 oo->setHideInExport(true);
2414 saveState(QString ("%1 hide export flag of %2").arg(s).arg(getName(selection))); //TODO undoCommand
2415 actionEditToggleHideExport->setOn (oo->hideInExport());
2417 mapCenter->reposition();
2423 QString MapEditor::getVymLink()
2425 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2426 typeid(*selection) == typeid(MapCenterObj)) )
2428 return ((BranchObj*)selection)->getVymLink();
2434 void MapEditor::removeBranchKeepChilds()
2436 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2438 BranchObj* bo=(BranchObj*)selection;
2439 BranchObj* par=(BranchObj*)(bo->getParObj());
2440 QString s=QString("Remove %1 and keep its childs").arg(getName(bo));
2441 if (bo->getDepth()==1)
2444 saveState(selection->getParObj(),s); // TODO undoCommand
2445 QString sel=selection->getSelectString();
2447 par->removeBranchHere(bo);
2448 mapCenter->reposition();
2453 void MapEditor::removeChilds()
2455 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2457 saveState(selection->getParObj(), QString("Remove childs of branch %1").arg(getName(selection)));
2458 ((BranchObj*)selection)->removeChilds();
2459 mapCenter->reposition();
2463 void MapEditor::editMapInfo()
2465 ExtraInfoDialog dia;
2466 dia.setMapName (getFileName() );
2467 dia.setAuthor (mapCenter->getAuthor() );
2468 dia.setComment(mapCenter->getComment() );
2473 Q3CanvasItemList l=canvas()->allItems();
2474 for (Q3CanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2476 stats+=QString ("%1 items on canvas\n").arg (i,6);
2483 bo=mapCenter->first();
2486 if (!bo->getNote().isEmpty() ) n++;
2487 f+= bo->countFloatImages();
2489 xl+=bo->countXLinks();
2492 stats+=QString ("%1 branches\n").arg (b-1,6);
2493 stats+=QString ("%1 xLinks \n").arg (xl,6);
2494 stats+=QString ("%1 notes\n").arg (n,6);
2495 stats+=QString ("%1 images\n").arg (f,6);
2496 dia.setStats (stats);
2498 // Finally show dialog
2499 if (dia.exec() == QDialog::Accepted)
2501 saveState("Edit info about map"); //TODO undoCommand
2502 mapCenter->setAuthor (dia.getAuthor() );
2503 mapCenter->setComment (dia.getComment() );
2507 void MapEditor::updateActions()
2510 if (getLinkColorHint()==HeadingColor)
2511 actionFormatLinkColorHint->setOn(true);
2513 actionFormatLinkColorHint->setOn(false);
2518 actionFormatLinkStyleLine->setOn(true);
2521 actionFormatLinkStyleParabel->setOn(true);
2524 actionFormatLinkStylePolyLine->setOn(true);
2526 case StylePolyParabel:
2527 actionFormatLinkStylePolyParabel->setOn(true);
2533 QPixmap pix( 16, 16 );
2534 pix.fill( mapCanvas->backgroundColor() );
2535 actionFormatBackColor->setIconSet( pix );
2536 pix.fill( defLinkColor );
2537 actionFormatLinkColor->setIconSet( pix );
2539 actionEditUndo->setEnabled( mapChanged );
2540 actionFileSave->setEnabled( mapUnsaved );
2544 if ( (typeid(*selection) == typeid(BranchObj)) ||
2545 (typeid(*selection) == typeid(MapCenterObj)) )
2547 BranchObj *bo=(BranchObj*)selection;
2548 // Take care of links
2549 if (bo->countXLinks()==0)
2551 branchLinksContextMenu->clear();
2552 branchLinksContextMenu->insertItem ("No xLink available");
2553 branchLinksContextMenuDup->clear();
2554 branchLinksContextMenuDup->insertItem ("No xLink available");
2560 branchLinksContextMenu->clear();
2561 branchLinksContextMenuDup->clear();
2562 for (int i=0; i<=bo->countXLinks();i++)
2564 bot=bo->XLinkTargetAt(i);
2567 s=bot->getHeading();
2570 branchLinksContextMenu->insertItem (s);
2571 branchLinksContextMenuDup->insertItem (s);
2576 standardFlagsDefault->setEnabled (true);
2578 actionEditToggleScroll->setEnabled (true);
2579 if ( bo->isScrolled() )
2580 actionEditToggleScroll->setOn(true);
2582 actionEditToggleScroll->setOn(false);
2584 if ( bo->getURL().isEmpty() )
2586 actionEditOpenURL->setEnabled (false);
2587 actionEditOpenURLTab->setEnabled (false);
2591 actionEditOpenURL->setEnabled (true);
2592 actionEditOpenURLTab->setEnabled (true);
2594 if ( bo->getVymLink().isEmpty() )
2596 actionEditOpenVymLink->setEnabled (false);
2597 actionEditDeleteVymLink->setEnabled (false);
2600 actionEditOpenVymLink->setEnabled (true);
2601 actionEditDeleteVymLink->setEnabled (true);
2604 if (bo->canMoveBranchUp())
2605 actionEditMoveUp->setEnabled (true);
2607 actionEditMoveUp->setEnabled (false);
2608 if (bo->canMoveBranchDown())
2609 actionEditMoveDown->setEnabled (true);
2611 actionEditMoveDown->setEnabled (false);
2614 actionEditToggleHideExport->setEnabled (true);
2615 actionEditToggleHideExport->setOn (bo->hideInExport() );
2617 actionEditCopy->setEnabled (true);
2618 actionEditCut->setEnabled (true);
2619 if (!clipboardEmpty)
2620 actionEditPaste->setEnabled (true);
2622 actionEditPaste->setEnabled (false);
2623 for (a=actionListBranches.first();a;a=actionListBranches.next())
2624 a->setEnabled(true);
2625 actionEditDelete->setEnabled (true);
2626 switch (selection->getFrameType())
2629 actionFormatFrameNone->setOn(true);
2632 actionFormatFrameRectangle->setOn(true);
2637 actionFormatIncludeImagesVer->setOn
2638 ( ((BranchObj*)selection)->getIncludeImagesVer());
2639 actionFormatIncludeImagesHor->setOn
2640 ( ((BranchObj*)selection)->getIncludeImagesHor());
2641 actionFormatHideLinkUnselected->setOn
2642 (selection->getHideLinkUnselected());
2644 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2646 FloatObj *fo=(FloatImageObj*)selection;
2647 //FIXME do this in mainwindow standardFlagsDefault->setEnabled (false);
2649 actionEditOpenURL->setEnabled (false);
2650 actionEditOpenVymLink->setEnabled (false);
2651 actionEditDeleteVymLink->setEnabled (false);
2652 actionEditToggleHideExport->setEnabled (true);
2653 actionEditToggleHideExport->setOn (fo->hideInExport() );
2656 actionEditCopy->setEnabled (true);
2657 actionEditCut->setEnabled (true);
2658 actionEditPaste->setEnabled (false);
2659 for (a=actionListBranches.first();a;a=actionListBranches.next())
2660 a->setEnabled(false);
2661 actionEditDelete->setEnabled (true);
2662 actionFormatHideLinkUnselected->setOn
2663 ( selection->getHideLinkUnselected());
2664 actionEditMoveUp->setEnabled (false);
2665 actionEditMoveDown->setEnabled (false);
2670 //FIXME do this in mainwindow standardFlagsDefault->setEnabled (false);
2672 actionEditCopy->setEnabled (false);
2673 actionEditCut->setEnabled (false);
2674 actionEditPaste->setEnabled (false);
2675 for (a=actionListBranches.first();a;a=actionListBranches.next())
2676 a->setEnabled(false);
2678 actionEditToggleScroll->setEnabled (false);
2679 actionEditOpenURL->setEnabled (false);
2680 actionEditOpenVymLink->setEnabled (false);
2681 actionEditDeleteVymLink->setEnabled (false);
2682 actionEditHeading2URL->setEnabled (false);
2683 actionEditDelete->setEnabled (false);
2684 actionEditMoveUp->setEnabled (false);
2685 actionEditMoveDown->setEnabled (false);
2686 actionEditToggleHideExport->setEnabled (false);
2690 void MapEditor::updateNoteFlag()
2693 if ( (typeid(*selection) == typeid(BranchObj)) ||
2694 (typeid(*selection) == typeid(MapCenterObj)) )
2695 ((BranchObj*)selection)->updateNoteFlag();
2698 void MapEditor::setLinkStyle (LinkStyle ls)
2702 saveState("Set link style"); // TODO undoCommand
2704 bo=mapCenter->first();
2708 bo->setLinkStyle(bo->getDefLinkStyle());
2711 mapCenter->reposition();
2714 LinkStyle MapEditor::getLinkStyle ()
2719 void MapEditor::setLinkColor(QColor c)
2725 void MapEditor::setLinkColorHint()
2727 // called from setLinkColorHint(lch) or at end of parse
2729 bo=mapCenter->first();
2737 void MapEditor::setLinkColorHint(LinkColorHint lch)
2743 void MapEditor::toggleLinkColorHint()
2745 if (linkcolorhint==HeadingColor)
2746 linkcolorhint=DefaultColor;
2748 linkcolorhint=HeadingColor;
2750 bo=mapCenter->first();
2758 LinkColorHint MapEditor::getLinkColorHint()
2760 return linkcolorhint;
2763 QColor MapEditor::getDefLinkColor()
2765 return defLinkColor;
2768 void MapEditor::setDefXLinkColor(QColor col)
2773 QColor MapEditor::getDefXLinkColor()
2775 return defXLinkColor;
2778 void MapEditor::setDefXLinkWidth (int w)
2783 int MapEditor::getDefXLinkWidth()
2785 return defXLinkWidth;
2788 void MapEditor::selectLinkColor()
2790 // Finish open lineEdits
2791 if (lineedit) finishedLineEdit();
2793 QColor col = QColorDialog::getColor( defLinkColor, this );
2794 if ( !col.isValid() ) return;
2795 setLinkColor( col );
2796 saveState(QString("Set link color to %1").arg(col.name())); //TODO undoCommand
2800 void MapEditor::toggleScroll()
2802 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2804 BranchObj *bo=((BranchObj*)selection);
2805 if (bo->countBranches()==0) return;
2806 if (bo->getDepth()==0) return;
2808 if (bo->isScrolled())
2812 saveState(selection, QString ("%1 %2").arg(s).arg(getName(bo)));
2819 void MapEditor::unScrollAll()
2822 bo=mapCenter->first();
2825 if (bo->isScrolled()) bo->toggleScroll();
2830 void MapEditor::loadFloatImage ()
2833 (typeid(*selection) == typeid(BranchObj)) ||
2834 (typeid(*selection) == typeid(MapCenterObj)) )
2836 BranchObj *bo=((BranchObj*)selection);
2838 Q3FileDialog *fd=new Q3FileDialog( this);
2839 fd->setMode (Q3FileDialog::ExistingFiles);
2840 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2841 ImagePreview *p =new ImagePreview (fd);
2842 fd->setContentsPreviewEnabled( TRUE );
2843 fd->setContentsPreview( p, p );
2844 fd->setPreviewMode( Q3FileDialog::Contents );
2845 fd->setCaption(__VYM " - " +tr("Load image"));
2846 fd->setDir (lastImageDir);
2850 if ( fd->exec() == QDialog::Accepted )
2852 saveState(selection, QString("Add floatimage to %1").arg(getName(selection)));
2853 lastImageDir=fn.left(fn.findRev ("/"));
2854 QStringList flist = fd->selectedFiles();
2855 QStringList::Iterator it = flist.begin();
2856 while( it != flist.end() )
2859 bo->addFloatImage();
2860 // TODO check if load was successful
2861 bo->getLastFloatImage()->load(*it);
2862 bo->getLastFloatImage()->setOriginalFilename(fn);
2866 mapCenter->reposition();
2875 void MapEditor::saveFloatImage (int item)
2878 (typeid(*selection) == typeid(FloatImageObj)) )
2880 FloatImageObj *fio=((FloatImageObj*)selection);
2881 const char* fmt = saveImageFormatMenu->text(item);
2883 Q3FileDialog *fd=new Q3FileDialog( this, tr("vym - save image as") + fmt);
2884 fd->addFilter ("PNG (*.png)");
2885 fd->addFilter ("BMP (*.bmp)");
2886 fd->addFilter ("XBM (*.xbm)");
2887 fd->addFilter ("JPG (*.jpg)");
2888 fd->addFilter ("XPM (*.xpm)");
2889 fd->addFilter ("GIF (*.gif)");
2890 fd->addFilter ("PNM (*.pnm)");
2891 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2892 fd->setCaption(__VYM " - " +tr("Save image as %1").arg(fmt));
2893 fd->setMode( Q3FileDialog::AnyFile );
2894 fd->setSelection (fio->getOriginalFilename());
2898 if ( fd->exec() == QDialog::Accepted )
2900 if (QFile (fd->selectedFile()).exists() )
2902 QMessageBox mb( __VYM,
2903 tr("The file %1 exists already.\n"
2904 "Do you want to overwrite it?").arg(fd->selectedFile()),
2905 QMessageBox::Warning,
2906 QMessageBox::Yes | QMessageBox::Default,
2907 QMessageBox::Cancel | QMessageBox::Escape,
2908 QMessageBox::QMessageBox::NoButton );
2910 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2911 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2914 case QMessageBox::Yes:
2917 case QMessageBox::Cancel:
2923 fio->save (fd->selectedFile(),fmt);
2928 void MapEditor::setFrame(const FrameType &t)
2931 (typeid(*selection) == typeid(BranchObj)) ||
2932 (typeid(*selection) == typeid(MapCenterObj)) )
2934 selection->setFrameType (t);
2935 mapCenter->reposition();
2936 selection->updateLink();
2940 void MapEditor::setIncludeImagesVer(bool b)
2943 (typeid(*selection) == typeid(BranchObj)) ||
2944 (typeid(*selection) == typeid(MapCenterObj)) )
2945 ((BranchObj*)selection)->setIncludeImagesVer(b);
2946 mapCenter->reposition();
2949 void MapEditor::setIncludeImagesHor(bool b)
2952 (typeid(*selection) == typeid(BranchObj)) ||
2953 (typeid(*selection) == typeid(MapCenterObj)) )
2954 ((BranchObj*)selection)->setIncludeImagesHor(b);
2955 mapCenter->reposition();
2958 void MapEditor::setHideLinkUnselected (bool b)
2961 (typeid(*selection) == typeid(BranchObj)) ||
2962 (typeid(*selection) == typeid(MapCenterObj)) ||
2963 (typeid(*selection) == typeid(FloatImageObj)) )
2964 selection->setHideLinkUnselected(b);
2967 void MapEditor::importDir(BranchObj *dst, QDir d)
2970 (typeid(*selection) == typeid(BranchObj)) ||
2971 (typeid(*selection) == typeid(MapCenterObj)) )
2975 // Traverse directories
2976 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2977 QFileInfoList list = d.entryInfoList();
2980 for (int i = 0; i < list.size(); ++i)
2983 if (fi.fileName() != "." && fi.fileName() != ".." )
2986 bo=dst->getLastBranch();
2987 bo->setHeading (fi.fileName() );
2988 bo->setColor (QColor("blue"));
2990 if ( !d.cd(fi.fileName()) )
2991 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
2994 // Recursively add subdirs
3001 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
3002 list = d.entryInfoList();
3004 for (int i = 0; i < list.size(); ++i)
3008 bo=dst->getLastBranch();
3009 bo->setHeading (fi.fileName() );
3010 bo->setColor (QColor("black"));
3011 if (fi.fileName().right(4) == ".vym" )
3012 bo->setVymLink (fi.filePath());
3017 void MapEditor::importDir()
3020 (typeid(*selection) == typeid(BranchObj)) ||
3021 (typeid(*selection) == typeid(MapCenterObj)) )
3023 Q3FileDialog *fd=new Q3FileDialog( this,__VYM " - " +tr("Choose directory structure to import"));
3024 fd->setMode (Q3FileDialog::DirectoryOnly);
3025 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
3026 fd->setCaption(__VYM " - " +tr("Choose directory structure to import"));
3030 if ( fd->exec() == QDialog::Accepted )
3032 BranchObj *bo=((BranchObj*)selection);
3033 importDir (bo,QDir(fd->selectedFile()) );
3034 mapCenter->reposition();
3041 void MapEditor::followXLink(int i)
3044 (typeid(*selection) == typeid(BranchObj)) ||
3045 (typeid(*selection) == typeid(MapCenterObj)) )
3047 BranchObj *bo=((BranchObj*)selection)->XLinkTargetAt(i);
3050 selection->unselect();
3052 selection->select();
3053 ensureSelectionVisible();
3058 void MapEditor::editXLink(int i)
3061 (typeid(*selection) == typeid(BranchObj)) ||
3062 (typeid(*selection) == typeid(MapCenterObj)) )
3064 XLinkObj *xlo=((BranchObj*)selection)->XLinkAt(i);
3067 EditXLinkDialog dia;
3069 dia.setSelection(selection);
3070 if (dia.exec() == QDialog::Accepted)
3072 if (dia.useSettingsGlobal() )
3074 setDefXLinkColor (xlo->getColor() );
3075 setDefXLinkWidth (xlo->getWidth() );
3077 if (dia.deleteXLink())
3078 ((BranchObj*)selection)->deleteXLinkAt(i);
3079 saveState("Edit xLink"); //TODO undoCommand
3085 void MapEditor::testFunction()
3087 cout << "MapEditor::testFunction() called\n";
3089 mapCenter->positionBBox();
3093 dia.setCancelButton (true);
3094 dia.setText("This is a longer \nWarning");
3095 dia.setCaption("Warning: Flux problem");
3096 dia.setShowAgainName("/vym/warnings/mapeditor");
3097 if (dia.exec()==QDialog::Accepted)
3098 cout << "accepted!\n";
3100 cout << "canceled!\n";
3103 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
3104 Q3Process *proc = new Q3Process( this );
3105 proc->addArgument(ub);
3107 if ( !proc->start() )
3109 QMessageBox::warning(0,
3111 tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
3116 if (hidemode==HideNone)
3118 setHideTmpMode (HideExport);
3119 mapCenter->calcBBoxSizeWithChilds();
3120 QRect totalBBox=mapCenter->getTotalBBox();
3121 QRect mapRect=totalBBox;
3122 QCanvasRectangle *frame=NULL;
3124 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
3126 mapRect.setRect (totalBBox.x(), totalBBox.y(),
3127 totalBBox.width(), totalBBox.height());
3128 frame=new QCanvasRectangle (mapRect,mapCanvas);
3129 frame->setBrush (QColor(white));
3130 frame->setPen (QColor(black));
3136 setHideTmpMode (HideNone);
3138 cout <<" hidemode="<<hidemode<<endl;
3142 void MapEditor::ensureSelectionVisible()
3146 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
3148 if (selection->getOrientation() == OrientLeftOfCenter)
3149 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
3151 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
3152 ensureVisible (p.x(), p.y() );
3157 void MapEditor::updateViewCenter()
3159 // Update movingCenter, so that we can zoom comfortably later
3160 QRect rc = QRect( contentsX(), contentsY(),
3161 visibleWidth(), visibleHeight() );
3162 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
3163 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
3164 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
3167 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
3169 // Lineedits are already closed by preceding
3170 // mouseEvent, we don't need to close here.
3172 QPoint p = inverseWorldMatrix().map(e->pos());
3173 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3176 { // MapObj was found
3177 if (selection != lmo)
3179 // select the MapObj
3180 if (selection) selection->unselect();
3182 selection->select();
3188 if (typeid(*selection)==typeid(BranchObj) ||
3189 typeid(*selection)==typeid(MapCenterObj) )
3191 // Context Menu on branch or mapcenter
3193 branchContextMenu->popup(e->globalPos() );
3195 if (typeid(*selection)==typeid(FloatImageObj))
3197 // Context Menu on floatimage
3199 floatimageContextMenu->popup(e->globalPos() );
3203 { // No MapObj found, we are on the Canvas itself
3204 // Context Menu on Canvas
3206 canvasContextMenu->popup(e->globalPos() );
3211 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
3213 // Ignore right clicks, these will go to context menus
3214 if (e->button() == Qt::RightButton )
3220 // Finish open lineEdits
3221 if (lineedit) finishedLineEdit();
3223 QPoint p = inverseWorldMatrix().map(e->pos());
3224 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3228 //Take care of clickdesystem flags _or_ modifier modes
3230 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
3231 typeid(*lmo)==typeid(MapCenterObj) ))
3233 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
3234 if (!foname.isEmpty())
3236 // systemFlag clicked
3240 if (e->state() & Qt::ControlModifier)
3241 mainWindow->editOpenURLTab();
3243 mainWindow->editOpenURL();
3245 else if (foname=="vymLink")
3247 mainWindow->editOpenVymLink();
3248 // tabWidget may change, better return now
3249 // before segfaulting...
3250 } else if (foname=="note")
3251 mainWindow->windowToggleNoteEditor();
3252 else if (foname=="hideInExport")
3257 // No system flag clicked, take care of modmodes
3259 // Special case: CTRL is pressed
3260 if (e->state() & Qt::ControlModifier)
3262 if (actionModModeColor->isOn())
3265 setCursor (pickColorCursor);
3268 if (actionModModeLink->isOn())
3270 BranchObj *bo_begin=NULL;
3272 bo_begin=(BranchObj*)(lmo);
3275 ((typeid(*selection) == typeid(BranchObj)) ||
3276 (typeid(*selection) == typeid(MapCenterObj))) )
3277 bo_begin=(BranchObj*)selection;
3281 linkingObj_src=bo_begin;
3282 tmpXLink=new XLinkObj (mapCanvas);
3283 tmpXLink->setBegin (bo_begin);
3284 tmpXLink->setEnd (p);
3285 tmpXLink->setColor(defXLinkColor);
3286 tmpXLink->setWidth(defXLinkWidth);
3287 tmpXLink->updateXLink();
3288 tmpXLink->setVisibility (true);
3296 // Left Button Move Branches
3297 if (e->button() == Qt::LeftButton )
3299 movingObj_start.setX( p.x() - selection->x() );
3300 movingObj_start.setY( p.y() - selection->y() );
3301 movingObj_orgPos.setX (lmo->x() );
3302 movingObj_orgPos.setY (lmo->y() );
3304 // If modMode==copy, then we want to "move" the _new_ object around
3305 // then we need the offset from p to the _old_ selection, because of tmp
3306 if (actionModModeCopy->isOn() &&
3307 e->state() & Qt::ControlModifier)
3309 if (typeid(*selection)==typeid(BranchObj) )
3312 mapCenter->addBranch ((BranchObj*)selection);
3314 selection=mapCenter->getLastBranch();
3315 selection->select();
3316 mapCenter->reposition();
3319 movingObj=selection;
3321 // Middle Button Toggle Scroll
3322 // (On Mac OS X this won't work, but we still have
3323 // a button in the toolbar)
3324 if (e->button() == Qt::MidButton )
3328 { // No MapObj found, we are on the Canvas itself
3329 // Left Button move Pos of CanvasView
3330 if (e->button() == Qt::LeftButton )
3332 movingObj=NULL; // move Content not Obj
3333 movingObj_start=e->globalPos();
3334 movingCont_start=QPoint (contentsX(), contentsY() );
3335 movingVec=QPoint(0,0);
3336 setCursor(handOpenCursor);
3341 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3343 QPoint p = inverseWorldMatrix().map(e->pos());
3345 // Move the selected MapObj
3346 if ( selection && movingObj)
3348 // To avoid jumping of the CanvasView, only
3349 // ensureSelectionVisible, if not tmp linked
3350 if (!selection->hasParObjTmp())
3351 ensureSelectionVisible ();
3353 // Now move the selection, but add relative position
3354 // (movingObj_start) where selection was chosen with
3355 // mousepointer. (This avoids flickering resp. jumping
3356 // of selection back to absPos)
3358 LinkableMapObj *lmosel;
3359 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3361 // Check if we could link
3362 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3365 if (typeid(*selection) == typeid(FloatImageObj))
3367 FloatObj *fo=(FloatObj*)selection;
3369 "move "+qpointToString(movingObj_orgPos),fo->getSelectString() ,
3370 QString("Move %1").arg(getName(selection)));
3371 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3375 // Relink float to new mapcenter or branch, if shift is pressed
3376 // Only relink, if selection really has a new parent
3377 if ( (e->state() & Qt::ShiftModifier) && lmo &&
3378 ( (typeid(*lmo)==typeid(BranchObj)) ||
3379 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3380 ( lmo != fo->getParObj())
3383 if (typeid(*fo) == typeid(FloatImageObj))
3385 saveState(QString("Relink %1 to %2").arg(getName(fo)).arg(getName(lmo) ) );
3386 FloatImageObj *fio=(FloatImageObj*)(fo);
3387 ((BranchObj*)(lmo))->addFloatImage (fio);
3389 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3390 fio=((BranchObj*)(lmo))->getLastFloatImage();
3393 selection=(LinkableMapObj*)(fio);
3394 selection->select();
3395 movingObj=(MapObj*)(fio);
3398 } else // selection != a FloatObj
3400 if (lmosel->getDepth()==0)
3402 if (e->state() == Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
3403 // If mapCenter is moved, move all the rest by default, too.
3404 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3406 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3409 if (lmosel->getDepth()==1)
3411 // depth==1, mainbranch
3412 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3416 if (lmosel->getOrientation() == OrientLeftOfCenter)
3417 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3418 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3419 p.y()-movingObj_start.y() +lmosel->getTopPad() );
3421 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
3423 // reposition subbranch
3424 lmosel->reposition();
3425 //ensureSelectionVisible();
3427 if (lmo && (lmo!=selection) &&
3428 (typeid(*lmo) == typeid(BranchObj) ||
3429 (typeid(*lmo) == typeid(MapCenterObj) )
3432 if (e->state() & Qt::ControlModifier)
3434 // Special case: CTRL to link below lmo
3435 lmosel->setParObjTmp (lmo,p,+1);
3437 else if (e->state() & Qt::ShiftModifier)
3438 lmosel->setParObjTmp (lmo,p,-1);
3440 lmosel->setParObjTmp (lmo,p,0);
3443 lmosel->unsetParObjTmp();
3447 } // no FloatImageObj
3451 } // selection && moving_obj
3453 // Draw a link from one branch to another
3456 tmpXLink->setEnd (p);
3457 tmpXLink->updateXLink();
3461 if (!movingObj && !pickingColor &&!drawingLink)
3463 QPoint p=e->globalPos();
3464 movingVec.setX(-p.x() + movingObj_start.x() );
3465 movingVec.setY(-p.y() + movingObj_start.y() );
3466 setContentsPos( movingCont_start.x() + movingVec.x(),
3467 movingCont_start.y() + movingVec.y());
3474 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3476 LinkableMapObj *dst;
3477 // Have we been picking color?
3481 setCursor (Qt::ArrowCursor);
3482 // Check if we are over another branch
3483 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3484 if (dst && selection)
3486 if (e->state() & Qt::ShiftModifier)
3488 ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor());
3489 ((BranchObj*)selection)->setLinkColor ();
3493 ((BranchObj*)selection)->setColorChilds (((BranchObj*)(dst))->getColor());
3494 ((BranchObj*)selection)->setLinkColor ();
3500 // Have we been drawing a link?
3504 // Check if we are over another branch
3505 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3506 if (dst && selection)
3508 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3509 tmpXLink->updateXLink();
3510 tmpXLink->activate();
3511 saveState(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) ); //TODO undoCommand
3520 // Have we been moving something?
3521 if ( selection && movingObj )
3523 // Moved FloatObj? Maybe we need to reposition
3524 if(typeid(*selection)==typeid (FloatImageObj))
3526 selection->getParObj()->requestReposition();
3527 mapCenter->reposition();
3530 // Check if we are over another branch, but ignore
3531 // any found LMOs, which are FloatObjs
3532 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3533 ((LinkableMapObj*)selection) );
3535 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
3538 // Now check, if we have been moving a branch
3539 if (typeid(*selection) == typeid(BranchObj) )
3541 // save the position in case we link to mapcenter
3542 QPoint savePos=QPoint (selection->x(),selection->y() );
3544 // Reset the temporary drawn link to the original one
3545 ((LinkableMapObj*)selection)->unsetParObjTmp();
3551 BranchObj* bs=((BranchObj*)selection);
3552 QString undoCom="linkBranchToPos (\""+
3553 (bs->getParObj())->getSelectString()+
3555 QString("%1").arg(bs->getNum())+
3557 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+
3559 // TODO we also could check, if dest and src are on same branch,
3560 // then it would be sufficient to saveState of this branch
3562 // Modifiers allow to insert above/below dst
3563 if (e->state() & Qt::ShiftModifier)
3565 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum());
3567 if (e->state() & Qt::ControlModifier)
3569 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum()+1);
3572 bs->moveBranchTo ((BranchObj*)(dst),-1);
3573 if (dst->getDepth()==0)
3576 saveState (undoCom,bs->getSelectString(),QString("Relink %1 to %2").arg(getName(bs)).arg(getName(dst)) );
3578 if (selection->getDepth()==1)
3579 // If we have moved mainbranch only save endposition
3580 saveState("move "+qpointToString(movingObj_orgPos), selection->getSelectString(), QString("Move %1 to %2").arg(getName(selection)).arg(qpointToString(movingObj_orgPos)));
3582 // Draw the original link, before selection was moved around
3583 mapCenter->reposition();
3585 // Finally resize canvas, if needed
3590 // maybe we moved View: set old cursor
3591 setCursor (Qt::ArrowCursor);
3595 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3597 // Finish open lineEdits
3598 if (lineedit) finishedLineEdit();
3600 if (e->button() == Qt::LeftButton )
3602 QPoint p = inverseWorldMatrix().map(e->pos());
3603 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3604 if (lmo) { // MapObj was found
3605 // First select the MapObj than edit heading
3606 if (selection) selection->unselect();
3608 selection->select();
3614 void MapEditor::resizeEvent (QResizeEvent* e)
3616 Q3CanvasView::resizeEvent( e );
3620 void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3623 // for (unsigned int i=0;event->format(i);i++) // Debug mime type
3624 // cerr << event->format(i) << endl;
3627 (typeid(*selection) == typeid(BranchObj)) ||
3628 (typeid(*selection) == typeid(MapCenterObj))) {
3630 // If QImageDrag can decode mime type
3631 if (Q3ImageDrag::canDecode(event)) {
3636 // If image are dragged from firefox
3637 if (event->provides("application/x-moz-file-promise-url") &&
3638 event->provides("application/x-moz-nativeimage")) {
3639 event->accept(true);
3643 // If QUriDrag can decode mime type
3644 if (Q3UriDrag::canDecode(event)) {
3649 // If Uri are dragged from firefox
3650 if (event->provides("_NETSCAPE_URL")){
3655 // If QTextDrag can decode mime type
3656 if (Q3TextDrag::canDecode(event)) {
3665 bool isUnicode16(const QByteArray &d)
3667 // TODO: make more precise check for unicode 16.
3668 // Guess unicode16 if any of second bytes are zero
3669 unsigned int length = max(0,d.size()-2)/2;
3670 for (unsigned int i = 0; i<length ; i++)
3671 if (d.at(i*2+1)==0) return true;
3675 void MapEditor::contentsDropEvent(QDropEvent *event)
3678 (typeid(*selection) == typeid(BranchObj)) ||
3679 (typeid(*selection) == typeid(MapCenterObj)))
3684 if (event->provides("image/png"))
3687 if (Q3ImageDrag::decode(event, pix))
3695 } else if (event->provides("application/x-moz-file-promise-url") &&
3696 event->provides("application/x-moz-nativeimage"))
3698 // Contains url to the img src in unicode16
3699 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3700 QString url = QString((const QChar*)d.data(),d.size()/2);
3704 } else if (event->provides ("text/uri-list"))
3705 { // Uris provided e.g. by konqueror
3706 Q3UriDrag::decode (event,uris);
3707 } else if (event->provides ("_NETSCAPE_URL"))
3708 { // Uris provided by Mozilla
3709 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
3712 } else if (event->provides("text/html")) {
3714 // Handels text mime types
3715 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
3716 QByteArray d = event->encodedData("text/html");
3719 text = QString((const QChar*)d.data(),d.size()/2);
3723 textEditor->setText(text);
3727 } else if (event->provides("text/plain")) {
3728 QByteArray d = event->encodedData("text/plain");
3731 text = QString((const QChar*)d.data(),d.size()/2);
3735 textEditor->setText(text);
3747 for (const char* u=uris.first(); u; u=uris.next())
3749 bo=((BranchObj*)selection)->addBranch();
3752 s=Q3UriDrag::uriToLocalFile(u);
3755 QString file = QDir::convertSeparators(s);
3756 heading = QFileInfo(file).baseName();
3758 if (file.endsWith(".vym", false))
3759 bo->setVymLink(file);
3768 if (!heading.isEmpty())
3769 bo->setHeading(heading);
3779 //FIXME saveState has to be called earlier for each of the drops...
3780 saveState("Drop Event"); //TODO undo Command
3781 mapCenter->reposition();
3788 void MapEditor::addFloatImage(const QPixmap &img)
3791 (typeid(*selection) == typeid(BranchObj)) ||
3792 (typeid(*selection) == typeid(MapCenterObj)) )
3794 BranchObj *bo=((BranchObj*)selection);
3795 saveState(selection,QString("Add floatimage to %1").arg(getName(bo)));
3796 //QString fn=fd->selectedFile();
3797 //lastImageDir=fn.left(fn.findRev ("/"));
3798 bo->addFloatImage();
3799 // FIXME check if load was successful
3800 bo->getLastFloatImage()->load(img);
3801 //bo->getLastFloatImage()->setOriginalFilename(fn);
3802 mapCenter->reposition();
3809 void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation */*nop*/)
3811 if (!imageBuffer) imageBuffer = new QBuffer();
3812 if (!imageBuffer->isOpen()) {
3813 imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
3815 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
3819 void MapEditor::imageDataFinished(Q3NetworkOperation *nop)
3821 if (nop->state()==Q3NetworkProtocol::StDone) {
3822 QPixmap img(imageBuffer->buffer());
3827 imageBuffer->close();
3829 imageBuffer->close();
3836 void MapEditor::fetchImage(const QString &url)
3839 urlOperator->stop();
3840 disconnect(urlOperator);
3844 urlOperator = new Q3UrlOperator(url);
3845 connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)),
3846 this, SLOT(imageDataFinished(Q3NetworkOperation*)));
3848 connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
3849 this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));