QTfrontend/ui/page/pagevideos.cpp
changeset 7235 baa69bd025d9
child 7280 fd707afbc3a2
equal deleted inserted replaced
7231:f484455dd055 7235:baa69bd025d9
       
     1 /*
       
     2  * Hedgewars, a free turn based strategy game
       
     3  * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com>
       
     4  *
       
     5  * This program is free software; you can redistribute it and/or modify
       
     6  * it under the terms of the GNU General Public License as published by
       
     7  * the Free Software Foundation; version 2 of the License
       
     8  *
       
     9  * This program is distributed in the hope that it will be useful,
       
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12  * GNU General Public License for more details.
       
    13  *
       
    14  * You should have received a copy of the GNU General Public License
       
    15  * along with this program; if not, write to the Free Software
       
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
       
    17  */
       
    18 
       
    19 #include <QGridLayout>
       
    20 #include <QPushButton>
       
    21 #include <QGroupBox>
       
    22 #include <QComboBox>
       
    23 #include <QCheckBox>
       
    24 #include <QLabel>
       
    25 #include <QLineEdit>
       
    26 #include <QSpinBox>
       
    27 #include <QTableWidget>
       
    28 
       
    29 #include "pagevideos.h"
       
    30 #include "igbox.h"
       
    31 #include "libav_iteraction.h"
       
    32 #include "gameuiconfig.h"
       
    33 
       
    34 QLayout * PageVideos::bodyLayoutDefinition()
       
    35 {
       
    36     QGridLayout * pageLayout = new QGridLayout();
       
    37     pageLayout->setColumnStretch(0, 1);
       
    38     pageLayout->setColumnStretch(1, 1);
       
    39 
       
    40     {
       
    41         IconedGroupBox* groupRec = new IconedGroupBox(this);
       
    42         groupRec->setIcon(QIcon(":/res/graphicsicon.png"));
       
    43         groupRec->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
       
    44         groupRec->setTitle(QGroupBox::tr("Video recording options"));
       
    45         QGridLayout * RecLayout = new QGridLayout(groupRec);
       
    46 
       
    47         // Label for format
       
    48         QLabel *labelFormat = new QLabel(groupRec);
       
    49         labelFormat->setText(QLabel::tr("Format"));
       
    50         RecLayout->addWidget(labelFormat, 0, 0);
       
    51 
       
    52         // List of supported formats
       
    53         CBAVFormats = new QComboBox(groupRec);
       
    54         RecLayout->addWidget(CBAVFormats, 0, 1, 1, 4);
       
    55         LibavIteraction::instance().FillFormats(CBAVFormats);
       
    56 
       
    57         QFrame * hr = new QFrame(groupRec);
       
    58         hr->setFrameStyle(QFrame::HLine);
       
    59         hr->setLineWidth(3);
       
    60         hr->setFixedHeight(10);
       
    61         RecLayout->addWidget(hr, 1, 0, 1, 5);
       
    62 
       
    63         // Label for audio codec
       
    64         QLabel *labelACodec = new QLabel(groupRec);
       
    65         labelACodec->setText(QLabel::tr("Audio codec"));
       
    66         RecLayout->addWidget(labelACodec, 2, 0);
       
    67 
       
    68         // List of supported audio codecs
       
    69         CBAudioCodecs = new QComboBox(groupRec);
       
    70         RecLayout->addWidget(CBAudioCodecs, 2, 1, 1, 3);
       
    71 
       
    72         // record audio
       
    73         CBRecordAudio = new QCheckBox(groupRec);
       
    74         CBRecordAudio->setText(QCheckBox::tr("Record audio"));
       
    75         RecLayout->addWidget(CBRecordAudio, 2, 4);
       
    76 
       
    77         hr = new QFrame(groupRec);
       
    78         hr->setFrameStyle(QFrame::HLine);
       
    79         hr->setLineWidth(3);
       
    80         hr->setFixedHeight(10);
       
    81         RecLayout->addWidget(hr, 3, 0, 1, 5);
       
    82 
       
    83         // Label for video codec
       
    84         QLabel *labelVCodec = new QLabel(groupRec);
       
    85         labelVCodec->setText(QLabel::tr("Video codec"));
       
    86         RecLayout->addWidget(labelVCodec, 4, 0);
       
    87 
       
    88         // List of supported video codecs
       
    89         CBVideoCodecs = new QComboBox(groupRec);
       
    90         RecLayout->addWidget(CBVideoCodecs, 4, 1, 1, 4);
       
    91 
       
    92         // Label for resolution
       
    93         QLabel *labelRes = new QLabel(groupRec);
       
    94         labelRes->setText(QLabel::tr("Resolution"));
       
    95         RecLayout->addWidget(labelRes, 5, 0);
       
    96 
       
    97         // width
       
    98         widthEdit = new QLineEdit(groupRec);
       
    99         widthEdit->setValidator(new QIntValidator(this));
       
   100         RecLayout->addWidget(widthEdit, 5, 1);
       
   101 
       
   102         // x
       
   103         QLabel *labelX = new QLabel(groupRec);
       
   104         labelX->setText("X");
       
   105         RecLayout->addWidget(labelX, 5, 2);
       
   106 
       
   107         // height
       
   108         heightEdit = new QLineEdit(groupRec);
       
   109         heightEdit->setValidator(new QIntValidator(groupRec));
       
   110         RecLayout->addWidget(heightEdit, 5, 3);
       
   111 
       
   112         // use game res
       
   113         CBUseGameRes = new QCheckBox(groupRec);
       
   114         CBUseGameRes->setText(QCheckBox::tr("Use game resolution"));
       
   115         RecLayout->addWidget(CBUseGameRes, 5, 4);
       
   116 
       
   117         // Label for framerate
       
   118         QLabel *labelFramerate = new QLabel(groupRec);
       
   119         labelFramerate->setText(QLabel::tr("Framerate"));
       
   120         RecLayout->addWidget(labelFramerate, 6, 0);
       
   121 
       
   122         // framerate
       
   123         framerateBox = new QSpinBox(groupRec);
       
   124         framerateBox->setRange(1, 200);
       
   125         framerateBox->setSingleStep(1);
       
   126         RecLayout->addWidget(framerateBox, 6, 1);
       
   127 
       
   128         BtnDefaults = new QPushButton(groupRec);
       
   129         BtnDefaults->setText(QPushButton::tr("Set default options"));
       
   130         RecLayout->addWidget(BtnDefaults, 7, 0, 1, 5);
       
   131 
       
   132         pageLayout->addWidget(groupRec, 0, 0);
       
   133     }
       
   134 
       
   135     {
       
   136         IconedGroupBox* groupTable = new IconedGroupBox(this);
       
   137         //groupRec->setContentTopPadding(0);
       
   138         groupTable->setIcon(QIcon(":/res/graphicsicon.png"));
       
   139         groupTable->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
       
   140         groupTable->setTitle(QGroupBox::tr("Videos"));
       
   141 
       
   142         QStringList columns;
       
   143         columns << tr("Name") << tr("Lenght") << tr("...");
       
   144 
       
   145         filesTable = new QTableWidget(groupTable);
       
   146         filesTable->setColumnCount(3);
       
   147         filesTable->setHorizontalHeaderLabels(columns);
       
   148         QVBoxLayout *box = new QVBoxLayout(groupTable);
       
   149         box->addWidget(filesTable);
       
   150 
       
   151         pageLayout->addWidget(groupTable, 0, 1, 2, 1);
       
   152     }
       
   153 
       
   154     return pageLayout;
       
   155 }
       
   156 
       
   157 QLayout * PageVideos::footerLayoutDefinition()
       
   158 {
       
   159     return NULL;
       
   160 }
       
   161 
       
   162 void PageVideos::connectSignals()
       
   163 {
       
   164     connect(CBUseGameRes, SIGNAL(stateChanged(int)), this, SLOT(changeUseGameRes(int)));
       
   165     connect(CBRecordAudio, SIGNAL(stateChanged(int)), this, SLOT(changeRecordAudio(int)));
       
   166     connect(CBAVFormats, SIGNAL(currentIndexChanged(int)), this, SLOT(changeAVFormat(int)));
       
   167     connect(BtnDefaults, SIGNAL(clicked()), this, SLOT(setDefaultOptions()));
       
   168 }
       
   169 
       
   170 PageVideos::PageVideos(QWidget* parent) : AbstractPage(parent)
       
   171 {
       
   172     initPage();
       
   173 }
       
   174 
       
   175 void PageVideos::changeAVFormat(int index)
       
   176 {
       
   177     QString prevVCodec = getVideoCodec();
       
   178     QString prevACodec = getAudioCodec();
       
   179     CBVideoCodecs->clear();
       
   180     CBAudioCodecs->clear();
       
   181     LibavIteraction::instance().FillCodecs(CBAVFormats->itemData(index), CBVideoCodecs, CBAudioCodecs);
       
   182     if (CBAudioCodecs->count() == 0)
       
   183     {
       
   184         CBRecordAudio->setChecked(false);
       
   185         CBRecordAudio->setEnabled(false);
       
   186     }
       
   187     else
       
   188         CBRecordAudio->setEnabled(true);
       
   189     int iVCodec = CBVideoCodecs->findData(prevVCodec);
       
   190     if (iVCodec != -1)
       
   191         CBVideoCodecs->setCurrentIndex(iVCodec);
       
   192     int iACodec = CBAudioCodecs->findData(prevACodec);
       
   193     if (iACodec != -1)
       
   194         CBAudioCodecs->setCurrentIndex(iACodec);
       
   195 }
       
   196 
       
   197 void PageVideos::changeUseGameRes(int state)
       
   198 {
       
   199     if (state && config)
       
   200     {
       
   201         QRect resolution = config->vid_Resolution();
       
   202         widthEdit->setText(QString::number(resolution.width()));
       
   203         heightEdit->setText(QString::number(resolution.height()));
       
   204     }
       
   205     widthEdit->setEnabled(!state);
       
   206     heightEdit->setEnabled(!state);
       
   207 }
       
   208 
       
   209 void PageVideos::changeRecordAudio(int state)
       
   210 {
       
   211     CBAudioCodecs->setEnabled(!!state);
       
   212 }
       
   213 
       
   214 void PageVideos::setDefaultCodecs()
       
   215 {
       
   216     if (tryCodecs("mp4", "libx264", "libmp3lame"))
       
   217         return;
       
   218     if (tryCodecs("mp4", "libx264", "ac3_fixed"))
       
   219         return;
       
   220     if (tryCodecs("avi", "libxvid", "libmp3lame"))
       
   221         return;
       
   222     if (tryCodecs("avi", "libxvid", "ac3_fixed"))
       
   223         return;
       
   224     if (tryCodecs("avi", "mpeg4", "libmp3lame"))
       
   225         return;
       
   226     if (tryCodecs("avi", "mpeg4", "ac3_fixed"))
       
   227         return;
       
   228 
       
   229     // this shouldn't happen, just in case
       
   230     if (tryCodecs("ogg", "libtheora", "libvorbis"))
       
   231         return;
       
   232     tryCodecs("ogg", "libtheora", "flac");
       
   233 }
       
   234 
       
   235 void PageVideos::setDefaultOptions()
       
   236 {
       
   237     framerateBox->setValue(25);
       
   238     CBRecordAudio->setChecked(true);
       
   239     CBUseGameRes->setChecked(true);
       
   240     setDefaultCodecs();
       
   241 }
       
   242 
       
   243 bool PageVideos::tryCodecs(const QString & format, const QString & vcodec, const QString & acodec)
       
   244 {
       
   245     int iFormat = CBAVFormats->findData(format);
       
   246     if (iFormat == -1)
       
   247         return false;
       
   248     CBAVFormats->setCurrentIndex(iFormat);
       
   249 
       
   250     int iVCodec = CBVideoCodecs->findData(vcodec);
       
   251     if (iVCodec == -1)
       
   252         return false;
       
   253     CBVideoCodecs->setCurrentIndex(iVCodec);
       
   254 
       
   255     int iACodec = CBAudioCodecs->findData(acodec);
       
   256     if (iACodec == -1 && CBRecordAudio->isChecked())
       
   257         return false;
       
   258     if (iACodec != -1)
       
   259         CBAudioCodecs->setCurrentIndex(iACodec);
       
   260 
       
   261     return true;
       
   262 }