diff --git a/tools/chatgui/src/inputbar.cpp b/tools/chatgui/src/inputbar.cpp index 20d158d2..a375aa9d 100644 --- a/tools/chatgui/src/inputbar.cpp +++ b/tools/chatgui/src/inputbar.cpp @@ -16,6 +16,8 @@ #include #include #include +#include +#include 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); + } } diff --git a/tools/chatgui/src/inputbar.h b/tools/chatgui/src/inputbar.h index 965fd4a1..3793e4eb 100644 --- a/tools/chatgui/src/inputbar.h +++ b/tools/chatgui/src/inputbar.h @@ -5,6 +5,7 @@ class QTextEdit; class QPushButton; class QLabel; +class QProgressBar; class EmojiPanel; class AudioRecorder; @@ -42,6 +43,7 @@ private: QWidget *m_recordOverlay = nullptr; QLabel *m_recordLabel = nullptr; QPushButton *m_cancelRecBtn = nullptr; + QProgressBar *m_levelBar = nullptr; bool m_pttActive = false; QString m_voiceFilePath; QString m_mediaDirBase;