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