QCodeEdit
2.2
|
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 _QLINE_MARKS_INFO_CENTER_H_ 00017 #define _QLINE_MARKS_INFO_CENTER_H_ 00018 00030 #include "qce-config.h" 00031 00032 #include <QColor> 00033 #include <QPixmap> 00034 #include <QObject> 00035 #include <QMetaType> 00036 #include <QStringList> 00037 00038 class QEditor; 00039 class QDataStream; 00040 class QDocumentLineHandle; 00041 00042 struct QLineMark 00043 { 00044 inline QLineMark() : line(-1) {} 00045 00046 inline QLineMark(const QString& f, int l, int m) 00047 : mark(m), line(l), file(f) 00048 {} 00049 00050 inline bool operator == (const QLineMark& m) 00051 { return (line == m.line) && (file == m.file) && (mark == m.mark); } 00052 00053 inline bool operator != (const QLineMark& m) 00054 { return (line != m.line) || (file != m.file) || (mark != m.mark); } 00055 00056 int mark; 00057 int line; 00058 QString file; 00059 }; 00060 00061 Q_DECLARE_METATYPE(QLineMark) 00062 00063 typedef QList<QLineMark> QLineMarkList; 00064 00065 Q_DECLARE_TYPEINFO(QLineMark, Q_MOVABLE_TYPE); 00066 00067 struct QLineMarkHandle 00068 { 00069 inline QLineMarkHandle() : line(0) {} 00070 00071 inline QLineMarkHandle(const QString& f, QDocumentLineHandle *l, int m) 00072 : mark(m), line(l), file(f) 00073 {} 00074 00075 inline bool operator == (const QLineMarkHandle& m) 00076 { return (line == m.line) && (file == m.file) && (mark == m.mark); } 00077 00078 inline bool operator != (const QLineMarkHandle& m) 00079 { return (line != m.line) || (file != m.file) || (mark != m.mark); } 00080 00081 int mark; 00082 QDocumentLineHandle *line; 00083 QString file; 00084 }; 00085 00086 Q_DECLARE_METATYPE(QLineMarkHandle) 00087 00088 typedef QList<QLineMarkHandle> QLineMarkHandleList; 00089 00090 Q_DECLARE_TYPEINFO(QLineMarkHandle, Q_MOVABLE_TYPE); 00091 00092 QCE_EXPORT QDataStream& operator >> (QDataStream& d, QLineMark& m); 00093 QCE_EXPORT QDataStream& operator << (QDataStream& d, const QLineMark& m); 00094 00095 struct QLineMarkType 00096 { 00097 inline QLineMarkType() 00098 : user(false), focus(false), priority(-1), persistency(0) 00099 {} 00100 00101 bool user; 00102 bool focus; 00103 QString id; 00104 QPixmap icon; 00105 QColor color; 00106 int priority; 00107 int persistency; 00108 QStringList rules; 00109 }; 00110 00111 Q_DECLARE_METATYPE(QLineMarkType) 00112 00113 typedef QList<QLineMarkType> QLineMarkTypeList; 00114 00115 Q_DECLARE_TYPEINFO(QLineMarkType, Q_MOVABLE_TYPE); 00116 00117 class QCE_EXPORT QLineMarksInfoCenter : public QObject 00118 { 00119 friend class QEditor; 00120 friend class QCodeEdit; 00121 00122 Q_OBJECT 00123 00124 public: 00125 static QLineMarksInfoCenter* instance(); 00126 static void destroy(); 00127 00128 QLineMarkList marks(const QString& file = QString()); 00129 00130 QString markTypeId(int id); 00131 int markTypeId(const QString& id); 00132 00133 QLineMarkType markType(int id); 00134 QLineMarkType markType(const QString& id); 00135 00136 int priority(const QList<int>& marks); 00137 QString priority(const QStringList& marks); 00138 00139 QStringList availableMarkTypes(const QString& context = QString()); 00140 QList<QStringList> marksLayout(const QString& context = QString()); 00141 00142 public slots: 00143 void loadMarks(const QString& f); 00144 void saveMarks(const QString& f); 00145 00146 void loadMarkTypes(const QString& f); 00147 00148 void clear(); 00149 00150 void removeMarks(const QString& file); 00151 00152 void addLineMark(const QLineMark& mark); 00153 void toggleLineMark(const QLineMark& mark); 00154 void removeLineMark(const QLineMark& mark); 00155 00156 void addLineMark(const QLineMarkHandle& mark); 00157 void toggleLineMark(const QLineMarkHandle& mark); 00158 void removeLineMark(const QLineMarkHandle& mark); 00159 00160 void flush(const QString& file); 00161 00162 signals: 00163 void lineMarkAdded(const QLineMark& mark); 00164 void lineMarkRemoved(const QLineMark& mark); 00165 00166 protected: 00167 QLineMarksInfoCenter(); 00168 virtual ~QLineMarksInfoCenter(); 00169 00170 protected slots: 00171 void cursorMoved(QEditor *e); 00172 void lineDeleted(QDocumentLineHandle *h); 00173 void markChanged(const QString& f, QDocumentLineHandle *h, int mark, bool on); 00174 00175 private: 00176 QLineMarkList m_delayed; 00177 QLineMarkHandleList m_lineMarks; 00178 QLineMarkTypeList m_lineMarkTypes; 00179 00180 static QLineMarksInfoCenter *m_instance; 00181 }; 00182 00183 #endif // !_QLINE_MARKS_INFO_CENTER_H_