Debian Codegraph @

avogadro/qtplugins/coordinateeditor/coordinatetextedit.h

raw
1 /******************************************************************************
2 This source file is part of the Avogadro project.
3 This source code is released under the 3-Clause BSD License, (see "LICENSE").
4 ******************************************************************************/
5
6 #ifndef AVOGADRO_QTPLUGINS_COORDINATETEXTEDIT_H
7 #define AVOGADRO_QTPLUGINS_COORDINATETEXTEDIT_H
8
9 #include <QtWidgets/QTextEdit>
10
11 #include <QtGui/QTextCharFormat>
12
13 class QHelpEvent;
14
15 namespace Avogadro {
16 namespace QtPlugins {
17
18 /**
19 * @brief The CoordinateTextEdit class extends QTextEdit to provide context
20 * tooltips and highlighting for syntax errors.
21 */
22 class CoordinateTextEdit : public QTextEdit
23 {
24 Q_OBJECT
25 public:
26 explicit CoordinateTextEdit(QWidget* p = nullptr);
27
28 bool hasInvalidMarks() const { return m_hasInvalidMarks; }
29
30 public slots:
31 void resetMarks();
32 void markInvalid(QTextCursor& cur, const QString& tooltip);
33 void markValid(QTextCursor& cur, const QString& tooltip);
34
35 protected:
36 bool event(QEvent* e) override;
37
38 private:
39 void showToolTip(QHelpEvent* e) const;
40
41 struct Mark
42 {
43 int start;
44 int end;
45 QString tooltip;
46 Mark(int s, int e, const QString& t) : start(s), end(e), tooltip(t) {}
47 bool contains(int i) const { return i >= start && i <= end; }
48 };
49 QList<Mark> m_marks;
50 bool m_hasInvalidMarks;
51
52 QTextCharFormat m_unmarkedFormat;
53 QTextCharFormat m_invalidFormat;
54 QTextCharFormat m_validFormat;
55 };
56
57 } // namespace QtPlugins
58 } // namespace Avogadro
59
60 #endif // AVOGADRO_QTPLUGINS_COORDINATETEXTEDIT_H