mapeditor.h
author insilmaril
Mon, 25 Jun 2007 12:54:19 +0000
changeset 528 36d140349897
parent 527 f19bbd639726
child 531 be24af55da40
permissions -rw-r--r--
1.8.75
     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  URL
   243 	void editURL();							// edit URL
   244 	void editLocalURL();					// edit URL to local file
   245 	QString getURL();						// returns URL of selection or ""
   246 	QStringList getURLs();					// returns URLs of subtree
   247 	void editHeading2URL();					// copy heading to URL
   248 	void editBugzilla2URL();				// create URL to Bugzilla
   249 	void editFATE2URL();					// create URL to FATE
   250 	void editVymLink();						// edit link to another map
   251 	void deleteVymLink();					// delete link to another map
   252 	QString getVymLink();					// return path to map
   253 	QStringList getVymLinks();				// return paths in subtree
   254 	void setHideExport(bool);				// toggle the export flag
   255 	void toggleHideExport();				// toggle the export flag
   256 	void deleteKeepChilds();				// remove but keep childs
   257 	void deleteChilds();					// remove childs
   258 	void editMapInfo();						// dialog to enter author, ...
   259 	void ensureSelectionVisible();		
   260 	void updateSelection();					// update geometry of selection
   261 	void updateActions();					// update e.g. format buttons
   262 	void updateNoteFlag();					// when TextEditor changes
   263 	void setMapAuthor (const QString &);
   264 	void setMapComment(const QString &);
   265 	void setMapLinkStyle (const QString &);	// Set style of link
   266 	LinkableMapObj::Style getMapLinkStyle ();	// requested in LMO
   267 	void setMapDefLinkColor(QColor);		// default color of links
   268 	void setMapLinkColorHintInt();			// color of links
   269 	void setMapLinkColorHint(LinkableMapObj::ColorHint);// color of links
   270 	LinkableMapObj::ColorHint getMapLinkColorHint();
   271 	QColor getMapDefLinkColor();
   272 	void setMapDefXLinkColor(QColor);
   273 	QColor getMapDefXLinkColor();
   274 	void setMapDefXLinkWidth (int);
   275 	int getMapDefXLinkWidth();
   276 	void toggleMapLinkColorHint();			// after changing linkStyles
   277     void selectMapLinkColor();
   278     void selectMapSelectionColor();
   279 private:	
   280     void setSelectionColorInt(QColor);
   281 public:	
   282     void setSelectionColor(QColor);
   283     QColor getSelectionColor();
   284 	bool scrollBranch(BranchObj*);
   285 	bool unscrollBranch(BranchObj*);
   286     void toggleScroll();
   287     void unscrollChilds();
   288 private:	
   289 	FloatImageObj* loadFloatImageInt (QString);
   290 public:	
   291 	void loadFloatImage ();
   292 private:	
   293 	void saveFloatImageInt (FloatImageObj*, const QString &, const QString &);
   294 public:	
   295 	void saveFloatImage ();
   296 	void setFrameType(const FrameObj::FrameType &);
   297 	void setFrameType(const QString &);
   298 	void setFramePenColor (const QColor &);
   299 	void setFrameBrushColor (const QColor &);
   300 	void setFramePadding (const int &);
   301 	void setFrameBorderWidth (const int &);
   302 	void setIncludeImagesVer(bool);
   303 	void setIncludeImagesHor(bool);
   304 	void setHideLinkUnselected (bool);
   305 	bool getHideLinkUnselected ();
   306 private:	
   307     void importDirInt(BranchObj *,QDir);
   308     void importDirInt(const QString&);
   309 public:	
   310     void importDir();
   311 	void followXLink (int);
   312 	void editXLink (int);
   313     void testFunction1();					// just testing new stuff
   314     void testFunction2();					// just testing new stuff
   315 											// set /mainwindo/showTestMenu=true...
   316 
   317 protected:
   318 	virtual void contextMenuEvent ( QContextMenuEvent *e );
   319     virtual void keyPressEvent(QKeyEvent*);
   320     virtual void keyReleaseEvent(QKeyEvent*);
   321     virtual void mousePressEvent(QMouseEvent*);
   322     virtual void mouseMoveEvent(QMouseEvent*);
   323     virtual void mouseReleaseEvent(QMouseEvent*);
   324     virtual void mouseDoubleClickEvent(QMouseEvent*);
   325     virtual void resizeEvent( QResizeEvent * );
   326 
   327 	void dragEnterEvent (QDragEnterEvent *);
   328 	void dragMoveEvent (QDragMoveEvent *);
   329 	void dragLeaveEvent (QDragLeaveEvent *);
   330 	void dropEvent (QDropEvent *);
   331 
   332 	void timerEvent(QTimerEvent *event);
   333 
   334 protected:
   335 	void sendSelection();
   336 
   337 public:
   338 	void newServer();
   339 
   340 private slots:	
   341 	void newClient();
   342 	void sendData(const QString &s);
   343 	void autosave ();
   344 
   345 private:
   346 	State state;				// State of MapEditor
   347 	QGraphicsScene *mapScene;
   348     MapCenterObj* mapCenter;
   349 	QTimer *autosaveTimer;
   350 
   351 	bool adjustCanvasRequested;	// collect requests until end of user event
   352 	BranchObj *editingBO;		// entering Text into BO
   353 
   354 	QColor defLinkColor;		// default color for links
   355 	QColor defXLinkColor;		// default color for xlinks
   356 	int defXLinkWidth;			// default width for xlinks
   357 	LinkableMapObj::ColorHint linkcolorhint;// use heading color or own color
   358 	LinkableMapObj::Style linkstyle;		// default style for links
   359 
   360     QCursor HandOpenCursor;		// cursor while moving canvas view
   361 	QCursor PickColorCursor;	// cursor while picking color 
   362 	QCursor CopyCursor;			// cursor while picking color 
   363 	QCursor XLinkCursor;		// cursor while picking color 
   364 	bool pickingColor;
   365 	bool drawingLink;			// true while creating a link
   366 	bool copyingObj;			// true while creating a link
   367 	XLinkObj* tmpXLink;
   368 
   369 	Selection xelection;	
   370     MapObj* movingObj;				// moving a MapObj
   371 	MapObj* linkingObj_src;			// part of a link
   372     QPointF movingObj_orgPos;		// org. pos of mouse before move
   373     QPointF movingObj_orgRelPos;	// org. relative pos of mouse before move
   374     QPointF movingObj_start;		// rel. pos of mouse to absPos 
   375     QPointF movingCont_start;		// inital pos of moving Content or
   376     QPointF movingVec;				// how far has Content moved
   377     QPrinter* printer;				// Printing
   378 
   379     bool mapDefault;				// Flag if map is untouched
   380     bool mapChanged;				// Flag if undo is possible
   381 	bool mapUnsaved;				// Flag if map should be saved
   382 
   383 	Parser parser;				// Parser stuff for scripting
   384 
   385 	bool printFrame;			// Print frame around map
   386 	bool printFooter;			// Print footer below map
   387 
   388 	bool zipped;				// should map be zipped
   389 	static	int mapNum;			// unique number for Editor
   390 	QString fileName;			// short name of file (for tab)
   391 	QString filePath;			// path to file which will be saved
   392 	QString fileDir;			// dir where file is saved
   393 	QString destPath;			// path to .vym file (needed for vymlinks)
   394 	QString mapName;			// fileName without ".vym"
   395 
   396 	QString tmpMapDir;			// tmp directory with undo history
   397 	QString histPath;			// Path to history file
   398 	SimpleSettings undoSet;		// undo/redo commands, saved in histPath
   399 	int stepsTotal;				// total number of steps (undos+redos) 
   400 	int curStep;				// Current step in history (ring buffer)
   401 	int curClipboard;			// number of history step, which is the current clipboard
   402 	int redosAvail;				// Available number of redo steps
   403 	int undosAvail;				// Available number of undo steps
   404 	bool blockReposition;		// block while load or undo
   405 	bool blockSaveState;		// block while load or undo
   406 
   407 	BranchObj* itFind;			// next object in find process
   408 	bool EOFind;				// true, if search failed
   409 
   410 	QPoint exportOffset;		// set before export, used in save
   411 	BranchObj::HideTmpMode hidemode;	// true while exporting to hide some stuff
   412 
   413 	QTcpServer *tcpServer;		// Act as server in conference mode (experimental)
   414 	QList <QTcpSocket*> clientList;
   415 
   416 	int timerId;				// animation timer
   417 	QList <MapObj*> animObjList;// list with animated objects
   418 };
   419 #endif
   420