itom
Loading...
Searching...
No Matches
autoindent.h
1/* ********************************************************************
2 itom software
3 URL: http://www.uni-stuttgart.de/ito
4 Copyright (C) 2020, Institut für Technische Optik (ITO),
5 Universität 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 Further hints:
23 ------------------------
24
25 This file belongs to the code editor of itom. The code editor is
26 in major parts a fork / rewritten version of the python-based source
27 code editor PyQode from Colin Duquesnoy and others
28 (see https://github.com/pyQode). PyQode itself is licensed under
29 the MIT License (MIT).
30
31 Some parts of the code editor of itom are also inspired by the
32 source code editor of the Spyder IDE (https://github.com/spyder-ide),
33 also licensed under the MIT License and developed by the Spyder Project
34 Contributors.
35
36*********************************************************************** */
37
38#ifndef AUTOINDENT_H
39#define AUTOINDENT_H
40
41#include "../utils/utils.h"
42#include "../mode.h"
43#include <qevent.h>
44#include <qobject.h>
45#include <qpair.h>
46#include <qstring.h>
47
48namespace ito {
49
50/*
51Contains the automatic generic indenter
52*/
53
54
55/*
56Indents text automatically.
57Generic indenter mode that indents the text when the user press RETURN.
58
59You can customize this mode by overriding
60:meth:`pyqode.core.modes.AutoIndentMode._get_indent`
61
62This mode contains two features:
63
641. The auto indentation itself
652. It is possible to remove trailing whitespaces and tabs
66 from the current line before the newline character is
67 applied. This improves the accordance to Pep8, which
68 does not allow empty lines, that contains only spaces.
69
70To handle these two features, always enable the mode and
71control the enable/disable state of the two features using
72the specific setters enableAutoIndent,
73setAutoStripTrailingSpacesAfterReturn.
74*/
75class AutoIndentMode : public QObject, public Mode
76{
77 Q_OBJECT
78public:
79 AutoIndentMode(const QString &name, const QString &description = "", QObject *parent = NULL);
80 virtual ~AutoIndentMode();
81
82 virtual void onStateChanged(bool state);
83
84 void setKeyPressedModifiers(Qt::KeyboardModifiers modifiers);
85 Qt::KeyboardModifiers keyPressedModifiers() const;
86
87 void setAutoStripTrailingSpacesAfterReturn(bool strip);
88 bool autoStripTrailingSpacesAfterReturn() const;
89
90 void enableAutoIndent(bool autoIndent);
91 bool isAutoIndentEnabled() const;
92
93private slots:
94 void onKeyPressed(QKeyEvent *e);
95
96protected:
97 QChar indentChar() const;
98 QString singleIndent() const;
99 virtual QPair<QString, QString> getIndent(const QTextCursor &cursor) const;
100
101private:
102 Qt::KeyboardModifiers m_keyPressedModifiers;
103 bool m_autoStripTrailingSpacesAfterReturn;
104 bool m_enableAutoIndent;
105
106};
107
108} //end namespace ito
109
110#endif
Definition autoindent.h:76
Definition mode.h:70
Definition apiFunctionsGraph.cpp:40