calls_signal_bars.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #include "calls/calls_signal_bars.h"
  8. #include "calls/calls_call.h"
  9. #include "ui/painter.h"
  10. #include "styles/style_calls.h"
  11. namespace Calls {
  12. SignalBars::SignalBars(
  13. QWidget *parent,
  14. not_null<Call*> call,
  15. const style::CallSignalBars &st)
  16. : RpWidget(parent)
  17. , _st(st)
  18. , _count(Call::kSignalBarStarting) {
  19. resize(
  20. _st.width + (_st.width + _st.skip) * (Call::kSignalBarCount - 1),
  21. _st.max);
  22. call->signalBarCountValue(
  23. ) | rpl::start_with_next([=](int count) {
  24. changed(count);
  25. }, lifetime());
  26. }
  27. void SignalBars::paintEvent(QPaintEvent *e) {
  28. auto p = QPainter(this);
  29. PainterHighQualityEnabler hq(p);
  30. p.setPen(Qt::NoPen);
  31. p.setBrush(_st.color);
  32. for (auto i = 0; i < Call::kSignalBarCount; ++i) {
  33. p.setOpacity((i < _count) ? 1. : _st.inactiveOpacity);
  34. const auto barHeight = _st.min
  35. + (_st.max - _st.min) * (i / float64(Call::kSignalBarCount - 1));
  36. const auto barLeft = i * (_st.width + _st.skip);
  37. const auto barTop = height() - barHeight;
  38. p.drawRoundedRect(
  39. QRectF(
  40. barLeft,
  41. barTop,
  42. _st.width,
  43. barHeight),
  44. _st.radius,
  45. _st.radius);
  46. }
  47. p.setOpacity(1.);
  48. }
  49. void SignalBars::changed(int count) {
  50. if (_count == Call::kSignalBarFinished) {
  51. return;
  52. } else if (_count != count) {
  53. _count = count;
  54. update();
  55. }
  56. }
  57. } // namespace Calls