mapeditor.h
author insilmaril
Wed Jul 13 10:22:14 2005 +0000 (2005-07-13)
changeset 127 ebfc893dde31
parent 119 0f183befd9af
child 129 9b9c7e8b9147
permissions -rw-r--r--
added drag and drop of URLs
     1 #ifndef MAPEDITOR_H
     2 #define MAPEDITOR_H
     3 
     4 #include <qcanvas.h>
     5 #include <qlineedit.h>
     6 #include <qcursor.h>
     7 #include <qfiledialog.h>
     8 #include <qevent.h>
     9 #include <qprocess.h>
    10 #include <qbuffer.h>
    11 
    12 #include "mapcenterobj.h"
    13 #include "misc.h"
    14 
    15 class QNetworkOperation;
    16 class QUrlOperator;
    17 
    18 class MapEditor : public QCanvasView , public xmlObj {
    19     Q_OBJECT
    20 
    21 public:
    22     MapEditor(QWidget* parent=0, bool interactive=false, const char* name=0, WFlags f=0);
    23 	~MapEditor();
    24     QColor color();
    25     QColor backgroundColor();
    26     MapCenterObj* getMapCenter();
    27 	QCanvas* getCanvas();
    28 	void adjustCanvasSize();// adjust canvas size to map and scrollview
    29 	bool blockReposition(); // block while load or undo
    30 	
    31 private:
    32 	void makeTmpDirs();		// create temporary directories
    33 	void delTmpDirs();		// delete temporary directories
    34 	void makeSubDirs(const QString&);		
    35 							// create subdirs in dir
    36     QString saveToDir(const QString&,const QString &,bool, const QPoint &,LinkableMapObj*);
    37     void saveState();		// save actual state to backup
    38     void saveState(LinkableMapObj *);
    39     void saveState(const QString &);
    40     void saveState(const SaveMode&, LinkableMapObj *, const QString &);
    41     void parseAtom(const QString &);	
    42 
    43     void addFloatImage(const QPixmap &img);
    44 
    45   private slots:
    46     void finishedLineEditNoSave();
    47     void fetchImage(const QString &img);
    48     void imageDataFetched(const QByteArray &, QNetworkOperation *);
    49     void imageDataFinished(QNetworkOperation *);
    50 
    51 public:
    52 	bool isDefault();		// false, if map was changed once
    53     bool isUnsaved();		// save necessary
    54     bool hasChanged();		// undo possible
    55 	void setChanged();		// called from NoteEditor via LMO
    56 	void closeMap();
    57 	void setFilePath (QString);	
    58 	void setFilePath (QString,QString);	
    59 	QString getFilePath ();	// Full path e.g. "/home/tux/map.xml"
    60 	QString getFileName ();	// e.g. "map.xml"
    61 	QString getMapName ();	// e.g. "map"
    62 	QString getDestPath (); // e.g. "/home/tux/map.vym"
    63     int load (QString&, const LoadMode &);	// newmap, import/replace selection
    64     int save(const SaveMode &);	// Save map 
    65 	void setZipped(bool);		// save map zipped
    66 	bool saveZipped();			// 1 if file will be saved zipped
    67     void print();				// print canvas
    68 private:
    69     QPixmap getPixmap();
    70 public:
    71     void exportImage (QString fn);		// export as PNG	
    72     void exportImage (QString fn, int);	// export in given format
    73     void exportASCII();
    74     void exportXML(const QString&);		// export to directory
    75     void clear();		// clear map
    76     void copy();		// copy branch to clipboard
    77     void undo();		// undo last action
    78 private:	
    79     void undoXML(const QString &);	// undo by replacing with saved data
    80     LinkableMapObj* pasteNoSave();		// paste clipboard to branch
    81     void cutNoSave();	// cut to clipboard
    82 public:	
    83     void paste();		// paste clipboard to branch and backup
    84     void cut();			// cut to clipboard and backup
    85     void moveBranchUp();
    86     void moveBranchDown();
    87     void editHeading();					// Start editing heading 
    88 private:
    89 	void setHeading(const QString &);	// Just set the heading for selection
    90 public:	
    91     void addNewBranch(int);			// pos allows to add above/below selection
    92     void addNewBranchHere();		// insert and make selection its
    93     void deleteSelection();
    94 	LinkableMapObj* getSelection();	// returns selection
    95 	bool select(const QString &);	// Select 
    96 	void unselect();				// before changing current noteedit
    97 	void reselect();				// after  changing current noteedit
    98 private:	
    99 	void selectNextBranch();		// Increment number of branch
   100 	void selectPrevBranch();		// Decrement number of branch
   101 public:	
   102     void selectUpperBranch();
   103     void selectLowerBranch();
   104     void selectLeftBranch();
   105     void selectRightBranch();
   106     void selectFirstBranch();
   107     void selectLastBranch();
   108     void setColor(QColor);
   109     void selectBackgroundColor();
   110     void setBackgroundColor(QColor);
   111     QColor pickColor();
   112     void colorItem();
   113     void colorBranch();
   114 	void toggleStandardFlag(QString);
   115 	virtual void setViewCenter();			// needed for zooming
   116     BranchObj* findText(QString,bool);		// Find object
   117     void findReset();						// Reset Find 
   118 	void openURL();							// open URL in external browser
   119 	void editURL();							// edit the URL
   120 	void editHeading2URL();					// copy heading to URL
   121 	void editBugzilla2URL();				// create URL to Bugzilla
   122 	void editVymLink();						// edit link to another map
   123 	void deleteVymLink();					// delete link to another map
   124 	QString getVymLink();					// return path to map
   125 	void removeBranchHere();				// remove but keep childs
   126 	void removeChilds();					// remove childs
   127 	void editMapInfo();						// dialog to enter author, ...
   128 	void updateActions();					// update e.g. format buttons
   129 	void setLinkStyle (LinkStyle);			// Set style of link
   130 	LinkStyle getLinkStyle ();				// requested in LMO
   131 	void setLinkColor(QColor);				// default color of links
   132 	void setLinkColorHint();				// color of links
   133 	void setLinkColorHint(LinkColorHint);	// color of links
   134 	LinkColorHint getLinkColorHint();
   135 	QColor getDefLinkColor();
   136 	void setDefXLinkColor(QColor);
   137 	QColor getDefXLinkColor();
   138 	void setDefXLinkWidth (int);
   139 	int getDefXLinkWidth();
   140 	void toggleLinkColorHint();				// after changing linkStyles
   141     void selectLinkColor();
   142     void toggleScroll();
   143     void unScrollAll();
   144 	void loadFloatImage ();
   145 	void saveFloatImage (int);
   146 	void toggleFloatExport();
   147 	void setFrame(const FrameType &);
   148 private:	
   149     void importDir(BranchObj *,QDir);
   150 public:	
   151     void importDir();
   152 	void followXLink (int);
   153 	void editXLink (int);
   154     void testFunction();				// FIXME just testing
   155 
   156 protected:
   157 	void ensureSelectionVisible();		
   158 	virtual void updateViewCenter();	// needed for zooming
   159 	virtual void contentsContextMenuEvent ( QContextMenuEvent *e );
   160     virtual void contentsMousePressEvent(QMouseEvent*);
   161     virtual void contentsMouseReleaseEvent(QMouseEvent*);
   162     virtual void contentsMouseDoubleClickEvent(QMouseEvent*);
   163     virtual void contentsMouseMoveEvent(QMouseEvent*);
   164 
   165     virtual void contentsDragEnterEvent(QDragEnterEvent *event);
   166     virtual void contentsDropEvent(QDropEvent *event);
   167 private:
   168     QCanvas* mapCanvas;
   169     MapCenterObj* mapCenter;
   170 
   171 	bool adjustCanvasRequested;	// collect requests until end of user event
   172 	BranchObj *editingBO;		// entering Text into BO
   173     QLineEdit* lineedit;
   174 
   175     QColor actColor;			// actual color
   176 	QColor defLinkColor;		// default color for links
   177 	QColor defXLinkColor;		// default color for xlinks
   178 	int defXLinkWidth;			// default width for xlinks
   179 	LinkColorHint linkcolorhint;// use heading color or own color
   180 	LinkStyle linkstyle;		// default style for links
   181 
   182     QCursor handOpenCursor;		// cursor while moving canvas view
   183 	QCursor pickColorCursor;	// cursor while picking color 
   184 	bool pickingColor;
   185 	bool drawingLink;			// true while creating a link
   186 	bool copyingObj;			// true while creating a link
   187 	XLinkObj* tmpXLink;
   188 	
   189     LinkableMapObj* selection;		// select a LinkableMapObj
   190     LinkableMapObj* selectionLast;	// last selection 
   191     MapObj* movingObj;				// moving a MapObj
   192 	MapObj* linkingObj_src;			// part of a link
   193     QPoint movingObj_start;			// rel. pos of mouse to absPos 
   194     QPoint movingCont_start;		// inital pos of moving Content or
   195     QPoint movingVec;				// how far has Content moved
   196 	QPoint movingCenter;			// used when zooming
   197     QPrinter* printer;				// Printing
   198 
   199     bool mapDefault;				// Flag if map is untouched
   200     bool mapChanged;				// Flag if undo is possible
   201 	bool mapUnsaved;				// Flag if map should be saved
   202     QString backupXML;				// backup (XML) for undo
   203 	QString undoCommand;			// FIXME testing
   204 									// if != NULL
   205 
   206 	bool printFrame;			// Print frame around map
   207 	bool printFooter;			// Print footer below map
   208 
   209 	bool zipped;				// should map be zipped
   210 	QString fileName;			// short name of file (for tab)
   211 	QString filePath;			// path to file which will be saved
   212 	QString fileDir;			// dir where file is saved
   213 	QString destPath;			// path to .vym file (needed for vymlinks)
   214 	QString mapName;			// fileName without ".vym"
   215 	QString lastImageDir;		// save dir for adding images
   216 
   217 	bool isInteractive;			// non interactive don't need tmpdirs
   218 	QString bakMapDir;			// tmp directory with data for undo
   219 	bool blockreposition;		// block while load or undo
   220 
   221 	BranchObj* itFind;			// next object in find process
   222 	bool EOFind;				// true, if search failed
   223 
   224 	QPoint exportOffset;		// set before export, used in save
   225     void resizeEvent( QResizeEvent * );
   226 
   227   QUrlOperator *urlOperator;
   228   QDataStream *imageData;
   229   QBuffer *imageBuffer;
   230 
   231 };
   232 #endif
   233