Changeset View
Changeset View
Standalone View
Standalone View
src/render/katerenderrange.cpp
Show First 20 Lines • Show All 70 Lines • ▼ Show 20 Line(s) | 70 | if (!fg.isOpaque()) { | |||
---|---|---|---|---|---|
71 | QColor mixWithColor = fg.color(); | 71 | QColor mixWithColor = fg.color(); | ||
72 | mixWithColor.setAlpha(255); | 72 | mixWithColor.setAlpha(255); | ||
73 | fg.setColor(KColorUtils::mix(baseFgBrush.color(), mixWithColor, fg.color().alphaF())); | 73 | fg.setColor(KColorUtils::mix(baseFgBrush.color(), mixWithColor, fg.color().alphaF())); | ||
74 | base->setForeground(fg); | 74 | base->setForeground(fg); | ||
75 | } | 75 | } | ||
76 | } | 76 | } | ||
77 | } | 77 | } | ||
78 | 78 | | |||
79 | bool KateRenderRange::isReady() const | | |||
80 | { | | |||
81 | return false; | | |||
82 | } | | |||
83 | | ||||
84 | NormalRenderRange::NormalRenderRange() | 79 | NormalRenderRange::NormalRenderRange() | ||
85 | { | 80 | { | ||
86 | } | 81 | } | ||
87 | 82 | | |||
88 | NormalRenderRange::~NormalRenderRange() | 83 | void NormalRenderRange::addRange(const KTextEditor::Range &range, KTextEditor::Attribute::Ptr attribute) | ||
89 | { | | |||
90 | QVectorIterator<pairRA> it = m_ranges; | | |||
91 | while (it.hasNext()) { | | |||
92 | delete it.next().first; | | |||
93 | } | | |||
94 | } | | |||
95 | | ||||
96 | void NormalRenderRange::addRange(KTextEditor::Range *range, KTextEditor::Attribute::Ptr attribute) | | |||
97 | { | 84 | { | ||
98 | m_ranges.append(pairRA(range, attribute)); | 85 | m_ranges.push_back(std::make_pair(range, attribute)); | ||
99 | } | 86 | } | ||
100 | 87 | | |||
101 | KTextEditor::Cursor NormalRenderRange::nextBoundary() const | 88 | KTextEditor::Cursor NormalRenderRange::nextBoundary() const | ||
102 | { | 89 | { | ||
103 | return m_nextBoundary; | 90 | return m_nextBoundary; | ||
104 | } | 91 | } | ||
105 | 92 | | |||
106 | bool NormalRenderRange::advanceTo(const KTextEditor::Cursor &pos) | 93 | bool NormalRenderRange::advanceTo(const KTextEditor::Cursor &pos) | ||
107 | { | 94 | { | ||
108 | int index = m_currentRange; | 95 | size_t index = m_currentRange; | ||
109 | while (index < m_ranges.count()) { | 96 | while (index < m_ranges.size()) { | ||
110 | const pairRA &p = m_ranges.at(index); | 97 | const auto &p = m_ranges[index]; | ||
111 | KTextEditor::Range *r = p.first; | 98 | const auto &r = p.first; | ||
112 | if (r->end() <= pos) { | 99 | if (r.end() <= pos) { | ||
113 | ++index; | 100 | ++index; | ||
114 | } else { | 101 | } else { | ||
115 | bool ret = index != m_currentRange; | 102 | bool ret = index != m_currentRange; | ||
116 | m_currentRange = index; | 103 | m_currentRange = index; | ||
117 | 104 | | |||
118 | if (r->start() > pos) { | 105 | if (r.start() > pos) { | ||
119 | m_nextBoundary = r->start(); | 106 | m_nextBoundary = r.start(); | ||
120 | } else { | 107 | } else { | ||
121 | m_nextBoundary = r->end(); | 108 | m_nextBoundary = r.end(); | ||
122 | } | 109 | } | ||
123 | if (r->contains(pos)) { | 110 | if (r.contains(pos)) { | ||
124 | m_currentAttribute = p.second; | 111 | m_currentAttribute = p.second; | ||
125 | } else { | 112 | } else { | ||
126 | m_currentAttribute.reset(); | 113 | m_currentAttribute.reset(); | ||
127 | } | 114 | } | ||
128 | 115 | | |||
129 | return ret; | 116 | return ret; | ||
130 | } | 117 | } | ||
131 | } | 118 | } | ||
132 | 119 | | |||
133 | m_nextBoundary = KTextEditor::Cursor(INT_MAX, INT_MAX); | 120 | m_nextBoundary = KTextEditor::Cursor(INT_MAX, INT_MAX); | ||
134 | m_currentAttribute.reset(); | 121 | m_currentAttribute.reset(); | ||
135 | return false; | 122 | return false; | ||
136 | } | 123 | } | ||
137 | 124 | | |||
138 | KTextEditor::Attribute::Ptr NormalRenderRange::currentAttribute() const | 125 | KTextEditor::Attribute::Ptr NormalRenderRange::currentAttribute() const | ||
139 | { | 126 | { | ||
140 | return m_currentAttribute; | 127 | return m_currentAttribute; | ||
141 | } | 128 | } | ||
142 | 129 | | |||
143 | KTextEditor::Cursor RenderRangeList::nextBoundary() const | 130 | KTextEditor::Cursor RenderRangeVector::nextBoundary() const | ||
144 | { | 131 | { | ||
145 | KTextEditor::Cursor ret = m_currentPos; | 132 | KTextEditor::Cursor ret = m_currentPos; | ||
146 | bool first = true; | 133 | bool first = true; | ||
147 | foreach (KateRenderRange *r, *this) { | 134 | for (auto &r : m_ranges) { | ||
148 | if (first) { | 135 | if (first) { | ||
149 | ret = r->nextBoundary(); | 136 | ret = r.nextBoundary(); | ||
150 | first = false; | 137 | first = false; | ||
151 | 138 | | |||
152 | } else { | 139 | } else { | ||
153 | KTextEditor::Cursor nb = r->nextBoundary(); | 140 | KTextEditor::Cursor nb = r.nextBoundary(); | ||
154 | if (ret > nb) { | 141 | if (ret > nb) { | ||
155 | ret = nb; | 142 | ret = nb; | ||
156 | } | 143 | } | ||
157 | } | 144 | } | ||
158 | } | 145 | } | ||
159 | return ret; | 146 | return ret; | ||
160 | } | 147 | } | ||
161 | 148 | | |||
162 | RenderRangeList::~RenderRangeList() | 149 | NormalRenderRange &RenderRangeVector::pushNewRange() | ||
163 | { | 150 | { | ||
151 | m_ranges.push_back(NormalRenderRange()); | ||||
152 | return m_ranges.back(); | ||||
164 | } | 153 | } | ||
165 | 154 | | |||
166 | void RenderRangeList::advanceTo(const KTextEditor::Cursor &pos) | 155 | void RenderRangeVector::advanceTo(const KTextEditor::Cursor &pos) | ||
167 | { | 156 | { | ||
168 | foreach (KateRenderRange *r, *this) { | 157 | for (auto &r : m_ranges) { | ||
169 | r->advanceTo(pos); | 158 | r.advanceTo(pos); | ||
170 | } | | |||
171 | | ||||
172 | //Delete lists that are ready, else the list may get too large due to temporaries | | |||
173 | for (int a = size() - 1; a >= 0; --a) { | | |||
174 | KateRenderRange *r = at(a); | | |||
175 | if (r->isReady()) { | | |||
176 | delete r; | | |||
177 | removeAt(a); | | |||
178 | } | | |||
179 | } | 159 | } | ||
180 | } | 160 | } | ||
181 | 161 | | |||
182 | bool RenderRangeList::hasAttribute() const | 162 | bool RenderRangeVector::hasAttribute() const | ||
183 | { | 163 | { | ||
184 | foreach (KateRenderRange *r, *this) | 164 | for (auto &r : m_ranges) { | ||
185 | if (r->currentAttribute()) { | 165 | if (r.currentAttribute()) { | ||
186 | return true; | 166 | return true; | ||
187 | } | 167 | } | ||
168 | } | ||||
188 | 169 | | |||
189 | return false; | 170 | return false; | ||
190 | } | 171 | } | ||
191 | 172 | | |||
192 | KTextEditor::Attribute::Ptr RenderRangeList::generateAttribute() const | 173 | KTextEditor::Attribute::Ptr RenderRangeVector::generateAttribute() const | ||
193 | { | 174 | { | ||
194 | KTextEditor::Attribute::Ptr a; | 175 | KTextEditor::Attribute::Ptr a; | ||
195 | bool ownsAttribute = false; | 176 | bool ownsAttribute = false; | ||
196 | 177 | | |||
197 | foreach (KateRenderRange *r, *this) { | 178 | for (auto &r : m_ranges) { | ||
198 | if (KTextEditor::Attribute::Ptr a2 = r->currentAttribute()) { | 179 | if (KTextEditor::Attribute::Ptr a2 = r.currentAttribute()) { | ||
199 | if (!a) { | 180 | if (!a) { | ||
200 | a = a2; | 181 | a = a2; | ||
201 | } else { | 182 | } else { | ||
202 | if (!ownsAttribute) { | 183 | if (!ownsAttribute) { | ||
203 | //Make an own copy of the attribute.. | 184 | //Make an own copy of the attribute.. | ||
204 | ownsAttribute = true; | 185 | ownsAttribute = true; | ||
205 | a = new KTextEditor::Attribute(*a); | 186 | a = new KTextEditor::Attribute(*a); | ||
206 | } | 187 | } | ||
207 | mergeAttributes(a, a2); | 188 | mergeAttributes(a, a2); | ||
208 | } | 189 | } | ||
209 | } | 190 | } | ||
210 | } | 191 | } | ||
211 | 192 | | |||
212 | return a; | 193 | return a; | ||
213 | } | 194 | } | ||
214 | 195 | |