File: LatexEditor.h

package info (click to toggle)
equalx 0.7.1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,268 kB
  • sloc: cpp: 7,119; ansic: 98; sql: 10; makefile: 6
file content (115 lines) | stat: -rw-r--r-- 3,441 bytes parent folder | download | duplicates (4)
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
/*
 * Copyright 2010 Mihai Niculescu <q.quark@gmail.com>
 *
 * This file is part of EqualX Project (https://launchpad.net/equalx/)
 *
 * EqualX 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 3 of the License, or
 * (at your option) any later version.
 *
 * EqualX is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef LATEXEDITOR_H
#define LATEXEDITOR_H

#include <QPlainTextEdit>
#include "HLSelections.h"


class QCompleter;
class QAbstractItemModel;
class LatexHighlighter;
class LatexEditor;

// class to have Line Number in LatexEditor
class LatexEditorLineNumberArea : public QWidget
{
public:
    LatexEditorLineNumberArea(LatexEditor *editor);

    QSize sizeHint() const;

protected:
    void paintEvent(QPaintEvent *event);

private:
    LatexEditor *codeEditor;
};


class LatexEditor : public QPlainTextEdit
{
    Q_OBJECT

public:
     LatexEditor(QWidget *parent = 0);
    ~LatexEditor();


    HLSelections getSelections() const;
    void lineNumberAreaPaintEvent(QPaintEvent *event);
    int lineNumberAreaWidth();
    void setHighLighting(bool activeHL=true);
    void setCompletion(bool activeCompletion=true);
    void setCompletionSensitive(bool caseSensitive=true);
    void setCompleter(QCompleter *c);
    void setModel(QAbstractItemModel *model);

    QCompleter *completer() const;

    QString selectedText() const;
    void  selectLines(const QMap<int,QString> &errorsMap); // highlight these lines

public slots:
    void clearSelections();// clear highlight of multiple find occurances

    void setMinCharMatch(int n) { minCompletionChars = n; } // set minimum of chars to match for completion
    void setStartCountingBlocks(int n); // start counting lineNumberArea from this
    bool find(const QString &expr, QTextDocument::FindFlags flags);
    bool findAll(const QString &expr, QTextDocument::FindFlags flags);
    bool findNext();
    bool findPrevious();

    void replace(const QString &expr); // replace current cursor selection with expr
    void replaceAll(const QString &expr);// replace All Selections with expr

protected:
    void keyPressEvent(QKeyEvent *e);
    void focusInEvent(QFocusEvent *e);
    QString textUnderCursor() const;
    void resizeEvent(QResizeEvent *event);
    void mousePressEvent(QMouseEvent *e);


private slots:
    void insertCompletion(const QString &completion);
    void updateLineNumberAreaWidth(int newBlockCount);
    void updateLineNumberArea(const QRect &, int);

private:
    QAbstractItemModel *modelFromFile(const QString& fileName);

    LatexHighlighter *highlighter;
    QCompleter *c;
    int minCompletionChars;
    bool m_activeCompletion;

    // last find Expression & last find Flags
    HLSelections hlSelections; // highlight Selections
    QString findExpr;
    QTextDocument::FindFlags findFlags;
    QWidget *lineNumberArea;
    int lineNumberAreaStartCount; // start counting lines from this number
    QPixmap* pixError;
    QMap<int,QString> errors;
};

#endif // LATEXEDITOR_H