mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Improved text resizing in playback speed item.
This commit is contained in:
parent
3d54192681
commit
504f5ee5d7
1 changed files with 24 additions and 12 deletions
|
@ -64,12 +64,16 @@ protected:
|
||||||
int contentHeight() const override;
|
int contentHeight() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
float64 computeSpeed(float64 value) const;
|
||||||
|
QString speedString(float64 value) const;
|
||||||
|
|
||||||
QRect _itemRect;
|
QRect _itemRect;
|
||||||
QRect _textRect;
|
QRect _textRect;
|
||||||
|
|
||||||
const style::MediaSlider &_sliderSt;
|
const style::MediaSlider &_sliderSt;
|
||||||
const base::unique_qptr<Ui::MediaSlider> _slider;
|
const base::unique_qptr<Ui::MediaSlider> _slider;
|
||||||
const not_null<QAction*> _dummyAction;
|
const not_null<QAction*> _dummyAction;
|
||||||
|
const int _lineCount;
|
||||||
const int _height;
|
const int _height;
|
||||||
|
|
||||||
rpl::event_stream<float64> _changeSpeedRequests;
|
rpl::event_stream<float64> _changeSpeedRequests;
|
||||||
|
@ -86,8 +90,10 @@ MenuSpeedItem::MenuSpeedItem(
|
||||||
this,
|
this,
|
||||||
_sliderSt))
|
_sliderSt))
|
||||||
, _dummyAction(new QAction(parent))
|
, _dummyAction(new QAction(parent))
|
||||||
|
, _lineCount(std::ceil(st.itemStyle.font->width(speedString(0.9))
|
||||||
|
/ float(st.widthMax)))
|
||||||
, _height(st.itemPadding.top() * 2
|
, _height(st.itemPadding.top() * 2
|
||||||
+ st.itemStyle.font->height
|
+ st.itemStyle.font->height * _lineCount
|
||||||
+ _sliderSt.seekSize.height()
|
+ _sliderSt.seekSize.height()
|
||||||
+ st.itemPadding.bottom() * 2) {
|
+ st.itemPadding.bottom() * 2) {
|
||||||
|
|
||||||
|
@ -95,16 +101,6 @@ MenuSpeedItem::MenuSpeedItem(
|
||||||
enableMouseSelecting();
|
enableMouseSelecting();
|
||||||
enableMouseSelecting(_slider.get());
|
enableMouseSelecting(_slider.get());
|
||||||
|
|
||||||
const auto computeSpeed = [=](float64 value) {
|
|
||||||
return anim::interpolate(kMinSpeed, kMaxSpeed, value) / 100.;
|
|
||||||
};
|
|
||||||
const auto speedString = [=](float64 value) {
|
|
||||||
return tr::lng_mediaview_playback_speed(
|
|
||||||
tr::now,
|
|
||||||
lt_speed,
|
|
||||||
QString::number(computeSpeed(value), 'f', 2) + 'x');
|
|
||||||
};
|
|
||||||
|
|
||||||
_slider->setAlwaysDisplayMarker(true);
|
_slider->setAlwaysDisplayMarker(true);
|
||||||
_slider->setValue((std::round(startSpeed * 100.) - kMinSpeed)
|
_slider->setValue((std::round(startSpeed * 100.) - kMinSpeed)
|
||||||
/ (kMaxSpeed - kMinSpeed));
|
/ (kMaxSpeed - kMinSpeed));
|
||||||
|
@ -129,8 +125,13 @@ MenuSpeedItem::MenuSpeedItem(
|
||||||
_itemRect = geometry - st.itemPadding;
|
_itemRect = geometry - st.itemPadding;
|
||||||
|
|
||||||
const auto height = _itemRect.height();
|
const auto height = _itemRect.height();
|
||||||
|
const auto penWidth = QPen(st.itemBgOver).width();
|
||||||
_textRect = _itemRect
|
_textRect = _itemRect
|
||||||
- style::margins(0, 0, 0, height - st.itemStyle.font->height);
|
- style::margins(
|
||||||
|
-penWidth,
|
||||||
|
0,
|
||||||
|
-penWidth,
|
||||||
|
height - st.itemStyle.font->height * _lineCount);
|
||||||
|
|
||||||
const auto sliderGeometry = _itemRect
|
const auto sliderGeometry = _itemRect
|
||||||
- style::margins(0, height - _sliderSt.seekSize.height(), 0, 0);
|
- style::margins(0, height - _sliderSt.seekSize.height(), 0, 0);
|
||||||
|
@ -170,6 +171,17 @@ MenuSpeedItem::MenuSpeedItem(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float64 MenuSpeedItem::computeSpeed(float64 value) const {
|
||||||
|
return anim::interpolate(kMinSpeed, kMaxSpeed, value) / 100.;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString MenuSpeedItem::speedString(float64 value) const {
|
||||||
|
return tr::lng_mediaview_playback_speed(
|
||||||
|
tr::now,
|
||||||
|
lt_speed,
|
||||||
|
QString::number(computeSpeed(value), 'f', 2) + 'x');
|
||||||
|
}
|
||||||
|
|
||||||
not_null<QAction*> MenuSpeedItem::action() const {
|
not_null<QAction*> MenuSpeedItem::action() const {
|
||||||
return _dummyAction;
|
return _dummyAction;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue