mapeditor.h
author insilmaril
Wed, 20 Jun 2007 10:51:44 +0000
changeset 515 f396157bbb06
parent 514 497fab7d1404
child 517 b525fdd445c4
permissions -rw-r--r--
scripted exports (continued)
     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 	void setExportMode (bool);			//!< Set or unset temporary hiding of objects during export
   139 	void exportASCII (QString fname="",bool askForName=true);  	//!< Export as ASCII
   140 
   141 	/*! Save as image */
   142     void exportImage (QString fname="",bool askForName=true,QString format="PNG");
   143     void exportOOPresentation(const QString &,const QString &);	//!< Export as OpenOfficeOrg presentation
   144     void exportXML(const QString&);		//!< Export as XML to directory
   145     void clear();						//!< Clear map
   146     void copy();						//!< Copy to clipboard
   147     void redo();						//!< Redo last action
   148 	bool isRedoAvailable();				//!< True, if redo is available
   149     void undo();						//!< Undo last action
   150 	bool isUndoAvailable();				//!< True, if undo is available
   151 	void gotoHistoryStep (int);			//!< Goto a specifig step in history
   152 private:	
   153     void addMapReplaceInt(const QString & undoSel, const QString & path);
   154     void addMapInsertInt (const QString & path, int pos);
   155     void pasteNoSave(const int &n);		//!< paste clipboard to branch
   156 public:	
   157     void paste();		//!< Paste clipboard to branch and backup
   158     void cut();			//!< Cut to clipboard (and copy)
   159 	/*! \brief Move absolutly
   160 
   161 		Move absolutly to (x,y).
   162 	*/	
   163     void move    (const int &x, const int &y);
   164 	/*! \brief Move relativly
   165 
   166 		Move relativly to (x,y).
   167 	*/	
   168     void moveRel (const int &x, const int &y);
   169     void moveBranchUp();	//!< Move branch up
   170     void moveBranchDown();	//!< Move branch down
   171 private:	
   172 	void linkTo(const QString &);
   173 public:	
   174 	QString getHeading (bool &ok,QPoint &p); //!< Get heading, ok if selection is branch
   175 	void setHeading(const QString &);		//!< Set heading of branch	
   176 private:
   177 	void setHeadingInt(const QString &);
   178 	void setVymLinkInt(const QString &);	// Set vymLink for selection
   179 	/*! \brief Add new branch
   180 
   181 		Depending on num the new branch is created
   182 
   183 		-3 above selection as child of selections parent
   184 		-2 as child of selection
   185 		-1 below selection as child of selections parent
   186 		0..n	insert at a specific position in selections parent
   187 		(needed for free relinking)
   188 	*/	
   189     BranchObj* addNewBranchInt(int);		// pos allows to add above/below selection
   190 public:	
   191 	/*! \Add new branch
   192 		
   193 		Depending on num the new branch is created
   194 		-1 above selection
   195 		 0 as child of selection
   196 		 1 below selection
   197 	*/
   198     BranchObj* addNewBranch(int pos);		
   199     BranchObj* addNewBranchBefore();		//!< Insert branch between selection and its parent
   200     void deleteSelection();					//!< Delete selection
   201 	LinkableMapObj* getSelection();			//!< Returns selection
   202 	BranchObj* getSelectedBranch();			// returns selected branch or NULL
   203 	FloatImageObj* getSelectedFloatImage();	// returns selected branch or NULL
   204 	void unselect();						// before changing current noteedit
   205 	void reselect();						// after  changing current noteedit
   206 	bool select(const QString &);			// Select by string
   207 	QString getSelectString();
   208 private:	
   209 	void selectInt(LinkableMapObj*);	
   210 	void selectNextBranchInt();		// Increment number of branch
   211 	void selectPrevBranchInt();		// Decrement number of branch
   212 public:	
   213     void selectUpperBranch();
   214     void selectLowerBranch();
   215     void selectLeftBranch();
   216     void selectRightBranch();
   217     void selectFirstBranch();
   218     void selectLastBranch();
   219     void selectMapBackgroundImage();
   220     void setMapBackgroundImage(const QString &);
   221     void selectMapBackgroundColor();
   222     void setMapBackgroundColor(QColor);
   223     QColor getMapBackgroundColor();
   224     QColor getCurrentHeadingColor();
   225     void colorBranch(QColor);
   226     void colorSubtree(QColor);
   227 	void toggleStandardFlag(QString);
   228     BranchObj* findText(QString,bool);		// Find object
   229     void findReset();						// Reset Find 
   230 	void setURL(const QString &);			// set the URL
   231 	void editURL();							// edit the URL
   232 	QString getURL();						// returns URL of selection or ""
   233 	QStringList getURLs();					// returns URLs of subtree
   234 	void editHeading2URL();					// copy heading to URL
   235 	void editBugzilla2URL();				// create URL to Bugzilla
   236 	void editFATE2URL();					// create URL to FATE
   237 	void editVymLink();						// edit link to another map
   238 	void deleteVymLink();					// delete link to another map
   239 	QString getVymLink();					// return path to map
   240 	QStringList getVymLinks();				// return paths in subtree
   241 	void setHideExport(bool);				// toggle the export flag
   242 	void toggleHideExport();				// toggle the export flag
   243 	void deleteKeepChilds();				// remove but keep childs
   244 	void deleteChilds();					// remove childs
   245 	void editMapInfo();						// dialog to enter author, ...
   246 	void ensureSelectionVisible();		
   247 	void updateSelection();					// update geometry of selection
   248 	void updateActions();					// update e.g. format buttons
   249 	void updateNoteFlag();					// when TextEditor changes
   250 	void setMapAuthor (const QString &);
   251 	void setMapComment(const QString &);
   252 	void setMapLinkStyle (const QString &);	// Set style of link
   253 	LinkableMapObj::Style getMapLinkStyle ();	// requested in LMO
   254 	void setMapDefLinkColor(QColor);		// default color of links
   255 	void setMapLinkColorHintInt();			// color of links
   256 	void setMapLinkColorHint(LinkableMapObj::ColorHint);// color of links
   257 	LinkableMapObj::ColorHint getMapLinkColorHint();
   258 	QColor getMapDefLinkColor();
   259 	void setMapDefXLinkColor(QColor);
   260 	QColor getMapDefXLinkColor();
   261 	void setMapDefXLinkWidth (int);
   262 	int getMapDefXLinkWidth();
   263 	void toggleMapLinkColorHint();			// after changing linkStyles
   264     void selectMapLinkColor();
   265     void selectMapSelectionColor();
   266 private:	
   267     void setSelectionColorInt(QColor);
   268 public:	
   269     void setSelectionColor(QColor);
   270     QColor getSelectionColor();
   271 	bool scrollBranch(BranchObj*);
   272 	bool unscrollBranch(BranchObj*);
   273     void toggleScroll();
   274     void unscrollChilds();
   275 private:	
   276 	FloatImageObj* loadFloatImageInt (QString);
   277 public:	
   278 	void loadFloatImage ();
   279 private:	
   280 	void saveFloatImageInt (FloatImageObj*, const QString &, const QString &);
   281 public:	
   282 	void saveFloatImage ();
   283 	void setFrameType(const FrameObj::FrameType &);
   284 	void setFrameType(const QString &);
   285 	void setFramePenColor (const QColor &);
   286 	void setFrameBrushColor (const QColor &);
   287 	void setFramePadding (const int &);
   288 	void setFrameBorderWidth (const int &);
   289 	void setIncludeImagesVer(bool);
   290 	void setIncludeImagesHor(bool);
   291 	void setHideLinkUnselected (bool);
   292 	bool getHideLinkUnselected ();
   293 private:	
   294     void importDirInt(BranchObj *,QDir);
   295     void importDirInt(const QString&);
   296 public:	
   297     void importDir();
   298 	void followXLink (int);
   299 	void editXLink (int);
   300     void testFunction();					// just testing new stuff
   301 											// set /mainwindo/showTestMenu=true...
   302 
   303 protected:
   304 	virtual void contextMenuEvent ( QContextMenuEvent *e );
   305     virtual void keyPressEvent(QKeyEvent*);
   306     virtual void keyReleaseEvent(QKeyEvent*);
   307     virtual void mousePressEvent(QMouseEvent*);
   308     virtual void mouseMoveEvent(QMouseEvent*);
   309     virtual void mouseReleaseEvent(QMouseEvent*);
   310     virtual void mouseDoubleClickEvent(QMouseEvent*);
   311     virtual void resizeEvent( QResizeEvent * );
   312 
   313 	void dragEnterEvent (QDragEnterEvent *);
   314 	void dragMoveEvent (QDragMoveEvent *);
   315 	void dragLeaveEvent (QDragLeaveEvent *);
   316 	void dropEvent (QDropEvent *);
   317 
   318 	void timerEvent(QTimerEvent *event);
   319 
   320 private slots:	
   321 	void autosave ();
   322 
   323 private:
   324 	State state;				// State of MapEditor
   325 	QGraphicsScene *mapScene;
   326     MapCenterObj* mapCenter;
   327 	QTimer *autosaveTimer;
   328 
   329 	bool adjustCanvasRequested;	// collect requests until end of user event
   330 	BranchObj *editingBO;		// entering Text into BO
   331 
   332 	QColor defLinkColor;		// default color for links
   333 	QColor defXLinkColor;		// default color for xlinks
   334 	int defXLinkWidth;			// default width for xlinks
   335 	LinkableMapObj::ColorHint linkcolorhint;// use heading color or own color
   336 	LinkableMapObj::Style linkstyle;		// default style for links
   337 
   338     QCursor HandOpenCursor;		// cursor while moving canvas view
   339 	QCursor PickColorCursor;	// cursor while picking color 
   340 	QCursor CopyCursor;			// cursor while picking color 
   341 	QCursor XLinkCursor;		// cursor while picking color 
   342 	bool pickingColor;
   343 	bool drawingLink;			// true while creating a link
   344 	bool copyingObj;			// true while creating a link
   345 	XLinkObj* tmpXLink;
   346 
   347 	Selection xelection;	
   348     MapObj* movingObj;				// moving a MapObj
   349 	MapObj* linkingObj_src;			// part of a link
   350     QPointF movingObj_orgPos;		// org. pos of mouse before move
   351     QPointF movingObj_orgRelPos;	// org. relative pos of mouse before move
   352     QPointF movingObj_start;		// rel. pos of mouse to absPos 
   353     QPointF movingCont_start;		// inital pos of moving Content or
   354     QPointF movingVec;				// how far has Content moved
   355     QPrinter* printer;				// Printing
   356 
   357     bool mapDefault;				// Flag if map is untouched
   358     bool mapChanged;				// Flag if undo is possible
   359 	bool mapUnsaved;				// Flag if map should be saved
   360 
   361 	Parser parser;				// Parser stuff for scripting
   362 
   363 	bool printFrame;			// Print frame around map
   364 	bool printFooter;			// Print footer below map
   365 
   366 	bool zipped;				// should map be zipped
   367 	static	int mapNum;			// unique number for Editor
   368 	QString fileName;			// short name of file (for tab)
   369 	QString filePath;			// path to file which will be saved
   370 	QString fileDir;			// dir where file is saved
   371 	QString destPath;			// path to .vym file (needed for vymlinks)
   372 	QString mapName;			// fileName without ".vym"
   373 
   374 	QString tmpMapDir;			// tmp directory with undo history
   375 	QString histPath;			// Path to history file
   376 	SimpleSettings undoSet;		// undo/redo commands, saved in histPath
   377 	int stepsTotal;				// total number of steps (undos+redos) 
   378 	int curStep;				// Current step in history (ring buffer)
   379 	int curClipboard;			// number of history step, which is the current clipboard
   380 	int redosAvail;				// Available number of redo steps
   381 	int undosAvail;				// Available number of undo steps
   382 	bool blockReposition;		// block while load or undo
   383 	bool blockSaveState;		// block while load or undo
   384 
   385 	BranchObj* itFind;			// next object in find process
   386 	bool EOFind;				// true, if search failed
   387 
   388 	QPoint exportOffset;		// set before export, used in save
   389 	BranchObj::HideTmpMode hidemode;	// true while exporting to hide some stuff
   390 
   391 	int timerId;				// animation timer
   392 	QList <MapObj*> animObjList;// list with animated objects
   393 };
   394 #endif
   395