Salome HOME
b11c5b94f56589fe0a1fac62c231bf9b7c119e26
[modules/gui.git] / tools / PyEditor / src / PyEditor_Editor.h
1 // Copyright (C) 2015-2022  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
50   QString text() const;
51
52   QStringList keywords() const;
53   void        appendKeywords( const QStringList&, int, const QColor& = QColor() );
54   void        removeKeywords( const QStringList& );
55
56   CompletionPolicy completionPolicy() const;
57   void             setCompletionPolicy( const CompletionPolicy& );
58
59 public Q_SLOTS:
60   void deleteSelected();
61   void append( const QString& );  
62   void setText( const QString& text );
63   void setCurrentLine( int );
64
65 protected:
66   virtual void keyPressEvent( QKeyEvent* );
67   virtual void resizeEvent( QResizeEvent* );
68   virtual void paintEvent( QPaintEvent* );
69   virtual void contextMenuEvent( QContextMenuEvent* );
70
71   PyEditor_Keywords* userKeywords() const;
72   PyEditor_Keywords* standardKeywords() const;
73
74 private Q_SLOTS:
75   void updateHighlightCurrentLine();
76   void matchParentheses();
77
78   void updateLineNumberAreaWidth( int );
79   void updateLineNumberArea( const QRect&, int );
80   
81 Q_SIGNALS:
82   void customizeMenu( QMenu* );
83
84 private:
85   bool matchLeftParenthesis( const QTextBlock&, int, int );
86   bool matchRightParenthesis( const QTextBlock&, int, int );
87   void createParenthesisSelection( int );
88   bool isLeftBrackets( QChar );
89   bool isRightBrackets( QChar );
90   void lineNumberAreaPaintEvent( QPaintEvent* );
91   int  lineNumberAreaWidth();
92
93   void handleHome( bool );
94   int  lineIndent();
95   void tabIndentation( bool );
96   void indentSelection( bool );
97
98   int findFirstNonSpace( const QString& );
99
100   QWidget*                myLineNumberArea;
101   PyEditor_PyHighlighter* mySyntaxHighlighter;
102   PyEditor_Completer*     myCompleter;
103   PyEditor_Settings       mySettings;
104
105   PyEditor_Keywords*      myStdKeywords;
106   PyEditor_Keywords*      myUserKeywords;
107
108   CompletionPolicy        myCompletionPolicy;
109
110   friend class PyEditor_LineNumberArea;
111 };
112
113 #endif // PYEDITOR_EDITOR_H