2020-10-02 18:14:41 +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
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "api/api_common.h"
|
|
|
|
#include "history/view/controls/compose_controls_common.h"
|
|
|
|
#include "ui/effects/animations.h"
|
|
|
|
#include "ui/rp_widget.h"
|
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
class SendButton;
|
|
|
|
} // namespace Ui
|
|
|
|
|
|
|
|
namespace Window {
|
|
|
|
class SessionController;
|
|
|
|
} // namespace Window
|
|
|
|
|
|
|
|
namespace HistoryView::Controls {
|
|
|
|
|
|
|
|
class VoiceRecordBar final : public Ui::RpWidget {
|
|
|
|
public:
|
|
|
|
using SendActionUpdate = Controls::SendActionUpdate;
|
|
|
|
using VoiceToSend = Controls::VoiceToSend;
|
|
|
|
|
|
|
|
void startRecording();
|
|
|
|
void finishAnimating();
|
|
|
|
|
|
|
|
[[nodiscard]] rpl::producer<SendActionUpdate> sendActionUpdates() const;
|
|
|
|
[[nodiscard]] rpl::producer<VoiceToSend> sendVoiceRequests() const;
|
|
|
|
[[nodiscard]] rpl::producer<bool> recordingStateChanges() const;
|
|
|
|
[[nodiscard]] rpl::producer<> startRecordingRequests() const;
|
|
|
|
|
|
|
|
[[nodiscard]] bool isRecording() const;
|
|
|
|
|
|
|
|
VoiceRecordBar(
|
|
|
|
not_null<Ui::RpWidget*> parent,
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
std::shared_ptr<Ui::SendButton> send,
|
|
|
|
int recorderHeight);
|
|
|
|
~VoiceRecordBar();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void init();
|
|
|
|
|
|
|
|
void updateControlsGeometry(QSize size);
|
|
|
|
|
|
|
|
void recordError();
|
|
|
|
void recordUpdated(quint16 level, int samples);
|
|
|
|
|
|
|
|
bool recordingAnimationCallback(crl::time now);
|
2020-10-04 18:19:34 +00:00
|
|
|
|
|
|
|
void stop(bool send);
|
2020-10-02 18:14:41 +00:00
|
|
|
void stopRecording(bool send);
|
2020-10-04 18:19:34 +00:00
|
|
|
void visibilityAnimate(bool show, Fn<void()> &&callback);
|
2020-10-02 18:14:41 +00:00
|
|
|
|
|
|
|
void recordStopCallback(bool active);
|
|
|
|
void recordUpdateCallback(QPoint globalPos);
|
|
|
|
|
|
|
|
bool showRecordButton() const;
|
|
|
|
void drawRecording(Painter &p, float64 recordActive);
|
|
|
|
void updateOverStates(QPoint pos);
|
|
|
|
|
|
|
|
bool isTypeRecord() const;
|
|
|
|
|
2020-10-04 13:32:45 +00:00
|
|
|
void activeAnimate(bool active);
|
|
|
|
float64 activeAnimationRatio() const;
|
|
|
|
|
2020-10-02 18:14:41 +00:00
|
|
|
const not_null<Window::SessionController*> _controller;
|
|
|
|
const std::unique_ptr<Ui::RpWidget> _wrap;
|
|
|
|
const std::shared_ptr<Ui::SendButton> _send;
|
|
|
|
|
|
|
|
rpl::event_stream<SendActionUpdate> _sendActionUpdates;
|
|
|
|
rpl::event_stream<VoiceToSend> _sendVoiceRequests;
|
|
|
|
|
|
|
|
int _centerY = 0;
|
|
|
|
QRect _redCircleRect;
|
2020-10-04 20:13:00 +00:00
|
|
|
QRect _durationRect;
|
2020-10-02 18:14:41 +00:00
|
|
|
|
|
|
|
rpl::variable<bool> _recording = false;
|
2020-10-04 13:32:45 +00:00
|
|
|
rpl::variable<bool> _inField = false;
|
2020-10-02 18:14:41 +00:00
|
|
|
int _recordingSamples = 0;
|
|
|
|
|
|
|
|
const style::font &_cancelFont;
|
|
|
|
int _recordCancelWidth;
|
|
|
|
|
|
|
|
rpl::lifetime _recordingLifetime;
|
|
|
|
|
|
|
|
// This can animate for a very long time (like in music playing),
|
|
|
|
// so it should be a Basic, not a Simple animation.
|
|
|
|
Ui::Animations::Basic _recordingAnimation;
|
2020-10-04 13:32:45 +00:00
|
|
|
Ui::Animations::Simple _activeAnimation;
|
2020-10-04 18:19:34 +00:00
|
|
|
Ui::Animations::Simple _showAnimation;
|
2020-10-02 18:14:41 +00:00
|
|
|
anim::value _recordingLevel;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace HistoryView::Controls
|