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