forked from mercutiodesign/texmaker-3.3.3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
latexeditor.h
218 lines (188 loc) · 7.07 KB
/
latexeditor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/***************************************************************************
* copyright : (C) 2003-2011 by Pascal Brachet *
* http://www.xm1math.net/texmaker/ *
* addons by Luis Silvestre *
* contains some code from CLedit (C) 2010 Heinz van Saanen -GPL *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef LATEXEDITOR_H
#define LATEXEDITOR_H
#include <QWidget>
#include <QString>
#include <QTextEdit>
#include <QPlainTextEdit>
#include <QTextDocument>
#include <QTextCursor>
#include <QTextBlock>
#include <QCompleter>
#include <QDateTime>
#include <QTimer>
#include <QKeySequence>
#include <QThread>
#include <QSemaphore>
#include <QMutex>
#include <QQueue>
#include <QDebug>
#include "latexhighlighter.h"
#include "textblockselection.h"
#include "hunspell/hunspell.hxx"
typedef int UserBookmarkList[3];
class StructItem {
public:
int line;
QString item;
int type;
QTextCursor cursor;
StructItem(int l, const QString& it, int t,const QTextCursor& curs): line(l),item(it),type(t),cursor(curs) { };
bool operator==( const StructItem other ) const {
return ((item==other.item) && (type==other.type));
}
bool operator<( const StructItem other ) const {
return (item<other.item);
}
};
struct updateStruct {
bool isdirty;
QList<StructItem> list;
};
class LatexEditor : public QPlainTextEdit {
Q_OBJECT
public:
LatexEditor(QWidget *parent,QFont & efont, QList<QColor> edcolors, QList<QColor> hicolors,bool inlinespelling=false, QString ignoredWords="",Hunspell *spellChecker=0,bool tabspaces=false,int tabwidth=4,const QKeySequence viewfocus=QKeySequence("Ctrl+Space"), QString name="",QStringList ulist=QStringList());
~LatexEditor();
static void clearMarkerFormat(const QTextBlock &block, int markerId);
void gotoLine( int line );
bool search( const QString &expr, bool cs, bool wo, bool forward, bool startAtCursor );
void replace( const QString &r);
void commentSelection();
void uncommentSelection();
void indentSelection();
void unindentSelection();
void changeFont(QFont & new_font);
QString getEncoding();
void setEncoding(QString enc);
int getCursorPosition(int parag, int index);
void setCursorPosition(int para, int index);
void removeOptAlt();
int numoflines();
int searchLine( const QString &expr);
int linefromblock(const QTextBlock& p);
UserBookmarkList UserBookmark;
void selectword(int line, int col, QString word);
LatexHighlighter *highlighter;
void setCompleter(QCompleter *completer);
QCompleter *completer() const;
QStringList alwaysignoredwordList;
void setSpellChecker(Hunspell * checker);
void activateInlineSpell(bool enable);
Hunspell * pChecker;
void insertNewLine();
void fold(int start, int end);
void unfold(int start, int end);
QRectF blockGeometry(const QTextBlock & block) {
return blockBoundingGeometry(block).translated(contentOffset());
}
//const QRectF blockGeometry(const QTextBlock & block);
//const QRectF blockRect(const QTextBlock & block) {return blockBoundingRect(block).translated(contentOffset());};
QMap<int,int> foldedLines;
QMap<int,int> foldableLines;
QStringList structlist, structitem;
//QList<int> structtype, structpos, structlen;
QList<QTextCursor> structcursor;
void checkStructUpdate(QTextDocument *doc,int blockpos,QString text,int line);
int getLastNumLines();
void setLastNumLines(int n);
QDateTime getLastSavedTime();
void setLastSavedTime(QDateTime t);
void setTabSettings(bool tabspaces,int tabwidth);
void setKeyViewerFocus(QKeySequence s);
void updateName(QString f);
const QList<StructItem> getStructItems() const {
return StructItemsList;
}
QString beginningLine();
void setTextCursor(const QTextCursor &cursor);
TextBlockSelection blockSelection;
public slots:
void matchAll();
void setHightLightLine();
void clearHightLightLine();
virtual void paste();
virtual void cut();
void setCursorVisible() {
ensureCursorVisible ();
};
void setColors(QList<QColor> colors);
void setUserTagsList(QStringList utlist);
private:
bool overmode;
QStringList userTagsList;
bool inBlockSelectionMode;
QKeySequence vfocus;
QString fname;
bool tabSpaces;
int tabWidth;
QDateTime lastSavedTime;
QList<StructItem> StructItemsList, OldStructItemsList;
QString encoding;
int lastnumlines;
//QString textUnderCursor() const;
QString commandUnderCursor() const;
QStringList fullcommandUnderCursor();
QCompleter *c;
QString spell_dic, spell_encoding;
QStringList ignoredwordList, hardignoredwordList;
bool inlinecheckSpelling;
bool isWordSeparator(QChar c) const;
bool isSpace(QChar c) const;
bool matchLeftPar ( QTextBlock currentBlock, int index, int numRightPar );
bool matchRightPar( QTextBlock currentBlock, int index, int numLeftPar );
void createParSelection( int pos );
bool matchLeftLat ( QTextBlock currentBlock, int index, int numRightLat, int bpos );
bool matchRightLat( QTextBlock currentBlock, int index, int numLeftLat, int epos );
void createLatSelection(int start, int end );
int endBlock;
QTimer highlightRemover;
bool highlightLine;
QString copyBlockSelection() const;
QColor colorBackground, colorLine, colorHighlight, colorCursor;
private slots:
void correctWord();
void checkSpellingWord();
void checkSpellingDocument();
void insertCompletion(const QString &completion);
void jumpToPdf();
void jumpToEndBlock();
void requestNewNumLines(int n);
void matchPar();
void matchLat();
void ensureFinalNewLine();//Qt 4.7.1 bug
void removeBlockSelection(const QString &text = QString());
void slotSelectionChanged();
protected:
void paintEvent(QPaintEvent *event);
void contextMenuEvent(QContextMenuEvent *e);
void keyPressEvent ( QKeyEvent * e );
void focusInEvent(QFocusEvent *e);
void mouseMoveEvent(QMouseEvent *);
void mousePressEvent(QMouseEvent *);
QMimeData *createMimeDataFromSelection() const;
bool canInsertFromMimeData(const QMimeData *source) const;
void insertFromMimeData(const QMimeData *source);
signals:
void spellme();
void tooltiptab();
void requestpdf(int );
void setBlockRange(int,int);
void updatelineWidget();
void requestUpdateStructure();
void requestGotoStructure(int);
void poshaschanged(int,int);
void numLinesChanged(int);
};
#endif