forked from trav/lintunes
v0.80.0: visualizer settings sliders are twice as tall and jump where clicked; radial dot size reads as a share of the gap between dots
This commit is contained in:
@@ -2,7 +2,7 @@ import time
|
||||
|
||||
from PyQt6.QtWidgets import (
|
||||
QWidget, QFrame, QHBoxLayout, QVBoxLayout, QLabel, QToolButton, QSlider,
|
||||
QPushButton, QSizePolicy, QStyle, QLayout, QSpacerItem,
|
||||
QPushButton, QSizePolicy, QStyle, QStyleOptionSlider, QLayout, QSpacerItem,
|
||||
)
|
||||
from PyQt6.QtCore import Qt, QTimer, QEvent, QPoint, QPointF, QRect, QSize, pyqtSignal
|
||||
from PyQt6.QtGui import QColor, QFont, QIcon, QPainter, QPen, QPixmap
|
||||
@@ -276,8 +276,22 @@ class ClickJumpSlider(QSlider):
|
||||
super().__init__(Qt.Orientation.Horizontal, parent)
|
||||
|
||||
def _value_at(self, x: float) -> int:
|
||||
"""The value that puts the handle's centre under ``x``: the handle
|
||||
travels the groove less its own width, so a click at either end of
|
||||
the groove is the end value."""
|
||||
option = QStyleOptionSlider()
|
||||
self.initStyleOption(option)
|
||||
style = self.style()
|
||||
CC, SC = QStyle.ComplexControl.CC_Slider, QStyle.SubControl
|
||||
groove = style.subControlRect(CC, option, SC.SC_SliderGroove, self)
|
||||
handle = style.subControlRect(CC, option, SC.SC_SliderHandle, self)
|
||||
span = groove.width() - handle.width()
|
||||
if span <= 0:
|
||||
return QStyle.sliderValueFromPosition(
|
||||
self.minimum(), self.maximum(), int(x), self.width())
|
||||
pos = round(x - groove.left() - handle.width() / 2)
|
||||
return QStyle.sliderValueFromPosition(
|
||||
self.minimum(), self.maximum(), int(x), self.width())
|
||||
self.minimum(), self.maximum(), max(0, min(span, pos)), span)
|
||||
|
||||
def mousePressEvent(self, event):
|
||||
if (event.button() == Qt.MouseButton.LeftButton
|
||||
|
||||
Reference in New Issue
Block a user