#include "Taskbar.h"
#include "SpectrumWidget.h"
#include "AudioAnalyze.h"
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QPushButton>
#include <QDebug>

Taskbar::Taskbar(QWidget* parent) : QMainWindow(parent)
{
    // 最简单的窗口设置
    setWindowTitle("Spectrum Display");
    setFixedSize(800, 100);

    // 创建中心部件
    QWidget* centralWidget = new QWidget(this);
    setCentralWidget(centralWidget);

    // 创建布局
    QHBoxLayout* layout = new QHBoxLayout(centralWidget);
    layout->setContentsMargins(10, 10, 10, 10);

    // 创建频谱显示组件
    m_spectrumWidget = new SpectrumWidget(this);
    m_spectrumWidget->setMinimumSize(600, 60);
    layout->addWidget(m_spectrumWidget);

    // 添加退出按钮
    QPushButton* exitBtn = new QPushButton("Exit", this);
    exitBtn->setFixedSize(60, 30);
    connect(exitBtn, &QPushButton::clicked, this, &QMainWindow::close);
    layout->addWidget(exitBtn);

    // 初始化音频分析器
    m_analyzer = new AudioSpectrumAnalyzer(this);

    if (m_analyzer->initialize()) {
        bool connected = connect(m_analyzer, &AudioSpectrumAnalyzer::spectrumDataReady,
            m_spectrumWidget, &SpectrumWidget::setSpectrumData);

        qDebug() << "Spectrum signal connected:" << connected;

        if (connected) {
            m_analyzer->startCapture();
        }
    }

    // 启动频谱动画
    m_spectrumWidget->startAnimation(30);
    qDebug() << "Simple spectrum display started";
}

Taskbar::~Taskbar()
{
    if (m_analyzer) {
        m_analyzer->stopCapture();
    }
}
