Skip to content

Commit 9b3a49e

Browse files
committed
Support three-color quote outlines.
1 parent 383b5b8 commit 9b3a49e

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

ui/text/text.cpp

+20-12
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,13 @@ void ValidateQuotePaintCache(
191191
const auto icon = st.icon.empty() ? nullptr : &st.icon;
192192
if (!cache.corners.isNull()
193193
&& cache.bgCached == cache.bg
194-
&& cache.outline1Cached == cache.outline1
195-
&& cache.outline2Cached == cache.outline2
194+
&& cache.outlines == cache.outlines
196195
&& (!st.header || cache.headerCached == cache.header)
197196
&& (!icon || cache.iconCached == cache.icon)) {
198197
return;
199198
}
200199
cache.bgCached = cache.bg;
201-
cache.outline1Cached = cache.outline1;
202-
cache.outline2Cached = cache.outline2;
200+
cache.outlinesCached = cache.outlines;
203201
if (st.header) {
204202
cache.headerCached = cache.header;
205203
}
@@ -220,25 +218,35 @@ void ValidateQuotePaintCache(
220218
const auto full = QSize(side, side);
221219
const auto ratio = style::DevicePixelRatio();
222220

223-
if (cache.outline1 == cache.outline2) {
221+
if (!cache.outlines[1].alpha()) {
224222
cache.outline = QImage();
225223
} else if (const auto outline = st.outline) {
226-
const auto size = QSize(outline, outline * 6);
224+
const auto third = (cache.outlines[2].alpha() != 0);
225+
const auto size = QSize(outline, outline * (third ? 6 : 4));
227226
cache.outline = QImage(
228227
size * ratio,
229228
QImage::Format_ARGB32_Premultiplied);
230-
cache.outline.fill(cache.outline1);
229+
cache.outline.fill(cache.outlines[0]);
231230
cache.outline.setDevicePixelRatio(ratio);
232231
auto p = QPainter(&cache.outline);
233232
p.setCompositionMode(QPainter::CompositionMode_Source);
234233
auto hq = PainterHighQualityEnabler(p);
235234
auto path = QPainterPath();
236235
path.moveTo(outline, outline);
237-
path.lineTo(outline, outline * 4);
238-
path.lineTo(0, outline * 5);
236+
path.lineTo(outline, outline * (third ? 4 : 3));
237+
path.lineTo(0, outline * (third ? 5 : 4));
239238
path.lineTo(0, outline * 2);
240239
path.lineTo(outline, outline);
241-
p.fillPath(path, cache.outline2);
240+
p.fillPath(path, cache.outlines[1]);
241+
if (third) {
242+
auto path = QPainterPath();
243+
path.moveTo(outline, outline * 3);
244+
path.lineTo(outline, outline * 5);
245+
path.lineTo(0, outline * 6);
246+
path.lineTo(0, outline * 4);
247+
path.lineTo(outline, outline * 3);
248+
p.fillPath(path, cache.outlines[2]);
249+
}
242250
}
243251

244252
auto image = QImage(full * ratio, QImage::Format_ARGB32_Premultiplied);
@@ -260,7 +268,7 @@ void ValidateQuotePaintCache(
260268
p.setClipRect(0, 0, outline, side);
261269
p.drawRoundedRect(rect, radius, radius);
262270
} else {
263-
p.setBrush(cache.outline1);
271+
p.setBrush(cache.outlines[0]);
264272
p.setClipRect(0, 0, outline, side);
265273
p.drawRoundedRect(rect, radius, radius);
266274
}
@@ -408,7 +416,7 @@ void FillQuotePaint(
408416
p.fillRect(0, skipped, outline, height, cache.outline);
409417
p.translate(-x, -top);
410418
} else {
411-
p.fillRect(x, y, outline, height, cache.outline1);
419+
p.fillRect(x, y, outline, height, cache.outlines[0]);
412420
}
413421
}
414422
p.fillRect(x + outline, y, width - outline, height, cache.bg);

ui/text/text.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -165,22 +165,22 @@ struct GeometryDescriptor {
165165
bool elisionOneLine,
166166
bool elisionBreakEverywhere);
167167

168+
constexpr auto kMaxQuoteOutlines = 3;
169+
168170
struct QuotePaintCache {
169171
QImage corners;
170172
QImage outline;
171173
mutable QImage bottomCorner;
172174
mutable QImage bottomRounding;
173175

176+
std::array<QColor, kMaxQuoteOutlines> outlinesCached;
174177
QColor headerCached;
175178
QColor bgCached;
176-
QColor outline1Cached;
177-
QColor outline2Cached;
178179
QColor iconCached;
179180

181+
std::array<QColor, kMaxQuoteOutlines> outlines;
180182
QColor header;
181183
QColor bg;
182-
QColor outline1;
183-
QColor outline2;
184184
QColor icon;
185185
};
186186

0 commit comments

Comments
 (0)