mapeditor.h
author insilmaril
Thu, 03 May 2007 14:40:13 +0000
changeset 487 8fca3a710dc4
parent 486 9c86935835a4
child 491 c58b3973337c
permissions -rw-r--r--
Fixed window captions
     1 #ifndef MAPEDITOR_H
     2 #define MAPEDITOR_H
     3 
     4 //#include <QBuffer>
     5 #include <QGraphicsView>
     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     MapEditor(QWidget* parent=0);
    23 	~MapEditor();
    24     MapCenterObj* getMapCenter();
    25 	QGraphicsScene * getScene();
    26 	bool isRepositionBlocked(); // block while load or undo
    27 	bool isSaveStateBlocked();	// block while undo/redo or while running scripts
    28 	void setSaveStateBlocked(bool);
    29 	
    30 protected:
    31 	QString getName(const LinkableMapObj*);	// Get e.g. heading or filename
    32 	void makeTmpDirs();		// create temporary directories
    33 
    34 	/*! This function saves all information of the map to disc.
    35 	    saveToDir also calls the functions for all BranchObj and other objects in the map.
    36 		The structure of the map itself is returned as QString and passed back to Main, 
    37 		where saveToDir is called initially
    38 	*/	
    39     QString saveToDir (const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel);
    40 
    41 
    42 	/*! \brief Save the current changes in map 
    43 
    44 		Two commands and selections are saved:
    45 
    46 			- undocommand and undoselection to undo the change
    47 			- redocommand and redoselection to redo the action after an undo
    48 
    49 		Additionally a comment is logged. 
    50 
    51 	*/	
    52     void saveState(const SaveMode& savemode, const QString &undoSelection, const QString &undoCommand, const QString &redoSelection, const QString &redoCommand, const QString &comment, LinkableMapObj *saveSelection);
    53 	/*! Overloaded for convenience */
    54     void saveStateChangingPart(LinkableMapObj *undoSelection, LinkableMapObj* redoSelection, const QString &rendoCommand, const QString &comment);
    55 	/*! Overloaded for convenience */
    56     void saveStateRemovingPart(LinkableMapObj *redoSelection, const QString &comment);
    57 	/*! Overloaded for convenience */
    58     void saveState(LinkableMapObj *undoSelection, const QString &undoCommand, LinkableMapObj *redoSelection, const QString &rendoCommand, const QString &comment); 
    59 	/*! Overloaded for convenience */
    60     void saveState(const QString &undoSelection, const QString &undoCommand, const QString &redoSelection, const QString &rendoCommand, const QString &comment) ;
    61 
    62 public:	
    63 
    64 	/* \brief Process one command and its parameters */
    65     void parseAtom (const QString &atom);	
    66 
    67 	/* \brief Runs the script */
    68 	void runScript (QString script);
    69 private:
    70     void addFloatImageInt(const QPixmap &img);
    71 
    72 public:
    73 	bool isDefault();		//!< true, if map is still the empty default map
    74     bool hasChanged();		//!< true, if something has changed and is not saved yet
    75 	void setChanged();		//!< called from TextEditor via LinkableMapObj
    76 	void closeMap();		//!< Closes the map
    77 
    78 	/*! \brief Sets filepath, filename and mapname
    79 
    80 	     If the filepath is "/home/tux/map.xml", then the filename will be set
    81 		 to map.xml. The destname is needed for vymLinks, pointing to another map. 
    82 		 The destname holds the real name of the file, after it has been compressed, e.g. "map.vym"
    83 	*/	 
    84 	void setFilePath (QString filepath,QString destname);	
    85 	void setFilePath (QString);	//!< Overloaded for convenience
    86 	QString getFilePath ();	//!< Full path e.g. "/home/tux/map.xml"
    87 	QString getFileName ();	//!< e.g. "map.xml"
    88 	QString getMapName ();	//!< e.g. "map"
    89 	QString getDestPath (); //!< e.g. "/home/tux/map.vym"
    90     ErrorCode load (QString, LoadMode );	// newmap, import/replace selection
    91 public:
    92     int save(const SaveMode &);	// Save map 
    93 	void setZipped(bool);		// save map zipped
    94 	bool saveZipped();			// 1 if file will be saved zipped
    95     void print();				// print canvas
    96 	void setAntiAlias (bool);
    97 	void setSmoothPixmap(bool);
    98 private:
    99     QPixmap getPixmap();
   100 	void setHideTmpMode (BranchObj::HideTmpMode);	// temporary hide stuff
   101 	BranchObj::HideTmpMode getHideTmpMode();		// temporary hide stuff
   102 public:
   103 	void setExportMode (bool);			// temporary hide stuff during export
   104     void exportImage (QString fn);			// export as PNG	
   105     void exportImage (QString fn, QString);	// export in given format
   106     void exportOOPresentation(const QString &,const QString &);
   107     void exportXML(const QString&);		// export to directory
   108     void clear();		// clear map
   109     void copy();		// copy branch to clipboard
   110     void redo();		// redo last action
   111 	bool isRedoAvailable();
   112     void undo();		// undo last action
   113 	bool isUndoAvailable();
   114 	void gotoHistoryStep (int);// goto a step in history
   115 private:	
   116     void addMapReplaceInt(const QString & undoSel, const QString & path);
   117     void addMapInsertInt (const QString & path, int pos);
   118     void pasteNoSave();		// paste clipboard to branch
   119     void cutNoSave();	// cut to clipboard
   120 public:	
   121     void paste();		// paste clipboard to branch and backup
   122     void cut();			// cut to clipboard and backup
   123     void move    (const int &x, const int &y);
   124     void moveRel (const int &x, const int &y);
   125     void moveBranchUp();
   126     void moveBranchDown();
   127 private:	
   128 	void linkTo(const QString &);
   129 public:	
   130 	QString getHeading (bool &ok,QPoint &p); // Get heading, ok if selection is branch
   131 	void setHeading(const QString &);
   132 private:
   133 	void setHeadingInt(const QString &);
   134 	void setURLInt(const QString &);		// Just set the URL for selection
   135 	void setVymLinkInt(const QString &);	// Set vymLink for selection
   136     BranchObj* addNewBranchInt(int);		// pos allows to add above/below selection
   137 public:	
   138     BranchObj* addNewBranch(int);			// pos allows to add above/below selection
   139     BranchObj* addNewBranchBefore();		// insert and make selection its
   140     void deleteSelection();
   141 	LinkableMapObj* getSelection();			// returns selection
   142 	BranchObj* getSelectedBranch();			// returns selected branch or NULL
   143 	FloatImageObj* getSelectedFloatImage();	// returns selected branch or NULL
   144 	void unselect();						// before changing current noteedit
   145 	void reselect();						// after  changing current noteedit
   146 	bool select(const QString &);			// Select by string
   147 	QString getSelectString();
   148 private:	
   149 	void selectInt(LinkableMapObj*);	
   150 	void selectNextBranchInt();		// Increment number of branch
   151 	void selectPrevBranchInt();		// Decrement number of branch
   152 public:	
   153     void selectUpperBranch();
   154     void selectLowerBranch();
   155     void selectLeftBranch();
   156     void selectRightBranch();
   157     void selectFirstBranch();
   158     void selectLastBranch();
   159     void selectMapBackgroundImage();
   160     void setMapBackgroundImage(const QString &);
   161     void selectMapBackgroundColor();
   162     void setMapBackgroundColor(QColor);
   163     QColor getMapBackgroundColor();
   164     QColor getCurrentHeadingColor();
   165     void colorBranch(QColor);
   166     void colorSubtree(QColor);
   167 	void toggleStandardFlag(QString);
   168     BranchObj* findText(QString,bool);		// Find object
   169     void findReset();						// Reset Find 
   170 	void setURL(const QString &);			// set the URL
   171 	void editURL();							// edit the URL
   172 	QString getURL();						// returns URL of selection or ""
   173 	QStringList getURLs();					// returns URLs of subtree
   174 	void editHeading2URL();					// copy heading to URL
   175 	void editBugzilla2URL();				// create URL to Bugzilla
   176 	void editFATE2URL();					// create URL to FATE
   177 	void editVymLink();						// edit link to another map
   178 	void deleteVymLink();					// delete link to another map
   179 	QString getVymLink();					// return path to map
   180 	QStringList getVymLinks();				// return paths in subtree
   181 	void setHideExport(bool);				// toggle the export flag
   182 	void toggleHideExport();				// toggle the export flag
   183 	void deleteKeepChilds();				// remove but keep childs
   184 	void deleteChilds();					// remove childs
   185 	void editMapInfo();						// dialog to enter author, ...
   186 	void ensureSelectionVisible();		
   187 	void updateSelection();					// update geometry of selection
   188 	void updateActions();					// update e.g. format buttons
   189 	void updateNoteFlag();					// when TextEditor changes
   190 	void setMapAuthor (const QString &);
   191 	void setMapComment(const QString &);
   192 	void setMapLinkStyle (const QString &);	// Set style of link
   193 	LinkableMapObj::Style getMapLinkStyle ();	// requested in LMO
   194 	void setMapDefLinkColor(QColor);		// default color of links
   195 	void setMapLinkColorHintInt();			// color of links
   196 	void setMapLinkColorHint(LinkableMapObj::ColorHint);// color of links
   197 	LinkableMapObj::ColorHint getMapLinkColorHint();
   198 	QColor getMapDefLinkColor();
   199 	void setMapDefXLinkColor(QColor);
   200 	QColor getMapDefXLinkColor();
   201 	void setMapDefXLinkWidth (int);
   202 	int getMapDefXLinkWidth();
   203 	void toggleMapLinkColorHint();			// after changing linkStyles
   204     void selectMapLinkColor();
   205     void selectMapSelectionColor();
   206 private:	
   207     void setSelectionColorInt(QColor);
   208 public:	
   209     void setSelectionColor(QColor);
   210     QColor getSelectionColor();
   211 	bool scrollBranch(BranchObj*);
   212 	bool unscrollBranch(BranchObj*);
   213     void toggleScroll();
   214     void unscrollChilds();
   215 private:	
   216 	FloatImageObj* loadFloatImageInt (QString);
   217 public:	
   218 	void loadFloatImage ();
   219 private:	
   220 	void saveFloatImageInt (FloatImageObj*, const QString &, const QString &);
   221 public:	
   222 	void saveFloatImage ();
   223 	void setFrameType(const FrameObj::FrameType &);
   224 	void setFrameType(const QString &);
   225 	void setFramePenColor (const QColor &);
   226 	void setFrameBrushColor (const QColor &);
   227 	void setFramePadding (const int &);
   228 	void setFrameBorderWidth (const int &);
   229 	void setIncludeImagesVer(bool);
   230 	void setIncludeImagesHor(bool);
   231 	void setHideLinkUnselected (bool);
   232 	bool getHideLinkUnselected ();
   233 private:	
   234     void importDirInt(BranchObj *,QDir);
   235 public:	
   236     void importDir();
   237 	void followXLink (int);
   238 	void editXLink (int);
   239     void testFunction();					// just testing new stuff
   240 											// set /mainwindo/showTestMenu=true...
   241 
   242 protected:
   243 	virtual void contextMenuEvent ( QContextMenuEvent *e );
   244     virtual void keyPressEvent(QKeyEvent*);
   245     virtual void keyReleaseEvent(QKeyEvent*);
   246     virtual void mousePressEvent(QMouseEvent*);
   247     virtual void mouseMoveEvent(QMouseEvent*);
   248     virtual void mouseReleaseEvent(QMouseEvent*);
   249     virtual void mouseDoubleClickEvent(QMouseEvent*);
   250     virtual void resizeEvent( QResizeEvent * );
   251 
   252 	void dragEnterEvent (QDragEnterEvent *);
   253 	void dragMoveEvent (QDragMoveEvent *);
   254 	void dragLeaveEvent (QDragLeaveEvent *);
   255 	void dropEvent (QDropEvent *);
   256 
   257 	void timerEvent(QTimerEvent *event);
   258 
   259 private slots:	
   260 	void autosave ();
   261 
   262 private:
   263 	QGraphicsScene *mapScene;
   264     MapCenterObj* mapCenter;
   265 	QTimer *autosaveTimer;
   266 
   267 	bool adjustCanvasRequested;	// collect requests until end of user event
   268 	BranchObj *editingBO;		// entering Text into BO
   269 
   270 	QColor defLinkColor;		// default color for links
   271 	QColor defXLinkColor;		// default color for xlinks
   272 	int defXLinkWidth;			// default width for xlinks
   273 	LinkableMapObj::ColorHint linkcolorhint;// use heading color or own color
   274 	LinkableMapObj::Style linkstyle;		// default style for links
   275 
   276     QCursor HandOpenCursor;		// cursor while moving canvas view
   277 	QCursor PickColorCursor;	// cursor while picking color 
   278 	QCursor CopyCursor;			// cursor while picking color 
   279 	QCursor XLinkCursor;		// cursor while picking color 
   280 	bool pickingColor;
   281 	bool drawingLink;			// true while creating a link
   282 	bool copyingObj;			// true while creating a link
   283 	XLinkObj* tmpXLink;
   284 
   285 	Selection xelection;	
   286     MapObj* movingObj;				// moving a MapObj
   287 	MapObj* linkingObj_src;			// part of a link
   288     QPointF movingObj_orgPos;		// org. pos of mouse before move
   289     QPointF movingObj_orgRelPos;	// org. relative pos of mouse before move
   290     QPointF movingObj_start;		// rel. pos of mouse to absPos 
   291     QPointF movingCont_start;		// inital pos of moving Content or
   292     QPointF movingVec;				// how far has Content moved
   293     QPrinter* printer;				// Printing
   294 
   295     bool mapDefault;				// Flag if map is untouched
   296     bool mapChanged;				// Flag if undo is possible
   297 	bool mapUnsaved;				// Flag if map should be saved
   298 
   299 	Parser parser;				// Parser stuff for scripting
   300 
   301 	bool printFrame;			// Print frame around map
   302 	bool printFooter;			// Print footer below map
   303 
   304 	bool zipped;				// should map be zipped
   305 	static	int mapNum;			// unique number for Editor
   306 	QString fileName;			// short name of file (for tab)
   307 	QString filePath;			// path to file which will be saved
   308 	QString fileDir;			// dir where file is saved
   309 	QString destPath;			// path to .vym file (needed for vymlinks)
   310 	QString mapName;			// fileName without ".vym"
   311 
   312 	QString tmpMapDir;			// tmp directory with undo history
   313 	QString histPath;			// Path to history file
   314 	int stepsTotal;				// total number of steps (undos+redos) 
   315 	SimpleSettings undoSet;		// undo/redo commands
   316 	bool blockReposition;		// block while load or undo
   317 	bool blockSaveState;		// block while load or undo
   318 
   319 	BranchObj* itFind;			// next object in find process
   320 	bool EOFind;				// true, if search failed
   321 
   322 	QPoint exportOffset;		// set before export, used in save
   323 	BranchObj::HideTmpMode hidemode;	// true while exporting to hide some stuff
   324 
   325 	int timerId;				// animation timer
   326 	QList <MapObj*> animObjList;// list with animated objects
   327 };
   328 #endif
   329