mapeditor.h
author insilmaril
Thu, 14 Sep 2006 11:38:17 +0000
changeset 383 bf5ba1bd4764
parent 381 c79df732d095
child 390 0e1aeb21cb78
permissions -rw-r--r--
1.8.57 - more changes in history window, Note Editor is QT4 now
     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 "historywindow.h"
    21 #include "misc.h"
    22 #include "selection.h"
    23 #include "settings.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 	void gotoStep (int);// goto a step in history
    95 private:	
    96     void undoXML(const QString &, const QString &);
    97     void pasteNoSave();		// paste clipboard to branch
    98     void cutNoSave();	// cut to clipboard
    99 public:	
   100     void paste();		// paste clipboard to branch and backup
   101     void cut();			// cut to clipboard and backup
   102     void move    (const int &,const int&);
   103     void moveRel (const int &,const int&);
   104     void moveBranchUp();
   105     void moveBranchDown();
   106 	QString getHeading (bool &,QPoint &);	// Get heading, ok if selection is branch
   107 	void setHeading(const QString &);
   108 private:
   109 	void setHeadingInt(const QString &);
   110 	void setURLInt(const QString &);		// Just set the URL for selection
   111 	void setVymLinkInt(const QString &);	// Set vymLink for selection
   112     BranchObj* addNewBranchInt(int);		// pos allows to add above/below selection
   113 public:	
   114     void addNewBranch(int);			// pos allows to add above/below selection
   115     void addNewBranchHere();		// insert and make selection its
   116     void deleteSelection();
   117 	LinkableMapObj* getSelection();	// returns selection
   118 	void unselect();				// before changing current noteedit
   119 	void reselect();				// after  changing current noteedit
   120 	bool select(const QString &);	// Select by string
   121 	QString getSelectString();
   122 private:	
   123 	void selectInt(LinkableMapObj*);	
   124 	void selectNextBranchInt();		// Increment number of branch
   125 	void selectPrevBranchInt();		// Decrement number of branch
   126 public:	
   127     void selectUpperBranch();
   128     void selectLowerBranch();
   129     void selectLeftBranch();
   130     void selectRightBranch();
   131     void selectFirstBranch();
   132     void selectLastBranch();
   133     void setColor(QColor);
   134     void selectBackgroundColor();
   135     void setBackgroundColor(QColor);
   136     QColor pickColor();
   137     void colorItem();
   138     void colorBranch();
   139 	void toggleStandardFlag(QString);
   140 	virtual void setViewCenter();			// needed for zooming
   141     BranchObj* findText(QString,bool);		// Find object
   142     void findReset();						// Reset Find 
   143 	void editURL();							// edit the URL
   144 	QString getURL();						// returns URL of selection or ""
   145 	QStringList getURLs();					// returns URLs of subtree
   146 	void editHeading2URL();					// copy heading to URL
   147 	void editBugzilla2URL();				// create URL to Bugzilla
   148 	void editFATE2URL();					// create URL to FATE
   149 	void editVymLink();						// edit link to another map
   150 	void deleteVymLink();					// delete link to another map
   151 	QString getVymLink();					// return path to map
   152 	QStringList getVymLinks();				// return paths in subtree
   153 	void toggleHideExport();				// toggle the export flag
   154 	void removeBranchKeepChilds();			// remove but keep childs
   155 	void removeChilds();					// remove childs
   156 	void editMapInfo();						// dialog to enter author, ...
   157 	void updateActions();					// update e.g. format buttons
   158 	void updateNoteFlag();					// when TextEditor changes
   159 	void setLinkStyle (LinkStyle);			// Set style of link
   160 	LinkStyle getLinkStyle ();				// requested in LMO
   161 	void setLinkColor(QColor);				// default color of links
   162 	void setLinkColorHint();				// color of links
   163 	void setLinkColorHint(LinkColorHint);	// color of links
   164 	LinkColorHint getLinkColorHint();
   165 	QColor getDefLinkColor();
   166 	void setDefXLinkColor(QColor);
   167 	QColor getDefXLinkColor();
   168 	void setDefXLinkWidth (int);
   169 	int getDefXLinkWidth();
   170 	void toggleLinkColorHint();				// after changing linkStyles
   171     void selectLinkColor();
   172     void toggleScroll();
   173     void unScrollAll();
   174 	void loadFloatImage ();
   175 	void saveFloatImage ();
   176 	void setFrame(const FrameType &);
   177 	void setIncludeImagesVer(bool);
   178 	void setIncludeImagesHor(bool);
   179 	void setHideLinkUnselected (bool);
   180 	bool getHideLinkUnselected ();
   181 private:	
   182     void importDirInt(BranchObj *,QDir);
   183 public:	
   184     void importDir();
   185 	void followXLink (int);
   186 	void editXLink (int);
   187     void testFunction();					// just testing new stuff
   188 											// set /mainwindo/showTestMenu=true...
   189 
   190 protected:
   191 	void ensureSelectionVisible();		
   192 	virtual void updateViewCenter();	// needed for zooming
   193 	virtual void contentsContextMenuEvent ( QContextMenuEvent *e );
   194     virtual void contentsMousePressEvent(QMouseEvent*);
   195     virtual void contentsMouseReleaseEvent(QMouseEvent*);
   196     virtual void contentsMouseDoubleClickEvent(QMouseEvent*);
   197     virtual void contentsMouseMoveEvent(QMouseEvent*);
   198 
   199     virtual void contentsDragEnterEvent(QDragEnterEvent *event);
   200     virtual void contentsDropEvent(QDropEvent *event);
   201 private:
   202     Q3Canvas* mapCanvas;
   203     MapCenterObj* mapCenter;
   204 
   205 	bool adjustCanvasRequested;	// collect requests until end of user event
   206 	BranchObj *editingBO;		// entering Text into BO
   207 
   208     QColor actColor;			// actual color
   209 	QColor defLinkColor;		// default color for links
   210 	QColor defXLinkColor;		// default color for xlinks
   211 	int defXLinkWidth;			// default width for xlinks
   212 	LinkColorHint linkcolorhint;// use heading color or own color
   213 	LinkStyle linkstyle;		// default style for links
   214 
   215     QCursor handOpenCursor;		// cursor while moving canvas view
   216 	QCursor pickColorCursor;	// cursor while picking color 
   217 	bool pickingColor;
   218 	bool drawingLink;			// true while creating a link
   219 	bool copyingObj;			// true while creating a link
   220 	XLinkObj* tmpXLink;
   221 
   222 	Selection xelection;
   223     LinkableMapObj* selection;		// select a LinkableMapObj
   224     LinkableMapObj* selectionLast;	// last selection 
   225     MapObj* movingObj;				// moving a MapObj
   226 	MapObj* linkingObj_src;			// part of a link
   227     QPoint movingObj_orgPos;		// org. pos of mouse before move
   228     QPoint movingObj_orgRelPos;		// org. relative pos of mouse before move
   229     QPoint movingObj_start;			// rel. pos of mouse to absPos 
   230     QPoint movingCont_start;		// inital pos of moving Content or
   231     QPoint movingVec;				// how far has Content moved
   232 	QPoint movingCenter;			// used when zooming
   233     QPrinter* printer;				// Printing
   234 
   235     bool mapDefault;				// Flag if map is untouched
   236     bool mapChanged;				// Flag if undo is possible
   237 	bool mapUnsaved;				// Flag if map should be saved
   238 
   239 	bool printFrame;			// Print frame around map
   240 	bool printFooter;			// Print footer below map
   241 
   242 	bool zipped;				// should map be zipped
   243 static	int mapNum;				// unique number for Editor
   244 	QString fileName;			// short name of file (for tab)
   245 	QString filePath;			// path to file which will be saved
   246 	QString fileDir;			// dir where file is saved
   247 	QString destPath;			// path to .vym file (needed for vymlinks)
   248 	QString mapName;			// fileName without ".vym"
   249 
   250 	bool isInteractive;			// non interactive don't need tmpdirs
   251 	QString tmpMapDir;			// tmp directory with undo history
   252 	QString histPath;			// Path to history file
   253 	int stepsTotal;				// total number of steps (undos+redos) 
   254 	SimpleSettings undoSet;		// undo/redo commands
   255 	bool blockReposition;		// block while load or undo
   256 	bool blockSaveState;		// block while load or undo
   257 
   258 	BranchObj* itFind;			// next object in find process
   259 	bool EOFind;				// true, if search failed
   260 
   261 	QPoint exportOffset;		// set before export, used in save
   262 	HideTmpMode hidemode;			// true while exporting to hide some stuff
   263 	
   264     void resizeEvent( QResizeEvent * );
   265 
   266 	Q3UrlOperator *urlOperator;
   267 	QDataStream *imageData;
   268 	QBuffer *imageBuffer;
   269 
   270 	HistoryWindow historyWindow;
   271 
   272 };
   273 #endif
   274