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