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