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