itom  4.1.0
outlineSelectorWidget.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2020, Institut fuer Technische Optik (ITO),
5  Universitaet Stuttgart, Germany
6 
7  This file is part of itom.
8 
9  itom is free software; you can redistribute it and/or modify it
10  under the terms of the GNU Library General Public Licence as published by
11  the Free Software Foundation; either version 2 of the Licence, or (at
12  your option) any later version.
13 
14  itom is distributed in the hope that it will be useful, but
15  WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
17  General Public Licence for more details.
18 
19  You should have received a copy of the GNU Library General Public License
20  along with itom. If not, see <http://www.gnu.org/licenses/>.
21 
22 *********************************************************************** */
23 
24 #pragma once
25 
26 /*
27 This module contains the OutlineSelectorWidget
28 */
29 
30 #include <qwidget.h>
31 #include <qdialog.h>
32 #include <qsharedpointer.h>
33 #include <qlist.h>
34 #include <qtreewidget.h>
35 #include <qitemdelegate.h>
36 
37 #include "../models/outlineItem.h"
38 
39 
40 namespace ito {
41 
42 class ScriptDockWidget;
43 
44 
46 /* Usually, this popup is displayed by a menu of the script dock widget
47 or if the Ctrl+D key is pressed.
48 
49 It then shows the outline of all classes and methods of the current script
50 or of all opened scripts.
51 
52 This outline can be filtered by a filter text box and if a method is
53 selected, the corresponding script is shown and the cursor is placed
54 at the definition of the selected method or class.
55 */
56 class OutlineSelectorWidget : public QDialog
57 {
58  Q_OBJECT
59 public:
61  {
62  QSharedPointer<OutlineItem> rootOutline;
63  int editorUID;
64  QString filename;
65  };
66 
67  OutlineSelectorWidget(const QList<EditorOutline> &outlines, int currentOutlineIndex, ScriptDockWidget *scriptDockWidget, QWidget *parent = nullptr);
68  virtual ~OutlineSelectorWidget();
69 
70 protected:
71  enum Scope { AllScripts, SingleScript };
72 
73  void setDialogPosition();
74  void fillContent();
75  QList<QTreeWidgetItem*> parseTree(const QString &filename, int editorUID, const QSharedPointer<OutlineItem> &root) const;
76  bool filterItemRec(QTreeWidgetItem *root, const QString &text);
77  QString renderTooltipText(const QSharedPointer<OutlineItem> &item) const;
78  QString argsWordWrap(QString argText, int maxLineLength) const;
79  bool selectFirstVisibleChild(QTreeWidgetItem *parent);
80 
81  void keyReleaseEvent(QKeyEvent* ev);
82  void keyPressEvent(QKeyEvent* ev);
83  void focusOutEvent(QFocusEvent* ev);
84  bool eventFilter(QObject* obj, QEvent *ev);
85 
86 private:
87  ScriptDockWidget* m_pScriptDockWidget;
88  QTreeWidget *m_pTreeWidget;
89  QLineEdit *m_pLineEdit;
90  Scope m_currentScope;
91  QList<EditorOutline> m_outlines;
92  int m_currentOutlineIndex;
93  bool m_sortItems;
94  QAction *m_actScopeChange;
95 
96 private slots:
97  void filterTextChanged(const QString &text);
98  void itemActivated(QTreeWidgetItem *item, int column);
99  void actSort(bool triggered);
100  void actScopeChanged(bool triggered);
101 };
102 
103 
104 /*
105 This delegate allows the list view of the switcher to look like it has
106  the focus, even when its focus policy is set to Qt.NoFocus.
107 */
108 class SelectorDelegate : public QItemDelegate
109 {
110 public:
111  SelectorDelegate(QObject *parent = nullptr);
112  ~SelectorDelegate();
113 
114 protected:
115  virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
116 
117 };
118 
119 
120 } //end namespace ito
widget containing one or multiple script editors (tabbed). This widget can either be a docking widget...
Definition: scriptDockWidget.h:60
Definition: apiFunctionsGraph.cpp:39
framless dialog, shown as popup over a script editor, to display the outline.
Definition: outlineSelectorWidget.h:56
Definition: outlineSelectorWidget.h:60
QString argsWordWrap(QString argText, int maxLineLength) const
< wraps the arguments text of a signature with a maximum line length
Definition: outlineSelectorWidget.cpp:191
Definition: outlineSelectorWidget.h:108