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