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