feat: mic level bar in recording overlay
- InputBar: QProgressBar with gradient (green→yellow→red) in recording overlay - updateRecordingUI: computes dB from peakLevel, updates bar every 100ms - showRecordOverlay: resets bar to 0 on new recording
This commit is contained in:
1 parent
5593bfdc0c
commit
7004b110ae
2 files changed
+24
No files matched your search
@@ -16,6 +16,8 @@
|
||||
#include <QLabel>
|
||||
#include <QResizeEvent>
|
||||
#include <QDir>
|
||||
#include <QProgressBar>
|
||||
#include <cmath>
|
||||
|
||||
static QPushButton *makeIconBtn(const QString &text, const QString &tooltip, QWidget *parent) {
|
||||
auto *btn = new QPushButton(text, parent);
|
||||
@@ -115,6 +117,18 @@ InputBar::InputBar(EmojiPanel *emojiPanel, AudioRecorder *recorder, QWidget *par
|
||||
m_recordLabel = new QLabel(m_recordOverlay);
|
||||
m_recordLabel->setStyleSheet("color: white; font-size: 14px; font-weight: bold; background: transparent;");
|
||||
roLayout->addWidget(m_recordLabel);
|
||||
|
||||
m_levelBar = new QProgressBar(m_recordOverlay);
|
||||
m_levelBar->setRange(0, 100);
|
||||
m_levelBar->setValue(0);
|
||||
m_levelBar->setTextVisible(false);
|
||||
m_levelBar->setFixedSize(80, 14);
|
||||
m_levelBar->setStyleSheet(
|
||||
"QProgressBar { border: 1px solid rgba(255,255,255,0.2); border-radius: 3px; background: rgba(0,0,0,0.3); }"
|
||||
"QProgressBar::chunk { background: qlineargradient(x1:0, y1:0, x2:1, y2:0,"
|
||||
" stop:0 #27ae60, stop:0.6 #f1c40f, stop:1 #e74c3c); border-radius: 2px; }");
|
||||
roLayout->addWidget(m_levelBar);
|
||||
|
||||
roLayout->addStretch();
|
||||
m_cancelRecBtn = new QPushButton(QString::fromUtf8("\xE2\x9C\x95"), m_recordOverlay);
|
||||
m_cancelRecBtn->setFixedSize(24, 24);
|
||||
@@ -261,6 +275,7 @@ void InputBar::showRecordOverlay() {
|
||||
m_recordOverlay->show();
|
||||
m_recordOverlay->raise();
|
||||
m_recordLabel->setText(QString::fromUtf8("\xF0\x9F\x94\xB4 Recording 0:00"));
|
||||
if (m_levelBar) m_levelBar->setValue(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -274,4 +289,11 @@ void InputBar::updateRecordingUI(int ms) {
|
||||
m_recordLabel->setText(QString::fromUtf8("\xF0\x9F\x94\xB4 Recording %1:%2")
|
||||
.arg(secs / 60).arg(secs % 60, 2, 10, QChar('0')));
|
||||
}
|
||||
if (m_levelBar && m_recorder) {
|
||||
float peak = m_recorder->peakLevel();
|
||||
float db = peak > 0.0001f ? 20.0f * log10f(peak) : -70.0f;
|
||||
int pct = (int)((db + 70.0f) / 70.0f * 100.0f);
|
||||
if (pct < 0) pct = 0; if (pct > 100) pct = 100;
|
||||
m_levelBar->setValue(pct);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user