feat(DrawUtils): add drawInsetShadow for inner shadow rendering - #779
feat(DrawUtils): add drawInsetShadow for inner shadow rendering#779zqq-dora wants to merge 1 commit into
Conversation
Add DDrawUtils::drawInsetShadow() parallel to the existing drawShadow(), for rendering inset (inner) shadows on QWidget controls. This mirrors the QML BoxInsetShadow component in dtkdeclarative, enabling consistent inset shadow effects across both frameworks. The implementation uses qt_blurImage (same as drawShadow) to blur a hole-punched alpha mask, then composites the shadow color and clips to the rounded-rect shape.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: zqq-dora 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 |
|
Hi @zqq-dora. Thanks for your PR. 😃 |
|
Hi @zqq-dora. Thanks for your PR. I'm waiting for a linuxdeepin member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Reviewer's GuideAdds DDrawUtils::drawInsetShadow for rendering clipped, blurred inner shadows in QWidget code, using the same blur pipeline as drawShadow and supporting high-DPI scaling, rounded corners, colors, blur radius, and directional offsets. Sequence diagram for inset shadow renderingsequenceDiagram
participant Caller as QWidget caller
participant DDrawUtils
participant QImage as Shadow image
participant QPainter
participant qt_blurImage
Caller->>DDrawUtils: drawInsetShadow(pa, rect, xRadius, yRadius, sc, radius, offset)
DDrawUtils->>QImage: Create opaque black image
DDrawUtils->>QPainter: CompositionMode_Clear rounded hole
QPainter-->>QImage: Offset rounded-rect cutout
DDrawUtils->>qt_blurImage: Blur alpha channel
qt_blurImage-->>QImage: Soft inward gradient
DDrawUtils->>QPainter: CompositionMode_SourceIn with sc
QPainter-->>QImage: Apply shadow color
DDrawUtils->>QPainter: Clip to rounded rect
QPainter-->>Caller as QWidget caller: Draw clipped inset shadow
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/widgets/dstyle.cpp" line_range="405" />
<code_context>
+ xRadius *= scale;
+ yRadius *= scale;
+ radius *= scale;
+ QPoint scaledOffset(offset.x() * scale, offset.y() * scale);
+
+ // Build an opaque image, then cut out a rounded-rect hole shifted by
</code_context>
<issue_to_address>
**issue (bug_risk):** The offset is multiplied by the device-pixel ratio and then truncated when constructing the `QPoint`, so a logical offset of 1 pixel becomes 1 physical pixel rather than 1.5 pixels on a 1.5x display. The inset shadow therefore has an incorrect offset on fractional-DPR devices.
**Triggers:** When the painter targets a device with a fractional device-pixel ratio and `offset` is nonzero.
**Suggested fix:** Use a `QPointF` for the scaled offset, or round the scaled components explicitly before drawing.
```suggestion
QPointF scaledOffset(offset.x() * scale, offset.y() * scale);
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| xRadius *= scale; | ||
| yRadius *= scale; | ||
| radius *= scale; | ||
| QPoint scaledOffset(offset.x() * scale, offset.y() * scale); |
There was a problem hiding this comment.
issue (bug_risk): The offset is multiplied by the device-pixel ratio and then truncated when constructing the QPoint, so a logical offset of 1 pixel becomes 1 physical pixel rather than 1.5 pixels on a 1.5x display. The inset shadow therefore has an incorrect offset on fractional-DPR devices.
Triggers: When the painter targets a device with a fractional device-pixel ratio and offset is nonzero.
Suggested fix: Use a QPointF for the scaled offset, or round the scaled components explicitly before drawing.
| QPoint scaledOffset(offset.x() * scale, offset.y() * scale); | |
| QPointF scaledOffset(offset.x() * scale, offset.y() * scale); |
|
这个pr,提交在https://github.com/linuxdeepin/dtkwidget/tree/v25-flowstyle 这个分支上吧, |
|
这个代码只在dtk6上提交,添加条件编译吧, |
Background
dtkdeclarative 的 PR #672 在 ToolButton 深色模式 hover 中使用了内阴影效果(
BoxInsetShadow),该效果目前只在 QML 中有组件支持。为了保持 QWidget 和 QML 两端视觉一致,需要在 dtkwidget 中提供等价的内阴影绘制能力。Changes
在
DDrawUtils命名空间中新增drawInsetShadow()函数,与现有的drawShadow()接口风格平行:实现原理
CompositionMode_Clear挖出按 offset 偏移的圆角矩形孔qt_blurImage对 alpha 通道做高斯模糊(与drawShadow使用同一函数)CompositionMode_SourceIn替换为实际阴影颜色与 QML BoxInsetShadow 的对应
cornerRadiusxRadius/yRadiusshadowColorscshadowOffsetY: 1(顶部高光)offset=(0, 1)shadowOffsetY: -1(底部暗角)offset=(0, -1)shadowBlurradiusFiles
include/widgets/dstyle.hdrawInsetShadow声明src/widgets/dstyle.cppdrawInsetShadow实现Summary by Sourcery
Add inset-shadow rendering support to DDrawUtils for consistent inner-shadow effects across QWidget and QML interfaces.
New Features:
Enhancements: