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();
}
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_;
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>367</width>
<height>258</height>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="sizePolicy">
......@@ -25,10 +25,7 @@
<property name="pixRedDot" stdset="0">
<pixmap resource="ressources.qrc">:/images/icons/av_icons/fiber_manual_record-24px.svg</pixmap>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>0</number>
</property>
......@@ -41,13 +38,21 @@
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4" stretch="1,0,1,1,1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<property name="topMargin">
<number>5</number>
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<item>
<spacer name="horizontalSpacer_3">
......@@ -55,24 +60,16 @@
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>20</height>
<width>13</width>
<height>17</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<item>
<widget class="Blinkable" name="redDotBlinkable" native="true">
<property name="sizePolicy">
......@@ -95,24 +92,6 @@
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>8</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="timerLabel">
<property name="sizePolicy">
......@@ -152,11 +131,11 @@
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<width>13</width>
<height>20</height>
</size>
</property>
......@@ -169,36 +148,110 @@
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>82</height>
<height>52</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="volumeMeterDisplayLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="spacing">
<number>0</number>
</property>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="inputIcon">
<property name="minimumSize">
<size>
<width>128</width>
<height>128</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="ressources.qrc">:/images/icons/av_icons/mic-24px.svg</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="LevelMeter" name="levelMeter">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>10</height>
</size>
</property>
<property name="value">
<number>0</number>
</property>
<property name="textVisible">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>83</height>
<height>38</height>
</size>
</property>
</spacer>
......@@ -206,7 +259,7 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>7</number>
<number>0</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
......@@ -220,7 +273,7 @@
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
......@@ -485,7 +538,7 @@
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
......@@ -498,6 +551,8 @@
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
......@@ -511,6 +566,12 @@
<header>widgethelpers.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>LevelMeter</class>
<extends>QProgressBar</extends>
<header>levelmeter.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="ressources.qrc"/>
......
......@@ -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