scide: DocManager - report warnings via the status bar
[supercollider.git] / editors / sc-ide / widgets / code_editor / editor.hpp
blob7a0f483a94e615e8cc64f4eec8014070495725d2
1 /*
2 SuperCollider Qt IDE
3 Copyright (c) 2012 Jakob Leben & Tim Blechmann
4 http://www.audiosynth.com
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef SCIDE_WIDGETS_CODE_EDITOR_EDITOR_HPP_INCLUDED
22 #define SCIDE_WIDGETS_CODE_EDITOR_EDITOR_HPP_INCLUDED
24 #include "tokens.hpp"
26 #include <QGraphicsScene>
27 #include <QPlainTextEdit>
28 #include <QTextBlock>
29 #include <QList>
31 namespace ScIDE {
33 namespace Settings { class Manager; }
35 class Document;
37 class GenericCodeEditor : public QPlainTextEdit
39 Q_OBJECT
41 friend class LineIndicator;
43 public:
44 GenericCodeEditor (Document *, QWidget * parent = NULL);
46 Document *document() { return mDoc; }
47 QTextDocument *textDocument() { return QPlainTextEdit::document(); }
48 void setDocument( Document * );
49 bool showWhitespace();
50 bool find( const QRegExp &expr, QTextDocument::FindFlags options = 0);
51 bool replace( const QRegExp &expr, const QString &replacement, QTextDocument::FindFlags options = 0);
52 int findAll( const QRegExp &expr, QTextDocument::FindFlags options = 0 );
53 int replaceAll( const QRegExp &expr, const QString &replacement,
54 QTextDocument::FindFlags options = 0 );
56 void showPosition( int charPosition, int selectionLength );
57 QString symbolUnderCursor();
59 protected:
60 virtual void keyPressEvent( QKeyEvent * );
61 virtual void wheelEvent( QWheelEvent * );
62 virtual void dragEnterEvent( QDragEnterEvent * );
64 public Q_SLOTS:
65 void zoomIn(int steps = 1);
66 void zoomOut(int steps = 1);
67 void resetFontSize();
68 void setShowWhitespace(bool);
69 void clearSearchHighlighting();
70 void toggleOverwriteMode();
71 void copyLineUp();
72 void copyLineDown();
73 void moveLineUp();
74 void moveLineDown();
75 void gotoPreviousEmptyLine();
76 void gotoNextEmptyLine();
78 protected Q_SLOTS:
79 void updateLayout();
80 void updateLineIndicator( QRect, int );
81 void onDocumentFontChanged();
83 protected:
84 void resizeEvent( QResizeEvent * );
85 void paintLineIndicator( QPaintEvent * );
86 virtual void updateExtraSelections();
87 virtual void indentCurrentRegion() {}
89 void zoomFont(int steps);
91 void copyUpDown(bool up);
92 void moveLineUpDown(bool up);
93 void gotoEmptyLineUpDown(bool up);
95 void hideMouseCursor();
97 class LineIndicator *mLineIndicator;
99 Document *mDoc;
100 QList<QTextEdit::ExtraSelection> mSearchSelections;
103 class CodeEditor : public GenericCodeEditor
105 Q_OBJECT
107 public:
108 CodeEditor( Document *, QWidget *parent = 0 );
109 void setIndentWidth( int );
110 QTextCursor currentRegion();
111 QTextCursor regionAtCursor( const QTextCursor & );
112 void blinkCode( const QTextCursor & c );
115 public Q_SLOTS:
116 void setSpaceIndent(bool on) { mSpaceIndent = on; }
117 void applySettings( Settings::Manager * );
118 void indent();
119 void triggerAutoCompletion();
120 void triggerMethodCallAid();
121 void toggleComment();
122 void gotoPreviousBlock();
123 void gotoNextBlock();
124 void selectCurrentRegion();
125 void gotoNextRegion();
126 void gotoPreviousRegion();
127 bool openDocumentation();
128 void openDefinition();
129 void findReferences();
131 protected:
132 virtual bool event( QEvent * );
133 virtual void keyPressEvent( QKeyEvent * );
134 virtual void mouseReleaseEvent ( QMouseEvent * );
135 virtual void mouseDoubleClickEvent( QMouseEvent * );
136 virtual void mouseMoveEvent( QMouseEvent * );
137 virtual void paintEvent( QPaintEvent * );
139 private Q_SLOTS:
140 void matchBrackets();
141 void onOverlayChanged ( const QList<QRectF> & region );
143 private:
144 struct BracketMatch {
145 TokenIterator first;
146 TokenIterator second;
149 void matchBracket( const TokenIterator & bracket, BracketMatch & match );
150 void updateExtraSelections();
151 void indentCurrentRegion();
153 void toggleCommentSingleLine( QTextCursor );
154 void toggleCommentSingleLine();
155 void toggleCommentSelection();
156 void addSingleLineComment( QTextCursor, int indentationLevel );
157 void removeSingleLineComment( QTextCursor );
159 QTextCursor blockAtCursor(const QTextCursor &); // text cursor should point to bracket!
161 int indentedStartOfLine( const QTextBlock & );
162 void indent( const QTextCursor & );
163 QTextBlock indent( const QTextBlock & b, int level );
164 QString makeIndentationString( int level );
165 int indentationLevel( const QTextCursor & );
167 QTextCursor cursorAt( const TokenIterator, int offset = 0 );
169 int mIndentWidth;
170 bool mSpaceIndent;
171 int mBlinkDuration;
172 QTextCharFormat mBracketHighlight;
174 QList<QTextEdit::ExtraSelection> mBracketSelections;
175 bool mMouseBracketMatch;
177 QGraphicsScene *mOverlay;
179 class AutoCompleter *mAutoCompleter;
182 } // namespace ScIDE
184 #endif // SCIDE_WIDGETS_CODE_EDITOR_EDITOR_HPP_INCLUDED