QCodeEdit 2.2
lib/qeditsession.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2006-2009 fullmetalcoder <fullmetalcoder@hotmail.fr>
00004 **
00005 ** This file is part of the Edyuk project <http://edyuk.org>
00006 ** 
00007 ** This file may be used under the terms of the GNU General Public License
00008 ** version 3 as published by the Free Software Foundation and appearing in the
00009 ** file GPL.txt included in the packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ****************************************************************************/
00015 
00016 #ifndef _QEDIT_SESSION_H_
00017 #define _QEDIT_SESSION_H_
00018 
00019 #include "qce-config.h"
00020 
00026 #include <QHash>
00027 #include <QObject>
00028 #include <QPointer>
00029 #include <QDateTime>
00030 #include <QStringList>
00031 
00032 class QEditor;
00033 
00034 class QDocument;
00035 class QDocumentCursor;
00036 class QDocumentCommand;
00037 
00038 class QDataStream;
00039 
00040 class QCE_EXPORT QEditSession : public QObject
00041 {
00042     Q_OBJECT
00043     
00044     public:
00045         QEditSession(QObject *p = 0);
00046         QEditSession(const QString& f, QObject *p = 0);
00047         virtual ~QEditSession();
00048         
00049         int autoUpdateInterval() const;
00050         
00051         QString fileName() const;
00052         
00053     public slots:
00054         virtual void addEditor(QEditor *e);
00055         virtual void removeEditor(QEditor *e);
00056         
00057         virtual void updateData();
00058         
00059         virtual void setAutoUpdateInterval(int ms);
00060         
00061         virtual void setFileName(const QString& filename, bool restore = false);
00062         
00063         virtual void clear(bool cleanup = false);
00064         
00065         virtual void save();
00066         virtual void restore();
00067         
00068         virtual void save(QDataStream& s);
00069         virtual void restore(QDataStream& s);
00070         
00071     signals:
00072         void restored(QEditor *e);
00073         
00074     protected slots:
00075         virtual void destroyed(QObject *o);
00076         
00077         virtual void saved(QEditor *e, const QString& fn);
00078         virtual void loaded(QEditor *e, const QString& fn);
00079         
00080     protected:
00081         virtual void timerEvent(QTimerEvent *e);
00082         
00083         virtual QEditor* createEditor();
00084         
00085         struct Cursor
00086         {
00087             Cursor()
00088              : beginLine(-1), beginColumn(-1), endLine(-1), endColumn(-1) {}
00089             
00090             Cursor(int line, int column)
00091              : beginLine(line), beginColumn(column), endLine(-1), endColumn(-1) {}
00092             
00093             Cursor(const Cursor& c)
00094              : beginLine(c.beginLine), beginColumn(c.beginColumn), endLine(c.endLine), endColumn(c.endColumn) {}
00095             
00096             Cursor(const QDocumentCursor& c);
00097             
00098             QDocumentCursor toDocumentCursor(QDocument *d) const;
00099             
00100             int beginLine;
00101             int beginColumn;
00102             int endLine;
00103             int endColumn;
00104         };
00105         
00106         struct Document
00107         {
00108             QString fileName;
00109             QDateTime timeStamp;
00110             
00111             int scrollX, scrollY;
00112             
00113             QList<Cursor> cursors;
00114             QHash<int, QList<int> > marks;
00115         };
00116         
00117         virtual void update(QEditor *e, Document *d);
00118         
00119         int m_id;
00120         int m_delay;
00121         QString m_fileName;
00122         
00123         QList<QEditor*> m_editors;
00124         QList<Document*> m_sessionData;
00125 };
00126 
00127 #endif // ! _QEDIT_SESSION_H_