itom
Loading...
Searching...
No Matches
utils.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 UTILS_H
39#define UTILS_H
40
41#include <qcolor.h>
42#include <qtextedit.h>
43#include <qchar.h>
44
45namespace ito {
46
47class CodeEditor;
48
49namespace Utils
50{
51 /*
52 Stores information about a parenthesis in a line of code.
53 */
55 {
56 public:
57 ParenthesisInfo(int pos, const QChar &chara) :
58 position(pos),
59 character(chara)
60 {
61 //: Position of the parenthesis, expressed as a number of character
62 //: The parenthesis character, one of "(", ")", "{", "}", "[", "]"
63 }
64
65 int position;
66 QChar character;
67 };
68
69 /*
70 Helps retrieving the various part of the user state bitmask.
71
72 This helper should be used to replace calls to
73
74 ``QTextBlock.setUserState``/``QTextBlock.getUserState`` as well as
75 ``QSyntaxHighlighter.setCurrentBlockState``/
76 ``QSyntaxHighlighter.currentBlockState`` and
77 ``QSyntaxHighlighter.previousBlockState``.
78
79 The bitmask is made up of the following fields:
80
81 - bit0 -> bit26: User state (for syntax highlighting)
82 - bit26: fold trigger state
83 - bit27-bit29: fold level (8 level max)
84 - bit30: fold trigger flag
85 - bit0 -> bit15: 16 bits for syntax highlighter user state (
86 for syntax highlighting)
87 - bit16-bit25: 10 bits for the fold level (1024 levels)
88 - bit26: 1 bit for the fold trigger flag (trigger or not trigger)
89 - bit27: 1 bit for the fold trigger state (expanded/collapsed)
90 */
92 {
93 public:
94 static int getState(const QTextBlock &block);
95 static void setState(QTextBlock &block, int state);
96 static int getFoldLvl(const QTextBlock &block);
97 static void setFoldLvl(QTextBlock &block, int val);
98 static bool isFoldTrigger(const QTextBlock &block);
99 static void setFoldTrigger(QTextBlock &block, int val);
100 static bool isCollapsed(const QTextBlock &block);
101 static void setCollapsed(QTextBlock &block, int val);
102 };
103
104 /*
105 Return color that is lighter or darker than the base color.*/
106 QColor driftColor(const QColor &baseColor, int factor = 110);
107
108 QList<ParenthesisInfo> listSymbols(CodeEditor *editor, const QTextBlock &block, const char* character);
109 void getBlockSymbolData(CodeEditor *editor, const QTextBlock &block, QList<ParenthesisInfo> &parentheses, QList<ParenthesisInfo> &squareBrackets, QList<ParenthesisInfo> &braces);
110
111 QString lstrip(const QString &string);
112 QString rstrip(const QString &string);
113 QString strip(const QString &string);
114 int numlines(const QString &string);
115 QStringList splitlines(const QString &string);
116 QString signatureWordWrap(QString signature, int width, int totalMaxLineWidth = -1);
117 QStringList parseStyledTooltipsFromSignature(const QStringList &signatures, const QString &docstring, int maxLineLength = 44, int maxDocStrLength = -1);
118};
119
120} //end namespace ito
121
122#endif
Definition codeEditor.h:110
Definition utils.h:55
Definition utils.h:92
Definition apiFunctionsGraph.cpp:40