/*****************************************************************************
 *
 *  confvidxvidmencoderdialog.h -- Input the Xvid codec encoding parameters.
 *
 *  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.
 *
 *****************************************************************************/

#ifndef VIDEOSETTINGSXVIDDIALOG_H
#define VIDEOSETTINGSXVIDDIALOG_H

#include "../video/video_struct.h"

#include <QtCore/QLocale>
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QCheckBox>
#include <QtGui/QComboBox>
#include <QtGui/QDialog>
#include <QtGui/QDialogButtonBox>
#include <QtGui/QGroupBox>
#include <QtGui/QHBoxLayout>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QPushButton>
#include <QtGui/QRadioButton>
#include <QtGui/QSlider>
#include <QtGui/QSpacerItem>
#include <QtGui/QTabWidget>
#include <QtGui/QVBoxLayout>
#include <QtGui/QWidget>


class ConfVidXvidMEncoderDialog : public QDialog
{
	Q_OBJECT

public:
	ConfVidXvidMEncoderDialog(encoder_video_settings_t *settings, 
		video_t *track,
		QWidget *parent = 0);

private slots:
	void accept();
	void bitrateRadioButtonToggled(const bool);
	void quantizerRadioButtonToggled(const bool);
	void targetRadioButtonToggled(const bool);
	void bitrateSliderChanged(const int);
	void bitrateLineEditChanged(const QString &);
	void quantizerSliderChanged(const int);
	void cartoonCheckBoxToggled(const bool);
	void turboCheckBoxToggled(const bool);
	void bvopCheckBoxClicked(const bool);
	void defaultPushButtonClicked();
	void profileDefaultPushButtonClicked();
	void presetDefaultPushButtonClicked();
	void selectPass(const int);
	void selectPreset(const int);
	void selectTarget(const int);
	void selectProfile(const int);
	void selectFps(const int);
	void selectRez(const int);
	void updateSettings();
	void updateQualitySettings();
	void updateProfileSettings();

private:
	void setToolTips();
	QString formatedTip( const QString name, const QString defaults, const QString range, const QString details );
	QString formatedTip( const QString name, const QString defaults, const QString range, QStringList details );

	void applyPresetOnControls(const int);
	void applyPresetOnSettings(const int);
	void applyProfileOnControls(const int);
	void applyProfileOnSettings(const int);
	void enterUserDefinedSize();
	void enterUserDefinedFps();
	void enterUserDefinedTarget();
	void setMaxBitrate(const int);
	void updateControls();
	void populateFps(QComboBox *);
	void populateRez(QComboBox *);
	void populatePass();
	void populatePreset(QComboBox *);
	void populateTarget();
	void populateProfiles(QComboBox *, const int);

	void populateQuantizationTypes(QComboBox *);
	void populateFourcc();
	void populateMe_quality(QComboBox *);
	void populateVhq(QComboBox *, const int);

	// Tabs
	QTabWidget *tabWidget;
	QDialogButtonBox *buttonBox;
	QVBoxLayout *verticalLayout;
	QWidget *mainTab;
	QWidget *qualityTab;
	QWidget *profileTab;

	// Main tab
	QVBoxLayout *mainTabVLayout;
	QHBoxLayout *horizontalLayout;
	QGroupBox *mainGroupBox;
	QVBoxLayout *mainVLayout;
	QGridLayout *mainGrid1GLayout;
	QGridLayout *mainGrid2GLayout;
	QHBoxLayout *passHLayout;
	QLabel *passLabel;
	QComboBox *passComboBox;
	QHBoxLayout *profileHLayout;
	QLabel *profileLabel;
	QComboBox *profileComboBox;
	QLabel *rezLabel;
	QComboBox *rezComboBox;
	QLabel *fpsLabel;
	QComboBox *fpsComboBox;
	QHBoxLayout *presetHLayout;
	QLabel *presetLabel;
	QComboBox *presetComboBox;
	QGroupBox *enc_modeGroupBox;
	QVBoxLayout *enc_modeVLayout;
	QHBoxLayout *bitrateHLayout;
	QRadioButton *bitrateRadioButton;
	QSlider *bitrateSlider;
	QLineEdit *bitrateLineEdit;
	QHBoxLayout *quantizerHLayout;
	QRadioButton *quantizerRadioButton;
	QSlider *quantizerSlider;
	QLabel *quantizerLabel;
	QHBoxLayout *targetHLayout;
	QRadioButton *targetRadioButton;
	QComboBox *targetComboBox;
	QGroupBox *moreOptionsGroup;	
	QVBoxLayout *moreOptionsVLayout;
	QCheckBox *turboCheckBox;
	QCheckBox *cartoonCheckBox;
	QHBoxLayout *defaultHLayout;
	QPushButton *defaultPushButton;
	QSpacerItem *horizontalSpacer;
	QSpacerItem *verticalSpacer;

	// Quality tab
	QVBoxLayout *qualityTabVLayout;
	QHBoxLayout *presetHLayout_2;
	QLabel *presetLabel_2;
	QComboBox *presetComboBox_2;
	QGroupBox *qualityGroup;
	QVBoxLayout *qualityVLayout;
	QHBoxLayout *me_qualityHLayout;
	QComboBox *me_qualityComboBox;
	QLabel *me_qualityLabel;
	QHBoxLayout *vhqHLayout;
	QComboBox *vhqComboBox;
	QLabel *vhqLabel;
	QHBoxLayout *bhvqHLayout;
	QCheckBox *bvhqCheckBox;
	QCheckBox *hq_acCheckBox;
	QCheckBox *chroma_meCheckBox;
	QCheckBox *chroma_optCheckBox;
	QCheckBox *trellisCheckBox;
	QHBoxLayout *presetDefaultHLayout;
	QPushButton *presetDefaultPushButton;
	QSpacerItem *verticalSpacer_3;

	// Profile tab
	QVBoxLayout *profileVLayout;
	QLabel *profileLabel_2;
	QComboBox *profileComboBox_2;
	QGroupBox *profileDetailsGroupBox;
	QVBoxLayout *profileDetailsVLayout;
	QHBoxLayout *profileDetailsHLayout;
	QGridLayout *rezfps_2GLayout;
	QLabel *rezLabel_2;
	QComboBox *rezComboBox_2;
	QLabel *fpsLabel_2;
	QComboBox *fpsComboBox_2;
	QCheckBox *lumi_maskCheckBox;
	QCheckBox *interlacingCheckBox;
	QCheckBox *qpelCheckBox;
	QCheckBox *gmcCheckBox;
	QGroupBox *bvopGroupBox;
	QVBoxLayout *bvopVLayout;
	QHBoxLayout *max_bframesHLayout;
	QLineEdit *max_bframesLineEdit;
	QLabel *max_bframesLabel;
	QHBoxLayout *bquant_ratioHLayout;
	QLineEdit *bquant_ratioLineEdit;
	QLabel *bquant_ratioLabel;
	QHBoxLayout *bquant_offsetHLayout;
	QLineEdit *bquant_offsetLineEdit;
	QLabel *bquant_offsetLabel;
	QComboBox *quant_typeComboBox;
	QHBoxLayout *quant_typeHLayout;
	QLabel *quant_typeLabel;
	QComboBox *fourccComboBox;
	QHBoxLayout *fourccHLayout;
	QLabel *fourccLabel;
	QHBoxLayout *profileDefaultHLayout;
	QPushButton *profileDefaultPushButton;
	QSpacerItem *verticalSpacer_2;
	
	QSpacerItem *horizontalSpacer_2;
	QSpacerItem *horizontalSpacer_3;
	QSpacerItem *horizontalSpacer_4;
	QSpacerItem *horizontalSpacer_5;
	QSpacerItem *horizontalSpacer_6;
	QSpacerItem *horizontalSpacer_7;
	QSpacerItem *horizontalSpacer_8;
	QSpacerItem *horizontalSpacer_9;
	QSpacerItem *horizontalSpacer_10;
	QSpacerItem *horizontalSpacer_11;
	QSpacerItem *horizontalSpacer_12;
	QSpacerItem *horizontalSpacer_13;
	QSpacerItem *horizontalSpacer_14;

	encoder_video_settings_t *callerSettings;  // settings to modify
	encoder_video_settings_t *encSettings;  // local copy
	video_t *videoSource;  // for recommended stuff (rez, fps)

	QIntValidator *bitrateValidator;

	const double fpsMin; // defined in constructor init = 0.01
	const double fpsMax; // defined in constructor init = = 200.0

	enum Preset { CustomPreset = 0, VeryHQ, HQ, Fast, VeryFast };
	enum Profile { DivX = -10, MPEG4, Devices, Free = 0,  // profile sets are < 0
		DivxHandheld, DivxPortableNtsc, DivxPortablePal, DivxHomeTheatreNtsc, DivxHomeTheatrePal, DivxHighDef,
		Simple0, Simple1, Simple2, Simple3,
		AdvancedSimple0, AdvancedSimple1, AdvancedSimple2, 
		AdvancedSimple3, AdvancedSimple4, AdvancedSimple5,
		SmallSmartphones, LargeSmartphones, 
		Apple_iPhone, Apple_iPad, Apple_MacBook13, Apple_MacBook15, Apple_MacBook17, Apple_iMac, 
		Archos7, Archos10,
		BlackBerry, 
		Netbook10, Netbook12, 
		Laptop13, Laptop15, Laptop17, 
		Desktop	};
	enum Quantization { H263 = 0, MPEG };
	enum Size { widthMin = 96, widthMax = 1920,
		heightMin = 54, heightMax = 1080 };
	enum Bitrate { bitrateMin = 16, bitrateMax = 10000 };
	enum Target { targetsizeMin = 600, targetsizeMax = 9000 };
};

#endif
