Changeset View
Changeset View
Standalone View
Standalone View
lib/hud/hudslider.cpp
Show First 20 Lines • Show All 102 Lines • ▼ Show 20 Line(s) | 102 | { | |||
---|---|---|---|---|---|
103 | d->q = this; | 103 | d->q = this; | ||
104 | d->mMin = 0; | 104 | d->mMin = 0; | ||
105 | d->mMax = 100; | 105 | d->mMax = 100; | ||
106 | d->mPageStep = 10; | 106 | d->mPageStep = 10; | ||
107 | d->mSingleStep = 1; | 107 | d->mSingleStep = 1; | ||
108 | d->mSliderPosition = d->mValue = 0; | 108 | d->mSliderPosition = d->mValue = 0; | ||
109 | d->mIsDown = false; | 109 | d->mIsDown = false; | ||
110 | d->mRepeatAction = QAbstractSlider::SliderNoAction; | 110 | d->mRepeatAction = QAbstractSlider::SliderNoAction; | ||
111 | d->updateHandleRect(); | | |||
112 | setCursor(Qt::ArrowCursor); | 111 | setCursor(Qt::ArrowCursor); | ||
113 | setAcceptHoverEvents(true); | 112 | setAcceptHoverEvents(true); | ||
114 | setFocusPolicy(Qt::WheelFocus); | 113 | setFocusPolicy(Qt::WheelFocus); | ||
114 | | ||||
115 | QTimer::singleShot(0, this, [this]() { | ||||
116 | d->updateHandleRect(); | ||||
117 | }); | ||||
115 | } | 118 | } | ||
116 | 119 | | |||
117 | HudSlider::~HudSlider() | 120 | HudSlider::~HudSlider() | ||
118 | { | 121 | { | ||
119 | delete d; | 122 | delete d; | ||
120 | } | 123 | } | ||
121 | 124 | | |||
122 | void HudSlider::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget*) | 125 | void HudSlider::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget*) | ||
123 | { | 126 | { | ||
124 | bool drawHandle = d->hasValidRange(); | 127 | bool drawHandle = d->hasValidRange(); | ||
125 | HudTheme::State state; | 128 | HudTheme::State state; | ||
126 | if (drawHandle && option->state.testFlag(QStyle::State_MouseOver)) { | 129 | if (drawHandle && option->state.testFlag(QStyle::State_MouseOver)) { | ||
rkflx: A small thing I noticed: `showEvent` is also called when navigating away and calling… | |||||
It doesn't make a difference in number of calls since the HudSlider object is deleted and recreated on navigation. But it's a more compact change now. :) muhlenpfordt: It doesn't make a difference in number of calls since the `HudSlider` object is deleted and… | |||||
For a moment you scared me ;) I double-checked, there will be a difference in the number of calls per slider: showEvent is apparently called when going to a video and when navigating away, but the constructor is thankfully called only a single time, i.e. when going to a video. rkflx: For a moment you scared me ;)
I double-checked, there will be a difference in the number of… | |||||
Sorry! Sure, when leaving a video it's one call less. I missed the "navigating away" in your first comment. muhlenpfordt: Sorry! Sure, when leaving a video it's one call less. I missed the "navigating away" in your… | |||||
127 | state = d->mIsDown ? HudTheme::DownState : HudTheme::MouseOverState; | 130 | state = d->mIsDown ? HudTheme::DownState : HudTheme::MouseOverState; | ||
128 | } else { | 131 | } else { | ||
129 | state = HudTheme::NormalState; | 132 | state = HudTheme::NormalState; | ||
130 | } | 133 | } | ||
131 | painter->setRenderHint(QPainter::Antialiasing); | 134 | painter->setRenderHint(QPainter::Antialiasing); | ||
132 | 135 | | |||
133 | const QRectF sliderRect = boundingRect(); | 136 | const QRectF sliderRect = boundingRect(); | ||
134 | 137 | | |||
▲ Show 20 Lines • Show All 253 Lines • Show Last 20 Lines |
A small thing I noticed: showEvent is also called when navigating away and calling updateHandleRect would not really needed. In other places we use something like this (in the constructor):
What do you think? (I would also be fine with your version.)