Commit c24fe538 authored by Yang Wang's avatar Yang Wang Committed by Andreas Traczyk

record widget: add volume meter display

Change-Id: I4cced5abd46424df4b8388fed3985131de1351db
parent 426c7be8
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M12 14c1.66 0 2.99-1.34 2.99-3L15 5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3zm5.3-3c0 3-2.54 5.1-5.3 5.1S6.7 14 6.7 11H5c0 3.41 2.72 6.23 6 6.72V21h2v-3.28c3.28-.48 6-3.3 6-6.72h-1.7z" fill="white"/><path d="M0 0h24v24H0z" fill="none"/></svg>
\ No newline at end of file
......@@ -20,6 +20,7 @@
#include "ui_recordoverlay.h"
#include "recordwidget.h"
#include "lrcinstance.h"
#include "utils.h"
RecordOverlay::RecordOverlay(RecordWidget* recordWidget) :
......@@ -40,7 +41,19 @@ RecordOverlay::RecordOverlay(RecordWidget* recordWidget) :
ui->recordOverlayPlayBtn->setVisible(false);
ui->recordOverlayStopPlayingBtn->setVisible(false);
setUpRecorderStatus(RecorderStatus::aboutToRecord);
connect(&LRCInstance::avModel(), &lrc::api::AVModel::audioMeter,
ui->levelMeter,
[this](const std::string& /*id*/, float level) {
ui->levelMeter->setLevel(level);
});
ui->inputIcon->setVisible(false);
ui->inputIcon->setPixmap(Utils::pixmapFromSvg(
QString(":/images/icons/av_icons/mic-24px.svg"),
ui->inputIcon->size()));
setRecorderState(RecorderState::aboutToRecord);
}
RecordOverlay::~RecordOverlay()
......@@ -49,30 +62,24 @@ RecordOverlay::~RecordOverlay()
}
void
RecordOverlay::setUpRecorderStatus(RecorderStatus status, bool isTimerToBeInvolved, bool isAimationToBeInvolved)
RecordOverlay::setRecorderState(RecorderState state)
{
status_ = status;
switch(status) {
case RecorderStatus::aboutToRecord:
reinitializeTimer();
recorderState_ = state;
switch(recorderState_) {
case RecorderState::aboutToRecord:
switchToAboutToRecordPage();
if(isTimerToBeInvolved) {reinitializeTimer();}
if(isAimationToBeInvolved) {stopRedDotBlink();}
ui->redDotBlinkable->stop();
break;
case RecorderStatus::recording:
case RecorderState::recording:
switchToRecordingPage();
if(isTimerToBeInvolved) {
reinitializeTimer();
recordTimer_.start(1000);
}
if(isAimationToBeInvolved) {
stopRedDotBlink();
startRedDotBlink();
}
recordTimer_.start(1000);
ui->redDotBlinkable->stop();
ui->redDotBlinkable->start();
break;
case RecorderStatus::recorded:
case RecorderState::recorded:
switchToRecordedPage();
if(isTimerToBeInvolved) {reinitializeTimer();}
if(isAimationToBeInvolved) {stopRedDotBlink();}
ui->redDotBlinkable->stop();
break;
}
}
......@@ -133,66 +140,72 @@ RecordOverlay::reinitializeTimer()
currentTime_ = 0;
}
void
RecordOverlay::startRedDotBlink()
{
ui->redDotBlinkable->start();
}
void
RecordOverlay::stopRedDotBlink()
{
ui->redDotBlinkable->stop();
}
void
RecordOverlay::showEvent(QShowEvent* event)
{
QWidget::showEvent(event);
setUpRecorderStatus(RecorderStatus::aboutToRecord);
if(recordWidget_->isAudio()) {
ui->inputIcon->setVisible(true);
ui->levelMeter->setVisible(true);
ui->levelMeter->start();
LRCInstance::startAudioMeter(true);
} else {
ui->inputIcon->setVisible(false);
ui->levelMeter->setVisible(false);
ui->levelMeter->stop();
LRCInstance::stopAudioMeter(true);
}
setRecorderState(RecorderState::aboutToRecord);
}
void
RecordOverlay::hideEvent(QHideEvent* event)
{
QWidget::hideEvent(event);
if(recordWidget_->isAudio()) {
ui->levelMeter->stop();
ui->levelMeter->setVisible(false);
ui->inputIcon->setVisible(false);
LRCInstance::stopAudioMeter(true);
}
// set the page to about record page
setUpRecorderStatus(RecorderStatus::aboutToRecord);
setRecorderState(RecorderState::aboutToRecord);
}
void
RecordOverlay::on_recordOverlayStartOrFinishRecordingBtn_toggled(bool checked)
{
if(status_ == RecorderStatus::aboutToRecord) {
if(recorderState_ == RecorderState::aboutToRecord) {
// start record function call, if call succeed, switch the page to recording page and start the timer
if(recordWidget_->startRecording()) {
setUpRecorderStatus(RecorderStatus::recording);
setRecorderState(RecorderState::recording);
} else {
ui->recordOverlayStartOrFinishRecordingBtn->setOverlayButtonChecked(!checked);
qDebug() << "The recording does not start properly";
}
} else if(status_ == RecorderStatus::recording) {
} else if(recorderState_ == RecorderState::recording) {
// finish the record, if it succeed, switch the page and re-initialize the timer
if(recordWidget_->finishRecording()) {
setUpRecorderStatus(RecorderStatus::recorded);
setRecorderState(RecorderState::recorded);
} else {
ui->recordOverlayStartOrFinishRecordingBtn->setOverlayButtonChecked(!checked);
qDebug() << "The recording does not finish properly";
}
} else {
ui->recordOverlayStartOrFinishRecordingBtn->setOverlayButtonChecked(!checked);
qDebug() << "This button should not appear on current page";
}
}
void
RecordOverlay::on_recordOverlaySendBtn_pressed()
{
if(status_ != RecorderStatus::recorded) {
if(recorderState_ != RecorderState::recorded) {
qDebug() << "The contented is not recorded and cannot be sent out";
return;
}
if(recordWidget_->sendRecording()) {
setUpRecorderStatus(RecorderStatus::aboutToRecord);
setRecorderState(RecorderState::aboutToRecord);
// define what to do when the record is sent out
recordWidget_->getContainer()->accept();
}
......@@ -201,24 +214,24 @@ RecordOverlay::on_recordOverlaySendBtn_pressed()
void
RecordOverlay::on_recordOverlayDeleteBtn_pressed()
{
if(status_ != RecorderStatus::recorded) {
if(recorderState_ != RecorderState::recorded) {
qDebug() << "The content is not recorded and cannot be deleted";
return;
}
recordWidget_->deleteRecording();
setUpRecorderStatus(RecorderStatus::aboutToRecord);
setRecorderState(RecorderState::aboutToRecord);
}
void
RecordOverlay::on_recordOverlayRerecordBtn_pressed()
{
if(status_ != RecorderStatus::recording) {
if(recorderState_ != RecorderState::recording) {
qDebug() << "it's not on the recording page and thus there's cannot re-record";
return;
}
recordWidget_->recordAgain();
// re-initialize the timer at the same time
setUpRecorderStatus(RecorderStatus::recording);
setRecorderState(RecorderState::recording);
}
void
......
......@@ -29,10 +29,10 @@ class RecordWidget;
class RecordOverlay : public VignetteWidget
{
Q_OBJECT
Q_PROPERTY(QPixmap pixRedDot READ getOriginPix WRITE setOriginPix DESIGNABLE true NOTIFY originPixChanged);
Q_PROPERTY(QPixmap pixRedDot READ getOriginPix WRITE setOriginPix DESIGNABLE true);
public:
enum class RecorderStatus
enum class RecorderState
{
aboutToRecord,
recording,
......@@ -42,17 +42,11 @@ public:
QPixmap getOriginPix();
void setOriginPix(QPixmap);
signals:
void originPixChanged(QPixmap);
public:
explicit RecordOverlay(RecordWidget *recordWidget);
~RecordOverlay();
void setUpRecorderStatus(RecorderStatus status, bool isTimerToBeInvolved = true, bool isAimationToBeInvolved = true);
void startRedDotBlink();
void stopRedDotBlink();
void setRecorderState(RecorderState status);
private:
void switchToAboutToRecordPage();
......@@ -77,7 +71,7 @@ private:
Ui::RecordOverlay* ui;
RecordWidget* recordWidget_;
RecorderStatus status_;
RecorderState recorderState_;
int currentTime_ = 0;
QTimer recordTimer_;
QPixmap redDotPix_;
......
This diff is collapsed.
......@@ -121,6 +121,12 @@ RecordWidget::openRecorder(bool isAudio)
widgetContainer_->show();
}
bool
RecordWidget::isAudio()
{
return isAudio_;
}
void RecordWidget::resizeEvent(QResizeEvent* event)
{
Q_UNUSED(event);
......
......@@ -44,6 +44,8 @@ public:
void openRecorder(bool isAudio);
bool isAudio();
protected:
void resizeEvent(QResizeEvent* event) override;
void hideEvent(QHideEvent* event) override;
......
......@@ -97,5 +97,6 @@
<file>images/icons/av_icons/pause-24px.svg</file>
<file>images/icons/av_icons/send-24px.svg</file>
<file>images/icons/av_icons/stop-24px.svg</file>
<file>images/icons/av_icons/mic-24px.svg</file>
</qresource>
</RCC>
......@@ -886,3 +886,14 @@ QLabel#timerLabel {
background-color: transparent;
color: white;
}
QProgressBar#levelMeter {
border: 2px solid white;
text-align: center;
background: transparent;
}
QProgressBar#levelMeter::chunk {
background-color: white;
margin: 2px;
}
\ No newline at end of file
......@@ -29,6 +29,15 @@
#include <shlwapi.h>
#endif
#include "pixbufmanipulator.h"
#include "globalsystemtray.h"
#include "lrcinstance.h"
#include "networkmanager.h"
#include "updateconfirmdialog.h"
#include "version.h"
#include <globalinstances.h>
//Qt
#include <QBitmap>
#include <QObject>
......@@ -41,15 +50,7 @@
#include <QMessageBox>
#include <QScreen>
#include <QtConcurrent/QtConcurrent>
#include <globalinstances.h>
#include "pixbufmanipulator.h"
#include "globalsystemtray.h"
#include "lrcinstance.h"
#include "networkmanager.h"
#include "updateconfirmdialog.h"
#include "version.h"
#include <QSvgRenderer>
bool
Utils::CreateStartupLink(const std::wstring& wstrAppName)
......@@ -680,6 +681,17 @@ Utils::cropImage(const QImage& img)
return img.copy({ 0, (h - w) / 2, w, w });
}
QPixmap
Utils::pixmapFromSvg(const QString& svg_resource, const QSize& size)
{
QSvgRenderer svgRenderer(svg_resource);
QPixmap pixmap(size);
pixmap.fill(Qt::transparent);
QPainter pixPainter(&pixmap);
svgRenderer.render(&pixPainter);
return pixmap;
}
QString
Utils::formattedTime(int duration)
{
......
......@@ -107,6 +107,7 @@ QPixmap generateTintedPixmap(const QPixmap& pix, QColor color);
QImage scaleAndFrame(const QImage photo, const QSize& size = IMAGE_SIZE);
QImage accountPhoto(const lrc::api::account::Info& accountInfo, const QSize& size = IMAGE_SIZE);
QImage cropImage(const QImage& img);
QPixmap pixmapFromSvg(const QString& svg_resource, const QSize& size);
// rounded corner
template<typename T>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment