Skip to content

feat(slider): add tick alignment support for Slider component#592

Merged
18202781743 merged 1 commit intolinuxdeepin:masterfrom
add-uos:fix-275271
Mar 25, 2026
Merged

feat(slider): add tick alignment support for Slider component#592
18202781743 merged 1 commit intolinuxdeepin:masterfrom
add-uos:fix-275271

Conversation

@add-uos
Copy link
Copy Markdown
Contributor

@add-uos add-uos commented Mar 24, 2026

Add alignToTicks property to Slider, allowing the groove to align with tick marks when enabled. The groove drawing is offset by half the handle width on both ends when alignToTicks is true.

为 Slider 组件添加 alignToTicks 属性,支持滑块槽与刻度标记对齐。
启用时,槽的绘制会在两端偏移半个手柄宽度。

Log: 添加 Slider 刻度对齐功能
PMS: BUG-275271
Influence: 当 TipsSlider 有刻度时,滑块槽会自动与刻度对齐,提升视觉效果。

Summary by Sourcery

Add optional tick-aligned groove rendering to the Slider component and enable it automatically for ticked TipsSlider instances.

New Features:

  • Introduce an alignToTicks property on Slider to support aligning the groove with tick marks when desired.
  • Enable tick-aligned groove rendering by default in TipsSlider whenever tick marks are present.

Enhancements:

  • Adjust Slider groove drawing to account for handle width when tick alignment is enabled, improving visual alignment of the track with ticks.

Add alignToTicks property to Slider, allowing the groove to align with
tick marks when enabled. The groove drawing is offset by half the handle
width on both ends when alignToTicks is true.

为 Slider 组件添加 alignToTicks 属性,支持滑块槽与刻度标记对齐。
启用时,槽的绘制会在两端偏移半个手柄宽度。

Log: 添加 Slider 刻度对齐功能
PMS: BUG-275271
Influence: 当 TipsSlider 有刻度时,滑块槽会自动与刻度对齐,提升视觉效果。
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Mar 24, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds an alignToTicks option to the Slider and wires TipsSlider to use it whenever ticks are present, so the groove rendering is horizontally inset by half the handle width at both ends to visually align with tick marks, while keeping vertical behavior unchanged.

Class diagram for updated Slider and TipsSlider alignment behavior

classDiagram
    class Slider {
        +real dashOffset
        +var dashPattern
        +bool highlightedPassedGroove
        +bool alignToTicks
        +bool horizontal
        +real leftPadding
        +real rightPadding
        +Item background
        +Item handle
        +real implicitWidth
        +real implicitHeight
    }

    class TipsSlider {
        +bool horizontal
        +TickDirection tickDirection
        +var ticks
    }

    class TickDirection {
        <<enumeration>>
        Front
        Back
    }

    class SliderGroovePath {
        +real startX
        +real startY
        +real strokeWidth
        +real dashOffset
        +var dashPattern
        +PathLine mainLine
    }

    class PathLine {
        +real x
        +real y
    }

    class Handle {
        +real width
        +real x
    }

    TipsSlider *-- Slider : contains __slider
    TipsSlider --> TickDirection : uses
    Slider *-- SliderGroovePath : draws_groove_with
    Slider *-- Handle : uses __handle
    SliderGroovePath *-- PathLine : contains

    %% Behavior notes modeled as operations on SliderGroovePath
    SliderGroovePath : setHorizontalAligned(control_alignToTicks, sliderGroove_width, handle_width)
    SliderGroovePath : setHorizontalStart(control_alignToTicks, handle_width)
    SliderGroovePath : setHorizontalEnd(control_alignToTicks, sliderGroove_width, handle_width)

    %% Logical behavior
    Slider : computeGrooveOffsets(horizontal, alignToTicks, handle_width, sliderGroove_width)
    TipsSlider : updateAlignToTicks(ticks_length)
Loading

File-Level Changes

Change Details Files
Introduce alignToTicks property on Slider and adjust groove path drawing for horizontal sliders when enabled.
  • Add a new boolean property alignToTicks with default false on the Slider control.
  • Modify the groove Path in the background to conditionally offset startX by half the handle width for horizontal sliders when alignToTicks is true.
  • Adjust the PathLine x endpoint for the full groove so it ends half a handle width before the right edge when alignToTicks is true.
  • Apply the same conditional startX offset to the highlighted/partial groove path used for the passed segment, keeping vertical calculations unchanged.
qt6/src/qml/Slider.qml
Auto-enable tick alignment in TipsSlider when it has ticks and update copyright headers.
  • Bind Slider.alignToTicks to whether TipsSlider has any ticks (ticks.length > 0), so tick alignment is automatic when ticks are configured.
  • Update SPDX copyright year range from 2022 to 2022 - 2026 in Slider and TipsSlider QML files.
qt6/src/qml/TipsSlider.qml
qt6/src/qml/Slider.qml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The alignToTicks logic repeats the same control.horizontal ? (control.alignToTicks ? __handle.width / 2 : 0) : sliderGroove.width / 2 expression in multiple places; consider extracting this into a small helper property (e.g., grooveStartX) to keep the QML cleaner and reduce the chance of inconsistencies later.
  • Using __handle.width directly in the groove start/end calculations assumes the handle is always available and sized; if there are states where the handle is invisible or its width is 0/undefined (e.g., in transitions or alternative styles), it may be safer to guard or default these values to avoid layout glitches.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `alignToTicks` logic repeats the same `control.horizontal ? (control.alignToTicks ? __handle.width / 2 : 0) : sliderGroove.width / 2` expression in multiple places; consider extracting this into a small helper property (e.g., `grooveStartX`) to keep the QML cleaner and reduce the chance of inconsistencies later.
- Using `__handle.width` directly in the groove start/end calculations assumes the handle is always available and sized; if there are states where the handle is invisible or its width is 0/undefined (e.g., in transitions or alternative styles), it may be safer to guard or default these values to avoid layout glitches.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos, BLumia

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@18202781743 18202781743 merged commit a55b6ee into linuxdeepin:master Mar 25, 2026
20 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants