Salome HOME
259d1b8a9876a0da75269d26b93f187332eb2ba6
[modules/gui.git] / tools / PyEditor / src / PyEditor_Completer.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_Completer.h
20 // Author : Sergey TELKOV, Open CASCADE S.A.S. (sergey.telkov@opencascade.com)
21 //
22
23 #ifndef PYEDITOR_COMPLETER_H
24 #define PYEDITOR_COMPLETER_H
25
26 #include <QCompleter>
27
28 class QTimer;
29 class PyEditor_Editor;
30 class PyEditor_Keywords;
31
32 class PyEditor_Completer : public QCompleter
33 {
34   Q_OBJECT
35
36 public:
37   PyEditor_Completer( PyEditor_Editor*,
38                       PyEditor_Keywords*, PyEditor_Keywords* );
39   virtual ~PyEditor_Completer();
40
41   void               perform();
42
43   void               uncomplete();
44
45   virtual bool       eventFilter(QObject*, QEvent*);
46
47 private Q_SLOTS:
48   void               onTimeout();
49   void               onTextChanged();
50   void               onKeywordsChanged();
51   void               onActivated( const QString& );
52
53 protected:
54   QRect              completionRect() const;
55   QString            completionText() const;
56   QPoint             completionRange() const;
57
58 private:
59   typedef QMap<QString, QColor> KeywordMap;
60
61 private:
62   KeywordMap         keywords() const;
63   void               updateKeywords();
64   void               triggerComplete();
65
66 private:
67   PyEditor_Editor*   myEditor;
68   QTimer*            myTimer;
69   PyEditor_Keywords* myStdKeywords;
70   PyEditor_Keywords* myUserKeywords;
71 };
72
73 #endif