#include <QtGui>

#include "mainwnd.h"

Mainwnd::Mainwnd()
{
    player = new VideoPlayer(Phonon::VideoCategory, this);
    createtoolbar();
    openbutton = new QPushButton(tr("Open..."), filetoolbar1);
    filetoolbar1->addWidget(openbutton);
    connect(openbutton, SIGNAL(clicked()), this, SLOT(selectfile()));
    playbutton = new QPushButton(tr("Play"), filetoolbar1);
    filetoolbar1->addWidget(playbutton);
    connect(playbutton, SIGNAL(clicked()), this, SLOT(playfile()));
    stopbutton = new QPushButton(tr("Stop"), filetoolbar1);
    filetoolbar1->addWidget(stopbutton);
    connect(stopbutton, SIGNAL(clicked()), player, SLOT(stop()));
    pausebutton = new QPushButton(tr("Pause"), filetoolbar1);
    filetoolbar1->addWidget(pausebutton);
    connect(pausebutton, SIGNAL(clicked()), player, SLOT(pause()));
    volumeslider = new QSlider(Qt::Horizontal, filetoolbar1);
    volumeslider->setRange(0, 100);
    volumeslider->setValue(100);
    filetoolbar1->addWidget(volumeslider);
    connect(volumeslider, SIGNAL(valueChanged(int)), this, SLOT(setvolume(int)));
    setCentralWidget(player);
}
void Mainwnd::selectfile()
{
    QString filename = QFileDialog::getOpenFileName(this, tr("Please, select video file"), ".");

    if (filename.isEmpty())
        return;

    player->play(filename);
    resize(sizeHint());
}

void Mainwnd::playfile()
{
    player->play();
    resize(sizeHint());
}

void Mainwnd::setvolume(int value)
{
    float volume;
    volume = (static_cast<float>(value)) / 100;
    player->setVolume(volume);
}

void Mainwnd::createtoolbar()
{
    filetoolbar1 = addToolBar(tr("toolbar 1"));
}

