Salome HOME
Merge branch 'master' into V9_dev
[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 class QMenu;
35
36 class PYEDITOR_EXPORT PyEditor_Editor : public QPlainTextEdit
37 {
38   Q_OBJECT
39
40 public:
41   typedef enum { None, Auto, Manual, Always } CompletionPolicy;
42
43 public:
44   PyEditor_Editor( QWidget* = 0 );
45   virtual ~PyEditor_Editor();
46   
47   void    setSettings( const PyEditor_Settings& );
48   const PyEditor_Settings& settings() const;
49   QString text() const;
50
51   QStringList keywords() const;
52   void        appendKeywords( const QStringList&, int, const QColor& = QColor() );
53   void        removeKeywords( const QStringList& );
54
55   CompletionPolicy completionPolicy() const;
56   void             setCompletionPolicy( const CompletionPolicy& );
57
58 public Q_SLOTS:
59   void deleteSelected();
60   void append( const QString& );  
61   void setText( const QString& text );
62
63 protected:
64   virtual void keyPressEvent( QKeyEvent* );
65   virtual void resizeEvent( QResizeEvent* );
66   virtual void paintEvent( QPaintEvent* );
67   virtual void contextMenuEvent( QContextMenuEvent* );
68
69   PyEditor_Keywords* userKeywords() const;
70   PyEditor_Keywords* standardKeywords() const;
71
72 private Q_SLOTS:
73   void updateHighlightCurrentLine();
74   void matchParentheses();
75
76   void updateLineNumberAreaWidth( int );
77   void updateLineNumberArea( const QRect&, int );
78   
79 Q_SIGNALS:
80   void customizeMenu( QMenu* );
81
82 private:
83   bool matchLeftParenthesis( const QTextBlock&, int, int );
84   bool matchRightParenthesis( const QTextBlock&, int, int );
85   void createParenthesisSelection( int );
86   bool isLeftBrackets( QChar );
87   bool isRightBrackets( QChar );
88   void lineNumberAreaPaintEvent( QPaintEvent* );
89   int  lineNumberAreaWidth();
90
91   void handleHome( bool );
92   int  lineIndent();
93   void tabIndentation( bool );
94   void indentSelection( bool );
95
96   int findFirstNonSpace( const QString& );
97
98   QWidget*                myLineNumberArea;
99   PyEditor_PyHighlighter* mySyntaxHighlighter;
100   PyEditor_Completer*     myCompleter;
101   PyEditor_Settings       mySettings;
102
103   PyEditor_Keywords*      myStdKeywords;
104   PyEditor_Keywords*      myUserKeywords;
105
106   CompletionPolicy        myCompletionPolicy;
107
108   friend class PyEditor_LineNumberArea;
109 };
110
111 #endif // PYEDITOR_EDITOR_H