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