| 1 | #include "codecdialog.h" |
| 2 | #include "codecdialog.moc" |
| 3 | |
| 4 | #include "pixmapbutton.h" |
| 5 | |
| 6 | #include "avm_cpuinfo.h" |
| 7 | #include "avm_creators.h" |
| 8 | #include "configfile.h" |
| 9 | #include "videoencoder.h" |
| 10 | |
| 11 | #include <qbitmap.h> |
| 12 | #include <qcheckbox.h> |
| 13 | #include <qcombobox.h> |
| 14 | #include <qgroupbox.h> |
| 15 | #include <qhbox.h> |
| 16 | #include <qlabel.h> |
| 17 | #include <qlayout.h> |
| 18 | #include <qlcdnumber.h> |
| 19 | #include <qlineedit.h> |
| 20 | #include <qlistbox.h> |
| 21 | #include <qlistview.h> |
| 22 | #include <qmessagebox.h> |
| 23 | #include <qpushbutton.h> |
| 24 | #include <qtextbrowser.h> |
| 25 | #include <qtextview.h> |
| 26 | #include <qvbox.h> |
| 27 | #include <qvgroupbox.h> |
| 28 | |
| 29 | #if QT_VERSION > 220 |
| 30 | #include <qdial.h> |
| 31 | #include <qvariant.h> |
| 32 | #include <qsplitter.h> |
| 33 | #endif |
| 34 | |
| 35 | #include <stdlib.h> |
| 36 | #include <stdio.h> |
| 37 | |
| 38 | |
| 39 | QavmPixmapButton::QavmPixmapButton(const char* ficon, QWidget* _parent) |
| 40 | :QToolButton( _parent ) |
| 41 | //:QPushButton( _parent ) |
| 42 | { |
| 43 | QString file = QString::fromLatin1( PIXMAP_PATH "/" ) |
| 44 | + QString::fromLatin1( ficon ) |
| 45 | + QString::fromLatin1( ".ppm" ); |
| 46 | QPixmap p(file); |
| 47 | p.setMask(p.createHeuristicMask()); |
| 48 | setIconSet(QIconSet(p)); |
| 49 | #if QT_VERSION >= 300 |
| 50 | // setFlat(TRUE); |
| 51 | #endif |
| 52 | //setFixedSize(p.width() + 8, p.height() + 8); |
| 53 | } |
| 54 | |
| 55 | QavmCodecDialog::Input::Input(QWidget* parent, const QString& title, const QString& defval) |
| 56 | :QavmOkDialog( parent, title, true ), val(defval) |
| 57 | { |
| 58 | setCaption( QString( tr("Enter new ") ) + title ); |
| 59 | |
| 60 | m_pEdit = new QLineEdit( val, this ); |
| 61 | gridLayout()->addWidget( m_pEdit, 0, 0 ); |
| 62 | } |
| 63 | |
| 64 | void QavmCodecDialog::Input::accept() |
| 65 | { |
| 66 | val = m_pEdit->text(); |
| 67 | return QDialog::accept(); |
| 68 | } |
| 69 | /* |
| 70 | QavmCodecDialog::QInputBoolean::QInputBoolean(QWidget* parent, |
| 71 | QString title, int defval) |
| 72 | :QavmOkDialog( parent, title, true ), _defval(defval) |
| 73 | { |
| 74 | char txt[256]; |
| 75 | sprintf(txt, "%d", defval); |
| 76 | setCaption( QString( "Enter new " ) + title ); |
| 77 | |
| 78 | m_pEdit = new QLineEdit( txt, this ); |
| 79 | gridLayout()->addWidget( m_pEdit, 0, 0 ); |
| 80 | } |
| 81 | */ |
| 82 | |
| 83 | |
| 84 | QavmCodecDialog::InputSelect::InputSelect(QWidget* parent, const QString& title, const avm::vector<avm::string>& options, int defval) |
| 85 | :QavmOkDialog( parent, title, true ), _options(options), _defval(defval) |
| 86 | { |
| 87 | setCaption( QString( tr("Enter new ") ) + title ); |
| 88 | |
| 89 | m_pBox = new QComboBox( QString().sprintf("%d", defval), this ); |
| 90 | gridLayout()->addWidget( m_pBox, 0, 0); |
| 91 | |
| 92 | int i = 0; |
| 93 | avm::vector<avm::string>::const_iterator it; |
| 94 | for(it = _options.begin(); it != _options.end(); it++) { |
| 95 | m_pBox->insertItem(_options[i].c_str(), i); |
| 96 | i++; |
| 97 | } |
| 98 | |
| 99 | m_pBox->setCurrentItem(_defval); |
| 100 | } |
| 101 | |
| 102 | void QavmCodecDialog::InputSelect::accept() |
| 103 | { |
| 104 | _defval = m_pBox->currentItem(); |
| 105 | return QDialog::accept(); |
| 106 | } |
| 107 | |
| 108 | QavmCodecDialog::QavmCodecDialog( QWidget* parent, const avm::vector<const avm::CodecInfo*>& codecs, |
| 109 | avm::CodecInfo::Direction dir ) |
| 110 | :QavmOkDialog( parent, "Select codec", true ), m_Codecs(codecs), |
| 111 | m_Direction(dir), m_pKeyframe(0), m_pQuality(0) |
| 112 | { |
| 113 | m_Order.resize(codecs.size()); |
| 114 | for (unsigned i = 0; i < codecs.size(); i++) |
| 115 | m_Order[i] = i; |
| 116 | |
| 117 | createGui(); |
| 118 | |
| 119 | //printf("CodecDialog: %x q:%d, %s\n", info.compressor, info.quality, info.cname.c_str()); |
| 120 | |
| 121 | #if QT_VERSION > 220 |
| 122 | connect(m_pListCodecs, SIGNAL( selectionChanged() ), this, SLOT( selectCodec() ) ); |
| 123 | #else |
| 124 | // Qt2.0 compatible - instead |
| 125 | connect(m_pListCodecs, SIGNAL( highlighted( int ) ), this, SLOT( selectCodec() ) ); |
| 126 | #endif |
| 127 | connect(m_pListCodecs, SIGNAL( selected( QListBoxItem* ) ), this, SLOT( selectCodec() ) ); |
| 128 | |
| 129 | codecUpdateList(); |
| 130 | setCurrent( 0 ); |
| 131 | } |
| 132 | |
| 133 | /* |
| 134 | * Destroys the object and frees any allocated resources |
| 135 | */ |
| 136 | QavmCodecDialog::~QavmCodecDialog() |
| 137 | { |
| 138 | // no need to delete child widgets, Qt does it all for us |
| 139 | } |
| 140 | |
| 141 | avm::VideoEncoderInfo QavmCodecDialog::getInfo() |
| 142 | { |
| 143 | avm::VideoEncoderInfo info; |
| 144 | int codec = getCurrent(); |
| 145 | info.compressor = m_Codecs[codec]->fourcc; |
| 146 | info.cname = m_Codecs[codec]->GetName(); |
| 147 | printf("CodecDialog returns: %x, %s\n", info.compressor, info.cname.c_str()); |
| 148 | |
| 149 | return info; |
| 150 | } |
| 151 | |
| 152 | int QavmCodecDialog::getCurrent() const |
| 153 | { |
| 154 | int c = m_pListCodecs->currentItem(); |
| 155 | return c < (int) m_Order.size() ? m_Order[c] : 0; |
| 156 | } |
| 157 | |
| 158 | void QavmCodecDialog::setCurrent( int c ) |
| 159 | { |
| 160 | m_pListCodecs->setCurrentItem( c ); |
| 161 | } |
| 162 | |
| 163 | void QavmCodecDialog::about() |
| 164 | { |
| 165 | int codec = getCurrent(); |
| 166 | if (codec < (int) m_Codecs.size()) |
| 167 | QMessageBox::information( this, m_Codecs[codec]->GetName(), |
| 168 | QString("<p align=center>") + m_Codecs[codec]->GetAbout(), |
| 169 | QMessageBox::Ok ); |
| 170 | } |
| 171 | |
| 172 | void QavmCodecDialog::shortNames(int) |
| 173 | { |
| 174 | //selectCodec(); |
| 175 | codecUpdateList(); |
| 176 | } |
| 177 | |
| 178 | void QavmCodecDialog::accept() |
| 179 | { |
| 180 | return QDialog::accept(); |
| 181 | } |
| 182 | |
| 183 | void QavmCodecDialog::clickedAttr( QListViewItem* item ) |
| 184 | { |
| 185 | //const AttributeInfo& ai = m_Codecs[codec].encoder_info; |
| 186 | if (!item) |
| 187 | return; |
| 188 | QString str = item->text(1); |
| 189 | int codec = getCurrent(); |
| 190 | const avm::vector<avm::AttributeInfo> ci = m_Codecs[codec]->encoder_info; |
| 191 | int row = 0; |
| 192 | avm::vector<avm::AttributeInfo>::const_iterator it; |
| 193 | for (it = ci.begin(); it != ci.end(); row++, it++) |
| 194 | if (!strcmp(it->GetAbout(), str.ascii())) |
| 195 | { |
| 196 | if (it->GetMin() == 0 && it->GetMax() == 1) |
| 197 | { |
| 198 | avm::CodecSetAttr(*m_Codecs[codec], it->GetName(), |
| 199 | ((QCheckListItem*)item)->isOn() ? 1 : 0); |
| 200 | //printf("STR %s %d %d\n", str.ascii(), row, ((QCheckListItem*)item)->isOn()); |
| 201 | } |
| 202 | break; |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | // backward compatible method |
| 207 | void QavmCodecDialog::rightClickedAttr( QListViewItem* item, const QPoint&, int ) |
| 208 | { |
| 209 | clickedAttr(item); |
| 210 | } |
| 211 | |
| 212 | void QavmCodecDialog::changeAttr( QListViewItem* item ) |
| 213 | { |
| 214 | if (!item) |
| 215 | return; |
| 216 | |
| 217 | QString str = item->text(1); |
| 218 | QString qs; |
| 219 | int defval = 0; |
| 220 | float deffval = 0.; |
| 221 | const char* def_str; |
| 222 | int codec = getCurrent(); |
| 223 | bool setc = false; |
| 224 | //printf("Getting %s for %s\n", str.ascii(), m_Codecs[codec].GetName()); |
| 225 | Input* inp; |
| 226 | InputSelect* qit; |
| 227 | |
| 228 | const avm::AttributeInfo* ai = m_Codecs[codec]->FindAttribute( str.ascii(), |
| 229 | m_Direction ); |
| 230 | if (!ai) |
| 231 | return; |
| 232 | |
| 233 | switch(ai->kind) |
| 234 | { |
| 235 | case avm::AttributeInfo::Integer: |
| 236 | avm::CodecGetAttr(*m_Codecs[codec], ai->GetName(), &defval); |
| 237 | { |
| 238 | Input i(this, str + QString( tr(" value") ), qs.setNum(defval)); |
| 239 | if (i.exec() == QDialog::Accepted) |
| 240 | { |
| 241 | //cerr<<"Setting "<<it->GetName()<<" to "<<inp->value()<<" for "<<m_Codecs[codec].GetName()<<endl; |
| 242 | avm::CodecSetAttr(*m_Codecs[codec], ai->GetName(), i.getInt()); |
| 243 | setc = true; |
| 244 | } |
| 245 | } |
| 246 | break; |
| 247 | case avm::AttributeInfo::Select: |
| 248 | avm::CodecGetAttr(*m_Codecs[codec], ai->GetName(), &defval); |
| 249 | { |
| 250 | InputSelect i(this, str + QString( tr(" value") ), ai->options, defval); |
| 251 | if (i.exec() == QDialog::Accepted) |
| 252 | { |
| 253 | //cerr<<"Setting "<<it->GetName()<<" to "<<qit->value()<<" for "<<m_Codecs[codec].GetName()<<endl; |
| 254 | avm::CodecSetAttr(*m_Codecs[codec], ai->GetName(), i.value()); |
| 255 | setc = true; |
| 256 | } |
| 257 | } |
| 258 | break; |
| 259 | case avm::AttributeInfo::String: |
| 260 | avm::CodecGetAttr(*m_Codecs[codec], ai->GetName(), &def_str); |
| 261 | { |
| 262 | Input i(this, str + QString( tr(" value") ), def_str); |
| 263 | if (i.exec() == QDialog::Accepted) |
| 264 | { |
| 265 | //cerr<<"Setting "<<it->GetName()<<" to "<<qis->value()<<" for "<<m_Codecs[codec].GetName()<<endl; |
| 266 | avm::CodecSetAttr(*m_Codecs[codec], ai->GetName(), i.getString()); |
| 267 | setc = true; |
| 268 | } |
| 269 | } |
| 270 | break; |
| 271 | case avm::AttributeInfo::Float: |
| 272 | avm::CodecGetAttr(*m_Codecs[codec], ai->GetName(), &deffval); |
| 273 | { |
| 274 | Input i(this, str + QString( tr(" value") ), qs.setNum(deffval)); |
| 275 | if (i.exec() == QDialog::Accepted) |
| 276 | { |
| 277 | //cerr<<"Setting "<<it->GetName()<<" to "<<qis->value()<<" for "<<m_Codecs[codec].GetName()<<endl; |
| 278 | avm::CodecSetAttr(*m_Codecs[codec], ai->GetName(), i.getFloat()); |
| 279 | setc = true; |
| 280 | } |
| 281 | } |
| 282 | break; |
| 283 | } |
| 284 | if (setc) |
| 285 | selectCodec(); |
| 286 | } |
| 287 | |
| 288 | void QavmCodecDialog::selectCodec() |
| 289 | { |
| 290 | int codec = getCurrent(); |
| 291 | m_pTabAttr->clear(); |
| 292 | //m_pTabAttr->setSorting(0, false); |
| 293 | //m_pTabAttr->setSorting(1, false); |
| 294 | |
| 295 | if (m_Direction == avm::CodecInfo::Encode |
| 296 | || m_Direction == avm::CodecInfo::Both) |
| 297 | addAttributes(*m_Codecs[codec], m_Codecs[codec]->encoder_info); |
| 298 | |
| 299 | if (m_Direction == avm::CodecInfo::Decode |
| 300 | || m_Direction == avm::CodecInfo::Both) |
| 301 | addAttributes(*m_Codecs[codec], m_Codecs[codec]->decoder_info); |
| 302 | } |
| 303 | |
| 304 | void QavmCodecDialog::addAttributes(const avm::CodecInfo& cdi, const avm::vector<avm::AttributeInfo>& ci) |
| 305 | { |
| 306 | QListViewItem* litem = 0; |
| 307 | avm::vector<avm::AttributeInfo>::const_iterator it; |
| 308 | int i = 0; |
| 309 | bool use_short = (m_pShortBox->state() == QButton::On); |
| 310 | |
| 311 | m_pTabAttr->setEnabled( (ci.size() != 0) ); |
| 312 | |
| 313 | for (it = ci.begin(); it != ci.end(); it++) |
| 314 | { |
| 315 | //printf("attr %s\n", it->GetAbout()); |
| 316 | avm::string val = "<none>"; |
| 317 | int param; |
| 318 | float fparam; |
| 319 | bool check = false; |
| 320 | |
| 321 | switch (it->kind) |
| 322 | { |
| 323 | case avm::AttributeInfo::Integer: |
| 324 | if (avm::CodecGetAttr(cdi, it->GetName(), ¶m) == 0) |
| 325 | { |
| 326 | //val=itoa(param, tmp, 10); |
| 327 | check = (it->GetMin() == 0 && it->GetMax() == 1); |
| 328 | val.sprintf("%d", param); |
| 329 | } |
| 330 | break; |
| 331 | case avm::AttributeInfo::Select: |
| 332 | if (avm::CodecGetAttr(cdi, it->GetName(), ¶m) == 0) |
| 333 | { |
| 334 | //val=itoa(param, tmp, 10); |
| 335 | val.sprintf("%d", param); |
| 336 | val += " ( "; |
| 337 | val += it->options[param]; |
| 338 | val += " )"; |
| 339 | break; |
| 340 | } |
| 341 | case avm::AttributeInfo::String: |
| 342 | { |
| 343 | const char* n = 0; |
| 344 | avm::CodecGetAttr(cdi, it->GetName(), &n); |
| 345 | if (n) |
| 346 | val = n; |
| 347 | else |
| 348 | val[0] = 0; |
| 349 | } |
| 350 | break; |
| 351 | case avm::AttributeInfo::Float: |
| 352 | if (avm::CodecGetAttr(cdi, it->GetName(), &fparam) == 0) |
| 353 | { |
| 354 | //val=itoa(param, tmp, 10); |
| 355 | val.sprintf("%f", fparam); |
| 356 | } |
| 357 | break; |
| 358 | } |
| 359 | |
| 360 | QListViewItem* item; |
| 361 | const char* n = (use_short) ? it->GetName() : it->GetAbout(); |
| 362 | if (check) |
| 363 | { |
| 364 | item = new QCheckListItem( m_pTabAttr, "", |
| 365 | QCheckListItem::CheckBox ); |
| 366 | ((QCheckListItem*)item)->setOn( param ); |
| 367 | #if QT_VERSION > 220 |
| 368 | if (litem) item->moveItem( litem ); |
| 369 | #endif |
| 370 | } |
| 371 | else |
| 372 | { |
| 373 | item = new QListViewItem( m_pTabAttr, litem ); |
| 374 | item->setText( 0, val.c_str() ); |
| 375 | } |
| 376 | item->setText( 1, n ); |
| 377 | litem = item; |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | void QavmCodecDialog::createGui() |
| 382 | { |
| 383 | setCaption( tr( "Configure codecs" ) ); |
| 384 | |
| 385 | #if QT_VERSION > 220 |
| 386 | setSizeGripEnabled( TRUE ); |
| 387 | QSplitter* spl = new QSplitter( this ); |
| 388 | spl->setOpaqueResize( TRUE ); |
| 389 | #else |
| 390 | QHBox* spl = new QHBox( this ); |
| 391 | #endif |
| 392 | |
| 393 | gridLayout()->addMultiCellWidget( spl, 0, 3, 0, 0 ); |
| 394 | |
| 395 | // left |
| 396 | QVBox* vbl = new QVBox( spl ); |
| 397 | vbl->setMargin( 5 ); |
| 398 | |
| 399 | // Codecs list |
| 400 | QGroupBox* gb = new QVGroupBox( vbl ); |
| 401 | gb->setTitle( tr( "Codecs" ) ); |
| 402 | |
| 403 | m_pListCodecs = new QListBox( gb ); |
| 404 | |
| 405 | createMoveGroup( gb ); |
| 406 | |
| 407 | // right |
| 408 | vbl = new QVBox( spl ); |
| 409 | vbl->setMargin( 5 ); |
| 410 | |
| 411 | // Attributes list |
| 412 | gb = new QVGroupBox( vbl ); |
| 413 | gb->setTitle( tr( "Attributes" ) ); |
| 414 | //gb->setColumnLayout(0, Qt::Vertical); |
| 415 | m_pTabAttr = new QListView( gb ); |
| 416 | m_pTabAttr->addColumn( tr( "Value" ) ); |
| 417 | m_pTabAttr->addColumn( tr( "Attribute" ) ); |
| 418 | //m_pTabAttr->setColumnAlignment( 1, Qt::AlignRight ); |
| 419 | m_pTabAttr->setSorting( -1, true ); |
| 420 | //QListViewItem * item = new QListViewItem( m_pTabAttr, 0 ); |
| 421 | |
| 422 | //createLCD( vbl ); |
| 423 | |
| 424 | QHBox* hb = new QHBox( vbl ); |
| 425 | m_pShortBox = new QCheckBox( tr( "&Shortcuts" ), hb ); |
| 426 | QWidget* w = new QWidget( hb ); |
| 427 | hb->setStretchFactor( w, 1 ); |
| 428 | QButton* pAbout = new QPushButton( tr( "&About..." ), hb ); |
| 429 | w = new QWidget( hb ); |
| 430 | hb->setStretchFactor( w, 1 ); |
| 431 | connect( m_pShortBox, SIGNAL( stateChanged(int) ), this, SLOT( shortNames(int) ) ); |
| 432 | connect( pAbout, SIGNAL( clicked() ), this, SLOT( about() ) ); |
| 433 | |
| 434 | |
| 435 | #if QT_VERSION > 220 |
| 436 | connect( m_pTabAttr, SIGNAL( clicked( QListViewItem* ) ), this, SLOT( clickedAttr( QListViewItem* ) ) ); |
| 437 | #else |
| 438 | connect( m_pTabAttr, SIGNAL( rightButtonClicked( QListViewItem*, const QPoint&, int ) ), this, SLOT( rightClickedAttr( QListViewItem*, const QPoint&, int ) ) ); |
| 439 | #endif |
| 440 | |
| 441 | connect( m_pTabAttr, SIGNAL( doubleClicked( QListViewItem* ) ), this, SLOT( changeAttr( QListViewItem* ) ) ); |
| 442 | } |
| 443 | |
| 444 | void QavmCodecDialog::createLCD( QWidget* parent ) |
| 445 | { |
| 446 | #if QT_VERSION > 220 |
| 447 | QHBox* hbl = new QHBox( parent ); |
| 448 | // Quality |
| 449 | QGroupBox* gb = new QGroupBox( hbl ); |
| 450 | gb->setTitle( tr( "Quality" ) ); |
| 451 | gb->setMaximumHeight( 100 ); |
| 452 | gb->setColumnLayout( 0, Qt::Horizontal ); |
| 453 | QHBoxLayout* hl = new QHBoxLayout( gb->layout() ); |
| 454 | QDial* d = new QDial( gb ); |
| 455 | d->setMaxValue( 100 ); |
| 456 | d->setValue( 95 ); |
| 457 | m_pQuality = d; |
| 458 | m_pLCDNumber1 = new QLCDNumber( gb ); |
| 459 | m_pLCDNumber1->setFrameShadow( QLCDNumber::Raised ); |
| 460 | m_pLCDNumber1->setSegmentStyle( QLCDNumber::Flat ); |
| 461 | m_pLCDNumber1->setNumDigits( 3 ); |
| 462 | m_pLCDNumber1->setProperty( "intValue", 95 ); |
| 463 | |
| 464 | hl->addWidget( m_pQuality ); |
| 465 | hl->addWidget( m_pLCDNumber1 ); |
| 466 | |
| 467 | // KeyFrame frequency |
| 468 | gb = new QGroupBox( hbl ); |
| 469 | gb->setTitle( tr( "Keyframe frequency" ) ); |
| 470 | gb->setMaximumHeight( 100 ); |
| 471 | gb->setColumnLayout( 0, Qt::Horizontal ); |
| 472 | hl = new QHBoxLayout( gb->layout() ); |
| 473 | d = new QDial( gb ); |
| 474 | d->setMaxValue( 200 ); |
| 475 | d->setValue( 75 ); |
| 476 | d->setMinValue( 1 ); |
| 477 | m_pKeyframe = d; |
| 478 | m_pLCDNumber2 = new QLCDNumber( gb ); |
| 479 | m_pLCDNumber2->setSegmentStyle( QLCDNumber::Flat ); |
| 480 | m_pLCDNumber2->setNumDigits( 3 ); |
| 481 | m_pLCDNumber2->setProperty( "intValue", 75 ); |
| 482 | |
| 483 | hl->addWidget( m_pKeyframe ); |
| 484 | hl->addWidget( m_pLCDNumber2 ); |
| 485 | |
| 486 | // signals and slots connections |
| 487 | connect( m_pKeyframe, SIGNAL( valueChanged( int ) ), m_pLCDNumber2, SLOT( display( int ) ) ); |
| 488 | connect( m_pQuality, SIGNAL( valueChanged( int ) ), m_pLCDNumber1, SLOT( display( int ) ) ); |
| 489 | #endif |
| 490 | } |
| 491 | |
| 492 | void QavmCodecDialog::createMoveGroup( QWidget* parent ) |
| 493 | { |
| 494 | QHBox* hb = new QHBox( parent ); |
| 495 | hb->setMargin( 5 ); |
| 496 | //hb->setSpacing( 5 ); |
| 497 | |
| 498 | QWidget* w = new QWidget( hb ); |
| 499 | hb->setStretchFactor( w, 1 ); |
| 500 | |
| 501 | QButton* pTop = new QavmPixmapButton( "top", hb ); |
| 502 | QButton* pUp = new QavmPixmapButton( "up", hb ); |
| 503 | pUp->setAutoRepeat( TRUE ); |
| 504 | QButton* pDown = new QavmPixmapButton( "down", hb ); |
| 505 | pDown->setAutoRepeat( TRUE ); |
| 506 | QButton* pBottom = new QavmPixmapButton( "bottom", hb ); |
| 507 | |
| 508 | w = new QWidget( hb ); |
| 509 | hb->setStretchFactor( w, 1 ); |
| 510 | |
| 511 | connect( pTop, SIGNAL( clicked() ), this, SLOT( codecTop() ) ); |
| 512 | connect( pUp, SIGNAL( clicked() ), this, SLOT( codecUp() ) ); |
| 513 | connect( pDown, SIGNAL( clicked() ), this, SLOT( codecDown() ) ); |
| 514 | connect( pBottom, SIGNAL( clicked() ), this, SLOT( codecBottom() ) ); |
| 515 | } |
| 516 | |
| 517 | void QavmCodecDialog::codecMove(int dir) |
| 518 | { |
| 519 | //printf("MOVE %d\n", dir); |
| 520 | if (m_Order.size() < 2) |
| 521 | return; |
| 522 | unsigned c = m_pListCodecs->currentItem(); |
| 523 | switch (dir) |
| 524 | { |
| 525 | case 1: |
| 526 | if (c < (m_Order.size() - 1)) |
| 527 | { |
| 528 | unsigned cs = m_Order[c + 1]; |
| 529 | m_Order[c + 1] = m_Order[c]; |
| 530 | m_Order[c] = cs; |
| 531 | c++; |
| 532 | } |
| 533 | break; |
| 534 | case -1: |
| 535 | if (c > 0) |
| 536 | { |
| 537 | unsigned cs = m_Order[c - 1]; |
| 538 | m_Order[c - 1] = m_Order[c]; |
| 539 | m_Order[c] = cs; |
| 540 | c--; |
| 541 | } |
| 542 | break; |
| 543 | case 0: |
| 544 | for (unsigned i = c; i > 0; i--) |
| 545 | { |
| 546 | unsigned cs = m_Order[i - 1]; |
| 547 | m_Order[i - 1] = m_Order[i]; |
| 548 | m_Order[i] = cs; |
| 549 | } |
| 550 | break; |
| 551 | case -1000: |
| 552 | for (unsigned i = c; i < m_Order.size() - 1; i++) |
| 553 | { |
| 554 | unsigned cs = m_Order[i + 1]; |
| 555 | m_Order[i + 1] = m_Order[i]; |
| 556 | m_Order[i] = cs; |
| 557 | } |
| 558 | break; |
| 559 | } |
| 560 | |
| 561 | setCurrent( c ); |
| 562 | codecUpdateList(); |
| 563 | selectCodec(); |
| 564 | } |
| 565 | |
| 566 | void QavmCodecDialog::codecUpdateList() |
| 567 | { |
| 568 | bool use_short = (m_pShortBox->state() == QButton::On); |
| 569 | int codec = m_pListCodecs->currentItem(); |
| 570 | m_pListCodecs->clear(); |
| 571 | for (unsigned i = 0; i < m_Order.size(); i++) |
| 572 | { |
| 573 | const avm::CodecInfo& ci = *m_Codecs[m_Order[i]]; |
| 574 | const char* n = (use_short) ? ci.GetPrivateName() : ci.GetName(); |
| 575 | m_pListCodecs->insertItem( n ); |
| 576 | } |
| 577 | setCurrent( codec ); |
| 578 | } |