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