]> SALOME platform Git repositories - modules/gui.git/blob - tools/PyEditor/src/PyEditor_Editor.h
Salome HOME
Merge branch 'V8_3_asterstudy' into V8_3_BR
[modules/gui.git] / tools / PyEditor / src / PyEditor_Editor.h
1 // Copyright (C) 2015-2016  OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // File   : PyEditor_Editor.h
20 // Author : Maxim GLIBIN, Open CASCADE S.A.S. (maxim.glibin@opencascade.com)
21 //
22
23 #ifndef PYEDITOR_EDITOR_H
24 #define PYEDITOR_EDITOR_H
25
26 #include "PyEditor.h"
27 #include "PyEditor_Settings.h"
28
29 #include <QPlainTextEdit>
30
31 class PyEditor_Keywords;
32 class PyEditor_Completer;
33 class PyEditor_PyHighlighter;
34
35 class PYEDITOR_EXPORT PyEditor_Editor : public QPlainTextEdit
36 {
37   Q_OBJECT
38
39 public:
40   typedef enum { None, Auto, Manual, Always } CompletionPolicy;
41
42 public:
43   PyEditor_Editor( QWidget* = 0 );
44   virtual ~PyEditor_Editor();
45   
46   void    setSettings( const PyEditor_Settings& );
47   const PyEditor_Settings& settings() const;
48   QString text() const;
49
50   QStringList keywords() const;
51   void        appendKeywords( const QStringList&, int, const QColor& = QColor() );
52   void        removeKeywords( const QStringList& );
53
54   CompletionPolicy completionPolicy() const;
55   void             setCompletionPolicy( const CompletionPolicy& );
56
57 public Q_SLOTS:
58   void deleteSelected();
59   void append( const QString& );  
60   void setText( const QString& text );
61
62 protected:
63   virtual void keyPressEvent( QKeyEvent* );
64   virtual void resizeEvent( QResizeEvent* );
65   virtual void paintEvent( QPaintEvent* );
66
67   PyEditor_Keywords* userKeywords() const;
68   PyEditor_Keywords* standardKeywords() const;
69
70 private Q_SLOTS:
71   void updateHighlightCurrentLine();
72   void matchParentheses();
73
74   void updateLineNumberAreaWidth( int );
75   void updateLineNumberArea( const QRect&, int );
76   
77 private:
78   bool matchLeftParenthesis( const QTextBlock&, int, int );
79   bool matchRightParenthesis( const QTextBlock&, int, int );
80   void createParenthesisSelection( int );
81   bool isLeftBrackets( QChar );
82   bool isRightBrackets( QChar );
83   void lineNumberAreaPaintEvent( QPaintEvent* );
84   int  lineNumberAreaWidth();
85
86   void handleHome( bool );
87   int  lineIndent();
88   void tabIndentation( bool );
89   void indentSelection( bool );
90
91   int findFirstNonSpace( const QString& );
92
93   QWidget*                myLineNumberArea;
94   PyEditor_PyHighlighter* mySyntaxHighlighter;
95   PyEditor_Completer*     myCompleter;
96   PyEditor_Settings       mySettings;
97
98   PyEditor_Keywords*      myStdKeywords;
99   PyEditor_Keywords*      myUserKeywords;
100
101   CompletionPolicy        myCompletionPolicy;
102
103   friend class PyEditor_LineNumberArea;
104 };
105
106 #endif // PYEDITOR_EDITOR_H