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
26 #include <QGraphicsScene>
27 #include <QPlainTextEdit>
33 namespace Settings
{ class Manager
; }
37 class GenericCodeEditor
: public QPlainTextEdit
41 friend class LineIndicator
;
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();
60 virtual void keyPressEvent( QKeyEvent
* );
61 virtual void wheelEvent( QWheelEvent
* );
62 virtual void dragEnterEvent( QDragEnterEvent
* );
65 void zoomIn(int steps
= 1);
66 void zoomOut(int steps
= 1);
68 void setShowWhitespace(bool);
69 void clearSearchHighlighting();
70 void toggleOverwriteMode();
75 void gotoPreviousEmptyLine();
76 void gotoNextEmptyLine();
80 void updateLineIndicator( QRect
, int );
81 void onDocumentFontChanged();
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
;
100 QList
<QTextEdit::ExtraSelection
> mSearchSelections
;
103 class CodeEditor
: public GenericCodeEditor
108 CodeEditor( Document
*, QWidget
*parent
= 0 );
109 void setIndentWidth( int );
110 QTextCursor
currentRegion();
111 QTextCursor
regionAtCursor( const QTextCursor
& );
112 void blinkCode( const QTextCursor
& c
);
116 void setSpaceIndent(bool on
) { mSpaceIndent
= on
; }
117 void applySettings( Settings::Manager
* );
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();
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
* );
140 void matchBrackets();
141 void onOverlayChanged ( const QList
<QRectF
> & region
);
144 struct BracketMatch
{
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 );
172 QTextCharFormat mBracketHighlight
;
174 QList
<QTextEdit::ExtraSelection
> mBracketSelections
;
175 bool mMouseBracketMatch
;
177 QGraphicsScene
*mOverlay
;
179 class AutoCompleter
*mAutoCompleter
;
184 #endif // SCIDE_WIDGETS_CODE_EDITOR_EDITOR_HPP_INCLUDED