1.1 --- a/vymmodel.h Wed Jul 16 10:44:44 2008 +0000
1.2 +++ b/vymmodel.h Wed Jul 16 10:46:14 2008 +0000
1.3 @@ -2,60 +2,456 @@
1.4 #define VYMMODEL_H
1.5
1.6 #include <QGraphicsScene>
1.7 +#include <QtNetwork>
1.8
1.9 +#include "file.h"
1.10 #include "mapcenterobj.h"
1.11 #include "mapeditor.h"
1.12 +#include "parser.h"
1.13 +#include "selection.h"
1.14 +#include "xmlobj.h"
1.15
1.16
1.17 /*! \brief This will later be divided into Model/View
1.18 */
1.19
1.20 -class VymModel : public QObject{
1.21 +class VymModel : public QObject, public XMLObj {
1.22 Q_OBJECT
1.23
1.24 +////////////////////////////////////////////
1.25 +// General housekeeping
1.26 +////////////////////////////////////////////
1.27 +private:
1.28 + QGraphicsScene *mapScene;
1.29 + QList <MapCenterObj*> mapCenters;
1.30 + QString version; //!< version string saved in vym file
1.31 + QString author;
1.32 + QString comment;
1.33 + QDate date;
1.34 +
1.35 public:
1.36 VymModel();
1.37 ~VymModel ();
1.38 void clear();
1.39 void init();
1.40 + void makeTmpDirectories(); //!< create temporary directories e.g. for history
1.41 +
1.42 void setMapEditor(MapEditor *me); // FIXME should not be necessary in Model/View
1.43 - MapEditor* getMapEditor();
1.44 + MapEditor* getMapEditor(); // FIXME not necessary
1.45 +
1.46 + bool isRepositionBlocked(); //!< While load or undo there is no need to update graphicsview
1.47 +
1.48 + void updateActions(); //!< Update buttons in mainwindow
1.49 +
1.50 +
1.51 +////////////////////////////////////////////
1.52 +// Load/save
1.53 +////////////////////////////////////////////
1.54 +private:
1.55 +
1.56 + bool zipped; // should map be zipped
1.57 + static int mapNum; // unique number for model used in save/undo
1.58 + FileType fileType; // type of file, e.g. vym, freemind...
1.59 + QString fileName; // short name of file (for tab)
1.60 + QString filePath; // path to file which will be saved
1.61 + QString fileDir; // dir where file is saved
1.62 + QString destPath; // path to .vym file (needed for vymlinks)
1.63 + QString mapName; // fileName without ".vym"
1.64 +
1.65 + QString tmpMapDir; // tmp directory with undo history
1.66 +
1.67 + QTimer *autosaveTimer;
1.68 + QTimer *fileChangedTimer;
1.69 + QDateTime fileChangedTime;
1.70 +
1.71 +public:
1.72 + /*! This function saves all information of the map to disc.
1.73 + saveToDir also calls the functions for all BranchObj and other objects in the map.
1.74 + The structure of the map itself is returned as QString and passed back to Main,
1.75 + where saveToDir is called initially
1.76 + */
1.77 + QString saveToDir (const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel);
1.78 +
1.79 + /*! \brief Sets filepath, filename and mapname
1.80 +
1.81 + If the filepath is "/home/tux/map.xml", then the filename will be set
1.82 + to map.xml. The destname is needed for vymLinks, pointing to another map.
1.83 + The destname holds the real name of the file, after it has been compressed, e.g. "map.vym"
1.84 + */
1.85 +
1.86 +
1.87 + /*! \brief Set File path
1.88 +
1.89 + The destname is needed to construct the references between maps
1.90 + */
1.91 + void setFilePath (QString filepath,QString destname);
1.92 + void setFilePath (QString); //!< Overloaded for convenience
1.93 + QString getFilePath (); //!< Full path e.g. "/home/tux/map.xml"
1.94 + QString getFileName (); //!< e.g. "map.xml"
1.95 + QString getMapName (); //!< e.g. "map"
1.96 + QString getDestPath (); //!< e.g. "/home/tux/map.vym"
1.97 +
1.98 + /*! \brief Load map
1.99 +
1.100 + The data is read from file. Depending on LoadMode the current
1.101 + selection gets replaced by data or the data is appended.
1.102 + */
1.103 + ErrorCode load (QString, const LoadMode &, const FileType& ); // newmap, import/replace selection
1.104 +
1.105 +public:
1.106 + /*! \brief Save the map to file */
1.107 + ErrorCode save(const SaveMode &);
1.108 +
1.109 +private:
1.110 + void addMapReplaceInt(const QString & undoSel, const QString & path);
1.111 + void addMapInsertInt (const QString & path, int pos);
1.112 +
1.113 + FloatImageObj* loadFloatImageInt (QString);
1.114 + void saveFloatImageInt (FloatImageObj*, const QString &, const QString &);
1.115 +public:
1.116 + void loadFloatImage ();
1.117 + void saveFloatImage ();
1.118 +
1.119 +private:
1.120 + void importDirInt(BranchObj *,QDir);
1.121 + void importDirInt(const QString&);
1.122 +public:
1.123 + void importDir();
1.124 +
1.125 +private slots:
1.126 + void autosave ();
1.127 + void fileChanged();
1.128 +
1.129 +////////////////////////////////////////////
1.130 +// history (undo/redo)
1.131 +////////////////////////////////////////////
1.132 +private:
1.133 + bool mapDefault; //!< Flag if map is untouched
1.134 + bool mapChanged; //!< Flag if undo is possible
1.135 + bool mapUnsaved; //!< Flag if map should be saved
1.136 +
1.137 + QString histPath; //!< Path to history file
1.138 + SimpleSettings undoSet; //!< undo/redo commands, saved in histPath
1.139 + int stepsTotal; //!< total number of steps (undos+redos)
1.140 + int curStep; //!< Current step in history (ring buffer)
1.141 + int curClipboard; //!< number of history step, which is the current clipboard
1.142 + int redosAvail; //!< Available number of redo steps
1.143 + int undosAvail; //!< Available number of undo steps
1.144 + bool blockReposition; //!< block while load or undo
1.145 + bool blockSaveState; //!< block while load or undo
1.146 +public:
1.147 + bool isDefault(); //!< true, if map is still the empty default map
1.148 + void makeDefault(); //!< Reset changelog, declare this as default map
1.149 + bool hasChanged() ; //!< true, if something has changed and is not saved yet
1.150 + void setChanged(); //!< called from TextEditor via LinkableMapObj
1.151 +
1.152 + /*! \brief Get name of object
1.153 +
1.154 + Returns heading of a branch or name of an object for use in comment
1.155 + of undo/redo history
1.156 + */
1.157 + QString getObjectName(const LinkableMapObj*);
1.158 +
1.159 + void redo(); //!< Redo last action
1.160 + bool isRedoAvailable(); //!< True, if redo is available
1.161 + void undo(); //!< Undo last action
1.162 + bool isUndoAvailable(); //!< True, if undo is available
1.163 + void gotoHistoryStep (int); //!< Goto a specifig step in history
1.164 +
1.165 +
1.166 + QString getHistoryPath(); //!< Path to directory containing the history
1.167 +
1.168 + /*! \brief Save the current changes in map
1.169 +
1.170 + Two commands and selections are saved:
1.171 +
1.172 + - undocommand and undoselection to undo the change
1.173 + - redocommand and redoselection to redo the action after an undo
1.174 +
1.175 + Additionally a comment is logged.
1.176 +
1.177 + */
1.178 + void saveState(
1.179 + const SaveMode& savemode,
1.180 + const QString &undoSelection,
1.181 + const QString &undoCommand,
1.182 + const QString &redoSelection,
1.183 + const QString &redoCommand,
1.184 + const QString &comment,
1.185 + LinkableMapObj *saveSelection);
1.186 + /*! Overloaded for convenience */
1.187 + void saveStateChangingPart(
1.188 + LinkableMapObj *undoSelection,
1.189 + LinkableMapObj* redoSelection,
1.190 + const QString &redoCommand,
1.191 + const QString &comment);
1.192 + /*! Overloaded for convenience */
1.193 + void saveStateRemovingPart(
1.194 + LinkableMapObj *redoSelection,
1.195 + const QString &comment);
1.196 + /*! Overloaded for convenience */
1.197 + void saveState(
1.198 + LinkableMapObj *undoSelection,
1.199 + const QString &undoCommand,
1.200 + LinkableMapObj *redoSelection,
1.201 + const QString &redoCommand,
1.202 + const QString &comment);
1.203 + /*! Overloaded for convenience */
1.204 + void saveState(
1.205 + const QString &undoSelection,
1.206 + const QString &undoCommand,
1.207 + const QString &redoSelection,
1.208 + const QString &redoCommand,
1.209 + const QString &comment) ;
1.210 + void saveState(
1.211 + const QString &undoCommand,
1.212 + const QString &redoCommand,
1.213 + const QString &comment) ;
1.214 +
1.215 +
1.216 +////////////////////////////////////////////
1.217 +// unsorted so far
1.218 +////////////////////////////////////////////
1.219 +public:
1.220 + void setScene(QGraphicsScene *s);
1.221 + QGraphicsScene *getScene();
1.222 +
1.223 + BranchObj* first();
1.224 + BranchObj* next(BranchObj *bo);
1.225 +
1.226 + LinkableMapObj* findMapObj(QPointF,LinkableMapObj*); // find MapObj
1.227 + LinkableMapObj* findObjBySelect (const QString &s); // find MapObj by select string
1.228 + LinkableMapObj* findID (const QString &s); // find MapObj by previously set ID
1.229 +
1.230 + void removeSelection (); // remove selected object
1.231 +
1.232 + QString saveToDir (const QString&,const QString&,int, const QPointF&);// Save data recursivly to tempdir
1.233 +
1.234 +
1.235 +////////////////////////////////////////////
1.236 +// Interface
1.237 +////////////////////////////////////////////
1.238 +public:
1.239 void setVersion(const QString &);
1.240 void setAuthor (const QString &);
1.241 QString getAuthor ();
1.242 void setComment (const QString &);
1.243 QString getComment ();
1.244 QString getDate();
1.245 - void setScene(QGraphicsScene *s);
1.246 - QGraphicsScene *getScene();
1.247 +
1.248 +public:
1.249 + void setHeading(const QString &); //!< Set heading of branch
1.250 + QString getHeading (bool &ok,QPoint &p); //!< Get heading, ok if selection is branch
1.251 +private:
1.252 + void setHeadingInt(const QString &);
1.253 +
1.254 +private:
1.255 + BranchObj* itFind; // next object in find process
1.256 + bool EOFind; // true, if search failed
1.257 +public:
1.258 + BranchObj* findText(QString,bool); // Find object
1.259 + void findReset(); // Reset Search
1.260 +
1.261 + void setURL(const QString &url);
1.262 + QString getURL(); // returns URL of selection or ""
1.263 + QStringList getURLs(); // returns URLs of subtree
1.264 +
1.265 + void linkFloatImageTo(const QString &);
1.266 +
1.267 + void setFrameType(const FrameObj::FrameType &);
1.268 + void setFrameType(const QString &);
1.269 + void setFramePenColor (const QColor &);
1.270 + void setFrameBrushColor (const QColor &);
1.271 + void setFramePadding (const int &);
1.272 + void setFrameBorderWidth (const int &);
1.273 + void setIncludeImagesVer(bool);
1.274 + void setIncludeImagesHor(bool);
1.275 + void setHideLinkUnselected (bool);
1.276 +
1.277 + /*! Should object be hidden in exports (clouded)? */
1.278 + void setHideExport(bool);
1.279 +
1.280 + /*! Should object be hidden in exports (clouded)? */
1.281 + void toggleHideExport();
1.282 +
1.283 + void copy(); //!< Copy to clipboard
1.284 +private:
1.285 + void pasteNoSave(const int &n); //!< paste clipboard to branch
1.286 +public:
1.287 + void paste(); //!< Paste clipboard to branch and backup
1.288 + void cut(); //!< Cut to clipboard (and copy)
1.289 +
1.290 + void moveBranchUp(); //!< Move branch up
1.291 + void moveBranchDown(); //!< Move branch down
1.292 + void sortChildren(); //!< Sort children lexically
1.293 +
1.294 + /*! \brief Add new mapcenter
1.295 +
1.296 + Disclaimer: Still experimental, not fully supported yet.
1.297 + */
1.298 MapCenterObj* addMapCenter();
1.299 +private:
1.300 MapCenterObj* addMapCenter(QPointF absPos);
1.301 +public:
1.302 MapCenterObj* removeMapCenter(MapCenterObj *mco);
1.303
1.304 - BranchObj* first(); // FIXME replaced by ModelIndex later
1.305 - BranchObj* next(BranchObj *bo); // FIXME replaced by ModelIndex later
1.306 + /*! \brief Add new branch
1.307
1.308 - LinkableMapObj* findMapObj(QPointF,LinkableMapObj*); // find MapObj
1.309 - LinkableMapObj* findObjBySelect (const QString &s); // find MapObj by select string
1.310 - LinkableMapObj* findID (const QString &s); // find MapObj by previously set ID
1.311 - QString saveToDir (const QString&,const QString&,int, const QPointF&);// Save data recursivly to tempdir
1.312 + Depending on num the new branch is created
1.313
1.314 + -3 above selection as child of selections parent
1.315 + -2 as child of selection
1.316 + -1 below selection as child of selections parent
1.317 + 0..n insert at a specific position in selections parent
1.318 + (needed for free relinking)
1.319 + */
1.320 +private:
1.321 + BranchObj* addNewBranchInt(int); // pos allows to add above/below selection
1.322 +public:
1.323 + /*! \Add new branch
1.324 +
1.325 + Depending on num the new branch is created
1.326 + -1 above selection
1.327 + 0 as child of selection
1.328 + 1 below selection
1.329 + */
1.330 + BranchObj* addNewBranch(int pos);
1.331 + BranchObj* addNewBranchBefore(); //!< Insert branch between selection and its parent
1.332 + void deleteSelection(); //!< Delete selection
1.333 + void deleteKeepChildren(); //!< remove branch, but keep children
1.334 + void deleteChildren(); //!< keep branch, but remove children
1.335
1.336 -////////////////////////////////////////// View related
1.337 - // void updateLink(); FIXME needed?
1.338 +private:
1.339 + bool scrollBranch(BranchObj*);
1.340 + bool unscrollBranch(BranchObj*);
1.341 +public:
1.342 + void toggleScroll();
1.343 + void unscrollChildren();
1.344 +
1.345 + void addFloatImage(const QPixmap &img);
1.346 +
1.347 + void colorBranch(QColor);
1.348 + void colorSubtree(QColor);
1.349 + QColor getCurrentHeadingColor();
1.350 +
1.351 +
1.352 + void editURL(); // edit URL
1.353 + void editLocalURL(); // edit URL to local file
1.354 + void editHeading2URL(); // copy heading to URL
1.355 + void editBugzilla2URL(); // create URL to Bugzilla
1.356 + void editFATE2URL(); // create URL to FATE
1.357 + void editVymLink(); // edit link to another map
1.358 + void setVymLink (const QString &); // Set vymLink for selection
1.359 + void deleteVymLink(); // delete link to another map
1.360 + QString getVymLink(); // return path to map
1.361 + QStringList getVymLinks(); // return paths in subtree
1.362 + void followXLink (int);
1.363 + void editXLink (int);
1.364 +
1.365 +
1.366 +
1.367 +
1.368 +////////////////////////////////////////////
1.369 +// Scripting
1.370 +////////////////////////////////////////////
1.371 +public:
1.372 +
1.373 + /* \brief Process one command and its parameters */
1.374 + void parseAtom (const QString &atom);
1.375 +
1.376 + /* \brief Runs the script */
1.377 + void runScript (QString script);
1.378 +
1.379 +private:
1.380 + Parser parser;
1.381 +
1.382 +////////////////////////////////////////////
1.383 +// Exports
1.384 +////////////////////////////////////////////
1.385 +private:
1.386 + HideTmpMode hidemode; // true while exporting to hide some stuff
1.387 +
1.388 +public:
1.389 + /*! Set or unset temporary hiding of objects during export */
1.390 + void setExportMode (bool);
1.391 +
1.392 + /*! Save as image */
1.393 + void exportImage (QString fname="",bool askForName=true,QString format="PNG");
1.394 +
1.395 +
1.396 + /*! Export as XTML to directory */
1.397 + void exportXML(QString dir="", bool askForName=true);
1.398 +
1.399 + /*! Export as ASCII text to file */
1.400 + void exportASCII (QString fname="",bool askForName=true);
1.401 +
1.402 + /*! Export as XHTML to directory */
1.403 + void exportXHTML(const QString& dir="", bool askForName=true);
1.404 +
1.405 + /*! Export as OpenOfficeOrg presentation */
1.406 + void exportOOPresentation(const QString &,const QString &);
1.407 +
1.408 +
1.409 +////////////////////////////////////////////
1.410 +// View related
1.411 +////////////////////////////////////////////
1.412 +public:
1.413 + void registerEditor (QWidget *);
1.414 + void unregisterEditor (QWidget *);
1.415 + void updateNoteFlag(); //!< Signal origination in TextEditor
1.416 void updateRelPositions();
1.417
1.418 QRectF getTotalBBox();
1.419 void reposition(); //!< Call reposition for all MCOs
1.420 - void setHideTmp (HideTmpMode mode);
1.421 + void setHideTmpMode (HideTmpMode mode);
1.422 +
1.423 QPolygonF shape(BranchObj *bo); //!< Returns arbitrary shape of subtree
1.424 void moveAway (LinkableMapObj *lmo);//!< Autolayout: Move all out of the way
1.425
1.426 - // Animation **experimental**
1.427 -private slots:
1.428 - void animate(); //!< Called by timer to animate stuff
1.429 + //void ensureSelectionVisible(); //!< Show selection in all views
1.430 +
1.431 +private:
1.432 + MapEditor *mapEditor;
1.433 +
1.434 + QColor defLinkColor; // default color for links
1.435 + QColor defXLinkColor; // default color for xlinks
1.436 + int defXLinkWidth; // default width for xlinks
1.437 + LinkableMapObj::ColorHint linkcolorhint;// use heading color or own color
1.438 + LinkableMapObj::Style linkstyle; // default style for links
1.439 +
1.440 +private:
1.441 + QPixmap getPixmap();
1.442 +
1.443 public:
1.444 - void startAnimation(const QPointF &start, const QPointF &dest);
1.445 + void setMapLinkStyle (const QString &); // Set style of link
1.446 + LinkableMapObj::Style getMapLinkStyle (); // requested in LMO
1.447 + void setMapDefLinkColor(QColor); // default color of links
1.448 + void setMapLinkColorHintInt(); // color of links
1.449 + void setMapLinkColorHint(LinkableMapObj::ColorHint);// color of links
1.450 + void toggleMapLinkColorHint(); // after changing linkStyles
1.451 + void selectMapBackgroundImage();
1.452 + void setMapBackgroundImage(const QString &);
1.453 + void selectMapBackgroundColor();
1.454 + void setMapBackgroundColor(QColor);
1.455 + QColor getMapBackgroundColor();
1.456 +
1.457 +
1.458 + LinkableMapObj::ColorHint getMapLinkColorHint();
1.459 + QColor getMapDefLinkColor();
1.460 + void setMapDefXLinkColor(QColor);
1.461 + QColor getMapDefXLinkColor();
1.462 + void setMapDefXLinkWidth (int);
1.463 + int getMapDefXLinkWidth();
1.464 +
1.465 + /*! Move absolutly to (x,y). */
1.466 + void move (const double &x, const double &y);
1.467 +
1.468 + /*! Move relativly to (x,y). */
1.469 + void moveRel (const double &x, const double &y);
1.470 +
1.471 +////////////////////////////////////////////
1.472 +// Animation **experimental**
1.473 +////////////////////////////////////////////
1.474 private:
1.475 QTimer *animationTimer;
1.476 bool animationUse;
1.477 @@ -64,22 +460,102 @@
1.478 int timerId; // animation timer
1.479 QList <MapObj*> animObjList;// list with animated objects
1.480
1.481 -////////////////////////////////////////// Selection related
1.482 +private slots:
1.483 + void animate(); //!< Called by timer to animate stuff
1.484 public:
1.485 + void startAnimation(const QPointF &start, const QPointF &dest);
1.486 +////////////////////////////////////////////
1.487 +// Network related
1.488 +////////////////////////////////////////////
1.489 +public:
1.490 + /*! \brief Networking states
1.491 +
1.492 + In Network modus we want to switch of saveState, autosave, ...
1.493 + */
1.494 + enum NetState {
1.495 + Offline, //!< Offline
1.496 + Client, //!< I am the client and connected to server
1.497 + Server //!< I am the server
1.498 + };
1.499 +
1.500 +private:
1.501 + // Network connections **Experimental**
1.502 + NetState netstate; // offline, client, server
1.503 + QTcpServer *tcpServer; // Act as server in conference mode (experimental)
1.504 + QList <QTcpSocket*> clientList; // List of connected clients
1.505 + quint16 sendCounter; // Increased with every sent command
1.506 +
1.507 + QTcpSocket *clientSocket; // socket of this client
1.508 + QString server; // server address of this client
1.509 + int port; // server port of this client
1.510 +
1.511 +
1.512 +
1.513 +protected:
1.514 + void sendSelection();
1.515 +
1.516 +public:
1.517 + void newServer();
1.518 + void connectToServer();
1.519 +
1.520 +private slots:
1.521 + void newClient();
1.522 + void sendData(const QString &s);
1.523 + void readData();
1.524 + void displayNetworkError (QAbstractSocket::SocketError);
1.525 +
1.526 +private:
1.527 + void displayClientError(QAbstractSocket::SocketError socketError);
1.528 +
1.529 +
1.530 +////////////////////////////////////////////
1.531 +// Selection related
1.532 +////////////////////////////////////////////
1.533 +private:
1.534 + Selection selection;
1.535 + QString latestSelectionString; // select string of latest added object
1.536 +
1.537 +public:
1.538 + void setSelectionBlocked(bool);
1.539 + bool isSelectionBlocked();
1.540 +
1.541 + bool select(const QString &); // Select by string
1.542 + bool select(LinkableMapObj *lmo); // Select by pointer
1.543 + void unselect();
1.544 + void reselect();
1.545 +
1.546 + void ensureSelectionVisible(); //!< Show selection in all views
1.547 +
1.548 + void selectInt(LinkableMapObj*);
1.549 +
1.550 +private:
1.551 + void selectNextBranchInt(); // Increment number of branch
1.552 + void selectPrevBranchInt(); // Decrement number of branch
1.553 +public:
1.554 + void selectUpperBranch();
1.555 + void selectLowerBranch();
1.556 + void selectLeftBranch();
1.557 + void selectRightBranch();
1.558 + void selectFirstBranch();
1.559 + void selectLastBranch();
1.560 +
1.561 +public:
1.562 + Selection::Type selectionType();
1.563 LinkableMapObj* getSelection();
1.564 BranchObj* getSelectedBranch();
1.565 - bool select (const QString &s);
1.566 + FloatImageObj* getSelectedFloatImage();
1.567 + QString getSelectString ();
1.568 QString getSelectString (LinkableMapObj *lmo);
1.569 +
1.570 + void updateSelection();
1.571 + void selectMapLinkColor();
1.572 + void selectMapSelectionColor();
1.573 +private:
1.574 + void setSelectionColorInt(QColor);
1.575 +public:
1.576 + void setSelectionColor(QColor);
1.577 + QColor getSelectionColor();
1.578
1.579 -private:
1.580 - QGraphicsScene *mapScene;
1.581 - MapEditor *mapEditor;
1.582 - QList <MapCenterObj*> mapCenters;
1.583 - QString version; //!< version string saved in vym file
1.584 - QString author;
1.585 - QString comment;
1.586 - QDate date;
1.587 };
1.588
1.589 -
1.590 #endif