- Waveform visualization with theme accent color - Playback controls (play/pause, stop, position slider) - Time display with milliseconds (MM:SS.mmm) - Position tracking line on waveform - Volume control 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
91 lines
2.1 KiB
C++
91 lines
2.1 KiB
C++
#ifndef AUDIOPREVIEWWIDGET_H
|
|
#define AUDIOPREVIEWWIDGET_H
|
|
|
|
#include <QWidget>
|
|
#include <QLabel>
|
|
#include <QPushButton>
|
|
#include <QSlider>
|
|
#include <QVBoxLayout>
|
|
#include <QHBoxLayout>
|
|
#include <QMediaPlayer>
|
|
#include <QAudioOutput>
|
|
#include <QBuffer>
|
|
#include <QTreeWidget>
|
|
#include <QSplitter>
|
|
#include <QTimer>
|
|
#include <QColor>
|
|
|
|
#include "settings.h"
|
|
|
|
class AudioPreviewWidget : public QWidget
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit AudioPreviewWidget(QWidget *parent = nullptr);
|
|
~AudioPreviewWidget();
|
|
|
|
bool loadFromData(const QByteArray &data, const QString &filename);
|
|
void setMetadata(const QVariantMap &metadata);
|
|
|
|
private slots:
|
|
void onPlayPause();
|
|
void onStop();
|
|
void onPositionChanged(qint64 position);
|
|
void onDurationChanged(qint64 duration);
|
|
void onSliderMoved(int position);
|
|
void onMediaStatusChanged(QMediaPlayer::MediaStatus status);
|
|
void onUpdatePosition();
|
|
void applyTheme(const Theme &theme);
|
|
|
|
private:
|
|
void updateTimeLabel();
|
|
void parseWavHeader(const QByteArray &data);
|
|
void drawWaveform();
|
|
void updateWaveformPosition();
|
|
|
|
protected:
|
|
void showEvent(QShowEvent *event) override;
|
|
void resizeEvent(QResizeEvent *event) override;
|
|
|
|
private:
|
|
QMediaPlayer *mPlayer;
|
|
QAudioOutput *mAudioOutput;
|
|
QBuffer *mAudioBuffer;
|
|
QByteArray mAudioData;
|
|
QTimer *mPositionTimer;
|
|
|
|
// UI elements
|
|
QLabel *mFilenameLabel;
|
|
QLabel *mWaveformLabel;
|
|
QLabel *mTimeLabel;
|
|
QPushButton *mPlayButton;
|
|
QPushButton *mStopButton;
|
|
QSlider *mPositionSlider;
|
|
QSlider *mVolumeSlider;
|
|
QTreeWidget *mMetadataTree;
|
|
|
|
qint64 mDuration;
|
|
QString mFilename;
|
|
QPixmap mWaveformPixmap; // Store base waveform for position overlay
|
|
double mCalculatedDuration; // Duration in seconds from WAV header
|
|
|
|
// WAV info
|
|
int mSampleRate;
|
|
int mChannels;
|
|
int mBitsPerSample;
|
|
int mDataSize;
|
|
int mAudioFormat; // 1=PCM, 2=ADPCM, etc.
|
|
bool mBigEndian;
|
|
|
|
// Theme colors
|
|
QColor mAccentColor;
|
|
QColor mBgColor;
|
|
QColor mPanelColor;
|
|
QColor mTextColor;
|
|
QColor mTextColorMuted;
|
|
QColor mBorderColor;
|
|
};
|
|
|
|
#endif // AUDIOPREVIEWWIDGET_H
|