Slightly improved code style in voice record bar class.

This commit is contained in:
23rd 2024-01-03 12:55:57 +03:00
parent 7a139ecda7
commit 5cf0b6b50e
2 changed files with 43 additions and 48 deletions

View file

@ -32,6 +32,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/effects/ripple_animation.h" #include "ui/effects/ripple_animation.h"
#include "ui/text/format_values.h" #include "ui/text/format_values.h"
#include "ui/painter.h" #include "ui/painter.h"
#include "ui/rect.h"
#include "styles/style_chat.h" #include "styles/style_chat.h"
#include "styles/style_chat_helpers.h" #include "styles/style_chat_helpers.h"
#include "styles/style_layers.h" #include "styles/style_layers.h"
@ -316,7 +317,7 @@ void ListenWrap::init() {
_parent->paintRequest( _parent->paintRequest(
) | rpl::start_with_next([=](const QRect &clip) { ) | rpl::start_with_next([=](const QRect &clip) {
auto p = QPainter(_parent); auto p = QPainter(_parent);
PainterHighQualityEnabler hq(p); auto hq = PainterHighQualityEnabler(p);
const auto progress = _showProgress.current(); const auto progress = _showProgress.current();
p.setOpacity(progress); p.setOpacity(progress);
const auto &remove = _st.remove; const auto &remove = _st.remove;
@ -359,7 +360,7 @@ void ListenWrap::init() {
} }
p.setPen(Qt::NoPen); p.setPen(Qt::NoPen);
p.setBrush(_st.cancelActive); p.setBrush(_st.cancelActive);
QPainterPath path; auto path = QPainterPath();
path.setFillRule(Qt::WindingFill); path.setFillRule(Qt::WindingFill);
path.addEllipse(bgLeftCircleRect); path.addEllipse(bgLeftCircleRect);
path.addEllipse(bgRightCircleRect); path.addEllipse(bgRightCircleRect);
@ -627,7 +628,7 @@ protected:
private: private:
void init(); void init();
void drawProgress(Painter &p); void drawProgress(QPainter &p);
void setProgress(float64 progress); void setProgress(float64 progress);
void startLockingAnimation(float64 to); void startLockingAnimation(float64 to);
@ -648,12 +649,8 @@ RecordLock::RecordLock(
const style::RecordBarLock &st) const style::RecordBarLock &st)
: RippleButton(parent, st.ripple) : RippleButton(parent, st.ripple)
, _st(st) , _st(st)
, _rippleRect(QRect( , _rippleRect(Rect(Size(st::historyRecordLockTopShadow.width()))
0, - (st::historyRecordLockRippleMargin))
0,
st::historyRecordLockTopShadow.width(),
st::historyRecordLockTopShadow.width())
.marginsRemoved(st::historyRecordLockRippleMargin))
, _arcPen( , _arcPen(
QColor(Qt::white), QColor(Qt::white),
st::historyRecordLockIconLineWidth, st::historyRecordLockIconLineWidth,
@ -687,7 +684,7 @@ void RecordLock::init() {
if (!_visibleTopPart) { if (!_visibleTopPart) {
return; return;
} }
Painter p(this); auto p = QPainter(this);
if (_visibleTopPart > 0 && _visibleTopPart < height()) { if (_visibleTopPart > 0 && _visibleTopPart < height()) {
p.setClipRect(0, 0, width(), _visibleTopPart); p.setClipRect(0, 0, width(), _visibleTopPart);
} }
@ -704,7 +701,7 @@ void RecordLock::init() {
}, lifetime()); }, lifetime());
} }
void RecordLock::drawProgress(Painter &p) { void RecordLock::drawProgress(QPainter &p) {
const auto progress = _progress.current(); const auto progress = _progress.current();
const auto &originTop = _st.originTop; const auto &originTop = _st.originTop;
@ -770,7 +767,7 @@ void RecordLock::drawProgress(Painter &p) {
p.setOpacity(1.); p.setOpacity(1.);
} }
if (isLocked()) { if (isLocked()) {
paintRipple(p, _rippleRect.x(), _rippleRect.y()); Ui::RippleButton::paintRipple(p, _rippleRect.x(), _rippleRect.y());
} }
{ {
const auto &arcOffset = st::historyRecordLockIconLineSkip; const auto &arcOffset = st::historyRecordLockIconLineSkip;
@ -808,7 +805,7 @@ void RecordLock::drawProgress(Painter &p) {
if (_lockToStopProgress == 1.) { if (_lockToStopProgress == 1.) {
// Paint the block. // Paint the block.
PainterHighQualityEnabler hq(p); auto hq = PainterHighQualityEnabler(p);
p.translate(inner.topLeft() + lockTranslation); p.translate(inner.topLeft() + lockTranslation);
p.setPen(Qt::NoPen); p.setPen(Qt::NoPen);
p.setBrush(_st.fg); p.setBrush(_st.fg);
@ -821,8 +818,8 @@ void RecordLock::drawProgress(Painter &p) {
frame.setDevicePixelRatio(style::DevicePixelRatio()); frame.setDevicePixelRatio(style::DevicePixelRatio());
frame.fill(Qt::transparent); frame.fill(Qt::transparent);
Painter q(&frame); auto q = QPainter(&frame);
PainterHighQualityEnabler hq(q); auto hq = PainterHighQualityEnabler(q);
q.setPen(Qt::NoPen); q.setPen(Qt::NoPen);
q.setBrush(_arcPen.brush()); q.setBrush(_arcPen.brush());
@ -980,19 +977,19 @@ void CancelButton::init() {
paintRequest( paintRequest(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
Painter p(this); auto p = QPainter(this);
p.setOpacity(_showProgress.current()); p.setOpacity(_showProgress.current());
paintRipple(p, _rippleRect.x(), _rippleRect.y()); Ui::RippleButton::paintRipple(p, _rippleRect.x(), _rippleRect.y());
p.setPen(_st.cancelActive); p.setPen(_st.cancelActive);
_text.draw( _text.draw(p, {
p, .position = QPoint(0, (height() - _text.minHeight()) / 2),
0, .outerWidth = width(),
(height() - _text.minHeight()) / 2, .availableWidth = width(),
width(), .align = style::al_center,
style::al_center); });
}, lifetime()); }, lifetime());
} }
@ -1054,9 +1051,7 @@ VoiceRecordBar::~VoiceRecordBar() {
} }
void VoiceRecordBar::updateMessageGeometry() { void VoiceRecordBar::updateMessageGeometry() {
const auto left = _durationRect.x() const auto left = rect::right(_durationRect) + st::historyRecordTextLeft;
+ _durationRect.width()
+ st::historyRecordTextLeft;
const auto right = width() const auto right = width()
- _send->width() - _send->width()
- st::historyRecordTextRight; - st::historyRecordTextRight;
@ -1080,7 +1075,7 @@ void VoiceRecordBar::updateLockGeometry() {
- st::historyRecordLockPosition.y() - st::historyRecordLockPosition.y()
- _lock->height(); - _lock->height();
const auto finalRight = _outerContainer->width() const auto finalRight = _outerContainer->width()
- (me.x() + me.width()) - rect::right(me)
+ st::historyRecordLockPosition.x(); + st::historyRecordLockPosition.x();
const auto progress = _showLockAnimation.value( const auto progress = _showLockAnimation.value(
_lockShowing.current() ? 1. : 0.); _lockShowing.current() ? 1. : 0.);
@ -1143,7 +1138,7 @@ void VoiceRecordBar::init() {
paintRequest( paintRequest(
) | rpl::start_with_next([=](const QRect &clip) { ) | rpl::start_with_next([=](const QRect &clip) {
Painter p(this); auto p = QPainter(this);
if (_showAnimation.animating()) { if (_showAnimation.animating()) {
p.setOpacity(showAnimationRatio()); p.setOpacity(showAnimationRatio());
} }
@ -1506,7 +1501,7 @@ void VoiceRecordBar::stopRecording(StopType type) {
})); }));
} }
void VoiceRecordBar::drawDuration(Painter &p) { void VoiceRecordBar::drawDuration(QPainter &p) {
const auto duration = FormatVoiceDuration(_recordingSamples); const auto duration = FormatVoiceDuration(_recordingSamples);
p.setFont(_cancelFont); p.setFont(_cancelFont);
p.setPen(_st.durationFg); p.setPen(_st.durationFg);
@ -1529,8 +1524,8 @@ void VoiceRecordBar::startRedCircleAnimation() {
animation->start(); animation->start();
} }
void VoiceRecordBar::drawRedCircle(Painter &p) { void VoiceRecordBar::drawRedCircle(QPainter &p) {
PainterHighQualityEnabler hq(p); auto hq = PainterHighQualityEnabler(p);
p.setPen(Qt::NoPen); p.setPen(Qt::NoPen);
p.setBrush(st::historyRecordVoiceFgInactive); p.setBrush(st::historyRecordVoiceFgInactive);
@ -1542,18 +1537,18 @@ void VoiceRecordBar::drawRedCircle(Painter &p) {
p.setOpacity(opacity); p.setOpacity(opacity);
} }
void VoiceRecordBar::drawMessage(Painter &p, float64 recordActive) { void VoiceRecordBar::drawMessage(QPainter &p, float64 recordActive) {
p.setPen(anim::pen(_st.cancel, _st.cancelActive, 1. - recordActive)); p.setPen(anim::pen(_st.cancel, _st.cancelActive, 1. - recordActive));
const auto opacity = p.opacity(); const auto opacity = p.opacity();
p.setOpacity(opacity * (1. - _lock->lockToStopProgress())); p.setOpacity(opacity * (1. - _lock->lockToStopProgress()));
_message.draw( _message.draw(p, {
p, .position = _messageRect.topLeft(),
_messageRect.x(), .outerWidth = _messageRect.width(),
_messageRect.y(), .availableWidth = _messageRect.width(),
_messageRect.width(), .align = style::al_center,
style::al_center); });
p.setOpacity(opacity); p.setOpacity(opacity);
} }

View file

@ -112,29 +112,29 @@ private:
void recordUpdated(quint16 level, int samples); void recordUpdated(quint16 level, int samples);
bool recordingAnimationCallback(crl::time now); [[nodiscard]] bool recordingAnimationCallback(crl::time now);
void stop(bool send); void stop(bool send);
void stopRecording(StopType type); void stopRecording(StopType type);
void visibilityAnimate(bool show, Fn<void()> &&callback); void visibilityAnimate(bool show, Fn<void()> &&callback);
bool showRecordButton() const; [[nodiscard]] bool showRecordButton() const;
void drawDuration(Painter &p); void drawDuration(QPainter &p);
void drawRedCircle(Painter &p); void drawRedCircle(QPainter &p);
void drawMessage(Painter &p, float64 recordActive); void drawMessage(QPainter &p, float64 recordActive);
void startRedCircleAnimation(); void startRedCircleAnimation();
void installListenStateFilter(); void installListenStateFilter();
bool isTypeRecord() const; [[nodiscard]] bool isTypeRecord() const;
bool hasDuration() const; [[nodiscard]] bool hasDuration() const;
void finish(); void finish();
void activeAnimate(bool active); void activeAnimate(bool active);
float64 showAnimationRatio() const; [[nodiscard]] float64 showAnimationRatio() const;
float64 showListenAnimationRatio() const; [[nodiscard]] float64 showListenAnimationRatio() const;
float64 activeAnimationRatio() const; [[nodiscard]] float64 activeAnimationRatio() const;
void computeAndSetLockProgress(QPoint globalPos); void computeAndSetLockProgress(QPoint globalPos);