mapeditor.h
author insilmaril
Tue Jun 03 08:33:34 2008 +0000 (2008-06-03)
changeset 709 25eec6d77740
parent 684 5f9a2771680d
child 720 192e1392ba6a
permissions -rw-r--r--
Workaround for unreadable file with Qt 4.4
     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     ErrorCode save(const SaveMode &);	
   168 	/* FIXME no needed any longer
   169 	void setZipped(bool);		//!< Set or unset compression of map with zip save map zipped
   170 	bool saveZipped();			//!< True, if file will be saved zipped
   171 	*/
   172     void print();				//!< Print the map
   173 	void setAntiAlias (bool);	//!< Set or unset antialiasing
   174 	void setSmoothPixmap(bool); //!< Set or unset smoothing of pixmaps
   175 private:
   176     QPixmap getPixmap();
   177 	void setHideTmpMode (HideTmpMode);	// temporary hide stuff
   178 	HideTmpMode getHideTmpMode();		// temporary hide stuff
   179 public:
   180 	/*! Set or unset temporary hiding of objects during export  */
   181 	void setExportMode (bool);
   182 
   183 	/*! Export as ASCII text to file */
   184 	void exportASCII (QString fname="",bool askForName=true);  
   185 
   186 	/*! Save as image */
   187     void exportImage (QString fname="",bool askForName=true,QString format="PNG");
   188 
   189     /*! Export as OpenOfficeOrg presentation */
   190     void exportOOPresentation(const QString &,const QString &);	
   191 
   192 	/*! Export as XHTML to directory */
   193     void exportXHTML(const QString& dir="", bool askForName=true);	
   194 
   195 	/*! Export as XTML to directory */
   196     void exportXML(QString dir="", bool askForName=true);
   197 
   198     void clear();						//!< Clear map
   199     void copy();						//!< Copy to clipboard
   200     void redo();						//!< Redo last action
   201 	bool isRedoAvailable();				//!< True, if redo is available
   202     void undo();						//!< Undo last action
   203 	bool isUndoAvailable();				//!< True, if undo is available
   204 	void gotoHistoryStep (int);			//!< Goto a specifig step in history
   205 private:	
   206     void addMapReplaceInt(const QString & undoSel, const QString & path);
   207     void addMapInsertInt (const QString & path, int pos);
   208     void pasteNoSave(const int &n);		//!< paste clipboard to branch
   209 public:	
   210     void paste();		//!< Paste clipboard to branch and backup
   211     void cut();			//!< Cut to clipboard (and copy)
   212 	/*! \brief Move absolutly
   213 
   214 		Move absolutly to (x,y).
   215 	*/	
   216     void move    (const double &x, const double &y);
   217 	/*! \brief Move relativly
   218 
   219 		Move relativly to (x,y).
   220 	*/	
   221     void moveRel (const double &x, const double &y);
   222     void moveBranchUp();	//!< Move branch up
   223     void moveBranchDown();	//!< Move branch down
   224 	void sortChildren();	//!< Sort children lexically
   225 private:	
   226 	void linkTo(const QString &);
   227 public:	
   228 	QString getHeading (bool &ok,QPoint &p); //!< Get heading, ok if selection is branch
   229 	void setHeading(const QString &);		//!< Set heading of branch	
   230 private:
   231 	void setHeadingInt(const QString &);
   232 	void setVymLinkInt(const QString &);	// Set vymLink for selection
   233 	/*! \brief Add new mapcenter
   234 
   235 	    Disclaimer: Still experimental, not fully supported.
   236 	*/	
   237 public:	
   238     BranchObj* addMapCenter();		
   239 
   240 	/*! \brief Add new branch
   241 
   242 		Depending on num the new branch is created
   243 
   244 		-3 above selection as child of selections parent
   245 		-2 as child of selection
   246 		-1 below selection as child of selections parent
   247 		0..n	insert at a specific position in selections parent
   248 		(needed for free relinking)
   249 	*/	
   250 private:	
   251     BranchObj* addNewBranchInt(int);		// pos allows to add above/below selection
   252 public:	
   253 	/*! \Add new branch
   254 		
   255 		Depending on num the new branch is created
   256 		-1 above selection
   257 		 0 as child of selection
   258 		 1 below selection
   259 	*/
   260     BranchObj* addNewBranch(int pos);		
   261     BranchObj* addNewBranchBefore();		//!< Insert branch between selection and its parent
   262     void deleteSelection();					//!< Delete selection
   263 	LinkableMapObj* getSelection();			//!< Returns selection
   264 	BranchObj* getSelectedBranch();			// returns selected branch or NULL
   265 	FloatImageObj* getSelectedFloatImage();	// returns selected branch or NULL
   266 	void unselect();						// before changing current noteedit
   267 	void reselect();						// after  changing current noteedit
   268 	bool select(const QString &);			// Select by string
   269 	bool select(LinkableMapObj *lmo);		// Select by pointer
   270 	QString getSelectString();
   271 private:	
   272 	void selectInt(LinkableMapObj*);	
   273 	void selectNextBranchInt();		// Increment number of branch
   274 	void selectPrevBranchInt();		// Decrement number of branch
   275 public:	
   276     void selectUpperBranch();
   277     void selectLowerBranch();
   278     void selectLeftBranch();
   279     void selectRightBranch();
   280     void selectFirstBranch();
   281     void selectLastBranch();
   282     void selectMapBackgroundImage();
   283     void setMapBackgroundImage(const QString &);
   284     void selectMapBackgroundColor();
   285     void setMapBackgroundColor(QColor);
   286     QColor getMapBackgroundColor();
   287     QColor getCurrentHeadingColor();
   288     void colorBranch(QColor);
   289     void colorSubtree(QColor);
   290 	void toggleStandardFlag(QString);
   291     BranchObj* findText(QString,bool);		// Find object
   292     void findReset();						// Reset Find 
   293 	void setURL(const QString &);			// set  URL
   294 	void editURL();							// edit URL
   295 	void editLocalURL();					// edit URL to local file
   296 	QString getURL();						// returns URL of selection or ""
   297 	QStringList getURLs();					// returns URLs of subtree
   298 	void editHeading2URL();					// copy heading to URL
   299 	void editBugzilla2URL();				// create URL to Bugzilla
   300 	void editFATE2URL();					// create URL to FATE
   301 	void editVymLink();						// edit link to another map
   302 	void deleteVymLink();					// delete link to another map
   303 	QString getVymLink();					// return path to map
   304 	QStringList getVymLinks();				// return paths in subtree
   305 	void setHideExport(bool);				// toggle the export flag
   306 	void toggleHideExport();				// toggle the export flag
   307 	void deleteKeepChilds();				// remove but keep childs
   308 	void deleteChilds();					// remove childs
   309 	void editMapInfo();						// dialog to enter author, ...
   310 	void ensureSelectionVisible();		
   311 	void updateSelection();					// update geometry of selection
   312 	void updateActions();					// update e.g. format buttons
   313 	void updateNoteFlag();					// when TextEditor changes
   314 	void setMapAuthor (const QString &);
   315 	void setMapComment(const QString &);
   316 	void setMapLinkStyle (const QString &);	// Set style of link
   317 	LinkableMapObj::Style getMapLinkStyle ();	// requested in LMO
   318 	void setMapDefLinkColor(QColor);		// default color of links
   319 	void setMapLinkColorHintInt();			// color of links
   320 	void setMapLinkColorHint(LinkableMapObj::ColorHint);// color of links
   321 	LinkableMapObj::ColorHint getMapLinkColorHint();
   322 	QColor getMapDefLinkColor();
   323 	void setMapDefXLinkColor(QColor);
   324 	QColor getMapDefXLinkColor();
   325 	void setMapDefXLinkWidth (int);
   326 	int getMapDefXLinkWidth();
   327 	void toggleMapLinkColorHint();			// after changing linkStyles
   328     void selectMapLinkColor();
   329     void selectMapSelectionColor();
   330 private:	
   331     void setSelectionColorInt(QColor);
   332 public:	
   333     void setSelectionColor(QColor);
   334     QColor getSelectionColor();
   335 	bool scrollBranch(BranchObj*);
   336 	bool unscrollBranch(BranchObj*);
   337     void toggleScroll();
   338     void unscrollChilds();
   339 private:	
   340 	FloatImageObj* loadFloatImageInt (QString);
   341 public:	
   342 	void loadFloatImage ();
   343 private:	
   344 	void saveFloatImageInt (FloatImageObj*, const QString &, const QString &);
   345 public:	
   346 	void saveFloatImage ();
   347 	void setFrameType(const FrameObj::FrameType &);
   348 	void setFrameType(const QString &);
   349 	void setFramePenColor (const QColor &);
   350 	void setFrameBrushColor (const QColor &);
   351 	void setFramePadding (const int &);
   352 	void setFrameBorderWidth (const int &);
   353 	void setIncludeImagesVer(bool);
   354 	void setIncludeImagesHor(bool);
   355 	void setHideLinkUnselected (bool);
   356 	bool getHideLinkUnselected ();
   357 private:	
   358     void importDirInt(BranchObj *,QDir);
   359     void importDirInt(const QString&);
   360 public:	
   361     void importDir();
   362 	void followXLink (int);
   363 	void editXLink (int);
   364 	AttributeTable* attributeTable();
   365     void testFunction1();					// just testing new stuff
   366     void testFunction2();					// just testing new stuff
   367 											// set /mainwindo/showTestMenu=true...
   368 
   369 protected:
   370 	virtual void contextMenuEvent ( QContextMenuEvent *e );
   371     virtual void keyPressEvent(QKeyEvent*);
   372     virtual void keyReleaseEvent(QKeyEvent*);
   373     virtual void mousePressEvent(QMouseEvent*);
   374     virtual void mouseMoveEvent(QMouseEvent*);
   375     virtual void mouseReleaseEvent(QMouseEvent*);
   376     virtual void mouseDoubleClickEvent(QMouseEvent*);
   377     virtual void resizeEvent( QResizeEvent * );
   378 
   379 	void dragEnterEvent (QDragEnterEvent *);
   380 	void dragMoveEvent (QDragMoveEvent *);
   381 	void dragLeaveEvent (QDragLeaveEvent *);
   382 	void dropEvent (QDropEvent *);
   383 
   384 
   385 protected:
   386 	void sendSelection();
   387 
   388 public:
   389 	void newServer();
   390 	void connectToServer();
   391 
   392 private slots:	
   393 	void newClient();
   394 	void sendData(const QString &s);
   395 	void readData();
   396 	void displayNetworkError (QAbstractSocket::SocketError);
   397 
   398 	void autosave ();
   399 	void fileChanged();
   400 
   401 private:
   402 	State state;				// State of MapEditor
   403 	QGraphicsScene *mapScene;
   404 	VymModel *model;					// Vym Map, includding several mapCenters
   405 	QTimer *autosaveTimer;
   406 	QTimer *fileChangedTimer;
   407 	QDateTime fileChangedTime;
   408 
   409 	bool adjustCanvasRequested;	// collect requests until end of user event
   410 	BranchObj *editingBO;		// entering Text into BO
   411 
   412 	QColor defLinkColor;		// default color for links
   413 	QColor defXLinkColor;		// default color for xlinks
   414 	int defXLinkWidth;			// default width for xlinks
   415 	LinkableMapObj::ColorHint linkcolorhint;// use heading color or own color
   416 	LinkableMapObj::Style linkstyle;		// default style for links
   417 
   418     QCursor HandOpenCursor;		// cursor while moving canvas view
   419 	QCursor PickColorCursor;	// cursor while picking color 
   420 	QCursor CopyCursor;			// cursor while picking color 
   421 	QCursor XLinkCursor;		// cursor while picking color 
   422 	bool pickingColor;
   423 	bool drawingLink;			// true while creating a link
   424 	bool copyingObj;			// true while creating a link
   425 	XLinkObj* tmpXLink;
   426 
   427 	Selection xelection;	
   428 
   429 	QString latestSelection;		// select string of latest added object
   430 
   431     MapObj* movingObj;				// moving a MapObj
   432 	MapObj* linkingObj_src;			// part of a link
   433     QPointF movingObj_orgPos;		// org. pos of mouse before move
   434     QPointF movingObj_orgRelPos;	// org. relative pos of mouse before move
   435     QPointF movingObj_start;		// rel. pos of mouse to absPos 
   436     QPointF movingCont_start;		// inital pos of moving Content or
   437     QPointF movingVec;				// how far has Content moved
   438 
   439 	QPointF contextMenuPos;					// position where context event was triggered
   440 
   441     QPrinter* printer;				// Printing
   442 
   443     bool mapDefault;				// Flag if map is untouched
   444     bool mapChanged;				// Flag if undo is possible
   445 	bool mapUnsaved;				// Flag if map should be saved
   446 
   447 	Parser parser;				// Parser stuff for scripting
   448 
   449 	AttributeTable *attrTable;
   450 
   451 	bool printFrame;			// Print frame around map
   452 	bool printFooter;			// Print footer below map
   453 
   454 	bool zipped;				// should map be zipped
   455 	static	int mapNum;			// unique number for Editor
   456 	FileType fileType;			// type of file, e.g. vym, freemind...
   457 	QString fileName;			// short name of file (for tab)
   458 	QString filePath;			// path to file which will be saved
   459 	QString fileDir;			// dir where file is saved
   460 	QString destPath;			// path to .vym file (needed for vymlinks)
   461 	QString mapName;			// fileName without ".vym"
   462 
   463 	QString tmpMapDir;			// tmp directory with undo history
   464 	QString histPath;			// Path to history file
   465 	SimpleSettings undoSet;		// undo/redo commands, saved in histPath
   466 	int stepsTotal;				// total number of steps (undos+redos) 
   467 	int curStep;				// Current step in history (ring buffer)
   468 	int curClipboard;			// number of history step, which is the current clipboard
   469 	int redosAvail;				// Available number of redo steps
   470 	int undosAvail;				// Available number of undo steps
   471 	bool blockReposition;		// block while load or undo
   472 	bool blockSaveState;		// block while load or undo
   473 
   474 	BranchObj* itFind;			// next object in find process
   475 	bool EOFind;				// true, if search failed
   476 
   477 	QPoint exportOffset;		// set before export, used in save
   478 	HideTmpMode hidemode;	// true while exporting to hide some stuff
   479 
   480 	// Network connections **Experimental**
   481 	NetState netstate;			// offline, client, server
   482 	QTcpServer *tcpServer;		// Act as server in conference mode (experimental)
   483 	QList <QTcpSocket*> clientList;		// List of connected clients
   484 	quint16 sendCounter;		// Increased with every sent command
   485 
   486 	QTcpSocket	*clientSocket;	// socket of this client
   487 	QString server;				// server address of this client
   488 	int port;					// server port of this client
   489 	void displayClientError(QAbstractSocket::SocketError socketError);
   490 
   491 };
   492 #endif
   493