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