#include "TrayVolumeCtrl.h"
#include "AvReceiverGui.h"


CTrayVolumeCtrl::CTrayVolumeCtrl(CAvReceiverGui *AvReceiverGuiPtr, QWidget *parent) :
    QWidget(parent)
{
    mAvReceiverGuiHandle = AvReceiverGuiPtr;

    mMainZoneSlider = new QSlider();
    mZone2Slider = new QSlider();
    mMainZoneLabel = new QLabel("Main\n0");
    mMainZoneLabel->setAlignment(Qt::AlignCenter);
    mZone2Label = new QLabel("Zone 2\n0");
    mZone2Label->setAlignment(Qt::AlignCenter);
    mLayout = new QGridLayout(this);
    mButton1 = new QPushButton("1");
    mButton2 = new QPushButton("2");
    mButton3 = new QPushButton("3");
    mButton4 = new QPushButton("4");


    mLayout->addWidget(mMainZoneLabel,0,0);
    mLayout->addWidget(mZone2Label,0,1);
    mLayout->addWidget(mMainZoneSlider,1,0,4,1);
    mLayout->addWidget(mZone2Slider,1,1,4,1);
    mLayout->addWidget(mButton1,1,2);
    mLayout->addWidget(mButton2,2,2);
    mLayout->addWidget(mButton3,3,2);
    mLayout->addWidget(mButton4,4,2);
    mButton1->setMaximumWidth(25);
    mButton2->setMaximumWidth(25);
    mButton3->setMaximumWidth(25);
    mButton4->setMaximumWidth(25);

    mMainZoneSlider->setMaximum(182);
    mZone2Slider->setMaximum(182);


    connect(mMainZoneSlider,&QSlider::valueChanged,this,&CTrayVolumeCtrl::MainZoneSliderValueChanged);
    connect(mZone2Slider,&QSlider::valueChanged,this,&CTrayVolumeCtrl::Zone2SliderValueChanged);
    connect(mButton1,&QPushButton::clicked,mAvReceiverGuiHandle,&CAvReceiverGui::MainZoneScene1BtnClicked);
    connect(mButton2,&QPushButton::clicked,mAvReceiverGuiHandle,&CAvReceiverGui::MainZoneScene2BtnClicked);
    connect(mButton3,&QPushButton::clicked,mAvReceiverGuiHandle,&CAvReceiverGui::MainZoneScene3BtnClicked);
    connect(mButton4,&QPushButton::clicked,mAvReceiverGuiHandle,&CAvReceiverGui::MainZoneScene4BtnClicked);

}

CTrayVolumeCtrl::~CTrayVolumeCtrl()
{
    delete mLayout;
    delete mMainZoneSlider;
    delete mZone2Slider;
    delete mZone2Label;
    delete mMainZoneLabel;
}


void CTrayVolumeCtrl::MainZoneSliderValueChanged()
{
    float SetVolume = mAvReceiverGuiHandle->ConvertBarPositionToVolume(mMainZoneSlider->value());
    mMainZoneLabel->setText(QString("Main\n%1").arg(SetVolume));
    mAvReceiverGuiHandle->MainZoneVolumeSetChanged(mMainZoneSlider->value());
}

void CTrayVolumeCtrl::Zone2SliderValueChanged()
{
    float SetVolume = mAvReceiverGuiHandle->ConvertBarPositionToVolume(mZone2Slider->value());
    mZone2Label->setText(QString("Main\n%1").arg(SetVolume));
    mAvReceiverGuiHandle->Zone2VolumeSetChanged(mZone2Slider->value());
}

int CTrayVolumeCtrl::SetMainZoneVolume(int SliderValue, float Volume)
{
    mMainZoneSlider->blockSignals(true);
    mMainZoneLabel->setText(QString("Main\n%1").arg(Volume));
    mMainZoneSlider->setValue(SliderValue);
    mMainZoneSlider->blockSignals(false);
    mMainZoneCurVolume = Volume;
}

int CTrayVolumeCtrl::SetZone2Volume(int SliderValue, float Volume)
{
    mZone2Slider->blockSignals(true);
    mZone2Label->setText(QString("Zone 2\n%1").arg(Volume));
    mZone2Slider->setValue(SliderValue);
    mZone2Slider->blockSignals(false);
    mZone2CurVolume = Volume;
}
