/*****************************************************************************
 *
 *  confvidx264mencoderdialog.h -- Input the x264 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 VIDEOSETTINGSX264DIALOG_H
#define VIDEOSETTINGSX264DIALOG_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/QSlider>
#include <QtGui/QSpacerItem>
#include <QtGui/QTabWidget>
#include <QtGui/QVBoxLayout>
#include <QtGui/QWidget>

class ConfVidX264MEncoderDialog : public QDialog
{
	Q_OBJECT

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

private slots:
	void accept();
	void bitrateSliderChanged(const int);
	void bitrateSlider_2Changed(const int);
	void bitrateLineEditChanged(const QString &);
	void bitrateLineEdit_2Changed(const QString &);
	void defaultPushButtonClicked();
	void rateDefaultPushButtonClicked();
	void frametypeDefaultPushButtonClicked();
	void analysisDefaultPushButtonClicked();
	void partitionsPushButtonClicked();
	void selectRez(const int);
	void selectFps(const int);
	void selectPreset(const int);
	void selectProfile(const int);
	void selectTune(const int);
	void selectPass(const int);
	void updateSettings();
	void updateRateControlSettings();
	void updateFrameTypeSettings();
	void updateVideoAnalysisSettings();

private:
	void setToolTip();
	void setWhatsThis();

	void applyPresetOnSettings(const int);
	void applyProfileOnSettings(const int);
	void applyTuneOnSettings(const int);
	void enterUserDefinedSize();
	void enterUserDefinedFps();
	void populatePresets();
	void populateProfiles();
	void populateTunes();
	void populatePass();
	void populateFps();
	void populateRez();
	void populateRateControlAqMode();
	void populateFrameTypeBAdapt();
	void populateAnalysisMe();
	void populateAnalysisSubMe();
	void populateAnalysisTrellis();
	void populateAnalysisDirect();
	void settingsUpdateSetEnabled(const bool);
	bool settingsUpdateIsDisabled();
	void updateControls();

	// Tabs
	QTabWidget *tabWidget;
	QDialogButtonBox *buttonBox;
	QVBoxLayout *verticalLayout;
	QWidget *mainTab;
	QWidget *ratecontrolTab;
	QWidget *frametypeTab;
	QWidget *analysisTab;

	// Main tab
	QVBoxLayout *mainTabVLayout;
	QGroupBox *frameGroupBox;
	QHBoxLayout *horizontalLayout;
	QComboBox *rezComboBox;
	QComboBox *fpsComboBox;
	QGroupBox *bitrateGroupBox;
	QVBoxLayout *bitrateVLayout;
	QHBoxLayout *bitrateHLayout;
	QSlider *bitrateSlider;
	QLineEdit *bitrateLineEdit;
	QGroupBox *presetGroupBox;
	QVBoxLayout *presetVLayout;
	QHBoxLayout *presetHLayout;
	QLabel *presetLabel;
	QComboBox *presetComboBox;
	QGroupBox *profileGroupBox;
	QVBoxLayout *profileRestrictionsVLayout;
	QHBoxLayout *profileRestrictionsHLayout;
	QLabel *profileLabel;
	QComboBox *profileComboBox;
	QHBoxLayout *interlacedHLayout;
	QCheckBox *interlacedCheckBox;
	QGroupBox *tuneGroupBox;
	QVBoxLayout *tuneVLayout;
	QHBoxLayout *tuneHLayout;
	QLabel *tuneLabel;
	QComboBox *tuneComboBox;
	QSpacerItem *verticalSpacer;
	QHBoxLayout *defaultHLayout;
	QPushButton *defaultPushButton;
	QSpacerItem *horizontalSpacer;

	// Rate control tab
	QVBoxLayout *ratecontrolTabVLayout;
	QGroupBox *qualityActivableGroup;
	QVBoxLayout *qualityActivableVLayout;
	QGroupBox *bitrateGroupBox_2;
	QVBoxLayout *bitrateVLayout_2;
	QHBoxLayout *bitrateHLayout_2;
	QSlider *bitrateSlider_2;
	QLineEdit *bitrateLineEdit_2;	
	QHBoxLayout *aq_modeHLayout;
	QComboBox *aq_modeComboBox;
	QLabel *aq_modeLabel;
	QHBoxLayout *aq_strengthHLayout;
	QLineEdit *aq_strengthLineEdit;
	QLabel *aq_strengthLabel;
	QSpacerItem *aq_strengthSpacer;
	QCheckBox *no_mbtreeCheckBox;
	QHBoxLayout *rc_lookaheadHLayout;
	QLineEdit *rc_lookaheadLineEdit;
	QLabel *rc_lookaheadLabel;
	QSpacerItem *rc_lookaheadSpacer;
	QHBoxLayout *qcompHLayout;
	QLineEdit *qcompLineEdit;
	QLabel *qcompLabel;
	QSpacerItem *qcompSpacer;
	QHBoxLayout *ipratioHLayout;
	QLineEdit *ipratioLineEdit;
	QLabel *ipratioLabel;
	QSpacerItem *ipratioSpacer;
	QHBoxLayout *pbratioHLayout;
	QLineEdit *pbratioLineEdit;
	QLabel *pbratioLabel;
	QSpacerItem *pbratioSpacer;
	QGroupBox *passGroupBox;
	QVBoxLayout *passVLayout;
	QHBoxLayout *passHLayout;
	QComboBox *passComboBox;
	QLabel *passLabel;
	QHBoxLayout *statsHLayout;
	QLineEdit *statsLineEdit;
	QLabel *statsLabel;
	QCheckBox *slow_firstpassCheckBox;
	QSpacerItem *ratecontrolVSpacer;
	QHBoxLayout *rateDefaultHLayout;
	QPushButton *rateDefaultPushButton;
	QSpacerItem *rateDefaultHSpacer;

	// Frame type tab
	QVBoxLayout *frametypeTabVLayout;
	QHBoxLayout *refHLayout;
	QLineEdit *refLineEdit;
	QLabel *refLabel;
	QSpacerItem *refSpacer;
	QHBoxLayout *scenecutHLayout;
	QLineEdit *scenecutLineEdit;
	QLabel *scenecutLabel;
	QSpacerItem *scenecutSpacer;
	QCheckBox *no_deblockCheckBox;
	QGroupBox *groupBox;
	QHBoxLayout *deblockHLayout;
	QSpacerItem *deblockSpacer1;
	QLabel *deblockAlphaLabel;
	QLineEdit *deblockAlphaLineEdit;
	QLabel *deblockBetaLabel;
	QLineEdit *deblockBetaLineEdit;
	QSpacerItem *deblockSpacer2;
	QCheckBox *no_cabacCheckBox;
	QHBoxLayout *bframesHLayout;
	QLineEdit *bframesLineEdit;
	QLabel *bframesLabel;
	QSpacerItem *bframesSpacer;
	QHBoxLayout *b_adaptHLayout;
	QComboBox *b_adaptComboBox;
	QLabel *b_adaptLabel;
	QSpacerItem *frametypeSpacer;
	QHBoxLayout *frametypeDefaultHLayout;
	QPushButton *frametypeDefaultPushButton;
	QSpacerItem *frametypeDefaultSpacer;

	// Video analysis tab
	QVBoxLayout *analysisTabVLayout;
	QHBoxLayout *meHLayout;
	QComboBox *meComboBox;
	QLabel *meLabel;
	QHBoxLayout *merangeHLayout;
	QLineEdit *merangeLineEdit;
	QLabel *merangeLabel;
	QSpacerItem *merangeSpacer;
	QHBoxLayout *submeHLayout;
	QComboBox *submeComboBox;
	QLabel *submeLabel;
	QHBoxLayout *partitionsHLayout;
	QLineEdit *partitionsLineEdit;
	QPushButton *partitionsPushButton;
	QLabel *partitionsLabel;
	QCheckBox *no_mixed_refsCheckBox;
	QCheckBox *no_8x8dctCheckBox;
	QCheckBox *no_fast_pskipCheckBox;
	QHBoxLayout *trellisHLayout;
	QComboBox *trellisComboBox;
	QLabel *trellisLabel;
	QHBoxLayout *directHLayout;
	QComboBox *directComboBox;
	QLabel *directLabel;
	QCheckBox *no_psyCheckBox;
	QGroupBox *psyrdGroupBox;
	QHBoxLayout *psyrdGroupHLayout;
	QSpacerItem *psyrdGroupSpacer1;
	QLabel *psy_rdoLabel;
	QLineEdit *psy_rdoLineEdit;
	QLabel *psy_trellisLabel;
	QLineEdit *psy_trellisLineEdit;
	QSpacerItem *psyrdGroupSpacer2;
	QCheckBox *no_dct_decimateCheckBox;
	QGroupBox *deadzoneGroupBox;
	QHBoxLayout *deadzoneHLayout;
	QSpacerItem *deadzoneSpacer1;
	QLabel *deadzone_interLabel;
	QLineEdit *deadzone_interLineEdit;
	QLabel *deadzone_intraLabel;
	QLineEdit *deadzone_intraLineEdit;
	QSpacerItem *deadzoneSpacer2;
	QCheckBox *no_weightbCheckBox;
	QSpacerItem *analysisSpacer;
	QHBoxLayout *analysisDefaultHLayout;
	QPushButton *analysisDefaultPushButton;
	QSpacerItem *analysisDefaultSpacer;

	encoder_video_settings_t *encSettings;  // to fill in with result
	video_t *videoSource;  // for recommended stuff (rez, fps)

	QIntValidator *bitrateValidator;

	bool settingsUpdateFrozen;  // to freeze settings (ignore control events)

	enum { notset = 0 }; // common for preset, profile, tuning which must starts at 1
	enum Preset { ultrafast = 1, veryfast, faster, fast, medium, slow, slower, veryslow, placebo};
	enum Profile { baseline = 1, main, high, lossless };
	enum Tuning { film = 1, animation, grain, psnr, ssim, fastdecode, touhou };
	enum Size { widthMin = 196, widthMax = 1920,
		heightMin = 154, heightMax = 1080 };
	const double fpsMin; // defined in constructor init = 0.01
	const double fpsMax; // defined in constructor init = = 200.0
};

#endif
