mapeditor.h
author insilmaril
Mon, 27 Mar 2006 20:21:58 +0000
changeset 262 1f2c27608b4f
parent 260 69d648a0a15b
child 266 7d91b35c1b6f
permissions -rw-r--r--
More documentation, fixed small bug where links of unselected objects where visible again
     1 #ifndef MAPEDITOR_H
     2 #define MAPEDITOR_H
     3 
     4 #include <qcanvas.h>
     5 #include <qlineedit.h>
     6 #include <qcursor.h>
     7 #include <qfiledialog.h>
     8 #include <qevent.h>
     9 #include <qprocess.h>
    10 #include <qbuffer.h>
    11 
    12 #include "mapcenterobj.h"
    13 #include "file.h"
    14 #include "misc.h"
    15 
    16 class QNetworkOperation;
    17 class QUrlOperator;
    18 
    19 class MapEditor : public QCanvasView , public xmlObj {
    20     Q_OBJECT
    21 
    22 public:
    23     MapEditor(QWidget* parent=0, bool interactive=false, const char* name=0, WFlags f=0);
    24 	~MapEditor();
    25     QColor color();
    26     QColor backgroundColor();
    27     MapCenterObj* getMapCenter();
    28 	QCanvas* getCanvas();
    29 	void adjustCanvasSize();// adjust canvas size to map and scrollview
    30 	bool isRepositionBlocked(); // block while load or undo
    31 	
    32 private:
    33 	void makeTmpDirs();		// create temporary directories
    34     QString saveToDir(const QString&,const QString &,bool, const QPoint &,LinkableMapObj*);
    35     void saveState();		// save actual state to backup
    36     void saveState(LinkableMapObj *);
    37     void saveState(const QString &, const QString &);
    38     void saveState(const QString &, LinkableMapObj *);
    39     void saveState(const SaveMode&, const QString &, LinkableMapObj *, const QString &, LinkableMapObj *);
    40     void parseAtom(const QString &);	
    41 
    42     void addFloatImage(const QPixmap &img);
    43 
    44   private slots:
    45     void finishedLineEditNoSave();
    46     void fetchImage(const QString &img);
    47     void imageDataFetched(const QByteArray &, QNetworkOperation *);
    48     void imageDataFinished(QNetworkOperation *);
    49 
    50 public:
    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, int);	// 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     void undo();		// undo last action
    82 private:	
    83     void undoXML(const QString &, const QString &);
    84     void pasteNoSave();		// paste clipboard to branch
    85     void cutNoSave();	// cut to clipboard
    86 public:	
    87     void paste();		// paste clipboard to branch and backup
    88     void cut();			// cut to clipboard and backup
    89     void move(const int &,const int&);
    90     void moveBranchUp();
    91     void moveBranchDown();
    92     void editHeading();					// Start editing heading 
    93 private:
    94 	void setHeading(const QString &);	// Just set the heading for selection
    95 	void setURL(const QString &);		// Just set the URL for selection
    96 	void setVymLink(const QString &);	// Set vymLink for selection
    97 public:	
    98     void addNewBranch(int);			// pos allows to add above/below selection
    99     void addNewBranchHere();		// insert and make selection its
   100     void deleteSelection();
   101 	LinkableMapObj* getSelection();	// returns selection
   102 	bool select(const QString &);	// Select 
   103 	void unselect();				// before changing current noteedit
   104 	void reselect();				// after  changing current noteedit
   105 private:	
   106 	void selectNextBranch();		// Increment number of branch
   107 	void selectPrevBranch();		// Decrement number of branch
   108 public:	
   109     void selectUpperBranch();
   110     void selectLowerBranch();
   111     void selectLeftBranch();
   112     void selectRightBranch();
   113     void selectFirstBranch();
   114     void selectLastBranch();
   115     void setColor(QColor);
   116     void selectBackgroundColor();
   117     void setBackgroundColor(QColor);
   118     QColor pickColor();
   119     void colorItem();
   120     void colorBranch();
   121 	void toggleStandardFlag(QString);
   122 	virtual void setViewCenter();			// needed for zooming
   123     BranchObj* findText(QString,bool);		// Find object
   124     void findReset();						// Reset Find 
   125 	void openURL();							// open URL in external browser
   126 	void editURL();							// edit the URL
   127 	void editHeading2URL();					// copy heading to URL
   128 	void editBugzilla2URL();				// create URL to Bugzilla
   129 	void editFATE2URL();					// create URL to FATE
   130 	void editVymLink();						// edit link to another map
   131 	void deleteVymLink();					// delete link to another map
   132 	QString getVymLink();					// return path to map
   133 	void setHideExport();					// toggle the export flag
   134 protected:	
   135 	void toggleHideExport();				// toggle the export flag
   136 public:	
   137 	void removeBranchHere();				// remove but keep childs
   138 	void removeChilds();					// remove childs
   139 	void editMapInfo();						// dialog to enter author, ...
   140 	void updateActions();					// update e.g. format buttons
   141 	void updateNoteFlag();					// when TextEditor changes
   142 	void setLinkStyle (LinkStyle);			// Set style of link
   143 	LinkStyle getLinkStyle ();				// requested in LMO
   144 	void setLinkColor(QColor);				// default color of links
   145 	void setLinkColorHint();				// color of links
   146 	void setLinkColorHint(LinkColorHint);	// color of links
   147 	LinkColorHint getLinkColorHint();
   148 	QColor getDefLinkColor();
   149 	void setDefXLinkColor(QColor);
   150 	QColor getDefXLinkColor();
   151 	void setDefXLinkWidth (int);
   152 	int getDefXLinkWidth();
   153 	void toggleLinkColorHint();				// after changing linkStyles
   154     void selectLinkColor();
   155     void toggleScroll();
   156     void unScrollAll();
   157 	void loadFloatImage ();
   158 	void saveFloatImage (int);
   159 	void setFrame(const FrameType &);
   160 	void setIncludeImagesVer(bool);
   161 	void setIncludeImagesHor(bool);
   162 	void setHideLinkUnselected (bool);
   163 	bool getHideLinkUnselected ();
   164 private:	
   165     void importDir(BranchObj *,QDir);
   166 public:	
   167     void importDir();
   168 	void followXLink (int);
   169 	void editXLink (int);
   170     void testFunction();				// FIXME just testing
   171 
   172 protected:
   173 	void ensureSelectionVisible();		
   174 	virtual void updateViewCenter();	// needed for zooming
   175 	virtual void contentsContextMenuEvent ( QContextMenuEvent *e );
   176     virtual void contentsMousePressEvent(QMouseEvent*);
   177     virtual void contentsMouseReleaseEvent(QMouseEvent*);
   178     virtual void contentsMouseDoubleClickEvent(QMouseEvent*);
   179     virtual void contentsMouseMoveEvent(QMouseEvent*);
   180 
   181     virtual void contentsDragEnterEvent(QDragEnterEvent *event);
   182     virtual void contentsDropEvent(QDropEvent *event);
   183 private:
   184     QCanvas* mapCanvas;
   185     MapCenterObj* mapCenter;
   186 
   187 	bool adjustCanvasRequested;	// collect requests until end of user event
   188 	BranchObj *editingBO;		// entering Text into BO
   189     QLineEdit* lineedit;
   190 
   191     QColor actColor;			// actual color
   192 	QColor defLinkColor;		// default color for links
   193 	QColor defXLinkColor;		// default color for xlinks
   194 	int defXLinkWidth;			// default width for xlinks
   195 	LinkColorHint linkcolorhint;// use heading color or own color
   196 	LinkStyle linkstyle;		// default style for links
   197 
   198     QCursor handOpenCursor;		// cursor while moving canvas view
   199 	QCursor pickColorCursor;	// cursor while picking color 
   200 	bool pickingColor;
   201 	bool drawingLink;			// true while creating a link
   202 	bool copyingObj;			// true while creating a link
   203 	XLinkObj* tmpXLink;
   204 	
   205     LinkableMapObj* selection;		// select a LinkableMapObj
   206     LinkableMapObj* selectionLast;	// last selection 
   207     MapObj* movingObj;				// moving a MapObj
   208 	MapObj* linkingObj_src;			// part of a link
   209     QPoint movingObj_orgPos;		// org. pos of mouse before move
   210     QPoint movingObj_start;			// rel. pos of mouse to absPos 
   211     QPoint movingCont_start;		// inital pos of moving Content or
   212     QPoint movingVec;				// how far has Content moved
   213 	QPoint movingCenter;			// used when zooming
   214     QPrinter* printer;				// Printing
   215 
   216     bool mapDefault;				// Flag if map is untouched
   217     bool mapChanged;				// Flag if undo is possible
   218 	bool mapUnsaved;				// Flag if map should be saved
   219 
   220 	bool printFrame;			// Print frame around map
   221 	bool printFooter;			// Print footer below map
   222 
   223 	bool zipped;				// should map be zipped
   224 static	int mapNum;				// unique number for Editor
   225 	QString fileName;			// short name of file (for tab)
   226 	QString filePath;			// path to file which will be saved
   227 	QString fileDir;			// dir where file is saved
   228 	QString destPath;			// path to .vym file (needed for vymlinks)
   229 	QString mapName;			// fileName without ".vym"
   230 	QString lastImageDir;		// save dir for adding images
   231 
   232 	bool isInteractive;			// non interactive don't need tmpdirs
   233 	QString tmpMapDir;			// tmp directory with data for undo/redo
   234 	int undosTotal;				// total number of undos 
   235 	int undoNum;				// current number of bakMapDir to be used 
   236 	int undosAvail;				// how many actions can currently be undone
   237 	bool blockReposition;		// block while load or undo
   238 	bool blockSaveState;		// block while load or undo
   239 
   240 	BranchObj* itFind;			// next object in find process
   241 	bool EOFind;				// true, if search failed
   242 
   243 	QPoint exportOffset;		// set before export, used in save
   244 	HideTmpMode hidemode;			// true while exporting to hide some stuff
   245 	
   246     void resizeEvent( QResizeEvent * );
   247 
   248   QUrlOperator *urlOperator;
   249   QDataStream *imageData;
   250   QBuffer *imageBuffer;
   251 
   252 };
   253 #endif
   254