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