mapeditor.h
author insilmaril
Mon, 12 Feb 2007 09:28:46 +0000
changeset 426 e0a3449f4458
parent 424 d886c77ac0fe
child 427 fb74fa7bfb4c
permissions -rw-r--r--
1.8.66 Various fixes
     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 "selection.h"
    11 #include "settings.h"
    12 
    13 
    14 class MapEditor : public QGraphicsView, public xmlObj {
    15     Q_OBJECT
    16 
    17 public:
    18     MapEditor(QWidget* parent=0);
    19 	~MapEditor();
    20     MapCenterObj* getMapCenter();
    21 	QGraphicsScene * getScene();
    22 	bool isRepositionBlocked(); // block while load or undo
    23 	
    24 private:
    25 	QString getName(const LinkableMapObj*);	// Get e.g. heading or filename
    26 	void makeTmpDirs();		// create temporary directories
    27     QString saveToDir(const QString&,const QString &,bool, const QPointF &,LinkableMapObj*);
    28     void saveStateChangingPart (LinkableMapObj *, LinkableMapObj *, const QString &, const QString &);
    29     void saveStateRemovingPart (LinkableMapObj *, const QString &);
    30     void saveState(LinkableMapObj *, const QString &, LinkableMapObj *, const QString &, const QString &);
    31     void saveState(const QString &, const QString &, const QString &, const QString &, const QString &);
    32     void saveState(const SaveMode&, const QString &, const QString &, const QString &, const QString &, const QString &, LinkableMapObj *);
    33 public:	
    34     void parseAtom(const QString &);	
    35 private:
    36     void addFloatImageInt(const QPixmap &img);
    37 
    38 public:
    39 	bool isDefault();		// false, if map was changed once
    40     bool isUnsaved();		// save necessary
    41     bool hasChanged();		// undo possible
    42 	void setChanged();		// called from NoteEditor via LMO
    43 	void closeMap();
    44 	void setFilePath (QString);	
    45 	void setFilePath (QString,QString);	
    46 	QString getFilePath ();	// Full path e.g. "/home/tux/map.xml"
    47 	QString getFileName ();	// e.g. "map.xml"
    48 	QString getMapName ();	// e.g. "map"
    49 	QString getDestPath (); // e.g. "/home/tux/map.vym"
    50     ErrorCode load (QString, LoadMode );	// newmap, import/replace selection
    51 public:
    52     int save(const SaveMode &);	// Save map 
    53 	void setZipped(bool);		// save map zipped
    54 	bool saveZipped();			// 1 if file will be saved zipped
    55     void print();				// print canvas
    56 	void setAntiAlias (bool);
    57 	void setSmoothPixmap(bool);
    58 private:
    59     QPixmap getPixmap();
    60 	void setHideTmpMode (HideTmpMode);	// temporary hide stuff
    61 	HideTmpMode getHideTmpMode();		// temporary hide stuff
    62 public:
    63 	void setExportMode (bool);			// temporary hide stuff during export
    64     void exportImage (QString fn);			// export as PNG	
    65     void exportImage (QString fn, QString);	// export in given format
    66     void exportOOPresentation(const QString &,const QString &);
    67     void exportXML(const QString&);		// export to directory
    68     void clear();		// clear map
    69     void copy();		// copy branch to clipboard
    70     void redo();		// redo last action
    71 	bool isRedoAvailable();
    72     void undo();		// undo last action
    73 	bool isUndoAvailable();
    74 	void gotoHistoryStep (int);// goto a step in history
    75 private:	
    76     void addMapReplaceInt(const QString & undoSel, const QString & path);
    77     void addMapInsertInt (const QString & path, int pos);
    78     void pasteNoSave();		// paste clipboard to branch
    79     void cutNoSave();	// cut to clipboard
    80 public:	
    81     void paste();		// paste clipboard to branch and backup
    82     void cut();			// cut to clipboard and backup
    83     void move    (const int &x, const int &y);
    84     void moveRel (const int &x, const int &y);
    85     void moveBranchUp();
    86     void moveBranchDown();
    87 private:	
    88 	void linkTo(const QString &);
    89 public:	
    90 	QString getHeading (bool &ok,QPoint &p); // Get heading, ok if selection is branch
    91 	void setHeading(const QString &);
    92 private:
    93 	void setHeadingInt(const QString &);
    94 	void setURLInt(const QString &);		// Just set the URL for selection
    95 	void setVymLinkInt(const QString &);	// Set vymLink for selection
    96     BranchObj* addNewBranchInt(int);		// pos allows to add above/below selection
    97 public:	
    98     BranchObj* addNewBranch(int);			// pos allows to add above/below selection
    99     BranchObj* addNewBranchBefore();		// insert and make selection its
   100     void deleteSelection();
   101 	LinkableMapObj* getSelection();	// returns selection
   102 	void unselect();				// before changing current noteedit
   103 	void reselect();				// after  changing current noteedit
   104 	bool select(const QString &);	// Select by string
   105 	QString getSelectString();
   106 private:	
   107 	void selectInt(LinkableMapObj*);	
   108 	void selectNextBranchInt();		// Increment number of branch
   109 	void selectPrevBranchInt();		// Decrement number of branch
   110 public:	
   111     void selectUpperBranch();
   112     void selectLowerBranch();
   113     void selectLeftBranch();
   114     void selectRightBranch();
   115     void selectFirstBranch();
   116     void selectLastBranch();
   117     void selectMapBackgroundImage();
   118     void setMapBackgroundImage(const QString &);
   119     void selectMapBackgroundColor();
   120     void setMapBackgroundColor(QColor);
   121     QColor getMapBackgroundColor();
   122     QColor getCurrentHeadingColor();
   123     void colorBranch(QColor);
   124     void colorSubtree(QColor);
   125 	void toggleStandardFlag(QString);
   126     BranchObj* findText(QString,bool);		// Find object
   127     void findReset();						// Reset Find 
   128 	void setURL(const QString &);			// set the URL
   129 	void editURL();							// edit the URL
   130 	QString getURL();						// returns URL of selection or ""
   131 	QStringList getURLs();					// returns URLs of subtree
   132 	void editHeading2URL();					// copy heading to URL
   133 	void editBugzilla2URL();				// create URL to Bugzilla
   134 	void editFATE2URL();					// create URL to FATE
   135 	void editVymLink();						// edit link to another map
   136 	void deleteVymLink();					// delete link to another map
   137 	QString getVymLink();					// return path to map
   138 	QStringList getVymLinks();				// return paths in subtree
   139 	void setHideExport(bool);				// toggle the export flag
   140 	void toggleHideExport();				// toggle the export flag
   141 	void deleteKeepChilds();				// remove but keep childs
   142 	void deleteChilds();					// remove childs
   143 	void editMapInfo();						// dialog to enter author, ...
   144 	void updateActions();					// update e.g. format buttons
   145 	void updateNoteFlag();					// when TextEditor changes
   146 	void setMapAuthor (const QString &);
   147 	void setMapComment(const QString &);
   148 	void setMapLinkStyle (const QString &);	// Set style of link
   149 	LinkStyle getMapLinkStyle ();			// requested in LMO
   150 	void setMapDefLinkColor(QColor);		// default color of links
   151 	void setMapLinkColorHintInt();			// color of links
   152 	void setMapLinkColorHint(LinkColorHint);// color of links
   153 	LinkColorHint getMapLinkColorHint();
   154 	QColor getMapDefLinkColor();
   155 	void setMapDefXLinkColor(QColor);
   156 	QColor getMapDefXLinkColor();
   157 	void setMapDefXLinkWidth (int);
   158 	int getMapDefXLinkWidth();
   159 	void toggleMapLinkColorHint();			// after changing linkStyles
   160     void selectMapLinkColor();
   161     void toggleScroll();
   162     void unScrollAll();
   163 	void loadFloatImage ();
   164 	void saveFloatImage ();
   165 	void setFrame(const FrameType &);
   166 	void setIncludeImagesVer(bool);
   167 	void setIncludeImagesHor(bool);
   168 	void setHideLinkUnselected (bool);
   169 	bool getHideLinkUnselected ();
   170 private:	
   171     void importDirInt(BranchObj *,QDir);
   172 public:	
   173     void importDir();
   174 	void followXLink (int);
   175 	void editXLink (int);
   176     void testFunction();					// just testing new stuff
   177 											// set /mainwindo/showTestMenu=true...
   178 
   179 protected:
   180 	void ensureSelectionVisible();		
   181 	virtual void contextMenuEvent ( QContextMenuEvent *e );
   182     virtual void keyPressEvent(QKeyEvent*);
   183     virtual void keyReleaseEvent(QKeyEvent*);
   184     virtual void mousePressEvent(QMouseEvent*);
   185     virtual void mouseReleaseEvent(QMouseEvent*);
   186     virtual void mouseDoubleClickEvent(QMouseEvent*);
   187     virtual void mouseMoveEvent(QMouseEvent*);
   188 
   189 	void dragEnterEvent (QDragEnterEvent *);
   190 	void dragMoveEvent (QDragMoveEvent *);
   191 	void dragLeaveEvent (QDragLeaveEvent *);
   192 	void dropEvent (QDropEvent *);
   193 
   194 private:
   195 	QGraphicsScene *mapScene;
   196     MapCenterObj* mapCenter;
   197 
   198 	bool adjustCanvasRequested;	// collect requests until end of user event
   199 	BranchObj *editingBO;		// entering Text into BO
   200 
   201 	QColor defLinkColor;		// default color for links
   202 	QColor defXLinkColor;		// default color for xlinks
   203 	int defXLinkWidth;			// default width for xlinks
   204 	LinkColorHint linkcolorhint;// use heading color or own color
   205 	LinkStyle linkstyle;		// default style for links
   206 
   207     QCursor HandOpenCursor;		// cursor while moving canvas view
   208 	QCursor PickColorCursor;	// cursor while picking color 
   209 	QCursor CopyCursor;			// cursor while picking color 
   210 	QCursor XLinkCursor;		// cursor while picking color 
   211 	bool pickingColor;
   212 	bool drawingLink;			// true while creating a link
   213 	bool copyingObj;			// true while creating a link
   214 	XLinkObj* tmpXLink;
   215 
   216 	Selection xelection;	
   217     MapObj* movingObj;				// moving a MapObj
   218 	MapObj* linkingObj_src;			// part of a link
   219     QPointF movingObj_orgPos;		// org. pos of mouse before move
   220     QPointF movingObj_orgRelPos;	// org. relative pos of mouse before move
   221     QPointF movingObj_start;		// rel. pos of mouse to absPos 
   222     QPointF movingCont_start;		// inital pos of moving Content or
   223     QPointF movingVec;				// how far has Content moved
   224     QPrinter* printer;				// Printing
   225 
   226     bool mapDefault;				// Flag if map is untouched
   227     bool mapChanged;				// Flag if undo is possible
   228 	bool mapUnsaved;				// Flag if map should be saved
   229 
   230 	bool printFrame;			// Print frame around map
   231 	bool printFooter;			// Print footer below map
   232 
   233 	bool zipped;				// should map be zipped
   234 	static	int mapNum;			// unique number for Editor
   235 	QString fileName;			// short name of file (for tab)
   236 	QString filePath;			// path to file which will be saved
   237 	QString fileDir;			// dir where file is saved
   238 	QString destPath;			// path to .vym file (needed for vymlinks)
   239 	QString mapName;			// fileName without ".vym"
   240 
   241 	QString tmpMapDir;			// tmp directory with undo history
   242 	QString histPath;			// Path to history file
   243 	int stepsTotal;				// total number of steps (undos+redos) 
   244 	SimpleSettings undoSet;		// undo/redo commands
   245 	bool blockReposition;		// block while load or undo
   246 	bool blockSaveState;		// block while load or undo
   247 
   248 	BranchObj* itFind;			// next object in find process
   249 	bool EOFind;				// true, if search failed
   250 
   251 	QPoint exportOffset;		// set before export, used in save
   252 	HideTmpMode hidemode;			// true while exporting to hide some stuff
   253 	
   254     void resizeEvent( QResizeEvent * );
   255 };
   256 #endif
   257