2020-08-06 16:55:58 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#include "calls/calls_signal_bars.h"
|
|
|
|
|
|
|
|
#include "calls/calls_call.h"
|
|
|
|
#include "styles/style_calls.h"
|
|
|
|
|
|
|
|
namespace Calls {
|
|
|
|
|
|
|
|
SignalBars::SignalBars(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Call*> call,
|
2020-08-14 12:51:47 +00:00
|
|
|
const style::CallSignalBars &st)
|
2020-08-06 16:55:58 +00:00
|
|
|
: RpWidget(parent)
|
|
|
|
, _st(st)
|
2020-08-14 12:51:47 +00:00
|
|
|
, _count(Call::kSignalBarStarting) {
|
2020-08-06 16:55:58 +00:00
|
|
|
resize(
|
|
|
|
_st.width + (_st.width + _st.skip) * (Call::kSignalBarCount - 1),
|
2020-08-14 12:51:47 +00:00
|
|
|
_st.max);
|
2020-08-06 16:55:58 +00:00
|
|
|
call->signalBarCountValue(
|
|
|
|
) | rpl::start_with_next([=](int count) {
|
|
|
|
changed(count);
|
|
|
|
}, lifetime());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SignalBars::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.setBrush(_st.color);
|
|
|
|
for (auto i = 0; i < Call::kSignalBarCount; ++i) {
|
|
|
|
p.setOpacity((i < _count) ? 1. : _st.inactiveOpacity);
|
2020-08-14 12:51:47 +00:00
|
|
|
const auto barHeight = _st.min
|
|
|
|
+ (_st.max - _st.min) * (i / float64(Call::kSignalBarCount - 1));
|
2020-08-06 16:55:58 +00:00
|
|
|
const auto barLeft = i * (_st.width + _st.skip);
|
|
|
|
const auto barTop = height() - barHeight;
|
|
|
|
p.drawRoundedRect(
|
2020-08-14 12:51:47 +00:00
|
|
|
QRectF(
|
|
|
|
barLeft,
|
|
|
|
barTop,
|
|
|
|
_st.width,
|
|
|
|
barHeight),
|
2020-08-06 16:55:58 +00:00
|
|
|
_st.radius,
|
|
|
|
_st.radius);
|
|
|
|
}
|
|
|
|
p.setOpacity(1.);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SignalBars::changed(int count) {
|
|
|
|
if (_count == Call::kSignalBarFinished) {
|
|
|
|
return;
|
2020-08-14 12:51:47 +00:00
|
|
|
} else if (_count != count) {
|
2020-08-06 16:55:58 +00:00
|
|
|
_count = count;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Calls
|