[KLF Backend][KLF Tools][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$ */
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
40
41
42// ------------------------------------------------
43
44
45struct KLFLatexEditPrivate;
46
51class KLF_EXPORT KLFLatexEdit : public QTextEdit
52{
53 Q_OBJECT
54
56 Q_PROPERTY(bool wrapLines READ wrapLines WRITE setWrapLines) ;
57
58public:
59 KLFLatexEdit(QWidget *parent);
60 virtual ~KLFLatexEdit();
61
63
71
74 int heightHintLines() const;
75
80 virtual QSize sizeHint() const;
81
82 QString latex() const;
83
84 bool wrapLines() const;
85
86signals:
91 void insertContextMenuActions(const QPoint& pos, QList<QAction*> *actionList);
92
93public slots:
99 void setLatex(const QString& latex);
100 void clearLatex();
101
105 void setWrapLines(bool wrap);
106
108 void setHeightHintLines(int lines);
109
112 void insertDelimiter(const QString& delim, int charsBack = 1);
113
115 void setPalette(const QPalette& palette);
116
117protected:
118 virtual void contextMenuEvent(QContextMenuEvent *event);
119 virtual bool canInsertFromMimeData(const QMimeData *source) const;
120 virtual void insertFromMimeData(const QMimeData *source);
121
122private:
124};
125
126
127struct KLFLatexParenSpecsPrivate;
128
130{
131public:
132 struct ParenSpec {
133 enum Flag { None = 0x00, IsLaTeXBrace = 0x01, AllowAlone = 0x02 };
134 ParenSpec(const QString& o, const QString& c, uint f = 0x00) : open(o), close(c), flags(f) { }
137 uint flags;
138 };
144
145 // loads the default paren & paren modifier specs
147 // loads the given paren & paren modifier spec list
148 KLFLatexParenSpecs(const QList<ParenSpec>& parens, const QList<ParenModifierSpec>& modifiers);
149 // copy constructor
151 virtual ~KLFLatexParenSpecs();
152
155
160
161 enum {
165 };
166
171 int identifyParen(const QString& parenstr, uint identflags);
172
177 int identifyModifier(const QString& modstr, uint identflags);
178
179private:
181};
182
183
184// ----------------------------------------------
185
186
188{
189 Q_OBJECT
190
199
200public:
201 KLFLatexSyntaxHighlighter(QTextEdit *textedit, QObject *parent);
203
235
236 QList<ParsedBlock> parsedContent() const { return pParsedBlocks; }
240 QList<ParsedBlock> parsedBlocksForPos(int pos, unsigned int filter_type = 0xffffffff) const;
241
242 virtual void highlightBlock(const QString& text);
243
244 bool highlightEnabled() const { return pConf.enabled; }
245 bool highlightParensOnly() const { return pConf.highlightParensOnly; }
246 bool highlightLonelyParens() const { return pConf.highlightLonelyParens; }
247 QTextCharFormat fmtKeyword() const { return pConf.fmtKeyword; }
248 QTextCharFormat fmtComment() const { return pConf.fmtComment; }
249 QTextCharFormat fmtParenMatch() const { return pConf.fmtParenMatch; }
250 QTextCharFormat fmtParenMismatch() const { return pConf.fmtParenMismatch; }
251 QTextCharFormat fmtLonelyParen() const { return pConf.fmtLonelyParen; }
252
253signals:
254 void newSymbolTyped(const QString& symbolName);
255
256public slots:
257 void setCaretPos(int position);
258
259 void refreshAll();
260
262 void resetEditing();
263
264 void setHighlightEnabled(bool on);
265 void setHighlightParensOnly(bool on);
266 void setHighlightLonelyParens(bool on);
267 void setFmtKeyword(const QTextFormat& f);
268 void setFmtComment(const QTextFormat& f);
269 void setFmtParenMatch(const QTextFormat& f);
270 void setFmtParenMismatch(const QTextFormat& f);
271 void setFmtLonelyParen(const QTextFormat& f);
272
273private:
274
275 QTextEdit *_textedit;
276
277 int _caretpos;
278
279 enum Format { FNormal = 0, FKeyWord, FComment, FParenMatch, FParenMismatch, FLonelyParen };
280
281 struct FormatRule {
282 FormatRule(int ps = -1, int l = 0, Format f = FNormal, bool needsfocus = false)
283 : pos(ps), len(l), format(f), onlyIfFocus(needsfocus)
284 {
285 if (len < 0) {
286 len = -len; // len is now positive
287 pos -= len; // pos is now at beginning of the region
288 }
289 }
290 int pos;
291 int len;
292 int end() const { return pos + len; }
293 Format format;
294 bool onlyIfFocus;
295 };
296
297 QList<FormatRule> _rulestoapply;
298
299 QList<ParsedBlock> pParsedBlocks;
300
301 void parseEverything();
302
303 QTextCharFormat charfmtForFormat(Format f);
304
307 QStringList pTypedSymbols;
308
309 struct Conf {
310 bool enabled;
311 bool highlightParensOnly;
312 bool highlightLonelyParens;
313 QTextCharFormat fmtKeyword;
314 QTextCharFormat fmtComment;
315 QTextCharFormat fmtParenMatch;
316 QTextCharFormat fmtParenMismatch;
317 QTextCharFormat fmtLonelyParen;
318 };
319 Conf pConf;
320};
321
322
324
325
326
327
328#endif
An abstract handler for when data is dropped.
Definition klfguiutil.h:527
void setPalette(const QPalette &palette)
KLFLatexSyntaxHighlighter * syntaxHighlighter()
void setLatex(const QString &latex)
virtual void contextMenuEvent(QContextMenuEvent *event)
KLFLatexEdit(QWidget *parent)
virtual void insertFromMimeData(const QMimeData *source)
virtual QSize sizeHint() const
void setDropDataHandler(KLFDropDataHandler *handler)
void insertDelimiter(const QString &delim, int charsBack=1)
void setWrapLines(bool wrap)
void setHeightHintLines(int lines)
void insertContextMenuActions(const QPoint &pos, QList< QAction * > *actionList)
QString latex() const
virtual bool canInsertFromMimeData(const QMimeData *source) const
QStringList openParenList() const
QList< ParenModifierSpec > parenModifierSpecList() const
QStringList openParenModifiers() const
QList< ParenSpec > parenSpecList() const
@ IdentifyFlagClose
Identify the paren as closing only.
@ IdentifyFlagOpen
Identify the paren as opening only.
@ IdentifyFlagOpenClose
Identify the paren as opening or closing.
QStringList closeParenModifiers() const
QStringList closeParenList() const
void setFmtParenMatch(const QTextFormat &f)
QTextCharFormat fmtLonelyParen() const
KLFLatexSyntaxHighlighter(QTextEdit *textedit, QObject *parent)
bool highlightLonelyParens() const
QTextCharFormat fmtParenMatch() const
void setFmtKeyword(const QTextFormat &f)
void setFmtLonelyParen(const QTextFormat &f)
void setFmtParenMismatch(const QTextFormat &f)
void newSymbolTyped(const QString &symbolName)
bool highlightParensOnly() const
void setCaretPos(int position)
QList< ParsedBlock > parsedContent() const
void setHighlightEnabled(bool on)
void setHighlightParensOnly(bool on)
QTextCharFormat fmtParenMismatch() const
void setFmtComment(const QTextFormat &f)
QTextCharFormat fmtComment() const
void setHighlightLonelyParens(bool on)
QTextCharFormat fmtKeyword() const
const char * format
Base declarations for klatexformula and some utilities.
#define KLF_DECLARE_PRIVATE(ClassName)
Definition klfdefs.h:74
#define KLF_EXPORT
Definition klfdefs.h:41
KLF_EXPORT QDebug operator<<(QDebug str, const KLFLatexSyntaxHighlighter::ParsedBlock &p)
QObject(QObject *parent)
QObject * parent() const
QSyntaxHighlighter(QObject *parent)
ParenModifierSpec(const QString &o, const QString &c)
ParenSpec(const QString &o, const QString &c, uint f=0x00)
static KLFLatexParenSpecs parenSpecs
ParsedBlock(Type t=Normal, int a=-1, int l=-1)

Generated by doxygen 1.13.1