mapeditor.h
author insilmaril
Mon, 16 Oct 2006 12:42:54 +0000
changeset 392 18f824bd3070
parent 390 0e1aeb21cb78
child 393 053b8645e3e9
permissions -rw-r--r--
Code simplifications
     1 #ifndef MAPEDITOR_H
     2 #define MAPEDITOR_H
     3 
     4 #include <q3canvas.h>
     5 #include <QBuffer>
     6 
     7 #include "mapcenterobj.h"
     8 #include "file.h"
     9 #include "historywindow.h"
    10 #include "misc.h"
    11 #include "selection.h"
    12 #include "settings.h"
    13 
    14 class Q3NetworkOperation;
    15 class Q3UrlOperator;
    16 
    17 class MapEditor : public Q3CanvasView , public xmlObj {
    18     Q_OBJECT
    19 
    20 public:
    21     MapEditor(QWidget* parent=0,  const char* name=0, Qt::WFlags f=0);
    22 	~MapEditor();
    23     QColor getColor();
    24     QColor getBackgroundColor();
    25     MapCenterObj* getMapCenter();
    26 	Q3Canvas* getCanvas();
    27 	void adjustCanvasSize();// adjust canvas size to map and scrollview
    28 	bool isRepositionBlocked(); // block while load or undo
    29 	
    30 private:
    31 	QString getName(LinkableMapObj*);	// Get e.g. heading or filename
    32 	void makeTmpDirs();		// create temporary directories
    33     QString saveToDir(const QString&,const QString &,bool, const QPoint &,LinkableMapObj*);
    34     void saveStateComplete       (const QString &);					
    35     void saveStatePart           (LinkableMapObj *, const QString &);
    36     void saveStateConstSelection (const QString &, const QString &, const QString &);
    37     void saveState(LinkableMapObj *, const QString &, LinkableMapObj *, const QString &, const QString &);
    38     void saveState(const QString &, const QString &, const QString &, const QString &, const QString &);
    39     void saveState(const SaveMode&, const QString &, const QString &, const QString &, const QString &, const QString &, LinkableMapObj *);
    40     void parseAtom(const QString &);	
    41 
    42     void addFloatImage(const QPixmap &img);
    43 
    44   private slots:
    45     void fetchImage(const QString &img);
    46     void imageDataFetched(const QByteArray &, Q3NetworkOperation *);
    47     void imageDataFinished(Q3NetworkOperation *);
    48 
    49 public:
    50 	void toggleHistoryWindow();
    51 	bool isDefault();		// false, if map was changed once
    52     bool isUnsaved();		// save necessary
    53     bool hasChanged();		// undo possible
    54 	void setChanged();		// called from NoteEditor via LMO
    55 	void closeMap();
    56 	void setFilePath (QString);	
    57 	void setFilePath (QString,QString);	
    58 	QString getFilePath ();	// Full path e.g. "/home/tux/map.xml"
    59 	QString getFileName ();	// e.g. "map.xml"
    60 	QString getMapName ();	// e.g. "map"
    61 	QString getDestPath (); // e.g. "/home/tux/map.vym"
    62     ErrorCode load (QString, LoadMode );	// newmap, import/replace selection
    63 public:
    64     int save(const SaveMode &);	// Save map 
    65 	void setZipped(bool);		// save map zipped
    66 	bool saveZipped();			// 1 if file will be saved zipped
    67     void print();				// print canvas
    68 private:
    69     QPixmap getPixmap();
    70 	void setHideTmpMode (HideTmpMode);	// temporary hide stuff
    71 	HideTmpMode getHideTmpMode();		// temporary hide stuff
    72 public:
    73 	void setExportMode (bool);			// temporary hide stuff during export
    74     void exportImage (QString fn);			// export as PNG	
    75     void exportImage (QString fn, QString);	// export in given format
    76     void exportOOPresentation(const QString &,const QString &);
    77     void exportXML(const QString&);		// export to directory
    78     void clear();		// clear map
    79     void copy();		// copy branch to clipboard
    80     void redo();		// redo last action
    81 	bool isRedoAvailable();
    82     void undo();		// undo last action
    83 	bool isUndoAvailable();
    84 	void gotoStep (int);// goto a step in history
    85 private:	
    86     void undoXML(const QString &, const QString &);
    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 &,const int&);
    93     void moveRel (const int &,const int&);
    94     void moveBranchUp();
    95     void moveBranchDown();
    96 	QString getHeading (bool &,QPoint &);	// Get heading, ok if selection is branch
    97 	void setHeading(const QString &);
    98 private:
    99 	void setHeadingInt(const QString &);
   100 	void setURLInt(const QString &);		// Just set the URL for selection
   101 	void setVymLinkInt(const QString &);	// Set vymLink for selection
   102     BranchObj* addNewBranchInt(int);		// pos allows to add above/below selection
   103 public:	
   104     void addNewBranch(int);			// pos allows to add above/below selection
   105     void addNewBranchHere();		// insert and make selection its
   106     void deleteSelection();
   107 	LinkableMapObj* getSelection();	// returns selection
   108 	void unselect();				// before changing current noteedit
   109 	void reselect();				// after  changing current noteedit
   110 	bool select(const QString &);	// Select by string
   111 	QString getSelectString();
   112 private:	
   113 	void selectInt(LinkableMapObj*);	
   114 	void selectNextBranchInt();		// Increment number of branch
   115 	void selectPrevBranchInt();		// Decrement number of branch
   116 public:	
   117     void selectUpperBranch();
   118     void selectLowerBranch();
   119     void selectLeftBranch();
   120     void selectRightBranch();
   121     void selectFirstBranch();
   122     void selectLastBranch();
   123     void setColor(QColor);
   124     void selectBackgroundColor();
   125     void setBackgroundColor(QColor);
   126     QColor pickColor();
   127     void colorItem();
   128     void colorBranch();
   129 	void toggleStandardFlag(QString);
   130 	virtual void setViewCenter();			// needed for zooming
   131     BranchObj* findText(QString,bool);		// Find object
   132     void findReset();						// Reset Find 
   133 	void editURL();							// edit the URL
   134 	QString getURL();						// returns URL of selection or ""
   135 	QStringList getURLs();					// returns URLs of subtree
   136 	void editHeading2URL();					// copy heading to URL
   137 	void editBugzilla2URL();				// create URL to Bugzilla
   138 	void editFATE2URL();					// create URL to FATE
   139 	void editVymLink();						// edit link to another map
   140 	void deleteVymLink();					// delete link to another map
   141 	QString getVymLink();					// return path to map
   142 	QStringList getVymLinks();				// return paths in subtree
   143 	void toggleHideExport();				// toggle the export flag
   144 	void removeBranchKeepChilds();			// remove but keep childs
   145 	void removeChilds();					// remove childs
   146 	void editMapInfo();						// dialog to enter author, ...
   147 	void updateActions();					// update e.g. format buttons
   148 	void updateNoteFlag();					// when TextEditor changes
   149 	void setLinkStyle (LinkStyle);			// Set style of link
   150 	LinkStyle getLinkStyle ();				// requested in LMO
   151 	void setLinkColor(QColor);				// default color of links
   152 	void setLinkColorHint();				// color of links
   153 	void setLinkColorHint(LinkColorHint);	// color of links
   154 	LinkColorHint getLinkColorHint();
   155 	QColor getDefLinkColor();
   156 	void setDefXLinkColor(QColor);
   157 	QColor getDefXLinkColor();
   158 	void setDefXLinkWidth (int);
   159 	int getDefXLinkWidth();
   160 	void toggleLinkColorHint();				// after changing linkStyles
   161     void selectLinkColor();
   162     void toggleScroll();
   163     void unScrollAll();
   164 	void loadFloatImage ();
   165 	void saveFloatImage ();
   166 	void setFrame(const FrameType &);
   167 	void setIncludeImagesVer(bool);
   168 	void setIncludeImagesHor(bool);
   169 	void setHideLinkUnselected (bool);
   170 	bool getHideLinkUnselected ();
   171 private:	
   172     void importDirInt(BranchObj *,QDir);
   173 public:	
   174     void importDir();
   175 	void followXLink (int);
   176 	void editXLink (int);
   177     void testFunction();					// just testing new stuff
   178 											// set /mainwindo/showTestMenu=true...
   179 
   180 protected:
   181 	void ensureSelectionVisible();		
   182 	virtual void updateViewCenter();	// needed for zooming
   183 	virtual void contentsContextMenuEvent ( QContextMenuEvent *e );
   184     virtual void contentsMousePressEvent(QMouseEvent*);
   185     virtual void contentsMouseReleaseEvent(QMouseEvent*);
   186     virtual void contentsMouseDoubleClickEvent(QMouseEvent*);
   187     virtual void contentsMouseMoveEvent(QMouseEvent*);
   188 
   189     virtual void contentsDragEnterEvent(QDragEnterEvent *event);
   190     virtual void contentsDropEvent(QDropEvent *event);
   191 private:
   192     Q3Canvas* mapCanvas;
   193     MapCenterObj* mapCenter;
   194 
   195 	bool adjustCanvasRequested;	// collect requests until end of user event
   196 	BranchObj *editingBO;		// entering Text into BO
   197 
   198     QColor actColor;			// actual color
   199 	QColor defLinkColor;		// default color for links
   200 	QColor defXLinkColor;		// default color for xlinks
   201 	int defXLinkWidth;			// default width for xlinks
   202 	LinkColorHint linkcolorhint;// use heading color or own color
   203 	LinkStyle linkstyle;		// default style for links
   204 
   205     QCursor handOpenCursor;		// cursor while moving canvas view
   206 	QCursor pickColorCursor;	// cursor while picking color 
   207 	bool pickingColor;
   208 	bool drawingLink;			// true while creating a link
   209 	bool copyingObj;			// true while creating a link
   210 	XLinkObj* tmpXLink;
   211 
   212 	Selection xelection;
   213     LinkableMapObj* selection;		// select a LinkableMapObj
   214     LinkableMapObj* selectionLast;	// last selection 
   215     MapObj* movingObj;				// moving a MapObj
   216 	MapObj* linkingObj_src;			// part of a link
   217     QPoint movingObj_orgPos;		// org. pos of mouse before move
   218     QPoint movingObj_orgRelPos;		// org. relative pos of mouse before move
   219     QPoint movingObj_start;			// rel. pos of mouse to absPos 
   220     QPoint movingCont_start;		// inital pos of moving Content or
   221     QPoint movingVec;				// how far has Content moved
   222 	QPoint movingCenter;			// used when zooming
   223     QPrinter* printer;				// Printing
   224 
   225     bool mapDefault;				// Flag if map is untouched
   226     bool mapChanged;				// Flag if undo is possible
   227 	bool mapUnsaved;				// Flag if map should be saved
   228 
   229 	bool printFrame;			// Print frame around map
   230 	bool printFooter;			// Print footer below map
   231 
   232 	bool zipped;				// should map be zipped
   233 static	int mapNum;				// unique number for Editor
   234 	QString fileName;			// short name of file (for tab)
   235 	QString filePath;			// path to file which will be saved
   236 	QString fileDir;			// dir where file is saved
   237 	QString destPath;			// path to .vym file (needed for vymlinks)
   238 	QString mapName;			// fileName without ".vym"
   239 
   240 	QString tmpMapDir;			// tmp directory with undo history
   241 	QString histPath;			// Path to history file
   242 	int stepsTotal;				// total number of steps (undos+redos) 
   243 	SimpleSettings undoSet;		// undo/redo commands
   244 	bool blockReposition;		// block while load or undo
   245 	bool blockSaveState;		// block while load or undo
   246 
   247 	BranchObj* itFind;			// next object in find process
   248 	bool EOFind;				// true, if search failed
   249 
   250 	QPoint exportOffset;		// set before export, used in save
   251 	HideTmpMode hidemode;			// true while exporting to hide some stuff
   252 	
   253     void resizeEvent( QResizeEvent * );
   254 
   255 	Q3UrlOperator *urlOperator;
   256 	QDataStream *imageData;
   257 	QBuffer *imageBuffer;
   258 
   259 	HistoryWindow historyWindow;
   260 
   261 };
   262 #endif
   263