mapeditor.h
author insilmaril
Wed, 02 May 2007 15:31:20 +0000
changeset 486 9c86935835a4
parent 473 8b9cfc26638c
child 491 c58b3973337c
permissions -rw-r--r--
Mainly documentation fixes
insilmaril@0
     1
#ifndef MAPEDITOR_H
insilmaril@0
     2
#define MAPEDITOR_H
insilmaril@0
     3
insilmaril@442
     4
//#include <QBuffer>
insilmaril@408
     5
#include <QGraphicsView>
insilmaril@0
     6
insilmaril@0
     7
#include "mapcenterobj.h"
insilmaril@175
     8
#include "file.h"
insilmaril@0
     9
#include "misc.h"
insilmaril@432
    10
#include "parser.h"
insilmaril@473
    11
#include "ornamentedobj.h"
insilmaril@366
    12
#include "selection.h"
insilmaril@366
    13
#include "settings.h"
insilmaril@0
    14
insilmaril@119
    15
insilmaril@486
    16
/*! \brief Main widget in vym to display and edit a map */
insilmaril@473
    17
insilmaril@408
    18
class MapEditor : public QGraphicsView, public xmlObj {
insilmaril@0
    19
    Q_OBJECT
insilmaril@0
    20
insilmaril@0
    21
public:
insilmaril@408
    22
    MapEditor(QWidget* parent=0);
insilmaril@0
    23
	~MapEditor();
insilmaril@0
    24
    MapCenterObj* getMapCenter();
insilmaril@408
    25
	QGraphicsScene * getScene();
insilmaril@139
    26
	bool isRepositionBlocked(); // block while load or undo
insilmaril@473
    27
	bool isSaveStateBlocked();	// block while undo/redo or while running scripts
insilmaril@473
    28
	void setSaveStateBlocked(bool);
insilmaril@0
    29
	
insilmaril@486
    30
protected:
insilmaril@420
    31
	QString getName(const LinkableMapObj*);	// Get e.g. heading or filename
insilmaril@0
    32
	void makeTmpDirs();		// create temporary directories
insilmaril@486
    33
insilmaril@486
    34
	/*! This function saves all information of the map to disc.
insilmaril@486
    35
	    saveToDir also calls the functions for all BranchObj and other objects in the map.
insilmaril@486
    36
		The structure of the map itself is returned as QString and passed back to Main, 
insilmaril@486
    37
		where saveToDir is called initially
insilmaril@486
    38
	*/	
insilmaril@486
    39
    QString saveToDir (const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel);
insilmaril@486
    40
insilmaril@486
    41
insilmaril@486
    42
	/*! \brief Save the current changes in map 
insilmaril@486
    43
insilmaril@486
    44
		Two commands and selections are saved:
insilmaril@486
    45
insilmaril@486
    46
			- undocommand and undoselection to undo the change
insilmaril@486
    47
			- redocommand and redoselection to redo the action after an undo
insilmaril@486
    48
insilmaril@486
    49
		Additionally a comment is logged. 
insilmaril@486
    50
insilmaril@486
    51
	*/	
insilmaril@486
    52
    void saveState(const SaveMode& savemode, const QString &undoSelection, const QString &undoCommand, const QString &redoSelection, const QString &redoCommand, const QString &comment, LinkableMapObj *saveSelection);
insilmaril@486
    53
	/*! Overloaded for convenience */
insilmaril@486
    54
    void saveStateChangingPart(LinkableMapObj *undoSelection, LinkableMapObj* redoSelection, const QString &rendoCommand, const QString &comment);
insilmaril@486
    55
	/*! Overloaded for convenience */
insilmaril@486
    56
    void saveStateRemovingPart(LinkableMapObj *redoSelection, const QString &comment);
insilmaril@486
    57
	/*! Overloaded for convenience */
insilmaril@486
    58
    void saveState(LinkableMapObj *undoSelection, const QString &undoCommand, LinkableMapObj *redoSelection, const QString &rendoCommand, const QString &comment); 
insilmaril@486
    59
	/*! Overloaded for convenience */
insilmaril@486
    60
    void saveState(const QString &undoSelection, const QString &undoCommand, const QString &redoSelection, const QString &rendoCommand, const QString &comment) ;
insilmaril@486
    61
insilmaril@393
    62
public:	
insilmaril@486
    63
insilmaril@486
    64
	/* \brief Process one command and its parameters */
insilmaril@486
    65
    void parseAtom (const QString &atom);	
insilmaril@486
    66
insilmaril@486
    67
	/* \brief Runs the script */
insilmaril@486
    68
	void runScript (QString script);
insilmaril@393
    69
private:
insilmaril@395
    70
    void addFloatImageInt(const QPixmap &img);
insilmaril@119
    71
insilmaril@0
    72
public:
insilmaril@486
    73
	bool isDefault();		//!< true, if map is still the empty default map
insilmaril@486
    74
    bool hasChanged();		//!< true, if something has changed and is not saved yet
insilmaril@486
    75
	void setChanged();		//!< called from TextEditor via LinkableMapObj
insilmaril@486
    76
	void closeMap();		//!< Closes the map
insilmaril@486
    77
insilmaril@486
    78
	/*! \brief Sets filepath, filename and mapname
insilmaril@486
    79
insilmaril@486
    80
	     If the filepath is "/home/tux/map.xml", then the filename will be set
insilmaril@486
    81
		 to map.xml. The destname is needed for vymLinks, pointing to another map. 
insilmaril@486
    82
		 The destname holds the real name of the file, after it has been compressed, e.g. "map.vym"
insilmaril@486
    83
	*/	 
insilmaril@486
    84
	void setFilePath (QString filepath,QString destname);	
insilmaril@486
    85
	void setFilePath (QString);	//!< Overloaded for convenience
insilmaril@486
    86
	QString getFilePath ();	//!< Full path e.g. "/home/tux/map.xml"
insilmaril@486
    87
	QString getFileName ();	//!< e.g. "map.xml"
insilmaril@486
    88
	QString getMapName ();	//!< e.g. "map"
insilmaril@486
    89
	QString getDestPath (); //!< e.g. "/home/tux/map.vym"
insilmaril@205
    90
    ErrorCode load (QString, LoadMode );	// newmap, import/replace selection
insilmaril@163
    91
public:
insilmaril@0
    92
    int save(const SaveMode &);	// Save map 
insilmaril@0
    93
	void setZipped(bool);		// save map zipped
insilmaril@0
    94
	bool saveZipped();			// 1 if file will be saved zipped
insilmaril@0
    95
    void print();				// print canvas
insilmaril@408
    96
	void setAntiAlias (bool);
insilmaril@408
    97
	void setSmoothPixmap(bool);
insilmaril@0
    98
private:
insilmaril@0
    99
    QPixmap getPixmap();
insilmaril@473
   100
	void setHideTmpMode (BranchObj::HideTmpMode);	// temporary hide stuff
insilmaril@473
   101
	BranchObj::HideTmpMode getHideTmpMode();		// temporary hide stuff
insilmaril@0
   102
public:
insilmaril@260
   103
	void setExportMode (bool);			// temporary hide stuff during export
insilmaril@366
   104
    void exportImage (QString fn);			// export as PNG	
insilmaril@366
   105
    void exportImage (QString fn, QString);	// export in given format
insilmaril@185
   106
    void exportOOPresentation(const QString &,const QString &);
insilmaril@0
   107
    void exportXML(const QString&);		// export to directory
insilmaril@0
   108
    void clear();		// clear map
insilmaril@106
   109
    void copy();		// copy branch to clipboard
insilmaril@163
   110
    void redo();		// redo last action
insilmaril@390
   111
	bool isRedoAvailable();
insilmaril@0
   112
    void undo();		// undo last action
insilmaril@390
   113
	bool isUndoAvailable();
insilmaril@404
   114
	void gotoHistoryStep (int);// goto a step in history
insilmaril@0
   115
private:	
insilmaril@394
   116
    void addMapReplaceInt(const QString & undoSel, const QString & path);
insilmaril@394
   117
    void addMapInsertInt (const QString & path, int pos);
insilmaril@166
   118
    void pasteNoSave();		// paste clipboard to branch
insilmaril@0
   119
    void cutNoSave();	// cut to clipboard
insilmaril@0
   120
public:	
insilmaril@0
   121
    void paste();		// paste clipboard to branch and backup
insilmaril@0
   122
    void cut();			// cut to clipboard and backup
insilmaril@393
   123
    void move    (const int &x, const int &y);
insilmaril@393
   124
    void moveRel (const int &x, const int &y);
insilmaril@0
   125
    void moveBranchUp();
insilmaril@0
   126
    void moveBranchDown();
insilmaril@420
   127
private:	
insilmaril@420
   128
	void linkTo(const QString &);
insilmaril@420
   129
public:	
insilmaril@393
   130
	QString getHeading (bool &ok,QPoint &p); // Get heading, ok if selection is branch
insilmaril@366
   131
	void setHeading(const QString &);
insilmaril@106
   132
private:
insilmaril@366
   133
	void setHeadingInt(const QString &);
insilmaril@366
   134
	void setURLInt(const QString &);		// Just set the URL for selection
insilmaril@366
   135
	void setVymLinkInt(const QString &);	// Set vymLink for selection
insilmaril@366
   136
    BranchObj* addNewBranchInt(int);		// pos allows to add above/below selection
insilmaril@106
   137
public:	
insilmaril@394
   138
    BranchObj* addNewBranch(int);			// pos allows to add above/below selection
insilmaril@394
   139
    BranchObj* addNewBranchBefore();		// insert and make selection its
insilmaril@0
   140
    void deleteSelection();
insilmaril@442
   141
	LinkableMapObj* getSelection();			// returns selection
insilmaril@442
   142
	BranchObj* getSelectedBranch();			// returns selected branch or NULL
insilmaril@442
   143
	FloatImageObj* getSelectedFloatImage();	// returns selected branch or NULL
insilmaril@442
   144
	void unselect();						// before changing current noteedit
insilmaril@442
   145
	void reselect();						// after  changing current noteedit
insilmaril@442
   146
	bool select(const QString &);			// Select by string
insilmaril@366
   147
	QString getSelectString();
insilmaril@0
   148
private:	
insilmaril@366
   149
	void selectInt(LinkableMapObj*);	
insilmaril@366
   150
	void selectNextBranchInt();		// Increment number of branch
insilmaril@366
   151
	void selectPrevBranchInt();		// Decrement number of branch
insilmaril@0
   152
public:	
insilmaril@0
   153
    void selectUpperBranch();
insilmaril@0
   154
    void selectLowerBranch();
insilmaril@0
   155
    void selectLeftBranch();
insilmaril@0
   156
    void selectRightBranch();
insilmaril@0
   157
    void selectFirstBranch();
insilmaril@0
   158
    void selectLastBranch();
insilmaril@408
   159
    void selectMapBackgroundImage();
insilmaril@408
   160
    void setMapBackgroundImage(const QString &);
insilmaril@398
   161
    void selectMapBackgroundColor();
insilmaril@398
   162
    void setMapBackgroundColor(QColor);
insilmaril@398
   163
    QColor getMapBackgroundColor();
insilmaril@395
   164
    QColor getCurrentHeadingColor();
insilmaril@395
   165
    void colorBranch(QColor);
insilmaril@417
   166
    void colorSubtree(QColor);
insilmaril@0
   167
	void toggleStandardFlag(QString);
insilmaril@0
   168
    BranchObj* findText(QString,bool);		// Find object
insilmaril@0
   169
    void findReset();						// Reset Find 
insilmaril@395
   170
	void setURL(const QString &);			// set the URL
insilmaril@0
   171
	void editURL();							// edit the URL
insilmaril@266
   172
	QString getURL();						// returns URL of selection or ""
insilmaril@366
   173
	QStringList getURLs();					// returns URLs of subtree
insilmaril@0
   174
	void editHeading2URL();					// copy heading to URL
insilmaril@0
   175
	void editBugzilla2URL();				// create URL to Bugzilla
insilmaril@175
   176
	void editFATE2URL();					// create URL to FATE
insilmaril@0
   177
	void editVymLink();						// edit link to another map
insilmaril@0
   178
	void deleteVymLink();					// delete link to another map
insilmaril@0
   179
	QString getVymLink();					// return path to map
insilmaril@366
   180
	QStringList getVymLinks();				// return paths in subtree
insilmaril@395
   181
	void setHideExport(bool);				// toggle the export flag
insilmaril@243
   182
	void toggleHideExport();				// toggle the export flag
insilmaril@395
   183
	void deleteKeepChilds();				// remove but keep childs
insilmaril@395
   184
	void deleteChilds();					// remove childs
insilmaril@0
   185
	void editMapInfo();						// dialog to enter author, ...
insilmaril@442
   186
	void ensureSelectionVisible();		
insilmaril@442
   187
	void updateSelection();					// update geometry of selection
insilmaril@0
   188
	void updateActions();					// update e.g. format buttons
insilmaril@160
   189
	void updateNoteFlag();					// when TextEditor changes
insilmaril@398
   190
	void setMapAuthor (const QString &);
insilmaril@398
   191
	void setMapComment(const QString &);
insilmaril@398
   192
	void setMapLinkStyle (const QString &);	// Set style of link
insilmaril@473
   193
	LinkableMapObj::Style getMapLinkStyle ();	// requested in LMO
insilmaril@398
   194
	void setMapDefLinkColor(QColor);		// default color of links
insilmaril@398
   195
	void setMapLinkColorHintInt();			// color of links
insilmaril@473
   196
	void setMapLinkColorHint(LinkableMapObj::ColorHint);// color of links
insilmaril@473
   197
	LinkableMapObj::ColorHint getMapLinkColorHint();
insilmaril@398
   198
	QColor getMapDefLinkColor();
insilmaril@398
   199
	void setMapDefXLinkColor(QColor);
insilmaril@398
   200
	QColor getMapDefXLinkColor();
insilmaril@398
   201
	void setMapDefXLinkWidth (int);
insilmaril@398
   202
	int getMapDefXLinkWidth();
insilmaril@398
   203
	void toggleMapLinkColorHint();			// after changing linkStyles
insilmaril@398
   204
    void selectMapLinkColor();
insilmaril@442
   205
    void selectMapSelectionColor();
insilmaril@442
   206
private:	
insilmaril@442
   207
    void setSelectionColorInt(QColor);
insilmaril@442
   208
public:	
insilmaril@442
   209
    void setSelectionColor(QColor);
insilmaril@442
   210
    QColor getSelectionColor();
insilmaril@473
   211
	bool scrollBranch(BranchObj*);
insilmaril@473
   212
	bool unscrollBranch(BranchObj*);
insilmaril@0
   213
    void toggleScroll();
insilmaril@428
   214
    void unscrollChilds();
insilmaril@432
   215
private:	
insilmaril@432
   216
	FloatImageObj* loadFloatImageInt (QString);
insilmaril@432
   217
public:	
insilmaril@0
   218
	void loadFloatImage ();
insilmaril@434
   219
private:	
insilmaril@434
   220
	void saveFloatImageInt (FloatImageObj*, const QString &, const QString &);
insilmaril@434
   221
public:	
insilmaril@366
   222
	void saveFloatImage ();
insilmaril@473
   223
	void setFrameType(const FrameObj::FrameType &);
insilmaril@445
   224
	void setFrameType(const QString &);
insilmaril@442
   225
	void setFramePenColor (const QColor &);
insilmaril@442
   226
	void setFrameBrushColor (const QColor &);
insilmaril@473
   227
	void setFramePadding (const int &);
insilmaril@473
   228
	void setFrameBorderWidth (const int &);
insilmaril@175
   229
	void setIncludeImagesVer(bool);
insilmaril@175
   230
	void setIncludeImagesHor(bool);
insilmaril@160
   231
	void setHideLinkUnselected (bool);
insilmaril@160
   232
	bool getHideLinkUnselected ();
insilmaril@0
   233
private:	
insilmaril@366
   234
    void importDirInt(BranchObj *,QDir);
insilmaril@0
   235
public:	
insilmaril@0
   236
    void importDir();
insilmaril@95
   237
	void followXLink (int);
insilmaril@95
   238
	void editXLink (int);
insilmaril@366
   239
    void testFunction();					// just testing new stuff
insilmaril@366
   240
											// set /mainwindo/showTestMenu=true...
insilmaril@0
   241
insilmaril@0
   242
protected:
insilmaril@408
   243
	virtual void contextMenuEvent ( QContextMenuEvent *e );
insilmaril@398
   244
    virtual void keyPressEvent(QKeyEvent*);
insilmaril@398
   245
    virtual void keyReleaseEvent(QKeyEvent*);
insilmaril@408
   246
    virtual void mousePressEvent(QMouseEvent*);
insilmaril@473
   247
    virtual void mouseMoveEvent(QMouseEvent*);
insilmaril@408
   248
    virtual void mouseReleaseEvent(QMouseEvent*);
insilmaril@408
   249
    virtual void mouseDoubleClickEvent(QMouseEvent*);
insilmaril@473
   250
    virtual void resizeEvent( QResizeEvent * );
insilmaril@0
   251
insilmaril@417
   252
	void dragEnterEvent (QDragEnterEvent *);
insilmaril@417
   253
	void dragMoveEvent (QDragMoveEvent *);
insilmaril@417
   254
	void dragLeaveEvent (QDragLeaveEvent *);
insilmaril@417
   255
	void dropEvent (QDropEvent *);
insilmaril@412
   256
insilmaril@473
   257
	void timerEvent(QTimerEvent *event);
insilmaril@473
   258
insilmaril@473
   259
private slots:	
insilmaril@473
   260
	void autosave ();
insilmaril@473
   261
insilmaril@0
   262
private:
insilmaril@408
   263
	QGraphicsScene *mapScene;
insilmaril@0
   264
    MapCenterObj* mapCenter;
insilmaril@473
   265
	QTimer *autosaveTimer;
insilmaril@0
   266
insilmaril@0
   267
	bool adjustCanvasRequested;	// collect requests until end of user event
insilmaril@0
   268
	BranchObj *editingBO;		// entering Text into BO
insilmaril@0
   269
insilmaril@97
   270
	QColor defLinkColor;		// default color for links
insilmaril@97
   271
	QColor defXLinkColor;		// default color for xlinks
insilmaril@97
   272
	int defXLinkWidth;			// default width for xlinks
insilmaril@473
   273
	LinkableMapObj::ColorHint linkcolorhint;// use heading color or own color
insilmaril@473
   274
	LinkableMapObj::Style linkstyle;		// default style for links
insilmaril@0
   275
insilmaril@398
   276
    QCursor HandOpenCursor;		// cursor while moving canvas view
insilmaril@398
   277
	QCursor PickColorCursor;	// cursor while picking color 
insilmaril@398
   278
	QCursor CopyCursor;			// cursor while picking color 
insilmaril@398
   279
	QCursor XLinkCursor;		// cursor while picking color 
insilmaril@83
   280
	bool pickingColor;
insilmaril@83
   281
	bool drawingLink;			// true while creating a link
insilmaril@93
   282
	bool copyingObj;			// true while creating a link
insilmaril@95
   283
	XLinkObj* tmpXLink;
insilmaril@366
   284
insilmaril@424
   285
	Selection xelection;	
insilmaril@0
   286
    MapObj* movingObj;				// moving a MapObj
insilmaril@83
   287
	MapObj* linkingObj_src;			// part of a link
insilmaril@408
   288
    QPointF movingObj_orgPos;		// org. pos of mouse before move
insilmaril@408
   289
    QPointF movingObj_orgRelPos;	// org. relative pos of mouse before move
insilmaril@408
   290
    QPointF movingObj_start;		// rel. pos of mouse to absPos 
insilmaril@408
   291
    QPointF movingCont_start;		// inital pos of moving Content or
insilmaril@408
   292
    QPointF movingVec;				// how far has Content moved
insilmaril@0
   293
    QPrinter* printer;				// Printing
insilmaril@0
   294
insilmaril@0
   295
    bool mapDefault;				// Flag if map is untouched
insilmaril@0
   296
    bool mapChanged;				// Flag if undo is possible
insilmaril@0
   297
	bool mapUnsaved;				// Flag if map should be saved
insilmaril@0
   298
insilmaril@432
   299
	Parser parser;				// Parser stuff for scripting
insilmaril@432
   300
insilmaril@0
   301
	bool printFrame;			// Print frame around map
insilmaril@0
   302
	bool printFooter;			// Print footer below map
insilmaril@0
   303
insilmaril@0
   304
	bool zipped;				// should map be zipped
insilmaril@393
   305
	static	int mapNum;			// unique number for Editor
insilmaril@0
   306
	QString fileName;			// short name of file (for tab)
insilmaril@0
   307
	QString filePath;			// path to file which will be saved
insilmaril@0
   308
	QString fileDir;			// dir where file is saved
insilmaril@0
   309
	QString destPath;			// path to .vym file (needed for vymlinks)
insilmaril@0
   310
	QString mapName;			// fileName without ".vym"
insilmaril@0
   311
insilmaril@377
   312
	QString tmpMapDir;			// tmp directory with undo history
insilmaril@366
   313
	QString histPath;			// Path to history file
insilmaril@381
   314
	int stepsTotal;				// total number of steps (undos+redos) 
insilmaril@366
   315
	SimpleSettings undoSet;		// undo/redo commands
insilmaril@139
   316
	bool blockReposition;		// block while load or undo
insilmaril@139
   317
	bool blockSaveState;		// block while load or undo
insilmaril@0
   318
insilmaril@0
   319
	BranchObj* itFind;			// next object in find process
insilmaril@0
   320
	bool EOFind;				// true, if search failed
insilmaril@0
   321
insilmaril@0
   322
	QPoint exportOffset;		// set before export, used in save
insilmaril@473
   323
	BranchObj::HideTmpMode hidemode;	// true while exporting to hide some stuff
insilmaril@473
   324
insilmaril@473
   325
	int timerId;				// animation timer
insilmaril@473
   326
	QList <MapObj*> animObjList;// list with animated objects
insilmaril@0
   327
};
insilmaril@0
   328
#endif
insilmaril@0
   329