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 @@ ...@@ -20,6 +20,7 @@
#include "ui_recordoverlay.h" #include "ui_recordoverlay.h"
#include "recordwidget.h" #include "recordwidget.h"
#include "lrcinstance.h"
#include "utils.h" #include "utils.h"
RecordOverlay::RecordOverlay(RecordWidget* recordWidget) : RecordOverlay::RecordOverlay(RecordWidget* recordWidget) :
...@@ -40,7 +41,19 @@ RecordOverlay::RecordOverlay(RecordWidget* recordWidget) : ...@@ -40,7 +41,19 @@ RecordOverlay::RecordOverlay(RecordWidget* recordWidget) :
ui->recordOverlayPlayBtn->setVisible(false); ui->recordOverlayPlayBtn->setVisible(false);
ui->recordOverlayStopPlayingBtn->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() RecordOverlay::~RecordOverlay()
...@@ -49,30 +62,24 @@ RecordOverlay::~RecordOverlay() ...@@ -49,30 +62,24 @@ RecordOverlay::~RecordOverlay()
} }
void void
RecordOverlay::setUpRecorderStatus(RecorderStatus status, bool isTimerToBeInvolved, bool isAimationToBeInvolved) RecordOverlay::setRecorderState(RecorderState state)
{ {
status_ = status; reinitializeTimer();
switch(status) { recorderState_ = state;
case RecorderStatus::aboutToRecord: switch(recorderState_) {
case RecorderState::aboutToRecord:
switchToAboutToRecordPage(); switchToAboutToRecordPage();
if(isTimerToBeInvolved) {reinitializeTimer();} ui->redDotBlinkable->stop();
if(isAimationToBeInvolved) {stopRedDotBlink();}
break; break;
case RecorderStatus::recording: case RecorderState::recording:
switchToRecordingPage(); switchToRecordingPage();
if(isTimerToBeInvolved) { recordTimer_.start(1000);
reinitializeTimer(); ui->redDotBlinkable->stop();
recordTimer_.start(1000); ui->redDotBlinkable->start();
}
if(isAimationToBeInvolved) {
stopRedDotBlink();
startRedDotBlink();
}
break; break;
case RecorderStatus::recorded: case RecorderState::recorded:
switchToRecordedPage(); switchToRecordedPage();
if(isTimerToBeInvolved) {reinitializeTimer();} ui->redDotBlinkable->stop();
if(isAimationToBeInvolved) {stopRedDotBlink();}
break; break;
} }
} }
...@@ -133,66 +140,72 @@ RecordOverlay::reinitializeTimer() ...@@ -133,66 +140,72 @@ RecordOverlay::reinitializeTimer()
currentTime_ = 0; currentTime_ = 0;
} }
void
RecordOverlay::startRedDotBlink()
{
ui->redDotBlinkable->start();
}
void
RecordOverlay::stopRedDotBlink()
{
ui->redDotBlinkable->stop();
}
void void
RecordOverlay::showEvent(QShowEvent* event) RecordOverlay::showEvent(QShowEvent* event)
{ {
QWidget::showEvent(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 void
RecordOverlay::hideEvent(QHideEvent* event) RecordOverlay::hideEvent(QHideEvent* event)
{ {
QWidget::hideEvent(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 // set the page to about record page
setUpRecorderStatus(RecorderStatus::aboutToRecord); setRecorderState(RecorderState::aboutToRecord);
} }
void void
RecordOverlay::on_recordOverlayStartOrFinishRecordingBtn_toggled(bool checked) 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 // start record function call, if call succeed, switch the page to recording page and start the timer
if(recordWidget_->startRecording()) { if(recordWidget_->startRecording()) {
setUpRecorderStatus(RecorderStatus::recording); setRecorderState(RecorderState::recording);
} else { } else {
ui->recordOverlayStartOrFinishRecordingBtn->setOverlayButtonChecked(!checked); ui->recordOverlayStartOrFinishRecordingBtn->setOverlayButtonChecked(!checked);
qDebug() << "The recording does not start properly"; 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 // finish the record, if it succeed, switch the page and re-initialize the timer
if(recordWidget_->finishRecording()) { if(recordWidget_->finishRecording()) {
setUpRecorderStatus(RecorderStatus::recorded); setRecorderState(RecorderState::recorded);
} else { } else {
ui->recordOverlayStartOrFinishRecordingBtn->setOverlayButtonChecked(!checked); ui->recordOverlayStartOrFinishRecordingBtn->setOverlayButtonChecked(!checked);
qDebug() << "The recording does not finish properly"; qDebug() << "The recording does not finish properly";
} }
} else { } else {
ui->recordOverlayStartOrFinishRecordingBtn->setOverlayButtonChecked(!checked);
qDebug() << "This button should not appear on current page";
} }
} }
void void
RecordOverlay::on_recordOverlaySendBtn_pressed() RecordOverlay::on_recordOverlaySendBtn_pressed()
{ {
if(status_ != RecorderStatus::recorded) { if(recorderState_ != RecorderState::recorded) {
qDebug() << "The contented is not recorded and cannot be sent out"; qDebug() << "The contented is not recorded and cannot be sent out";
return; return;
} }
if(recordWidget_->sendRecording()) { if(recordWidget_->sendRecording()) {
setUpRecorderStatus(RecorderStatus::aboutToRecord); setRecorderState(RecorderState::aboutToRecord);
// define what to do when the record is sent out // define what to do when the record is sent out
recordWidget_->getContainer()->accept(); recordWidget_->getContainer()->accept();
} }
...@@ -201,24 +214,24 @@ RecordOverlay::on_recordOverlaySendBtn_pressed() ...@@ -201,24 +214,24 @@ RecordOverlay::on_recordOverlaySendBtn_pressed()
void void
RecordOverlay::on_recordOverlayDeleteBtn_pressed() RecordOverlay::on_recordOverlayDeleteBtn_pressed()
{ {
if(status_ != RecorderStatus::recorded) { if(recorderState_ != RecorderState::recorded) {
qDebug() << "The content is not recorded and cannot be deleted"; qDebug() << "The content is not recorded and cannot be deleted";
return; return;
} }
recordWidget_->deleteRecording(); recordWidget_->deleteRecording();
setUpRecorderStatus(RecorderStatus::aboutToRecord); setRecorderState(RecorderState::aboutToRecord);
} }
void void
RecordOverlay::on_recordOverlayRerecordBtn_pressed() 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"; qDebug() << "it's not on the recording page and thus there's cannot re-record";
return; return;
} }
recordWidget_->recordAgain(); recordWidget_->recordAgain();
// re-initialize the timer at the same time // re-initialize the timer at the same time
setUpRecorderStatus(RecorderStatus::recording); setRecorderState(RecorderState::recording);
} }
void void
......
...@@ -29,10 +29,10 @@ class RecordWidget; ...@@ -29,10 +29,10 @@ class RecordWidget;
class RecordOverlay : public VignetteWidget class RecordOverlay : public VignetteWidget
{ {
Q_OBJECT 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: public:
enum class RecorderStatus enum class RecorderState
{ {
aboutToRecord, aboutToRecord,
recording, recording,
...@@ -42,17 +42,11 @@ public: ...@@ -42,17 +42,11 @@ public:
QPixmap getOriginPix(); QPixmap getOriginPix();
void setOriginPix(QPixmap); void setOriginPix(QPixmap);
signals:
void originPixChanged(QPixmap);
public: public:
explicit RecordOverlay(RecordWidget *recordWidget); explicit RecordOverlay(RecordWidget *recordWidget);
~RecordOverlay(); ~RecordOverlay();
void setUpRecorderStatus(RecorderStatus status, bool isTimerToBeInvolved = true, bool isAimationToBeInvolved = true); void setRecorderState(RecorderState status);
void startRedDotBlink();
void stopRedDotBlink();
private: private:
void switchToAboutToRecordPage(); void switchToAboutToRecordPage();
...@@ -77,7 +71,7 @@ private: ...@@ -77,7 +71,7 @@ private:
Ui::RecordOverlay* ui; Ui::RecordOverlay* ui;
RecordWidget* recordWidget_; RecordWidget* recordWidget_;
RecorderStatus status_; RecorderState recorderState_;
int currentTime_ = 0; int currentTime_ = 0;
QTimer recordTimer_; QTimer recordTimer_;
QPixmap redDotPix_; QPixmap redDotPix_;
......
This diff is collapsed.
...@@ -121,6 +121,12 @@ RecordWidget::openRecorder(bool isAudio) ...@@ -121,6 +121,12 @@ RecordWidget::openRecorder(bool isAudio)
widgetContainer_->show(); widgetContainer_->show();
} }
bool
RecordWidget::isAudio()
{
return isAudio_;
}
void RecordWidget::resizeEvent(QResizeEvent* event) void RecordWidget::resizeEvent(QResizeEvent* event)
{ {
Q_UNUSED(event); Q_UNUSED(event);
......
...@@ -44,6 +44,8 @@ public: ...@@ -44,6 +44,8 @@ public:
void openRecorder(bool isAudio); void openRecorder(bool isAudio);
bool isAudio();
protected: protected:
void resizeEvent(QResizeEvent* event) override; void resizeEvent(QResizeEvent* event) override;
void hideEvent(QHideEvent* event) override; void hideEvent(QHideEvent* event) override;
......
...@@ -97,5 +97,6 @@ ...@@ -97,5 +97,6 @@
<file>images/icons/av_icons/pause-24px.svg</file> <file>images/icons/av_icons/pause-24px.svg</file>
<file>images/icons/av_icons/send-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/stop-24px.svg</file>
<file>images/icons/av_icons/mic-24px.svg</file>
</qresource> </qresource>
</RCC> </RCC>
...@@ -886,3 +886,14 @@ QLabel#timerLabel { ...@@ -886,3 +886,14 @@ QLabel#timerLabel {
background-color: transparent; background-color: transparent;
color: white; 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 @@ ...@@ -29,6 +29,15 @@
#include <shlwapi.h> #include <shlwapi.h>
#endif #endif
#include "pixbufmanipulator.h"
#include "globalsystemtray.h"
#include "lrcinstance.h"
#include "networkmanager.h"
#include "updateconfirmdialog.h"
#include "version.h"
#include <globalinstances.h>
//Qt //Qt
#include <QBitmap> #include <QBitmap>
#include <QObject> #include <QObject>
...@@ -41,15 +50,7 @@ ...@@ -41,15 +50,7 @@
#include <QMessageBox> #include <QMessageBox>
#include <QScreen> #include <QScreen>
#include <QtConcurrent/QtConcurrent> #include <QtConcurrent/QtConcurrent>
#include <QSvgRenderer>
#include <globalinstances.h>
#include "pixbufmanipulator.h"
#include "globalsystemtray.h"
#include "lrcinstance.h"
#include "networkmanager.h"
#include "updateconfirmdialog.h"
#include "version.h"
bool bool
Utils::CreateStartupLink(const std::wstring& wstrAppName) Utils::CreateStartupLink(const std::wstring& wstrAppName)
...@@ -680,6 +681,17 @@ Utils::cropImage(const QImage& img) ...@@ -680,6 +681,17 @@ Utils::cropImage(const QImage& img)
return img.copy({ 0, (h - w) / 2, w, w }); 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 QString
Utils::formattedTime(int duration) Utils::formattedTime(int duration)
{ {
......
...@@ -107,6 +107,7 @@ QPixmap generateTintedPixmap(const QPixmap& pix, QColor color); ...@@ -107,6 +107,7 @@ QPixmap generateTintedPixmap(const QPixmap& pix, QColor color);
QImage scaleAndFrame(const QImage photo, const QSize& size = IMAGE_SIZE); QImage scaleAndFrame(const QImage photo, const QSize& size = IMAGE_SIZE);
QImage accountPhoto(const lrc::api::account::Info& accountInfo, const QSize& size = IMAGE_SIZE); QImage accountPhoto(const lrc::api::account::Info& accountInfo, const QSize& size = IMAGE_SIZE);
QImage cropImage(const QImage& img); QImage cropImage(const QImage& img);
QPixmap pixmapFromSvg(const QString& svg_resource, const QSize& size);
// rounded corner // rounded corner
template<typename T> 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