/*****************************************************************************
 *
 *  userdefinedtargetdialog.cpp -- Input user defined picture rezolution.
 *
 *  Copyright (C) 2010 Starbuck <starbuck@labdv.com>
 *  All rights reserved.
 *
 *  This file is part of the Gui4 module of the DVDx 4 application.
 *
 *  GNU Lesser General Public License Usage
 *  This file may be used under the terms of the GNU Lesser General
 *  Public License version 2.1 as published by the Free Software
 *  Foundation and appearing in the file LICENSE.LGPL included in the
 *  packaging of this file.  Please review the following information to
 *  ensure the GNU Lesser General Public License version 2.1 requirements
 *  will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 *
 *  GNU General Public License Usage
 *  Alternatively, this file may be used under the terms of the GNU
 *  General Public License version 3.0 as published by the Free Software
 *  Foundation and appearing in the file LICENSE.GPL included in the
 *  packaging of this file.  Please review the following information to
 *  ensure the GNU General Public License version 3.0 requirements will be
 *  met: http://www.gnu.org/copyleft/gpl.html.
 *
 *****************************************************************************/

#include "userdefinedtargetdialog.h"
#include "infoboxdialog.h"
#include <QtGui>

UserDefinedTargetDialog::UserDefinedTargetDialog(split_t *split, QWidget *parent)
	: QDialog(parent)
{
	setWindowTitle( tr("Set output volume size") );

	QVBoxLayout *mainLayout = new QVBoxLayout(this);
	QGroupBox *groupBox = new QGroupBox(this);
	QHBoxLayout *horizontalLayout = new QHBoxLayout(groupBox);
	QLabel *in1Label = new QLabel(groupBox);
	QLabel *in2Label = new QLabel(groupBox);
	QLabel *in3Label = new QLabel(groupBox);

	sizeLineEdit = new QLineEdit(groupBox);
	volumesSpin = new QSpinBox(groupBox);

	horizontalLayout->addWidget(in1Label);  
	horizontalLayout->addWidget(volumesSpin);  
	horizontalLayout->addWidget(in2Label);  
	horizontalLayout->addWidget(sizeLineEdit);
	horizontalLayout->addWidget(in3Label);

	// Split into [1] volume(s) of [   ] MiBytes
	in1Label->setText( tr("Split into ") );
	in2Label->setText( tr(" volume(s) of ") );
	in3Label->setText( tr(" MiBytes") );

	buttonBox = new QDialogButtonBox(this);
	buttonBox->setOrientation(Qt::Horizontal);
	buttonBox->setStandardButtons(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
	buttonBox->setCenterButtons(true);

	mainLayout->addWidget(groupBox);
	mainLayout->addWidget(buttonBox);

	setLayout(mainLayout);

	connect(buttonBox, SIGNAL(rejected()), this, SLOT(close()));
	connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));

	setAttribute(Qt::WA_AlwaysShowToolTips);

	groupBox->setTitle( tr(" Enter target split ") );

	volumesSpin->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Maximum);
	volumesSpin->setAlignment(Qt::AlignHCenter);
	volumesSpin->setMinimumWidth(36);
	volumesSpin->setRange(1, 9);
	volumesSpin->setSingleStep(1);

	sizeLineEdit->setMaxLength(6);
	sizeLineEdit->setAlignment(Qt::AlignHCenter);
	sizeLineEdit->setMinimumWidth(40);
	sizeLineEdit->setMaximumWidth(60);

	sizeLineEdit->setText(QString::number( split->size ));
	volumesSpin->setValue( split->volumes );

	userDefinedSplit = split;  // to store the user input before closing
}

void UserDefinedTargetDialog::accept()
{
	split_t split;

	split.size = qMax( 1, sizeLineEdit->text().toInt() );
	split.volumes = qMax( 1, volumesSpin->value() );

	*userDefinedSplit = split;

	QDialog::accept();
}
