itom
Loading...
Searching...
No Matches
codeEditorStyle.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 CODEEDITORSTYLE_H
39#define CODEEDITORSTYLE_H
40
41#include <qstring.h>
42#include <qbrush.h>
43#include <QTextCharFormat>
44#include <qmetaobject.h>
45#include <qlist.h>
46#include <qmap.h>
47
48namespace ito {
49
50//------------------------------------------------------------------
51/*
52*/
53class StyleItem : public QObject
54{
55 Q_OBJECT
56
57public:
58 enum StyleGroup
59 {
60 GroupCommentOrString = QTextFormat::UserObject,
61 GroupNumber = QTextFormat::UserObject + 1
62 };
63
64 enum StyleType
65 {
66 //the pre-defined indices are used to provide a backward-compatibility with old Scintilla styles!
67 KeyDefault = 0,
68 KeyComment = 1,
69 KeyNumber = 2,
70 KeyString = 3,
71 KeyKeyword = 5,
72 KeyDocstring = 6,
73 KeyClass = 8,
74 KeyFunction = 9,
75 KeyOperator = 10,
76 KeyDecorator = 15,
77
78 KeyBackground = 1000, /*special style: directly set by settings*/
79 KeyHighlight, /* not used any more, should be there to keep ids in settings. */
80 KeyNamespace,
81 KeyType,
82 KeyKeywordReserved,
83 KeyBuiltin,
84 KeyDefinition,
85 KeyInstance,
86 KeyWhitespace, /*special style: directly set by settings*/
87 KeyTag,
88 KeySelf,
89 KeyPunctuation,
90 KeyConstant,
91 KeyOperatorWord,
92 KeyStreamOutput,
93 KeyStreamError
94 };
95
96 //Q_ENUM exposes a meta object to the enumeration types, such that the key names for the enumeration
97 //values are always accessible.
98 Q_ENUM(StyleType)
99
100 StyleItem() : m_valid(false) {}
101
102 StyleItem(StyleType type, const QTextCharFormat &format);
103
104 StyleItem(const StyleItem &item);
105
106 StyleItem& operator= (const StyleItem &rhs);
107
108 bool isValid() const { return m_valid; }
109 QString name() const { return m_name; }
110 StyleType type() const { return m_type; }
111 QTextCharFormat& rformat() { return m_format; }
112 QTextCharFormat format() const { return m_format; }
113
114 static QMetaEnum styleTypeEnum();
115
116 static QList<StyleItem::StyleType> availableStyleTypes();
117
118 static QTextCharFormat createFormat(const QBrush &color, const QBrush &bgcolor = QBrush(), \
119 bool bold = false, bool italic = false, bool underline = false, \
120 QFont::StyleHint styleHint = QFont::SansSerif);
121
122 static QTextCharFormat createFormat(const QString &familyName, int pointSize, const QColor &color, \
123 const QColor &bgcolor = QColor(), bool bold = false, QFont::StyleHint styleHint = QFont::SansSerif);
124
125 void setObjectType(int type) { m_format.setObjectType(type); }
126
127private:
128 StyleType m_type;
129 QString m_name;
130 QTextCharFormat m_format;
131 bool m_valid;
132};
133
134//------------------------------------------------------------------
135/*
136*/
138{
139public:
141 virtual ~CodeEditorStyle();
142
143 int numStyles() const { return m_formats.size(); }
144 QList<int> styleKeys() const { return m_formats.keys(); }
145 StyleItem operator[](StyleItem::StyleType type) const;
146 StyleItem& operator[](StyleItem::StyleType type);
147 StyleItem at(StyleItem::StyleType type) const { return (*this)[type]; }
148 StyleItem& at(StyleItem::StyleType type) { return (*this)[type]; }
149 QTextCharFormat format(StyleItem::StyleType type) const;
150 QTextCharFormat& rformat(StyleItem::StyleType type);
151
152 QColor background() const;
153 void setBackground(const QColor &color);
154
155private:
156 QMap<int, StyleItem> m_formats;
157};
158
159} //end namespace ito
160
161#endif
Definition codeEditorStyle.h:138
Definition codeEditorStyle.h:54
Definition apiFunctionsGraph.cpp:40