mapeditor.h
author insilmaril
Wed, 20 Jun 2007 11:58:46 +0000
changeset 521 27cb122a88a6
parent 520 0ccc00c05a22
child 526 eacf1b165d2d
permissions -rw-r--r--
Added center function
     1 #ifndef MAPEDITOR_H
     2 #define MAPEDITOR_H
     3 
     4 #include <QGraphicsView>
     5 
     6 #include "mapcenterobj.h"
     7 #include "file.h"
     8 #include "misc.h"
     9 #include "parser.h"
    10 #include "ornamentedobj.h"
    11 #include "selection.h"
    12 #include "settings.h"
    13 
    14 
    15 /*! \brief Main widget in vym to display and edit a map */
    16 
    17 class MapEditor : public QGraphicsView, public xmlObj {
    18     Q_OBJECT
    19 
    20 public:
    21     /*! \brief State of the mapeditor 
    22 		
    23 		While a heading is edited, the state has to change, so
    24 		that e.g. no other object might get selected. This is done
    25 		in Main by calling setStateEditHeading
    26 	*/
    27 	enum State {
    28 		Idle,			//!< Idle, waiting for user event
    29 		EditHeading		//!< Editing heading (dont't select another branch now)
    30 	};
    31     MapEditor(QWidget* parent=0);
    32 	~MapEditor();
    33     MapCenterObj* getMapCenter();		//!< Return center of map
    34 	QGraphicsScene * getScene();
    35 	State getState();					//!< Return State of MapEditor
    36 	void setStateEditHeading (bool);	//!< If set to true, State will change to EditHeading
    37 	bool isRepositionBlocked(); //!< While load or undo there is no need to update graphicsview
    38 	bool isSaveStateBlocked();			//!< block while undo/redo or while running scripts
    39 	void setSaveStateBlocked(bool);		//!< block saving the undo/redo state
    40 	bool isSelectBlocked();		//!< true, if no change of selection is possible, e.g. while editing the heading of abranch
    41 	
    42 protected:
    43 	/*! \brief Get name of object
    44 	  
    45 	  Returns heading of a branch or name of an object for use in comment
    46 	  of undo/redo history
    47 	*/ 
    48 	QString getName(const LinkableMapObj*);	// Get e.g. heading or filename
    49 	void makeTmpDirs();		// create temporary directories
    50 
    51 	/*! This function saves all information of the map to disc.
    52 	    saveToDir also calls the functions for all BranchObj and other objects in the map.
    53 		The structure of the map itself is returned as QString and passed back to Main, 
    54 		where saveToDir is called initially
    55 	*/	
    56     QString saveToDir (const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel);
    57 
    58 	/*! \brief Get directory, where current step in history is save
    59 
    60 		saveState creates a directory for each step in history. This function returns the
    61 		path of the current directory
    62 	*/
    63 	QString getHistoryDir();
    64 
    65 	/*! \brief Save the current changes in map 
    66 
    67 		Two commands and selections are saved:
    68 
    69 			- undocommand and undoselection to undo the change
    70 			- redocommand and redoselection to redo the action after an undo
    71 
    72 		Additionally a comment is logged. 
    73 
    74 	*/	
    75     void saveState(const SaveMode& savemode, const QString &undoSelection, const QString &undoCommand, const QString &redoSelection, const QString &redoCommand, const QString &comment, LinkableMapObj *saveSelection);
    76 	/*! Overloaded for convenience */
    77     void saveStateChangingPart(LinkableMapObj *undoSelection, LinkableMapObj* redoSelection, const QString &redoCommand, const QString &comment);
    78 	/*! Overloaded for convenience */
    79     void saveStateRemovingPart(LinkableMapObj *redoSelection, const QString &comment);
    80 	/*! Overloaded for convenience */
    81     void saveState(LinkableMapObj *undoSelection, const QString &undoCommand, LinkableMapObj *redoSelection, const QString &redoCommand, const QString &comment); 
    82 	/*! Overloaded for convenience */
    83     void saveState(const QString &undoSelection, const QString &undoCommand, const QString &redoSelection, const QString &redoCommand, const QString &comment) ;
    84 
    85 public:	
    86 
    87 	/* \brief Process one command and its parameters */
    88     void parseAtom (const QString &atom);	
    89 
    90 	/* \brief Runs the script */
    91 	void runScript (QString script);
    92 private:
    93     void addFloatImageInt(const QPixmap &img);
    94 
    95 public:
    96 	bool isDefault();		//!< true, if map is still the empty default map
    97     bool hasChanged();		//!< true, if something has changed and is not saved yet
    98 	void setChanged();		//!< called from TextEditor via LinkableMapObj
    99 	void closeMap();		//!< Closes the map
   100 
   101 	/*! \brief Sets filepath, filename and mapname
   102 
   103 	     If the filepath is "/home/tux/map.xml", then the filename will be set
   104 		 to map.xml. The destname is needed for vymLinks, pointing to another map. 
   105 		 The destname holds the real name of the file, after it has been compressed, e.g. "map.vym"
   106 	*/	 
   107 
   108 	/*! \brief Set File path
   109 
   110 	     The destname is needed to construct the references between maps
   111 	*/	 
   112 	void setFilePath (QString filepath,QString destname);	
   113 	void setFilePath (QString);	//!< Overloaded for convenience
   114 	QString getFilePath ();	//!< Full path e.g. "/home/tux/map.xml"
   115 	QString getFileName ();	//!< e.g. "map.xml"
   116 	QString getMapName ();	//!< e.g. "map"
   117 	QString getDestPath (); //!< e.g. "/home/tux/map.vym"
   118 
   119 	/*! \brief Load map
   120 
   121 		The data is read from file. Depending on LoadMode the current
   122 		selection gets replaced by data or the data is appended.
   123 	*/	
   124     ErrorCode load (QString, LoadMode );	// newmap, import/replace selection
   125 public:
   126 	/*! \brief Save the map to file */
   127     int save(const SaveMode &);	
   128 	void setZipped(bool);		//!< Set or unset compression of map with zip save map zipped
   129 	bool saveZipped();			//!< True, if file will be saved zipped
   130     void print();				//!< Print the map
   131 	void setAntiAlias (bool);	//!< Set or unset antialiasing
   132 	void setSmoothPixmap(bool); //!< Set or unset smoothing of pixmaps
   133 private:
   134     QPixmap getPixmap();
   135 	void setHideTmpMode (BranchObj::HideTmpMode);	// temporary hide stuff
   136 	BranchObj::HideTmpMode getHideTmpMode();		// temporary hide stuff
   137 public:
   138 	/*! Set or unset temporary hiding of objects during export  */
   139 	void setExportMode (bool);
   140 
   141 	/*! Export as ASCII text to file */
   142 	void exportASCII (QString fname="",bool askForName=true);  
   143 
   144 	/*! Save as image */
   145     void exportImage (QString fname="",bool askForName=true,QString format="PNG");
   146 
   147     /*! Export as OpenOfficeOrg presentation */
   148     void exportOOPresentation(const QString &,const QString &);	
   149 
   150 	/*! Export as XHTML to directory */
   151     void exportXHTML(const QString& dir="", bool askForName=true);	
   152 
   153 	/*! Export as XTML to directory */
   154     void exportXML(const QString& dir="");
   155 
   156     void clear();						//!< Clear map
   157     void copy();						//!< Copy to clipboard
   158     void redo();						//!< Redo last action
   159 	bool isRedoAvailable();				//!< True, if redo is available
   160     void undo();						//!< Undo last action
   161 	bool isUndoAvailable();				//!< True, if undo is available
   162 	void gotoHistoryStep (int);			//!< Goto a specifig step in history
   163 private:	
   164     void addMapReplaceInt(const QString & undoSel, const QString & path);
   165     void addMapInsertInt (const QString & path, int pos);
   166     void pasteNoSave(const int &n);		//!< paste clipboard to branch
   167 public:	
   168     void paste();		//!< Paste clipboard to branch and backup
   169     void cut();			//!< Cut to clipboard (and copy)
   170 	/*! \brief Move absolutly
   171 
   172 		Move absolutly to (x,y).
   173 	*/	
   174     void move    (const int &x, const int &y);
   175 	/*! \brief Move relativly
   176 
   177 		Move relativly to (x,y).
   178 	*/	
   179     void moveRel (const int &x, const int &y);
   180     void moveBranchUp();	//!< Move branch up
   181     void moveBranchDown();	//!< Move branch down
   182 private:	
   183 	void linkTo(const QString &);
   184 public:	
   185 	QString getHeading (bool &ok,QPoint &p); //!< Get heading, ok if selection is branch
   186 	void setHeading(const QString &);		//!< Set heading of branch	
   187 private:
   188 	void setHeadingInt(const QString &);
   189 	void setVymLinkInt(const QString &);	// Set vymLink for selection
   190 	/*! \brief Add new branch
   191 
   192 		Depending on num the new branch is created
   193 
   194 		-3 above selection as child of selections parent
   195 		-2 as child of selection
   196 		-1 below selection as child of selections parent
   197 		0..n	insert at a specific position in selections parent
   198 		(needed for free relinking)
   199 	*/	
   200     BranchObj* addNewBranchInt(int);		// pos allows to add above/below selection
   201 public:	
   202 	/*! \Add new branch
   203 		
   204 		Depending on num the new branch is created
   205 		-1 above selection
   206 		 0 as child of selection
   207 		 1 below selection
   208 	*/
   209     BranchObj* addNewBranch(int pos);		
   210     BranchObj* addNewBranchBefore();		//!< Insert branch between selection and its parent
   211     void deleteSelection();					//!< Delete selection
   212 	LinkableMapObj* getSelection();			//!< Returns selection
   213 	BranchObj* getSelectedBranch();			// returns selected branch or NULL
   214 	FloatImageObj* getSelectedFloatImage();	// returns selected branch or NULL
   215 	void unselect();						// before changing current noteedit
   216 	void reselect();						// after  changing current noteedit
   217 	bool select(const QString &);			// Select by string
   218 	QString getSelectString();
   219 private:	
   220 	void selectInt(LinkableMapObj*);	
   221 	void selectNextBranchInt();		// Increment number of branch
   222 	void selectPrevBranchInt();		// Decrement number of branch
   223 public:	
   224     void selectUpperBranch();
   225     void selectLowerBranch();
   226     void selectLeftBranch();
   227     void selectRightBranch();
   228     void selectFirstBranch();
   229     void selectLastBranch();
   230     void selectMapBackgroundImage();
   231     void setMapBackgroundImage(const QString &);
   232     void selectMapBackgroundColor();
   233     void setMapBackgroundColor(QColor);
   234     QColor getMapBackgroundColor();
   235     QColor getCurrentHeadingColor();
   236     void colorBranch(QColor);
   237     void colorSubtree(QColor);
   238 	void toggleStandardFlag(QString);
   239     BranchObj* findText(QString,bool);		// Find object
   240     void findReset();						// Reset Find 
   241 	void setURL(const QString &);			// set the URL
   242 	void editURL();							// edit the URL
   243 	QString getURL();						// returns URL of selection or ""
   244 	QStringList getURLs();					// returns URLs of subtree
   245 	void editHeading2URL();					// copy heading to URL
   246 	void editBugzilla2URL();				// create URL to Bugzilla
   247 	void editFATE2URL();					// create URL to FATE
   248 	void editVymLink();						// edit link to another map
   249 	void deleteVymLink();					// delete link to another map
   250 	QString getVymLink();					// return path to map
   251 	QStringList getVymLinks();				// return paths in subtree
   252 	void setHideExport(bool);				// toggle the export flag
   253 	void toggleHideExport();				// toggle the export flag
   254 	void deleteKeepChilds();				// remove but keep childs
   255 	void deleteChilds();					// remove childs
   256 	void editMapInfo();						// dialog to enter author, ...
   257 	void ensureSelectionVisible();		
   258 	void updateSelection();					// update geometry of selection
   259 	void updateActions();					// update e.g. format buttons
   260 	void updateNoteFlag();					// when TextEditor changes
   261 	void setMapAuthor (const QString &);
   262 	void setMapComment(const QString &);
   263 	void setMapLinkStyle (const QString &);	// Set style of link
   264 	LinkableMapObj::Style getMapLinkStyle ();	// requested in LMO
   265 	void setMapDefLinkColor(QColor);		// default color of links
   266 	void setMapLinkColorHintInt();			// color of links
   267 	void setMapLinkColorHint(LinkableMapObj::ColorHint);// color of links
   268 	LinkableMapObj::ColorHint getMapLinkColorHint();
   269 	QColor getMapDefLinkColor();
   270 	void setMapDefXLinkColor(QColor);
   271 	QColor getMapDefXLinkColor();
   272 	void setMapDefXLinkWidth (int);
   273 	int getMapDefXLinkWidth();
   274 	void toggleMapLinkColorHint();			// after changing linkStyles
   275     void selectMapLinkColor();
   276     void selectMapSelectionColor();
   277 private:	
   278     void setSelectionColorInt(QColor);
   279 public:	
   280     void setSelectionColor(QColor);
   281     QColor getSelectionColor();
   282 	bool scrollBranch(BranchObj*);
   283 	bool unscrollBranch(BranchObj*);
   284     void toggleScroll();
   285     void unscrollChilds();
   286 private:	
   287 	FloatImageObj* loadFloatImageInt (QString);
   288 public:	
   289 	void loadFloatImage ();
   290 private:	
   291 	void saveFloatImageInt (FloatImageObj*, const QString &, const QString &);
   292 public:	
   293 	void saveFloatImage ();
   294 	void setFrameType(const FrameObj::FrameType &);
   295 	void setFrameType(const QString &);
   296 	void setFramePenColor (const QColor &);
   297 	void setFrameBrushColor (const QColor &);
   298 	void setFramePadding (const int &);
   299 	void setFrameBorderWidth (const int &);
   300 	void setIncludeImagesVer(bool);
   301 	void setIncludeImagesHor(bool);
   302 	void setHideLinkUnselected (bool);
   303 	bool getHideLinkUnselected ();
   304 private:	
   305     void importDirInt(BranchObj *,QDir);
   306     void importDirInt(const QString&);
   307 public:	
   308     void importDir();
   309 	void followXLink (int);
   310 	void editXLink (int);
   311     void testFunction();					// just testing new stuff
   312 											// set /mainwindo/showTestMenu=true...
   313 
   314 protected:
   315 	virtual void contextMenuEvent ( QContextMenuEvent *e );
   316     virtual void keyPressEvent(QKeyEvent*);
   317     virtual void keyReleaseEvent(QKeyEvent*);
   318     virtual void mousePressEvent(QMouseEvent*);
   319     virtual void mouseMoveEvent(QMouseEvent*);
   320     virtual void mouseReleaseEvent(QMouseEvent*);
   321     virtual void mouseDoubleClickEvent(QMouseEvent*);
   322     virtual void resizeEvent( QResizeEvent * );
   323 
   324 	void dragEnterEvent (QDragEnterEvent *);
   325 	void dragMoveEvent (QDragMoveEvent *);
   326 	void dragLeaveEvent (QDragLeaveEvent *);
   327 	void dropEvent (QDropEvent *);
   328 
   329 	void timerEvent(QTimerEvent *event);
   330 
   331 private slots:	
   332 	void autosave ();
   333 
   334 private:
   335 	State state;				// State of MapEditor
   336 	QGraphicsScene *mapScene;
   337     MapCenterObj* mapCenter;
   338 	QTimer *autosaveTimer;
   339 
   340 	bool adjustCanvasRequested;	// collect requests until end of user event
   341 	BranchObj *editingBO;		// entering Text into BO
   342 
   343 	QColor defLinkColor;		// default color for links
   344 	QColor defXLinkColor;		// default color for xlinks
   345 	int defXLinkWidth;			// default width for xlinks
   346 	LinkableMapObj::ColorHint linkcolorhint;// use heading color or own color
   347 	LinkableMapObj::Style linkstyle;		// default style for links
   348 
   349     QCursor HandOpenCursor;		// cursor while moving canvas view
   350 	QCursor PickColorCursor;	// cursor while picking color 
   351 	QCursor CopyCursor;			// cursor while picking color 
   352 	QCursor XLinkCursor;		// cursor while picking color 
   353 	bool pickingColor;
   354 	bool drawingLink;			// true while creating a link
   355 	bool copyingObj;			// true while creating a link
   356 	XLinkObj* tmpXLink;
   357 
   358 	Selection xelection;	
   359     MapObj* movingObj;				// moving a MapObj
   360 	MapObj* linkingObj_src;			// part of a link
   361     QPointF movingObj_orgPos;		// org. pos of mouse before move
   362     QPointF movingObj_orgRelPos;	// org. relative pos of mouse before move
   363     QPointF movingObj_start;		// rel. pos of mouse to absPos 
   364     QPointF movingCont_start;		// inital pos of moving Content or
   365     QPointF movingVec;				// how far has Content moved
   366     QPrinter* printer;				// Printing
   367 
   368     bool mapDefault;				// Flag if map is untouched
   369     bool mapChanged;				// Flag if undo is possible
   370 	bool mapUnsaved;				// Flag if map should be saved
   371 
   372 	Parser parser;				// Parser stuff for scripting
   373 
   374 	bool printFrame;			// Print frame around map
   375 	bool printFooter;			// Print footer below map
   376 
   377 	bool zipped;				// should map be zipped
   378 	static	int mapNum;			// unique number for Editor
   379 	QString fileName;			// short name of file (for tab)
   380 	QString filePath;			// path to file which will be saved
   381 	QString fileDir;			// dir where file is saved
   382 	QString destPath;			// path to .vym file (needed for vymlinks)
   383 	QString mapName;			// fileName without ".vym"
   384 
   385 	QString tmpMapDir;			// tmp directory with undo history
   386 	QString histPath;			// Path to history file
   387 	SimpleSettings undoSet;		// undo/redo commands, saved in histPath
   388 	int stepsTotal;				// total number of steps (undos+redos) 
   389 	int curStep;				// Current step in history (ring buffer)
   390 	int curClipboard;			// number of history step, which is the current clipboard
   391 	int redosAvail;				// Available number of redo steps
   392 	int undosAvail;				// Available number of undo steps
   393 	bool blockReposition;		// block while load or undo
   394 	bool blockSaveState;		// block while load or undo
   395 
   396 	BranchObj* itFind;			// next object in find process
   397 	bool EOFind;				// true, if search failed
   398 
   399 	QPoint exportOffset;		// set before export, used in save
   400 	BranchObj::HideTmpMode hidemode;	// true while exporting to hide some stuff
   401 
   402 	int timerId;				// animation timer
   403 	QList <MapObj*> animObjList;// list with animated objects
   404 };
   405 #endif
   406