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