Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
csshighlighter.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
5
7
8using namespace Qt::StringLiterals;
9
10namespace qdesigner_internal {
11
17
19{
21 static const int transitions[10][9] = {
28 { Quote, Quote, Quote, Quote, Quote, Quote, -1, Quote, Quote }, // Quote
29 { -1, -1, -1, -1, -1, -1, -1, -1, Comment }, // MaybeComment
31 { Comment, Comment, Comment, Comment, Comment, Comment, Comment, -1, MaybeCommentEnd } // MaybeCommentEnd
32 };
33
35 bool lastWasSlash = false;
37 if (state == -1) {
38 // As long as the text is empty, leave the state undetermined
39 if (text.isEmpty()) {
41 return;
42 }
43 // The initial state is based on the precense of a : and the absense of a {.
44 // This is because Qt style sheets support both a full stylesheet as well as
45 // an inline form with just properties.
46 state = save_state = (text.indexOf(u':') > -1 &&
47 text.indexOf(u'{') == -1) ? Property : Selector;
48 } else {
49 save_state = state>>16;
50 state &= 0x00ff;
51 }
52
53 if (state == MaybeCommentEnd) {
54 state = Comment;
55 } else if (state == MaybeComment) {
57 }
58
59 for (qsizetype i = 0; i < text.size(); ++i) {
60 int token = ALNUM;
61 const QChar c = text.at(i);
62 const char a = c.toLatin1();
63
64 if (state == Quote) {
65 if (a == '\\') {
66 lastWasSlash = true;
67 } else {
68 if (a == '\"' && !lastWasSlash) {
69 token = QUOTE;
70 }
71 lastWasSlash = false;
72 }
73 } else {
74 switch (a) {
75 case '{': token = LBRACE; break;
76 case '}': token = RBRACE; break;
77 case ':': token = COLON; break;
78 case ';': token = SEMICOLON; break;
79 case ',': token = COMMA; break;
80 case '\"': token = QUOTE; break;
81 case '/': token = SLASH; break;
82 case '*': token = STAR; break;
83 default: break;
84 }
85 }
86
88
89 if (new_state != state) {
91 || state == Quote;
93
94 if (new_state == Comment) {
95 lastIndex = i-1; // include the slash and star
96 } else {
97 lastIndex = i + ((token == ALNUM || new_state == Quote) ? 0 : 1);
98 }
99 }
100
101 if (new_state == -1) {
103 } else if (state <= Pseudo2) {
106 } else {
108 }
109 }
110
113}
114
116{
117 if (start >= text.size() || length <= 0)
118 return;
119
121
122 switch (state) {
123 case Selector:
125 break;
126 case Property:
128 break;
129 case Value:
131 break;
132 case Pseudo1:
134 break;
135 case Pseudo2:
137 break;
138 case Quote:
140 break;
141 case Comment:
142 case MaybeCommentEnd:
145 break;
146 default:
147 break;
148 }
149}
150
151} // namespace qdesigner_internal
152
153QT_END_NAMESPACE
Combined button and popup list for selecting options.
Auxiliary methods to store/retrieve settings.