mapeditor.h
author insilmaril
Fri, 29 Dec 2006 13:52:17 +0000
changeset 412 8059b6aa74d7
parent 408 c2a05fa925a1
child 417 1cc7bbf75f0b
permissions -rw-r--r--
Removed some FIXMEs. Added translations
     1 #ifndef MAPEDITOR_H
     2 #define MAPEDITOR_H
     3 
     4 #include <QBuffer>
     5 #include <QGraphicsView>
     6 
     7 #include "mapcenterobj.h"
     8 #include "file.h"
     9 #include "misc.h"
    10 #include "selection.h"
    11 #include "settings.h"
    12 
    13 class Q3NetworkOperation;
    14 class Q3UrlOperator;
    15 
    16 class MapEditor : public QGraphicsView, public xmlObj {
    17     Q_OBJECT
    18 
    19 public:
    20     MapEditor(QWidget* parent=0);
    21 	~MapEditor();
    22     MapCenterObj* getMapCenter();
    23 	QGraphicsScene * getScene();
    24 	bool isRepositionBlocked(); // block while load or undo
    25 	
    26 private:
    27 	QString getName(LinkableMapObj*);	// Get e.g. heading or filename
    28 	void makeTmpDirs();		// create temporary directories
    29     QString saveToDir(const QString&,const QString &,bool, const QPointF &,LinkableMapObj*);
    30     void saveStateChangingPart (LinkableMapObj *, LinkableMapObj *, const QString &, const QString &);
    31     void saveStateRemovingPart (LinkableMapObj *, const QString &);
    32     void saveState(LinkableMapObj *, const QString &, LinkableMapObj *, const QString &, const QString &);
    33     void saveState(const QString &, const QString &, const QString &, const QString &, const QString &);
    34     void saveState(const SaveMode&, const QString &, const QString &, const QString &, const QString &, const QString &, LinkableMapObj *);
    35 public:	
    36     void parseAtom(const QString &);	
    37 private:
    38     void addFloatImageInt(const QPixmap &img);
    39 
    40 /*
    41   private slots:
    42     void fetchImage(const QString &img);
    43     void imageDataFetched(const QByteArray &, Q3NetworkOperation *);
    44     void imageDataFinished(Q3NetworkOperation *);
    45 	*/
    46 
    47 public:
    48 	bool isDefault();		// false, if map was changed once
    49     bool isUnsaved();		// save necessary
    50     bool hasChanged();		// undo possible
    51 	void setChanged();		// called from NoteEditor via LMO
    52 	void closeMap();
    53 	void setFilePath (QString);	
    54 	void setFilePath (QString,QString);	
    55 	QString getFilePath ();	// Full path e.g. "/home/tux/map.xml"
    56 	QString getFileName ();	// e.g. "map.xml"
    57 	QString getMapName ();	// e.g. "map"
    58 	QString getDestPath (); // e.g. "/home/tux/map.vym"
    59     ErrorCode load (QString, LoadMode );	// newmap, import/replace selection
    60 public:
    61     int save(const SaveMode &);	// Save map 
    62 	void setZipped(bool);		// save map zipped
    63 	bool saveZipped();			// 1 if file will be saved zipped
    64     void print();				// print canvas
    65 	void setAntiAlias (bool);
    66 	void setSmoothPixmap(bool);
    67 private:
    68     QPixmap getPixmap();
    69 	void setHideTmpMode (HideTmpMode);	// temporary hide stuff
    70 	HideTmpMode getHideTmpMode();		// temporary hide stuff
    71 public:
    72 	void setExportMode (bool);			// temporary hide stuff during export
    73     void exportImage (QString fn);			// export as PNG	
    74     void exportImage (QString fn, QString);	// export in given format
    75     void exportOOPresentation(const QString &,const QString &);
    76     void exportXML(const QString&);		// export to directory
    77     void clear();		// clear map
    78     void copy();		// copy branch to clipboard
    79     void redo();		// redo last action
    80 	bool isRedoAvailable();
    81     void undo();		// undo last action
    82 	bool isUndoAvailable();
    83 	void gotoHistoryStep (int);// goto a step in history
    84 private:	
    85     void addMapReplaceInt(const QString & undoSel, const QString & path);
    86     void addMapInsertInt (const QString & path, int pos);
    87     void pasteNoSave();		// paste clipboard to branch
    88     void cutNoSave();	// cut to clipboard
    89 public:	
    90     void paste();		// paste clipboard to branch and backup
    91     void cut();			// cut to clipboard and backup
    92     void move    (const int &x, const int &y);
    93     void moveRel (const int &x, const int &y);
    94     void moveBranchUp();
    95     void moveBranchDown();
    96 	QString getHeading (bool &ok,QPoint &p); // Get heading, ok if selection is branch
    97 	void setHeading(const QString &);
    98 private:
    99 	void setHeadingInt(const QString &);
   100 	void setURLInt(const QString &);		// Just set the URL for selection
   101 	void setVymLinkInt(const QString &);	// Set vymLink for selection
   102     BranchObj* addNewBranchInt(int);		// pos allows to add above/below selection
   103 public:	
   104     BranchObj* addNewBranch(int);			// pos allows to add above/below selection
   105     BranchObj* addNewBranchBefore();		// insert and make selection its
   106     void deleteSelection();
   107 	LinkableMapObj* getSelection();	// returns selection
   108 	void unselect();				// before changing current noteedit
   109 	void reselect();				// after  changing current noteedit
   110 	bool select(const QString &);	// Select by string
   111 	QString getSelectString();
   112 private:	
   113 	void selectInt(LinkableMapObj*);	
   114 	void selectNextBranchInt();		// Increment number of branch
   115 	void selectPrevBranchInt();		// Decrement number of branch
   116 public:	
   117     void selectUpperBranch();
   118     void selectLowerBranch();
   119     void selectLeftBranch();
   120     void selectRightBranch();
   121     void selectFirstBranch();
   122     void selectLastBranch();
   123     void selectMapBackgroundImage();
   124     void setMapBackgroundImage(const QString &);
   125     void selectMapBackgroundColor();
   126     void setMapBackgroundColor(QColor);
   127     QColor getMapBackgroundColor();
   128     QColor getCurrentHeadingColor();
   129     void colorItem(QColor);
   130     void colorBranch(QColor);
   131 	void toggleStandardFlag(QString);
   132 	virtual void setViewCenter();			// needed for zooming
   133     BranchObj* findText(QString,bool);		// Find object
   134     void findReset();						// Reset Find 
   135 	void setURL(const QString &);			// set the URL
   136 	void editURL();							// edit the URL
   137 	QString getURL();						// returns URL of selection or ""
   138 	QStringList getURLs();					// returns URLs of subtree
   139 	void editHeading2URL();					// copy heading to URL
   140 	void editBugzilla2URL();				// create URL to Bugzilla
   141 	void editFATE2URL();					// create URL to FATE
   142 	void editVymLink();						// edit link to another map
   143 	void deleteVymLink();					// delete link to another map
   144 	QString getVymLink();					// return path to map
   145 	QStringList getVymLinks();				// return paths in subtree
   146 	void setHideExport(bool);				// toggle the export flag
   147 	void toggleHideExport();				// toggle the export flag
   148 	void deleteKeepChilds();				// remove but keep childs
   149 	void deleteChilds();					// remove childs
   150 	void editMapInfo();						// dialog to enter author, ...
   151 	void updateActions();					// update e.g. format buttons
   152 	void updateNoteFlag();					// when TextEditor changes
   153 	void setMapAuthor (const QString &);
   154 	void setMapComment(const QString &);
   155 	void setMapLinkStyle (const QString &);	// Set style of link
   156 	LinkStyle getMapLinkStyle ();			// requested in LMO
   157 	void setMapDefLinkColor(QColor);		// default color of links
   158 	void setMapLinkColorHintInt();			// color of links
   159 	void setMapLinkColorHint(LinkColorHint);// color of links
   160 	LinkColorHint getMapLinkColorHint();
   161 	QColor getMapDefLinkColor();
   162 	void setMapDefXLinkColor(QColor);
   163 	QColor getMapDefXLinkColor();
   164 	void setMapDefXLinkWidth (int);
   165 	int getMapDefXLinkWidth();
   166 	void toggleMapLinkColorHint();			// after changing linkStyles
   167     void selectMapLinkColor();
   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();					// just testing new stuff
   184 											// set /mainwindo/showTestMenu=true...
   185 
   186 protected:
   187 	void ensureSelectionVisible();		
   188 	virtual void updateViewCenter();	// needed for zooming
   189 	virtual void contextMenuEvent ( QContextMenuEvent *e );
   190     virtual void keyPressEvent(QKeyEvent*);
   191     virtual void keyReleaseEvent(QKeyEvent*);
   192     virtual void mousePressEvent(QMouseEvent*);
   193     virtual void mouseReleaseEvent(QMouseEvent*);
   194     virtual void mouseDoubleClickEvent(QMouseEvent*);
   195     virtual void mouseMoveEvent(QMouseEvent*);
   196 
   197 	virtual void dragEnterEvent (QDragEnterEvent *);
   198 	virtual void dropEvent (QDropEvent *);
   199 
   200     virtual void contentsDragEnterEvent(QDragEnterEvent *event);
   201     virtual void contentsDropEvent(QDropEvent *event);
   202 private:
   203 	QGraphicsScene *mapScene;
   204     MapCenterObj* mapCenter;
   205 
   206 	bool adjustCanvasRequested;	// collect requests until end of user event
   207 	BranchObj *editingBO;		// entering Text into BO
   208 
   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 	QCursor CopyCursor;			// cursor while picking color 
   218 	QCursor XLinkCursor;		// cursor while picking color 
   219 	bool pickingColor;
   220 	bool drawingLink;			// true while creating a link
   221 	bool copyingObj;			// true while creating a link
   222 	XLinkObj* tmpXLink;
   223 
   224 	Selection xelection;
   225     LinkableMapObj* selection;		// select a LinkableMapObj
   226     LinkableMapObj* selectionLast;	// last selection 
   227     MapObj* movingObj;				// moving a MapObj
   228 	MapObj* linkingObj_src;			// part of a link
   229     QPointF movingObj_orgPos;		// org. pos of mouse before move
   230     QPointF movingObj_orgRelPos;	// org. relative pos of mouse before move
   231     QPointF movingObj_start;		// rel. pos of mouse to absPos 
   232     QPointF movingCont_start;		// inital pos of moving Content or
   233     QPointF movingVec;				// how far has Content moved
   234 	QPointF movingCenter;			// used when zooming
   235     QPrinter* printer;				// Printing
   236 
   237     bool mapDefault;				// Flag if map is untouched
   238     bool mapChanged;				// Flag if undo is possible
   239 	bool mapUnsaved;				// Flag if map should be saved
   240 
   241 	bool printFrame;			// Print frame around map
   242 	bool printFooter;			// Print footer below map
   243 
   244 	bool zipped;				// should map be zipped
   245 	static	int mapNum;			// unique number for Editor
   246 	QString fileName;			// short name of file (for tab)
   247 	QString filePath;			// path to file which will be saved
   248 	QString fileDir;			// dir where file is saved
   249 	QString destPath;			// path to .vym file (needed for vymlinks)
   250 	QString mapName;			// fileName without ".vym"
   251 
   252 	QString tmpMapDir;			// tmp directory with undo history
   253 	QString histPath;			// Path to history file
   254 	int stepsTotal;				// total number of steps (undos+redos) 
   255 	SimpleSettings undoSet;		// undo/redo commands
   256 	bool blockReposition;		// block while load or undo
   257 	bool blockSaveState;		// block while load or undo
   258 
   259 	BranchObj* itFind;			// next object in find process
   260 	bool EOFind;				// true, if search failed
   261 
   262 	QPoint exportOffset;		// set before export, used in save
   263 	HideTmpMode hidemode;			// true while exporting to hide some stuff
   264 	
   265     void resizeEvent( QResizeEvent * );
   266 
   267 	Q3UrlOperator *urlOperator;
   268 	QDataStream *imageData;
   269 	QBuffer *imageBuffer;
   270 };
   271 #endif
   272