[KLF Application][KLF Tools][KLF Backend][KLF Home]
KLatexFormula Project
klflatexedit.h
Go to the documentation of this file.
1 /***************************************************************************
2  * file klflatexedit.h
3  * This file is part of the KLatexFormula Project.
4  * Copyright (C) 2011 by Philippe Faist
5  * philippe.faist at bluewin.ch
6  * *
7  * This program is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program; if not, write to the *
19  * Free Software Foundation, Inc., *
20  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  ***************************************************************************/
22 /* $Id: klflatexedit.h 603 2011-02-26 23:14:55Z phfaist $ */
23 
24 #ifndef KLFLATEXEDIT_H
25 #define KLFLATEXEDIT_H
26 
27 #include <klfdefs.h>
28 
29 #include <QObject>
30 #include <QTextEdit>
31 #include <QEvent>
32 #include <QContextMenuEvent>
33 #include <QMimeData>
34 #include <QSyntaxHighlighter>
35 #include <QTextCharFormat>
36 
37 
39 class KLFMainWin;
40 
41 
42 // ------------------------------------------------
43 
44 
45 
46 
51 class KLF_EXPORT KLFLatexEdit : public QTextEdit
52 {
53  Q_OBJECT
54 
55  Q_PROPERTY(int heightHintLines READ heightHintLines WRITE setHeightHintLines) ;
56 public:
57  KLFLatexEdit(QWidget *mainwin);
58  virtual ~KLFLatexEdit();
59 
60  KLFLatexSyntaxHighlighter *syntaxHighlighter() { return mSyntaxHighlighter; }
61 
68  void setMainWinDataOpener(KLFMainWin *mainwin) { mMainWin = mainwin; }
69 
72  inline int heightHintLines() const { return pHeightHintLines; }
73 
78  virtual QSize sizeHint() const;
79 
80 
81 signals:
86  void insertContextMenuActions(const QPoint& pos, QList<QAction*> *actionList);
87 
88 public slots:
94  void setLatex(const QString& latex);
95  void clearLatex();
96 
98  void setHeightHintLines(int lines);
99 
102  void insertDelimiter(const QString& delim, int charsBack = 1);
103 
104 protected:
105  virtual void contextMenuEvent(QContextMenuEvent *event);
106  virtual bool canInsertFromMimeData(const QMimeData *source) const;
107  virtual void insertFromMimeData(const QMimeData *source);
108 
109 private slots:
110  void slotInsertFromActionSender();
111 
112 private:
113  KLFLatexSyntaxHighlighter *mSyntaxHighlighter;
114 
116  KLFMainWin *mMainWin;
117 
118  int pHeightHintLines;
119 };
120 
121 
122 
123 
124 
125 // ----------------------------------------------
126 
127 
129 {
130  Q_OBJECT
131 public:
132  KLFLatexSyntaxHighlighter(QTextEdit *textedit, QObject *parent);
133  virtual ~KLFLatexSyntaxHighlighter();
134 
135  void setCaretPos(int position);
136 
137  virtual void highlightBlock(const QString& text);
138 
139  enum { Enabled = 0x01,
140  HighlightParensOnly = 0x02,
141  HighlightLonelyParen = 0x04 };
142 
143 signals:
144  void newSymbolTyped(const QString& symbolName);
145 
146 public slots:
147  void refreshAll();
148 
150  void resetEditing();
151 
152 private:
153 
154  QTextEdit *_textedit;
155 
156  int _caretpos;
157 
158  enum Format { FNormal = 0, FKeyWord, FComment, FParenMatch, FParenMismatch, FLonelyParen };
159 
160  struct FormatRule {
161  FormatRule(int ps = -1, int l = 0, Format f = FNormal, bool needsfocus = false)
162  : pos(ps), len(l), format(f), onlyIfFocus(needsfocus) { }
163  int pos;
164  int len;
165  int end() const { return pos + len; }
166  Format format;
167  bool onlyIfFocus;
168  };
169 
170  struct ParenItem {
171  ParenItem(int ps = -1, bool h = false, char c = 0, bool l = false)
172  : pos(ps), highlight(h), ch(c), left(l) { }
173  int pos;
174  bool highlight;
175  char ch;
176  bool left;
177  };
178 
179  QList<FormatRule> _rulestoapply;
180 
181  void parseEverything();
182 
183  QTextCharFormat charfmtForFormat(Format f);
184 
187  QStringList pTypedSymbols;
188 };
189 
190 
191 
192 
193 #endif
canInsertFromMimeData(const QMimeData *source)
highlightBlock(const QString &text)
contextMenuEvent(QContextMenuEvent *event)
int heightHintLines() const
Definition: klflatexedit.h:72
KLFLatexSyntaxHighlighter * syntaxHighlighter()
Definition: klflatexedit.h:60
void setMainWinDataOpener(KLFMainWin *mainwin)
Definition: klflatexedit.h:68
A text edit field that edits latex code.
Definition: klflatexedit.h:51
insertFromMimeData(const QMimeData *source)
const char * format

Generated by doxygen 1.8.11