fix(reader): adapt sidebar thumbnails and night mode to dark theme - #375
Conversation
Reviewer's GuideThe PR improves dark-theme sidebar contrast by applying bounded HSL lightness inversion to thumbnails and night-mode images, standardizing image writes on non-premultiplied ARGB32, caching bookmark inversion results, and adjusting unselected card borders only in dark themes. Sequence diagram for dark-theme thumbnail renderingsequenceDiagram
participant View as SidebarView
participant Delegate as ThumbnailDelegate
participant Theme as DGuiApplicationHelper
participant Image as ThumbnailPixmap
participant Painter as QPainter
View->>Delegate: paint(painter, option, index)
Delegate->>Theme: themeType()
alt DarkType
Delegate->>Image: toImage()
Delegate->>Image: convertToFormat(Format_ARGB32)
loop Each pixel
Delegate->>Image: getHsl()
Delegate->>Image: setHsl()
end
Delegate->>Painter: drawPixmap(inverted image)
Delegate->>Painter: drawRoundedRect(windowText alpha 0.2)
else Light theme
Delegate->>Painter: drawPixmap(original image)
Delegate->>Painter: drawRoundedRect(frameShadowBorder)
end
Sequence diagram for cached bookmark inversionsequenceDiagram
participant View as SidebarView
participant Delegate as BookMarkDelegate
participant Cache as m_darkPixmapCache
participant Painter as QPainter
View->>Delegate: paint(painter, option, index)
Delegate->>Cache: object(pixmap.cacheKey())
alt Cached inverted pixmap
Cache-->>Delegate: QPixmap
else Cache miss
Delegate->>Delegate: apply HSL lightness inversion
Delegate->>Cache: insert(cacheKey, invertedPixmap)
end
Delegate->>Painter: drawPixmap(invertedPixmap)
Flow diagram for bounded HSL lightness inversionflowchart TD
A[Source pixel] --> B[Convert to HSL]
B --> C[light = 255 - light]
C --> D{light >= 192?}
D -- Yes --> E[Set lightness to 255]
D -- No --> F[Keep inverted lightness]
E --> G[Clamp lightness to minimum 37 or 30]
F --> G
G --> H[Preserve hue saturation and alpha]
H --> I[Write non-premultiplied ARGB32 pixel]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: add-uos, lzwind The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 良好 ✅ 通过 潜在问题:
建议: 建议将缓存键改为 scalePix.cacheKey(),或在缓存键中包含缩放尺寸信息(如 pixmap.cacheKey() ^ qHash(scalePix.size())),以确保不同缩放尺寸的反色结果不会互相覆盖 2. 代码质量 ✅评价: 良好 ✅ 通过 潜在问题:
建议: 建议将 HSL 亮度反色算法提取为独立工具函数(如 QImage invertImageLightness(const QImage &img, int minLight, int maxBoostThreshold)),在三个调用处复用,减少维护成本 3. 代码性能 ✅评价: 良好 ✅ 通过 潜在问题:
建议: 建议直接使用缓存指针绘制:将 if-else 分支改为直接从 cached 指针调用 painter->drawPixmap(),避免不必要的 QPixmap 深拷贝。示例:if (QPixmap *cached = m_darkPixmapCache.object(pixmap.cacheKey())) { painter->drawPixmap(rect.x(), rect.y(), *cached); } else { ... } 4. 代码安全 🔒评价: 优秀 ✅ 通过
安全漏洞详情: 建议: 代码安全合规,无安全漏洞。reinterpret_cast<QRgb *>(img.scanLine(y)) 的使用是 Qt 图像处理的标准模式,在确保格式为 ARGB32 后操作安全。缓存操作不涉及用户输入,无注入风险。 💡 改进建议代码示例// 建议提取共享工具函数,减少代码重复
// utils/ImageUtils.h
#pragma once
#include <QImage>
namespace ImageUtils {
/// HSL 亮度反色,两端收敛
/// \param img 非预乘 ARGB32 图像(调用前确保格式)
/// \param minLight 反色后亮度下限(如 37 = #252525)
/// \param boostThreshold 提亮阈值(如 192 = 0xC0)
inline void invertLightness(QImage &img, int minLight, int boostThreshold)
{
const int w = img.width();
const int h = img.height();
for (int y = 0; y < h; ++y) {
QRgb *line = reinterpret_cast<QRgb *>(img.scanLine(y));
for (int x = 0; x < w; ++x) {
const QRgb px = line[x];
const int alpha = qAlpha(px);
QColor c = QColor::fromRgb(qRed(px), qGreen(px), qBlue(px));
int hue, sat, light, dummy;
c.getHsl(&hue, &sat, &light, &dummy);
light = 255 - light;
if (light >= boostThreshold)
light = 255;
light = qMax(light, minLight);
c.setHsl(hue, sat, light);
line[x] = qRgba(c.red(), c.green(), c.blue(), alpha);
}
}
}
} // namespace ImageUtils
// BookMarkDelegate.cpp - 缓存命中时直接使用指针绘制,避免拷贝
if (QPixmap *cached = m_darkPixmapCache.object(pixmap.cacheKey())) {
painter->drawPixmap(rect.x(), rect.y(), *cached);
} else {
QImage img = scalePix.toImage();
if (!img.isNull()) {
if (img.format() != QImage::Format_ARGB32)
img = img.convertToFormat(QImage::Format_ARGB32);
ImageUtils::invertLightness(img, 37, 192);
QPixmap invertedPixmap = QPixmap::fromImage(img);
invertedPixmap.setDevicePixelRatio(scalePix.devicePixelRatio());
m_darkPixmapCache.insert(pixmap.cacheKey(),
new QPixmap(invertedPixmap),
img.width() * img.height() * 4);
painter->drawPixmap(rect.x(), rect.y(), invertedPixmap);
} else {
painter->drawPixmap(rect.x(), rect.y(), scalePix);
}
}本报告由 AI 代码审查工具自动生成 |
Invert bookmark/thumbnail pixmaps via HSL lightness in dark theme, with min-clamp 37 (#252525) and >=192 boost to white for contrast; cache the inverted pixmap by source cacheKey. Darken unselected borders with windowText@0.2 alpha in dark theme only. Night mode now converts to non-premultiplied ARGB32 and clamps lightness both ends. 深色主题下书签/缩略图按 HSL 亮度反色并做两端收敛,反色结果按源图缓存; 未选中卡片外框淡化仅作用于深色主题;夜间模式统一转非预乘 ARGB32。 Log: 深色主题缩略图反色与夜间模式对比度优化 Influence: 深色主题下侧边栏缩略图变为黑底白字、卡片边框可见,浅色主题 显示保持不变;不改变缩略图数据与缓存结构。
|
/forcemerge |
|
This pr force merged! (status: unstable) |
Invert bookmark/thumbnail pixmaps via HSL lightness in dark theme, with min-clamp 37 (#252525) and >=192 boost to white for contrast; cache the inverted pixmap by source cacheKey. Darken unselected borders with windowText@0.2 alpha in dark theme only. Night mode now converts to non-premultiplied ARGB32 and clamps lightness both ends.
深色主题下书签/缩略图按 HSL 亮度反色并做两端收敛,反色结果按源图缓存;
未选中卡片外框淡化仅作用于深色主题;夜间模式统一转非预乘 ARGB32。
Log: 深色主题缩略图反色与夜间模式对比度优化
Influence: 深色主题下侧边栏缩略图变为黑底白字、卡片边框可见,浅色主题
显示保持不变;不改变缩略图数据与缓存结构。
Summary by Sourcery
Improve dark-theme sidebar readability and night-mode image contrast without changing stored thumbnail data.
New Features:
Bug Fixes:
Enhancements: