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