Galaxis Codebase  1.0.0
Team Galaxis software stack for the Carolo Cup 2023 - ROS2 based software
jsedit.h
Go to the documentation of this file.
1 /*
2  This file is part of the Ofi Labs X2 project.
3 
4  Copyright (C) 2011 Ariya Hidayat <ariya.hidayat@gmail.com>
5  Copyright (C) 2010 Ariya Hidayat <ariya.hidayat@gmail.com>
6 
7  Redistribution and use in source and binary forms, with or without
8  modification, are permitted provided that the following conditions are met:
9 
10  * Redistributions of source code must retain the above copyright
11  notice, this list of conditions and the following disclaimer.
12  * Redistributions in binary form must reproduce the above copyright
13  notice, this list of conditions and the following disclaimer in the
14  documentation and/or other materials provided with the distribution.
15  * Neither the name of the <organization> nor the
16  names of its contributors may be used to endorse or promote products
17  derived from this software without specific prior written permission.
18 
19  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
23  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30 
31 #ifndef OFILABS_JSEDIT
32 #define OFILABS_JSEDIT
33 
34 #include <QColor>
35 #include <QPlainTextEdit>
36 #include <QScopedPointer>
37 
38 #undef BOOLEAN
39 #undef boolean
40 #include <QtGui>
41 
42 class JSBlockData: public QTextBlockUserData
43 {
44 public:
45  QList<int> bracketPositions;
46 };
47 
48 class JSEditPrivate;
49 
50 class JSEdit: public QPlainTextEdit
51 {
52  Q_OBJECT
57 
58 public:
59 
60  typedef enum {
78 
79  JSEdit(QWidget *parent = 0);
80  ~JSEdit();
81 
82  void setColor(ColorComponent component, const QColor &color);
83 
84  QStringList keywords() const;
85  void setKeywords(const QStringList &keywords);
86 
87  bool isBracketsMatchingEnabled() const;
88  bool isCodeFoldingEnabled() const;
89  bool isLineNumbersVisible() const;
90  bool isTextWrapEnabled() const;
91 
92  bool isFoldable(int line) const;
93  bool isFolded(int line) const;
94 
95 public slots:
96  void updateSidebar();
97  void mark(const QString &str, Qt::CaseSensitivity sens = Qt::CaseInsensitive);
98  void setBracketsMatchingEnabled(bool enable);
99  void setCodeFoldingEnabled(bool enable);
100  void setLineNumbersVisible(bool visible);
101  void setTextWrapEnabled(bool enable);
102 
103  void fold(int line);
104  void unfold(int line);
105  void toggleFold(int line);
106 
107 protected:
108  void resizeEvent(QResizeEvent *e);
109  void wheelEvent(QWheelEvent *e);
110 
111 private slots:
112  void updateCursor();
113  void updateSidebar(const QRect &rect, int d);
114 
115 private:
116  QScopedPointer<JSEditPrivate> d_ptr;
119 };
120 
121 class JSHighlighter : public QSyntaxHighlighter
122 {
123 public:
124  JSHighlighter(QTextDocument *parent = 0);
125  void setColor(JSEdit::ColorComponent component, const QColor &color);
126  void mark(const QString &str, Qt::CaseSensitivity caseSensitivity);
127 
128  QStringList keywords() const;
129  void setKeywords(const QStringList &keywords);
130 
131 protected:
132  void highlightBlock(const QString &text);
133 
134 private:
135  QSet<QString> m_keywords;
136  QSet<QString> m_knownIds;
137  QHash<JSEdit::ColorComponent, QColor> m_colors;
138  QString m_markString;
139  Qt::CaseSensitivity m_markCaseSensitivity;
140 };
141 
142 #endif // OFILABS_JSEDIT
JSHighlighter::m_markString
QString m_markString
Definition: jsedit.h:138
JSEdit::bracketsMatchingEnabled
bool bracketsMatchingEnabled
Definition: jsedit.h:53
JSEditPrivate
Definition: jsedit.cpp:605
JSHighlighter::mark
void mark(const QString &str, Qt::CaseSensitivity caseSensitivity)
Definition: jsedit.cpp:400
JSHighlighter::setColor
void setColor(JSEdit::ColorComponent component, const QColor &color)
Definition: jsedit.cpp:224
JSEdit::Q_DISABLE_COPY
Q_DISABLE_COPY(JSEdit)
JSEdit::String
@ String
Definition: jsedit.h:65
JSEdit::setCodeFoldingEnabled
void setCodeFoldingEnabled(bool enable)
Definition: jsedit.cpp:748
JSEdit::textWrapEnabled
bool textWrapEnabled
Definition: jsedit.h:56
JSEdit::Background
@ Background
Definition: jsedit.h:61
JSBlockData
Definition: jsedit.h:42
JSEdit::BracketError
@ BracketError
Definition: jsedit.h:75
JSEdit::updateSidebar
void updateSidebar()
Definition: jsedit.cpp:950
JSEdit::setKeywords
void setKeywords(const QStringList &keywords)
Definition: jsedit.cpp:705
JSEdit::BuiltIn
@ BuiltIn
Definition: jsedit.h:69
JSHighlighter::m_markCaseSensitivity
Qt::CaseSensitivity m_markCaseSensitivity
Definition: jsedit.h:139
JSHighlighter
Definition: jsedit.h:121
JSEdit::keywords
QStringList keywords() const
Definition: jsedit.cpp:700
JSHighlighter::highlightBlock
void highlightBlock(const QString &text)
Definition: jsedit.cpp:230
JSEdit::FoldIndicator
@ FoldIndicator
Definition: jsedit.h:76
JSHighlighter::keywords
QStringList keywords() const
Definition: jsedit.cpp:407
JSEdit::isTextWrapEnabled
bool isTextWrapEnabled() const
Definition: jsedit.cpp:721
JSEdit::Operator
@ Operator
Definition: jsedit.h:66
JSEdit::Cursor
@ Cursor
Definition: jsedit.h:72
JSEdit::Number
@ Number
Definition: jsedit.h:64
JSEdit::lineNumbersVisible
bool lineNumbersVisible
Definition: jsedit.h:55
JSEdit::JSEdit
JSEdit(QWidget *parent=0)
Definition: jsedit.cpp:623
JSEdit::Marker
@ Marker
Definition: jsedit.h:73
JSHighlighter::JSHighlighter
JSHighlighter(QTextDocument *parent=0)
Definition: jsedit.cpp:33
JSHighlighter::m_knownIds
QSet< QString > m_knownIds
Definition: jsedit.h:136
JSHighlighter::m_keywords
QSet< QString > m_keywords
Definition: jsedit.h:135
JSEdit::BracketMatch
@ BracketMatch
Definition: jsedit.h:74
JSEdit::isFolded
bool isFolded(int line) const
Definition: jsedit.cpp:787
JSEdit::codeFoldingEnabled
bool codeFoldingEnabled
Definition: jsedit.h:54
JSEdit::~JSEdit
~JSEdit()
Definition: jsedit.cpp:657
JSEdit::Identifier
@ Identifier
Definition: jsedit.h:67
JSEdit::setLineNumbersVisible
void setLineNumbersVisible(bool visible)
Definition: jsedit.cpp:715
JSEdit::Q_DECLARE_PRIVATE
Q_DECLARE_PRIVATE(JSEdit)
JSEdit::unfold
void unfold(int line)
Definition: jsedit.cpp:821
JSEdit::mark
void mark(const QString &str, Qt::CaseSensitivity sens=Qt::CaseInsensitive)
Definition: jsedit.cpp:1007
JSEdit
Definition: jsedit.h:50
JSEdit::fold
void fold(int line)
Definition: jsedit.cpp:798
JSEdit::updateCursor
void updateCursor()
Definition: jsedit.cpp:874
JSEdit::LineNumber
@ LineNumber
Definition: jsedit.h:71
JSEdit::isFoldable
bool isFoldable(int line) const
Definition: jsedit.cpp:776
JSEdit::Sidebar
@ Sidebar
Definition: jsedit.h:70
JSEdit::isCodeFoldingEnabled
bool isCodeFoldingEnabled() const
Definition: jsedit.cpp:743
JSEdit::isLineNumbersVisible
bool isLineNumbersVisible() const
Definition: jsedit.cpp:710
JSEdit::setColor
void setColor(ColorComponent component, const QColor &color)
Definition: jsedit.cpp:662
JSEdit::d_ptr
QScopedPointer< JSEditPrivate > d_ptr
Definition: jsedit.h:116
JSEdit::isBracketsMatchingEnabled
bool isBracketsMatchingEnabled() const
Definition: jsedit.cpp:732
JSHighlighter::setKeywords
void setKeywords(const QStringList &keywords)
Definition: jsedit.cpp:412
JSHighlighter::m_colors
QHash< JSEdit::ColorComponent, QColor > m_colors
Definition: jsedit.h:137
JSEdit::resizeEvent
void resizeEvent(QResizeEvent *e)
Definition: jsedit.cpp:850
JSEdit::toggleFold
void toggleFold(int line)
Definition: jsedit.cpp:842
JSEdit::Keyword
@ Keyword
Definition: jsedit.h:68
JSEdit::setTextWrapEnabled
void setTextWrapEnabled(bool enable)
Definition: jsedit.cpp:726
JSEdit::ColorComponent
ColorComponent
Definition: jsedit.h:60
JSEdit::Normal
@ Normal
Definition: jsedit.h:62
JSEdit::setBracketsMatchingEnabled
void setBracketsMatchingEnabled(bool enable)
Definition: jsedit.cpp:737
JSBlockData::bracketPositions
QList< int > bracketPositions
Definition: jsedit.h:45
JSEdit::Comment
@ Comment
Definition: jsedit.h:63
JSEdit::wheelEvent
void wheelEvent(QWheelEvent *e)
Definition: jsedit.cpp:856