Skip to content

Commit 611224c

Browse files
committed
Support three-color quote outlines.
1 parent 383b5b8 commit 611224c

File tree

3 files changed

+37
-24
lines changed

3 files changed

+37
-24
lines changed

ui/basic.style

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ QuoteStyle {
2727
icon: icon;
2828
iconPosition: point;
2929
outline: pixels;
30+
outlineShift: pixels;
3031
radius: pixels;
3132
scrollable: bool;
3233
}

ui/text/text.cpp

+32-20
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[third ? 2 : 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[1]);
249+
}
242250
}
243251

244252
auto image = QImage(full * ratio, QImage::Format_ARGB32_Premultiplied);
@@ -256,11 +264,14 @@ void ValidateQuotePaintCache(
256264
if (outline) {
257265
const auto rect = QRect(0, 0, outline + radius * 2, side);
258266
if (!cache.outline.isNull()) {
267+
const auto shift = QPoint(0, st.outlineShift);
268+
p.translate(shift);
259269
p.setBrush(cache.outline);
260-
p.setClipRect(0, 0, outline, side);
261-
p.drawRoundedRect(rect, radius, radius);
270+
p.setClipRect(QRect(-shift, QSize(outline, side)));
271+
p.drawRoundedRect(rect.translated(-shift), radius, radius);
272+
p.translate(-shift);
262273
} else {
263-
p.setBrush(cache.outline1);
274+
p.setBrush(cache.outlines[0]);
264275
p.setClipRect(0, 0, outline, side);
265276
p.drawRoundedRect(rect, radius, radius);
266277
}
@@ -380,9 +391,9 @@ void FillQuotePaint(
380391
radius);
381392
}
382393
auto q = QPainter(&cache.bottomCorner);
383-
const auto skipped = ihalf
384-
+ int(parts.skippedTop)
385-
+ (height - bottom);
394+
const auto skipped = (height - bottom)
395+
+ (parts.skippedTop ? int(parts.skippedTop) : ihalf)
396+
- st.outlineShift;
386397
q.translate(0, -skipped);
387398
q.fillRect(0, skipped, skip, bottom, cache.outline);
388399
q.setCompositionMode(QPainter::CompositionMode_DestinationIn);
@@ -402,13 +413,14 @@ void FillQuotePaint(
402413
}
403414
if (outline) {
404415
if (!cache.outline.isNull()) {
405-
const auto skipped = ihalf + int(parts.skippedTop);
406-
const auto top = y - skipped;
416+
const auto skipped = st.outlineShift
417+
- (parts.skippedTop ? int(parts.skippedTop) : ihalf);
418+
const auto top = y + skipped;
407419
p.translate(x, top);
408-
p.fillRect(0, skipped, outline, height, cache.outline);
420+
p.fillRect(0, -skipped, outline, height, cache.outline);
409421
p.translate(-x, -top);
410422
} else {
411-
p.fillRect(x, y, outline, height, cache.outline1);
423+
p.fillRect(x, y, outline, height, cache.outlines[0]);
412424
}
413425
}
414426
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)