Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: merge media controls. #805

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions tagstudio/src/qt/helpers/qslider_wrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright (C) 2024 Travis Abendshien (CyanVoxel).
# Licensed under the GPL-3.0 License.
# Created for TagStudio: https://github.com/CyanVoxel/TagStudio

from PySide6.QtWidgets import QSlider, QStyle, QStyleOptionSlider


class QClickSlider(QSlider):
"""Custom QSlider wrapper.

The purpose of this wrapper is to allow us to set slider positions
based on click events.
"""

mouse_pressed = False

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

def mousePressEvent(self, event): # noqa: N802
"""Overide to handle mouse clicks.

Overriding the mousePressEvent allows us to seek
directly to the position the user clicked instead
of stepping.
"""
opt = QStyleOptionSlider()
self.initStyleOption(opt)
opt.subControls = QStyle.SubControl.SC_SliderGroove | QStyle.SubControl.SC_SliderHandle

Check failure on line 29 in tagstudio/src/qt/helpers/qslider_wrapper.py

View workflow job for this annotation

GitHub Actions / Run MyPy

[mypy] reported by reviewdog 🐶 "QStyleOptionSlider" has no attribute "subControls" [attr-defined] Raw Output: /home/runner/work/TagStudio/TagStudio/tagstudio/src/qt/helpers/qslider_wrapper.py:29:9: error: "QStyleOptionSlider" has no attribute "subControls" [attr-defined]
handle_rect = self.style().subControlRect(
QStyle.ComplexControl.CC_Slider, opt, QStyle.SubControl.SC_SliderHandle, self
)

was_slider_clicked = handle_rect.contains(event.position().x(), event.position().y())

if was_slider_clicked:
super().mousePressEvent(event)
else:
self.setValue(
QStyle.sliderValueFromPosition(
self.minimum(), self.maximum(), event.x(), self.width()
)
)
self.mouse_pressed = True
Loading
Loading