Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef KLFLATEXEDIT_H
00025 #define KLFLATEXEDIT_H
00026
00027 #include <klfdefs.h>
00028
00029 #include <QObject>
00030 #include <QTextEdit>
00031 #include <QEvent>
00032 #include <QContextMenuEvent>
00033 #include <QMimeData>
00034 #include <QSyntaxHighlighter>
00035 #include <QTextCharFormat>
00036
00037
00038 class KLFLatexSyntaxHighlighter;
00039 class KLFMainWin;
00040
00041
00042
00043
00044
00045
00046
00051 class KLF_EXPORT KLFLatexEdit : public QTextEdit
00052 {
00053 Q_OBJECT
00054
00055 Q_PROPERTY(int heightHintLines READ heightHintLines WRITE setHeightHintLines) ;
00056 public:
00057 KLFLatexEdit(QWidget *mainwin);
00058 virtual ~KLFLatexEdit();
00059
00060 KLFLatexSyntaxHighlighter *syntaxHighlighter() { return mSyntaxHighlighter; }
00061
00068 void setMainWinDataOpener(KLFMainWin *mainwin) { mMainWin = mainwin; }
00069
00072 inline int heightHintLines() const { return pHeightHintLines; }
00073
00078 virtual QSize sizeHint() const;
00079
00080
00081 signals:
00086 void insertContextMenuActions(const QPoint& pos, QList<QAction*> *actionList);
00087
00088 public slots:
00094 void setLatex(const QString& latex);
00095 void clearLatex();
00096
00098 void setHeightHintLines(int lines);
00099
00102 void insertDelimiter(const QString& delim, int charsBack = 1);
00103
00104 protected:
00105 virtual void contextMenuEvent(QContextMenuEvent *event);
00106 virtual bool canInsertFromMimeData(const QMimeData *source) const;
00107 virtual void insertFromMimeData(const QMimeData *source);
00108
00109 private slots:
00110 void slotInsertFromActionSender();
00111
00112 private:
00113 KLFLatexSyntaxHighlighter *mSyntaxHighlighter;
00114
00116 KLFMainWin *mMainWin;
00117
00118 int pHeightHintLines;
00119 };
00120
00121
00122
00123
00124
00125
00126
00127
00128 class KLF_EXPORT KLFLatexSyntaxHighlighter : public QSyntaxHighlighter
00129 {
00130 Q_OBJECT
00131 public:
00132 KLFLatexSyntaxHighlighter(QTextEdit *textedit, QObject *parent);
00133 virtual ~KLFLatexSyntaxHighlighter();
00134
00135 void setCaretPos(int position);
00136
00137 virtual void highlightBlock(const QString& text);
00138
00139 enum { Enabled = 0x01,
00140 HighlightParensOnly = 0x02,
00141 HighlightLonelyParen = 0x04 };
00142
00143 signals:
00144 void newSymbolTyped(const QString& symbolName);
00145
00146 public slots:
00147 void refreshAll();
00148
00150 void resetEditing();
00151
00152 private:
00153
00154 QTextEdit *_textedit;
00155
00156 int _caretpos;
00157
00158 enum Format { FNormal = 0, FKeyWord, FComment, FParenMatch, FParenMismatch, FLonelyParen };
00159
00160 struct FormatRule {
00161 FormatRule(int ps = -1, int l = 0, Format f = FNormal, bool needsfocus = false)
00162 : pos(ps), len(l), format(f), onlyIfFocus(needsfocus) { }
00163 int pos;
00164 int len;
00165 int end() const { return pos + len; }
00166 Format format;
00167 bool onlyIfFocus;
00168 };
00169
00170 struct ParenItem {
00171 ParenItem(int ps = -1, bool h = false, char c = 0, bool l = false)
00172 : pos(ps), highlight(h), ch(c), left(l) { }
00173 int pos;
00174 bool highlight;
00175 char ch;
00176 bool left;
00177 };
00178
00179 QList<FormatRule> _rulestoapply;
00180
00181 void parseEverything();
00182
00183 QTextCharFormat charfmtForFormat(Format f);
00184
00187 QStringList pTypedSymbols;
00188 };
00189
00190
00191
00192
00193 #endif