mapeditor.h
author insilmaril
Tue, 21 Feb 2006 16:18:23 +0000
changeset 217 375be2baa976
parent 205 30c4a6c7ff10
child 228 654ad4b03c5a
permissions -rw-r--r--
rudimentary mmap import
     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 	void delTmpDirs();		// delete temporary directories
    35     QString saveToDir(const QString&,const QString &,bool, const QPoint &,LinkableMapObj*);
    36     void saveState();		// save actual state to backup
    37     void saveState(LinkableMapObj *);
    38     void saveState(const QString &, const QString &);
    39     void saveState(const QString &, LinkableMapObj *);
    40     void saveState(const SaveMode&, const QString &, LinkableMapObj *, const QString &, LinkableMapObj *);
    41     void parseAtom(const QString &);	
    42 
    43     void addFloatImage(const QPixmap &img);
    44 
    45   private slots:
    46     void finishedLineEditNoSave();
    47     void fetchImage(const QString &img);
    48     void imageDataFetched(const QByteArray &, QNetworkOperation *);
    49     void imageDataFinished(QNetworkOperation *);
    50 
    51 public:
    52 	bool isDefault();		// false, if map was changed once
    53     bool isUnsaved();		// save necessary
    54     bool hasChanged();		// undo possible
    55 	void setChanged();		// called from NoteEditor via LMO
    56 	void closeMap();
    57 	void setFilePath (QString);	
    58 	void setFilePath (QString,QString);	
    59 	QString getFilePath ();	// Full path e.g. "/home/tux/map.xml"
    60 	QString getFileName ();	// e.g. "map.xml"
    61 	QString getMapName ();	// e.g. "map"
    62 	QString getDestPath (); // e.g. "/home/tux/map.vym"
    63     ErrorCode load (QString, LoadMode );	// newmap, import/replace selection
    64 public:
    65     int save(const SaveMode &);	// Save map 
    66 	void setZipped(bool);		// save map zipped
    67 	bool saveZipped();			// 1 if file will be saved zipped
    68     void print();				// print canvas
    69 private:
    70     QPixmap getPixmap();
    71 public:
    72     void exportImage (QString fn);		// export as PNG	
    73     void exportImage (QString fn, int);	// export in given format
    74     void exportASCII();
    75     void exportLaTeX();
    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 removeBranchHere();				// remove but keep childs
   134 	void removeChilds();					// remove childs
   135 	void editMapInfo();						// dialog to enter author, ...
   136 	void updateActions();					// update e.g. format buttons
   137 	void updateNoteFlag();					// when TextEditor changes
   138 	void setLinkStyle (LinkStyle);			// Set style of link
   139 	LinkStyle getLinkStyle ();				// requested in LMO
   140 	void setLinkColor(QColor);				// default color of links
   141 	void setLinkColorHint();				// color of links
   142 	void setLinkColorHint(LinkColorHint);	// color of links
   143 	LinkColorHint getLinkColorHint();
   144 	QColor getDefLinkColor();
   145 	void setDefXLinkColor(QColor);
   146 	QColor getDefXLinkColor();
   147 	void setDefXLinkWidth (int);
   148 	int getDefXLinkWidth();
   149 	void toggleLinkColorHint();				// after changing linkStyles
   150     void selectLinkColor();
   151     void toggleScroll();
   152     void unScrollAll();
   153 	void loadFloatImage ();
   154 	void saveFloatImage (int);
   155 	void toggleFloatExport();
   156 	void setFrame(const FrameType &);
   157 	void setIncludeImagesVer(bool);
   158 	void setIncludeImagesHor(bool);
   159 	void setHideLinkUnselected (bool);
   160 	bool getHideLinkUnselected ();
   161 private:	
   162     void importDir(BranchObj *,QDir);
   163 public:	
   164     void importDir();
   165 	void followXLink (int);
   166 	void editXLink (int);
   167     void testFunction();				// FIXME just testing
   168 
   169 protected:
   170 	void ensureSelectionVisible();		
   171 	virtual void updateViewCenter();	// needed for zooming
   172 	virtual void contentsContextMenuEvent ( QContextMenuEvent *e );
   173     virtual void contentsMousePressEvent(QMouseEvent*);
   174     virtual void contentsMouseReleaseEvent(QMouseEvent*);
   175     virtual void contentsMouseDoubleClickEvent(QMouseEvent*);
   176     virtual void contentsMouseMoveEvent(QMouseEvent*);
   177 
   178     virtual void contentsDragEnterEvent(QDragEnterEvent *event);
   179     virtual void contentsDropEvent(QDropEvent *event);
   180 private:
   181     QCanvas* mapCanvas;
   182     MapCenterObj* mapCenter;
   183 
   184 	bool adjustCanvasRequested;	// collect requests until end of user event
   185 	BranchObj *editingBO;		// entering Text into BO
   186     QLineEdit* lineedit;
   187 
   188     QColor actColor;			// actual color
   189 	QColor defLinkColor;		// default color for links
   190 	QColor defXLinkColor;		// default color for xlinks
   191 	int defXLinkWidth;			// default width for xlinks
   192 	LinkColorHint linkcolorhint;// use heading color or own color
   193 	LinkStyle linkstyle;		// default style for links
   194 
   195     QCursor handOpenCursor;		// cursor while moving canvas view
   196 	QCursor pickColorCursor;	// cursor while picking color 
   197 	bool pickingColor;
   198 	bool drawingLink;			// true while creating a link
   199 	bool copyingObj;			// true while creating a link
   200 	XLinkObj* tmpXLink;
   201 	
   202     LinkableMapObj* selection;		// select a LinkableMapObj
   203     LinkableMapObj* selectionLast;	// last selection 
   204     MapObj* movingObj;				// moving a MapObj
   205 	MapObj* linkingObj_src;			// part of a link
   206     QPoint movingObj_orgPos;		// org. pos of mouse before move
   207     QPoint movingObj_start;			// rel. pos of mouse to absPos 
   208     QPoint movingCont_start;		// inital pos of moving Content or
   209     QPoint movingVec;				// how far has Content moved
   210 	QPoint movingCenter;			// used when zooming
   211     QPrinter* printer;				// Printing
   212 
   213     bool mapDefault;				// Flag if map is untouched
   214     bool mapChanged;				// Flag if undo is possible
   215 	bool mapUnsaved;				// Flag if map should be saved
   216 
   217 	bool printFrame;			// Print frame around map
   218 	bool printFooter;			// Print footer below map
   219 
   220 	bool zipped;				// should map be zipped
   221 static	int mapNum;				// unique number for Editor
   222 	QString fileName;			// short name of file (for tab)
   223 	QString filePath;			// path to file which will be saved
   224 	QString fileDir;			// dir where file is saved
   225 	QString destPath;			// path to .vym file (needed for vymlinks)
   226 	QString mapName;			// fileName without ".vym"
   227 	QString lastImageDir;		// save dir for adding images
   228 
   229 	bool isInteractive;			// non interactive don't need tmpdirs
   230 	QString tmpMapDir;			// tmp directory with data for undo/redo
   231 	int undosTotal;				// total number of undos 
   232 	int undoNum;				// current number of bakMapDir to be used 
   233 	int undosAvail;				// how many actions can currently be undone
   234 	bool blockReposition;		// block while load or undo
   235 	bool blockSaveState;		// block while load or undo
   236 
   237 	BranchObj* itFind;			// next object in find process
   238 	bool EOFind;				// true, if search failed
   239 
   240 	QPoint exportOffset;		// set before export, used in save
   241     void resizeEvent( QResizeEvent * );
   242 
   243   QUrlOperator *urlOperator;
   244   QDataStream *imageData;
   245   QBuffer *imageBuffer;
   246 
   247 };
   248 #endif
   249