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