diff -r 192e1392ba6a -r 12958f987bcf vymmodel.h --- a/vymmodel.h Wed Jul 16 10:44:44 2008 +0000 +++ b/vymmodel.h Wed Jul 16 10:46:14 2008 +0000 @@ -2,60 +2,456 @@ #define VYMMODEL_H #include +#include +#include "file.h" #include "mapcenterobj.h" #include "mapeditor.h" +#include "parser.h" +#include "selection.h" +#include "xmlobj.h" /*! \brief This will later be divided into Model/View */ -class VymModel : public QObject{ +class VymModel : public QObject, public XMLObj { Q_OBJECT +//////////////////////////////////////////// +// General housekeeping +//////////////////////////////////////////// +private: + QGraphicsScene *mapScene; + QList mapCenters; + QString version; //!< version string saved in vym file + QString author; + QString comment; + QDate date; + public: VymModel(); ~VymModel (); void clear(); void init(); + void makeTmpDirectories(); //!< create temporary directories e.g. for history + void setMapEditor(MapEditor *me); // FIXME should not be necessary in Model/View - MapEditor* getMapEditor(); + MapEditor* getMapEditor(); // FIXME not necessary + + bool isRepositionBlocked(); //!< While load or undo there is no need to update graphicsview + + void updateActions(); //!< Update buttons in mainwindow + + +//////////////////////////////////////////// +// Load/save +//////////////////////////////////////////// +private: + + bool zipped; // should map be zipped + static int mapNum; // unique number for model used in save/undo + FileType fileType; // type of file, e.g. vym, freemind... + QString fileName; // short name of file (for tab) + QString filePath; // path to file which will be saved + QString fileDir; // dir where file is saved + QString destPath; // path to .vym file (needed for vymlinks) + QString mapName; // fileName without ".vym" + + QString tmpMapDir; // tmp directory with undo history + + QTimer *autosaveTimer; + QTimer *fileChangedTimer; + QDateTime fileChangedTime; + +public: + /*! This function saves all information of the map to disc. + saveToDir also calls the functions for all BranchObj and other objects in the map. + The structure of the map itself is returned as QString and passed back to Main, + where saveToDir is called initially + */ + QString saveToDir (const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel); + + /*! \brief Sets filepath, filename and mapname + + If the filepath is "/home/tux/map.xml", then the filename will be set + to map.xml. The destname is needed for vymLinks, pointing to another map. + The destname holds the real name of the file, after it has been compressed, e.g. "map.vym" + */ + + + /*! \brief Set File path + + The destname is needed to construct the references between maps + */ + void setFilePath (QString filepath,QString destname); + void setFilePath (QString); //!< Overloaded for convenience + QString getFilePath (); //!< Full path e.g. "/home/tux/map.xml" + QString getFileName (); //!< e.g. "map.xml" + QString getMapName (); //!< e.g. "map" + QString getDestPath (); //!< e.g. "/home/tux/map.vym" + + /*! \brief Load map + + The data is read from file. Depending on LoadMode the current + selection gets replaced by data or the data is appended. + */ + ErrorCode load (QString, const LoadMode &, const FileType& ); // newmap, import/replace selection + +public: + /*! \brief Save the map to file */ + ErrorCode save(const SaveMode &); + +private: + void addMapReplaceInt(const QString & undoSel, const QString & path); + void addMapInsertInt (const QString & path, int pos); + + FloatImageObj* loadFloatImageInt (QString); + void saveFloatImageInt (FloatImageObj*, const QString &, const QString &); +public: + void loadFloatImage (); + void saveFloatImage (); + +private: + void importDirInt(BranchObj *,QDir); + void importDirInt(const QString&); +public: + void importDir(); + +private slots: + void autosave (); + void fileChanged(); + +//////////////////////////////////////////// +// history (undo/redo) +//////////////////////////////////////////// +private: + bool mapDefault; //!< Flag if map is untouched + bool mapChanged; //!< Flag if undo is possible + bool mapUnsaved; //!< Flag if map should be saved + + QString histPath; //!< Path to history file + SimpleSettings undoSet; //!< undo/redo commands, saved in histPath + int stepsTotal; //!< total number of steps (undos+redos) + int curStep; //!< Current step in history (ring buffer) + int curClipboard; //!< number of history step, which is the current clipboard + int redosAvail; //!< Available number of redo steps + int undosAvail; //!< Available number of undo steps + bool blockReposition; //!< block while load or undo + bool blockSaveState; //!< block while load or undo +public: + bool isDefault(); //!< true, if map is still the empty default map + void makeDefault(); //!< Reset changelog, declare this as default map + bool hasChanged() ; //!< true, if something has changed and is not saved yet + void setChanged(); //!< called from TextEditor via LinkableMapObj + + /*! \brief Get name of object + + Returns heading of a branch or name of an object for use in comment + of undo/redo history + */ + QString getObjectName(const LinkableMapObj*); + + void redo(); //!< Redo last action + bool isRedoAvailable(); //!< True, if redo is available + void undo(); //!< Undo last action + bool isUndoAvailable(); //!< True, if undo is available + void gotoHistoryStep (int); //!< Goto a specifig step in history + + + QString getHistoryPath(); //!< Path to directory containing the history + + /*! \brief Save the current changes in map + + Two commands and selections are saved: + + - undocommand and undoselection to undo the change + - redocommand and redoselection to redo the action after an undo + + Additionally a comment is logged. + + */ + void saveState( + const SaveMode& savemode, + const QString &undoSelection, + const QString &undoCommand, + const QString &redoSelection, + const QString &redoCommand, + const QString &comment, + LinkableMapObj *saveSelection); + /*! Overloaded for convenience */ + void saveStateChangingPart( + LinkableMapObj *undoSelection, + LinkableMapObj* redoSelection, + const QString &redoCommand, + const QString &comment); + /*! Overloaded for convenience */ + void saveStateRemovingPart( + LinkableMapObj *redoSelection, + const QString &comment); + /*! Overloaded for convenience */ + void saveState( + LinkableMapObj *undoSelection, + const QString &undoCommand, + LinkableMapObj *redoSelection, + const QString &redoCommand, + const QString &comment); + /*! Overloaded for convenience */ + void saveState( + const QString &undoSelection, + const QString &undoCommand, + const QString &redoSelection, + const QString &redoCommand, + const QString &comment) ; + void saveState( + const QString &undoCommand, + const QString &redoCommand, + const QString &comment) ; + + +//////////////////////////////////////////// +// unsorted so far +//////////////////////////////////////////// +public: + void setScene(QGraphicsScene *s); + QGraphicsScene *getScene(); + + BranchObj* first(); + BranchObj* next(BranchObj *bo); + + LinkableMapObj* findMapObj(QPointF,LinkableMapObj*); // find MapObj + LinkableMapObj* findObjBySelect (const QString &s); // find MapObj by select string + LinkableMapObj* findID (const QString &s); // find MapObj by previously set ID + + void removeSelection (); // remove selected object + + QString saveToDir (const QString&,const QString&,int, const QPointF&);// Save data recursivly to tempdir + + +//////////////////////////////////////////// +// Interface +//////////////////////////////////////////// +public: void setVersion(const QString &); void setAuthor (const QString &); QString getAuthor (); void setComment (const QString &); QString getComment (); QString getDate(); - void setScene(QGraphicsScene *s); - QGraphicsScene *getScene(); + +public: + void setHeading(const QString &); //!< Set heading of branch + QString getHeading (bool &ok,QPoint &p); //!< Get heading, ok if selection is branch +private: + void setHeadingInt(const QString &); + +private: + BranchObj* itFind; // next object in find process + bool EOFind; // true, if search failed +public: + BranchObj* findText(QString,bool); // Find object + void findReset(); // Reset Search + + void setURL(const QString &url); + QString getURL(); // returns URL of selection or "" + QStringList getURLs(); // returns URLs of subtree + + void linkFloatImageTo(const QString &); + + void setFrameType(const FrameObj::FrameType &); + void setFrameType(const QString &); + void setFramePenColor (const QColor &); + void setFrameBrushColor (const QColor &); + void setFramePadding (const int &); + void setFrameBorderWidth (const int &); + void setIncludeImagesVer(bool); + void setIncludeImagesHor(bool); + void setHideLinkUnselected (bool); + + /*! Should object be hidden in exports (clouded)? */ + void setHideExport(bool); + + /*! Should object be hidden in exports (clouded)? */ + void toggleHideExport(); + + void copy(); //!< Copy to clipboard +private: + void pasteNoSave(const int &n); //!< paste clipboard to branch +public: + void paste(); //!< Paste clipboard to branch and backup + void cut(); //!< Cut to clipboard (and copy) + + void moveBranchUp(); //!< Move branch up + void moveBranchDown(); //!< Move branch down + void sortChildren(); //!< Sort children lexically + + /*! \brief Add new mapcenter + + Disclaimer: Still experimental, not fully supported yet. + */ MapCenterObj* addMapCenter(); +private: MapCenterObj* addMapCenter(QPointF absPos); +public: MapCenterObj* removeMapCenter(MapCenterObj *mco); - BranchObj* first(); // FIXME replaced by ModelIndex later - BranchObj* next(BranchObj *bo); // FIXME replaced by ModelIndex later + /*! \brief Add new branch - LinkableMapObj* findMapObj(QPointF,LinkableMapObj*); // find MapObj - LinkableMapObj* findObjBySelect (const QString &s); // find MapObj by select string - LinkableMapObj* findID (const QString &s); // find MapObj by previously set ID - QString saveToDir (const QString&,const QString&,int, const QPointF&);// Save data recursivly to tempdir + Depending on num the new branch is created + -3 above selection as child of selections parent + -2 as child of selection + -1 below selection as child of selections parent + 0..n insert at a specific position in selections parent + (needed for free relinking) + */ +private: + BranchObj* addNewBranchInt(int); // pos allows to add above/below selection +public: + /*! \Add new branch + + Depending on num the new branch is created + -1 above selection + 0 as child of selection + 1 below selection + */ + BranchObj* addNewBranch(int pos); + BranchObj* addNewBranchBefore(); //!< Insert branch between selection and its parent + void deleteSelection(); //!< Delete selection + void deleteKeepChildren(); //!< remove branch, but keep children + void deleteChildren(); //!< keep branch, but remove children -////////////////////////////////////////// View related - // void updateLink(); FIXME needed? +private: + bool scrollBranch(BranchObj*); + bool unscrollBranch(BranchObj*); +public: + void toggleScroll(); + void unscrollChildren(); + + void addFloatImage(const QPixmap &img); + + void colorBranch(QColor); + void colorSubtree(QColor); + QColor getCurrentHeadingColor(); + + + void editURL(); // edit URL + void editLocalURL(); // edit URL to local file + void editHeading2URL(); // copy heading to URL + void editBugzilla2URL(); // create URL to Bugzilla + void editFATE2URL(); // create URL to FATE + void editVymLink(); // edit link to another map + void setVymLink (const QString &); // Set vymLink for selection + void deleteVymLink(); // delete link to another map + QString getVymLink(); // return path to map + QStringList getVymLinks(); // return paths in subtree + void followXLink (int); + void editXLink (int); + + + + +//////////////////////////////////////////// +// Scripting +//////////////////////////////////////////// +public: + + /* \brief Process one command and its parameters */ + void parseAtom (const QString &atom); + + /* \brief Runs the script */ + void runScript (QString script); + +private: + Parser parser; + +//////////////////////////////////////////// +// Exports +//////////////////////////////////////////// +private: + HideTmpMode hidemode; // true while exporting to hide some stuff + +public: + /*! Set or unset temporary hiding of objects during export */ + void setExportMode (bool); + + /*! Save as image */ + void exportImage (QString fname="",bool askForName=true,QString format="PNG"); + + + /*! Export as XTML to directory */ + void exportXML(QString dir="", bool askForName=true); + + /*! Export as ASCII text to file */ + void exportASCII (QString fname="",bool askForName=true); + + /*! Export as XHTML to directory */ + void exportXHTML(const QString& dir="", bool askForName=true); + + /*! Export as OpenOfficeOrg presentation */ + void exportOOPresentation(const QString &,const QString &); + + +//////////////////////////////////////////// +// View related +//////////////////////////////////////////// +public: + void registerEditor (QWidget *); + void unregisterEditor (QWidget *); + void updateNoteFlag(); //!< Signal origination in TextEditor void updateRelPositions(); QRectF getTotalBBox(); void reposition(); //!< Call reposition for all MCOs - void setHideTmp (HideTmpMode mode); + void setHideTmpMode (HideTmpMode mode); + QPolygonF shape(BranchObj *bo); //!< Returns arbitrary shape of subtree void moveAway (LinkableMapObj *lmo);//!< Autolayout: Move all out of the way - // Animation **experimental** -private slots: - void animate(); //!< Called by timer to animate stuff + //void ensureSelectionVisible(); //!< Show selection in all views + +private: + MapEditor *mapEditor; + + QColor defLinkColor; // default color for links + QColor defXLinkColor; // default color for xlinks + int defXLinkWidth; // default width for xlinks + LinkableMapObj::ColorHint linkcolorhint;// use heading color or own color + LinkableMapObj::Style linkstyle; // default style for links + +private: + QPixmap getPixmap(); + public: - void startAnimation(const QPointF &start, const QPointF &dest); + void setMapLinkStyle (const QString &); // Set style of link + LinkableMapObj::Style getMapLinkStyle (); // requested in LMO + void setMapDefLinkColor(QColor); // default color of links + void setMapLinkColorHintInt(); // color of links + void setMapLinkColorHint(LinkableMapObj::ColorHint);// color of links + void toggleMapLinkColorHint(); // after changing linkStyles + void selectMapBackgroundImage(); + void setMapBackgroundImage(const QString &); + void selectMapBackgroundColor(); + void setMapBackgroundColor(QColor); + QColor getMapBackgroundColor(); + + + LinkableMapObj::ColorHint getMapLinkColorHint(); + QColor getMapDefLinkColor(); + void setMapDefXLinkColor(QColor); + QColor getMapDefXLinkColor(); + void setMapDefXLinkWidth (int); + int getMapDefXLinkWidth(); + + /*! Move absolutly to (x,y). */ + void move (const double &x, const double &y); + + /*! Move relativly to (x,y). */ + void moveRel (const double &x, const double &y); + +//////////////////////////////////////////// +// Animation **experimental** +//////////////////////////////////////////// private: QTimer *animationTimer; bool animationUse; @@ -64,22 +460,102 @@ int timerId; // animation timer QList animObjList;// list with animated objects -////////////////////////////////////////// Selection related +private slots: + void animate(); //!< Called by timer to animate stuff public: + void startAnimation(const QPointF &start, const QPointF &dest); +//////////////////////////////////////////// +// Network related +//////////////////////////////////////////// +public: + /*! \brief Networking states + + In Network modus we want to switch of saveState, autosave, ... + */ + enum NetState { + Offline, //!< Offline + Client, //!< I am the client and connected to server + Server //!< I am the server + }; + +private: + // Network connections **Experimental** + NetState netstate; // offline, client, server + QTcpServer *tcpServer; // Act as server in conference mode (experimental) + QList clientList; // List of connected clients + quint16 sendCounter; // Increased with every sent command + + QTcpSocket *clientSocket; // socket of this client + QString server; // server address of this client + int port; // server port of this client + + + +protected: + void sendSelection(); + +public: + void newServer(); + void connectToServer(); + +private slots: + void newClient(); + void sendData(const QString &s); + void readData(); + void displayNetworkError (QAbstractSocket::SocketError); + +private: + void displayClientError(QAbstractSocket::SocketError socketError); + + +//////////////////////////////////////////// +// Selection related +//////////////////////////////////////////// +private: + Selection selection; + QString latestSelectionString; // select string of latest added object + +public: + void setSelectionBlocked(bool); + bool isSelectionBlocked(); + + bool select(const QString &); // Select by string + bool select(LinkableMapObj *lmo); // Select by pointer + void unselect(); + void reselect(); + + void ensureSelectionVisible(); //!< Show selection in all views + + void selectInt(LinkableMapObj*); + +private: + void selectNextBranchInt(); // Increment number of branch + void selectPrevBranchInt(); // Decrement number of branch +public: + void selectUpperBranch(); + void selectLowerBranch(); + void selectLeftBranch(); + void selectRightBranch(); + void selectFirstBranch(); + void selectLastBranch(); + +public: + Selection::Type selectionType(); LinkableMapObj* getSelection(); BranchObj* getSelectedBranch(); - bool select (const QString &s); + FloatImageObj* getSelectedFloatImage(); + QString getSelectString (); QString getSelectString (LinkableMapObj *lmo); + + void updateSelection(); + void selectMapLinkColor(); + void selectMapSelectionColor(); +private: + void setSelectionColorInt(QColor); +public: + void setSelectionColor(QColor); + QColor getSelectionColor(); -private: - QGraphicsScene *mapScene; - MapEditor *mapEditor; - QList mapCenters; - QString version; //!< version string saved in vym file - QString author; - QString comment; - QDate date; }; - #endif