mapeditor.h
author insilmaril
Thu, 22 Sep 2005 12:56:05 +0000
changeset 165 4244bcd9e6ea
parent 164 d442a66e9121
child 166 325958acb69b
permissions -rw-r--r--
fixed problem where note got lost by copying a branch
     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 "misc.h"
    14 
    15 class QNetworkOperation;
    16 class QUrlOperator;
    17 
    18 class MapEditor : public QCanvasView , public xmlObj {
    19     Q_OBJECT
    20 
    21 public:
    22     MapEditor(QWidget* parent=0, bool interactive=false, const char* name=0, WFlags f=0);
    23 	~MapEditor();
    24     QColor color();
    25     QColor backgroundColor();
    26     MapCenterObj* getMapCenter();
    27 	QCanvas* getCanvas();
    28 	void adjustCanvasSize();// adjust canvas size to map and scrollview
    29 	bool isRepositionBlocked(); // block while load or undo
    30 	
    31 private:
    32 	void makeTmpDirs();		// create temporary directories
    33 	void delTmpDirs();		// delete temporary directories
    34 	void makeSubDirs(const QString&);		
    35 							// create subdirs in dir
    36     QString saveToDir(const QString&,const QString &,bool, const QPoint &,LinkableMapObj*);
    37     void saveState();		// save actual state to backup
    38     void saveState(LinkableMapObj *);
    39     void saveState(const QString &, const QString &);
    40     void saveState(const QString &, LinkableMapObj *);
    41     void saveState(const SaveMode&, const QString &, LinkableMapObj *, const QString &, LinkableMapObj *);
    42     void parseAtom(const QString &);	
    43 
    44     void addFloatImage(const QPixmap &img);
    45 
    46   private slots:
    47     void finishedLineEditNoSave();
    48     void fetchImage(const QString &img);
    49     void imageDataFetched(const QByteArray &, QNetworkOperation *);
    50     void imageDataFinished(QNetworkOperation *);
    51 
    52 public:
    53 	bool isDefault();		// false, if map was changed once
    54     bool isUnsaved();		// save necessary
    55     bool hasChanged();		// undo possible
    56 	void setChanged();		// called from NoteEditor via LMO
    57 	void closeMap();
    58 	void setFilePath (QString);	
    59 	void setFilePath (QString,QString);	
    60 	QString getFilePath ();	// Full path e.g. "/home/tux/map.xml"
    61 	QString getFileName ();	// e.g. "map.xml"
    62 	QString getMapName ();	// e.g. "map"
    63 	QString getDestPath (); // e.g. "/home/tux/map.vym"
    64     int load (QString&, const LoadMode &);	// newmap, import/replace selection
    65 public:
    66     int save(const SaveMode &);	// Save map 
    67 	void setZipped(bool);		// save map zipped
    68 	bool saveZipped();			// 1 if file will be saved zipped
    69     void print();				// print canvas
    70 private:
    71     QPixmap getPixmap();
    72 public:
    73     void exportImage (QString fn);		// export as PNG	
    74     void exportImage (QString fn, int);	// export in given format
    75     void exportASCII();
    76     void exportLaTeX();
    77     void exportOOPresentation();
    78     void exportXML(const QString&);		// export to directory
    79     void clear();		// clear map
    80     void copy();		// copy branch to clipboard
    81     void redo();		// redo last action
    82     void undo();		// undo last action
    83 private:	
    84     void undoXML(const QString &, const QString &);
    85     LinkableMapObj* pasteNoSave();		// paste clipboard to branch
    86     void cutNoSave();	// cut to clipboard
    87 public:	
    88     void paste();		// paste clipboard to branch and backup
    89     void cut();			// cut to clipboard and backup
    90     void move(const int &,const int&);
    91     void moveBranchUp();
    92     void moveBranchDown();
    93     void editHeading();					// Start editing heading 
    94 private:
    95 	void setHeading(const QString &);	// Just set the heading for selection
    96 	void setURL(const QString &);		// Just set the URL for selection
    97 	void setVymLink(const QString &);	// Set vymLink for selection
    98 public:	
    99     void addNewBranch(int);			// pos allows to add above/below selection
   100     void addNewBranchHere();		// insert and make selection its
   101     void deleteSelection();
   102 	LinkableMapObj* getSelection();	// returns selection
   103 	bool select(const QString &);	// Select 
   104 	void unselect();				// before changing current noteedit
   105 	void reselect();				// after  changing current noteedit
   106 private:	
   107 	void selectNextBranch();		// Increment number of branch
   108 	void selectPrevBranch();		// Decrement number of branch
   109 public:	
   110     void selectUpperBranch();
   111     void selectLowerBranch();
   112     void selectLeftBranch();
   113     void selectRightBranch();
   114     void selectFirstBranch();
   115     void selectLastBranch();
   116     void setColor(QColor);
   117     void selectBackgroundColor();
   118     void setBackgroundColor(QColor);
   119     QColor pickColor();
   120     void colorItem();
   121     void colorBranch();
   122 	void toggleStandardFlag(QString);
   123 	virtual void setViewCenter();			// needed for zooming
   124     BranchObj* findText(QString,bool);		// Find object
   125     void findReset();						// Reset Find 
   126 	void openURL();							// open URL in external browser
   127 	void editURL();							// edit the URL
   128 	void editHeading2URL();					// copy heading to URL
   129 	void editBugzilla2URL();				// create URL to Bugzilla
   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 setHideLinkUnselected (bool);
   158 	bool getHideLinkUnselected ();
   159 private:	
   160     void importDir(BranchObj *,QDir);
   161 public:	
   162     void importDir();
   163 	void followXLink (int);
   164 	void editXLink (int);
   165     void testFunction();				// FIXME just testing
   166 
   167 protected:
   168 	void ensureSelectionVisible();		
   169 	virtual void updateViewCenter();	// needed for zooming
   170 	virtual void contentsContextMenuEvent ( QContextMenuEvent *e );
   171     virtual void contentsMousePressEvent(QMouseEvent*);
   172     virtual void contentsMouseReleaseEvent(QMouseEvent*);
   173     virtual void contentsMouseDoubleClickEvent(QMouseEvent*);
   174     virtual void contentsMouseMoveEvent(QMouseEvent*);
   175 
   176     virtual void contentsDragEnterEvent(QDragEnterEvent *event);
   177     virtual void contentsDropEvent(QDropEvent *event);
   178 private:
   179     QCanvas* mapCanvas;
   180     MapCenterObj* mapCenter;
   181 
   182 	bool adjustCanvasRequested;	// collect requests until end of user event
   183 	BranchObj *editingBO;		// entering Text into BO
   184     QLineEdit* lineedit;
   185 
   186     QColor actColor;			// actual color
   187 	QColor defLinkColor;		// default color for links
   188 	QColor defXLinkColor;		// default color for xlinks
   189 	int defXLinkWidth;			// default width for xlinks
   190 	LinkColorHint linkcolorhint;// use heading color or own color
   191 	LinkStyle linkstyle;		// default style for links
   192 
   193     QCursor handOpenCursor;		// cursor while moving canvas view
   194 	QCursor pickColorCursor;	// cursor while picking color 
   195 	bool pickingColor;
   196 	bool drawingLink;			// true while creating a link
   197 	bool copyingObj;			// true while creating a link
   198 	XLinkObj* tmpXLink;
   199 	
   200     LinkableMapObj* selection;		// select a LinkableMapObj
   201     LinkableMapObj* selectionLast;	// last selection 
   202     MapObj* movingObj;				// moving a MapObj
   203 	MapObj* linkingObj_src;			// part of a link
   204     QPoint movingObj_orgPos;		// org. pos of mouse before move
   205     QPoint movingObj_start;			// rel. pos of mouse to absPos 
   206     QPoint movingCont_start;		// inital pos of moving Content or
   207     QPoint movingVec;				// how far has Content moved
   208 	QPoint movingCenter;			// used when zooming
   209     QPrinter* printer;				// Printing
   210 
   211     bool mapDefault;				// Flag if map is untouched
   212     bool mapChanged;				// Flag if undo is possible
   213 	bool mapUnsaved;				// Flag if map should be saved
   214 
   215 	bool printFrame;			// Print frame around map
   216 	bool printFooter;			// Print footer below map
   217 
   218 	bool zipped;				// should map be zipped
   219 static	int mapNum;				// unique number for Editor
   220 	QString fileName;			// short name of file (for tab)
   221 	QString filePath;			// path to file which will be saved
   222 	QString fileDir;			// dir where file is saved
   223 	QString destPath;			// path to .vym file (needed for vymlinks)
   224 	QString mapName;			// fileName without ".vym"
   225 	QString lastImageDir;		// save dir for adding images
   226 
   227 	bool isInteractive;			// non interactive don't need tmpdirs
   228 	QString tmpMapDir;			// tmp directory with data for undo/redo
   229 	int undosTotal;				// total number of undos 
   230 	int undoNum;				// current number of bakMapDir to be used 
   231 	int undosAvail;				// how many actions can currently be undone
   232 	bool blockReposition;		// block while load or undo
   233 	bool blockSaveState;		// block while load or undo
   234 
   235 	BranchObj* itFind;			// next object in find process
   236 	bool EOFind;				// true, if search failed
   237 
   238 	QPoint exportOffset;		// set before export, used in save
   239     void resizeEvent( QResizeEvent * );
   240 
   241   QUrlOperator *urlOperator;
   242   QDataStream *imageData;
   243   QBuffer *imageBuffer;
   244 
   245 };
   246 #endif
   247