mapeditor.h
author insilmaril
Wed Mar 08 12:59:08 2006 +0000 (2006-03-08)
changeset 237 10b1ead03424
parent 205 30c4a6c7ff10
child 243 fad762341d2d
permissions -rw-r--r--
Fixed Image Preview in FileDialog
     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 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     void undo();		// undo last action
    80 private:	
    81     void undoXML(const QString &, const QString &);
    82     void pasteNoSave();		// paste clipboard to branch
    83     void cutNoSave();	// cut to clipboard
    84 public:	
    85     void paste();		// paste clipboard to branch and backup
    86     void cut();			// cut to clipboard and backup
    87     void move(const int &,const int&);
    88     void moveBranchUp();
    89     void moveBranchDown();
    90     void editHeading();					// Start editing heading 
    91 private:
    92 	void setHeading(const QString &);	// Just set the heading for selection
    93 	void setURL(const QString &);		// Just set the URL for selection
    94 	void setVymLink(const QString &);	// Set vymLink for selection
    95 public:	
    96     void addNewBranch(int);			// pos allows to add above/below selection
    97     void addNewBranchHere();		// insert and make selection its
    98     void deleteSelection();
    99 	LinkableMapObj* getSelection();	// returns selection
   100 	bool select(const QString &);	// Select 
   101 	void unselect();				// before changing current noteedit
   102 	void reselect();				// after  changing current noteedit
   103 private:	
   104 	void selectNextBranch();		// Increment number of branch
   105 	void selectPrevBranch();		// Decrement number of branch
   106 public:	
   107     void selectUpperBranch();
   108     void selectLowerBranch();
   109     void selectLeftBranch();
   110     void selectRightBranch();
   111     void selectFirstBranch();
   112     void selectLastBranch();
   113     void setColor(QColor);
   114     void selectBackgroundColor();
   115     void setBackgroundColor(QColor);
   116     QColor pickColor();
   117     void colorItem();
   118     void colorBranch();
   119 	void toggleStandardFlag(QString);
   120 	virtual void setViewCenter();			// needed for zooming
   121     BranchObj* findText(QString,bool);		// Find object
   122     void findReset();						// Reset Find 
   123 	void openURL();							// open URL in external browser
   124 	void editURL();							// edit the URL
   125 	void editHeading2URL();					// copy heading to URL
   126 	void editBugzilla2URL();				// create URL to Bugzilla
   127 	void editFATE2URL();					// create URL to FATE
   128 	void editVymLink();						// edit link to another map
   129 	void deleteVymLink();					// delete link to another map
   130 	QString getVymLink();					// return path to map
   131 	void removeBranchHere();				// remove but keep childs
   132 	void removeChilds();					// remove childs
   133 	void editMapInfo();						// dialog to enter author, ...
   134 	void updateActions();					// update e.g. format buttons
   135 	void updateNoteFlag();					// when TextEditor changes
   136 	void setLinkStyle (LinkStyle);			// Set style of link
   137 	LinkStyle getLinkStyle ();				// requested in LMO
   138 	void setLinkColor(QColor);				// default color of links
   139 	void setLinkColorHint();				// color of links
   140 	void setLinkColorHint(LinkColorHint);	// color of links
   141 	LinkColorHint getLinkColorHint();
   142 	QColor getDefLinkColor();
   143 	void setDefXLinkColor(QColor);
   144 	QColor getDefXLinkColor();
   145 	void setDefXLinkWidth (int);
   146 	int getDefXLinkWidth();
   147 	void toggleLinkColorHint();				// after changing linkStyles
   148     void selectLinkColor();
   149     void toggleScroll();
   150     void unScrollAll();
   151 	void loadFloatImage ();
   152 	void saveFloatImage (int);
   153 	void toggleFloatExport();
   154 	void setFrame(const FrameType &);
   155 	void setIncludeImagesVer(bool);
   156 	void setIncludeImagesHor(bool);
   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