QTfrontend/gameuiconfig.cpp
branchflibqtfrontend
changeset 8208 171da01bd04d
parent 8206 1633a6510834
child 8216 4a7535d17d57
equal deleted inserted replaced
8141:6482875b0d97 8208:171da01bd04d
    92     Form->ui.pageOptions->CBSavePassword->setChecked(savePwd);
    92     Form->ui.pageOptions->CBSavePassword->setChecked(savePwd);
    93 
    93 
    94     Form->ui.pageOptions->editNetPassword->installEventFilter(this);
    94     Form->ui.pageOptions->editNetPassword->installEventFilter(this);
    95 
    95 
    96     int passLength = value("net/passwordlength", 0).toInt();
    96     int passLength = value("net/passwordlength", 0).toInt();
    97     setNetPasswordLength(passLength);
    97     if (!savePwd) {
    98     if (savePwd == false) {
    98         Form->ui.pageOptions->editNetPassword->setEnabled(false);
    99         Form->ui.pageOptions->editNetPassword->setEnabled(savePwd);
       
   100         Form->ui.pageOptions->editNetPassword->setText("");
    99         Form->ui.pageOptions->editNetPassword->setText("");
   101         setNetPasswordLength(0);
   100         setNetPasswordLength(0);
       
   101     } else
       
   102     {
       
   103         setNetPasswordLength(passLength);
   102     }
   104     }
   103 
   105 
   104     delete netHost;
   106     delete netHost;
   105     netHost = new QString(value("net/ip", "").toString());
   107     netHost = new QString(value("net/ip", "").toString());
   106     netPort = value("net/port", 46631).toUInt();
   108     netPort = value("net/port", 46631).toUInt();
   137     }
   139     }
   138 }
   140 }
   139 
   141 
   140 void GameUIConfig::reloadVideosValues(void)
   142 void GameUIConfig::reloadVideosValues(void)
   141 {
   143 {
   142     Form->ui.pageVideos->framerateBox->setValue(value("videorec/fps",25).toUInt());
   144     // one pass with default values
   143     Form->ui.pageVideos->bitrateBox->setValue(value("videorec/bitrate",400).toUInt());
   145     Form->ui.pageOptions->setDefaultOptions();
   144     bool useGameRes = value("videorec/usegameres",true).toBool();
   146 
       
   147     // then load user configuration
       
   148     Form->ui.pageOptions->framerateBox->setCurrentIndex(
       
   149             Form->ui.pageOptions->framerateBox->findData(
       
   150                         value("videorec/framerate", rec_Framerate()).toString() + " fps",
       
   151                     Qt::MatchExactly) );
       
   152     Form->ui.pageOptions->bitrateBox->setValue(value("videorec/bitrate", rec_Bitrate()).toUInt());
       
   153     bool useGameRes = value("videorec/usegameres",Form->ui.pageOptions->checkUseGameRes->isChecked()).toBool();
   145     if (useGameRes)
   154     if (useGameRes)
   146     {
   155     {
   147         QRect res = vid_Resolution();
   156         QRect res = vid_Resolution();
   148         Form->ui.pageVideos->widthEdit->setText(QString::number(res.width()));
   157         Form->ui.pageOptions->widthEdit->setText(QString::number(res.width()));
   149         Form->ui.pageVideos->heightEdit->setText(QString::number(res.height()));
   158         Form->ui.pageOptions->heightEdit->setText(QString::number(res.height()));
   150     }
   159     }
   151     else
   160     else
   152     {
   161     {
   153         Form->ui.pageVideos->widthEdit->setText(value("videorec/width","800").toString());
   162         Form->ui.pageOptions->widthEdit->setText(value("videorec/width","800").toString());
   154         Form->ui.pageVideos->heightEdit->setText(value("videorec/height","600").toString());
   163         Form->ui.pageOptions->heightEdit->setText(value("videorec/height","600").toString());
   155     }
   164     }
   156     Form->ui.pageVideos->checkUseGameRes->setChecked(useGameRes);
   165     Form->ui.pageOptions->checkUseGameRes->setChecked(useGameRes);
   157     Form->ui.pageVideos->checkRecordAudio->setChecked(value("videorec/audio",true).toBool());
   166     Form->ui.pageOptions->checkRecordAudio->setChecked(
   158     if (!Form->ui.pageVideos->tryCodecs(value("videorec/format","no").toString(),
   167             value("videorec/audio",Form->ui.pageOptions->checkRecordAudio->isChecked()).toBool() );
       
   168     if (!Form->ui.pageOptions->tryCodecs(value("videorec/format","no").toString(),
   159                                         value("videorec/videocodec","no").toString(),
   169                                         value("videorec/videocodec","no").toString(),
   160                                         value("videorec/audiocodec","no").toString()))
   170                                         value("videorec/audiocodec","no").toString()))
   161         Form->ui.pageVideos->setDefaultCodecs();
   171         Form->ui.pageOptions->setDefaultCodecs();
   162 }
   172 }
   163 
   173 
   164 QStringList GameUIConfig::GetTeamsList()
   174 QStringList GameUIConfig::GetTeamsList()
   165 {
   175 {
   166     QDir teamdir;
   176     QDir teamdir;
   175     return cleanedList;
   185     return cleanedList;
   176 }
   186 }
   177 
   187 
   178 void GameUIConfig::resizeToConfigValues()
   188 void GameUIConfig::resizeToConfigValues()
   179 {
   189 {
   180     Form->resize(value("frontend/width", 800).toUInt(), value("frontend/height", 600).toUInt());
   190     // fill 2/3 of the screen desktop
       
   191     const QRect deskSize = QApplication::desktop()->screenGeometry(-1);
       
   192     Form->resize(value("frontend/width", deskSize.width()*2/3).toUInt(),
       
   193                  value("frontend/height", deskSize.height()*2/3).toUInt());
       
   194 
       
   195     // move the window to the center of the screen
       
   196     QPoint center = QApplication::desktop()->availableGeometry(-1).center();
       
   197     center.setX(center.x() - (Form->width()/2));
       
   198     center.setY(center.y() - (Form->height()/2));
       
   199     Form->move(center);
   181 }
   200 }
   182 
   201 
   183 void GameUIConfig::SaveOptions()
   202 void GameUIConfig::SaveOptions()
   184 {
   203 {
   185     setValue("video/resolution", Form->ui.pageOptions->CBResolution->currentText());
   204     setValue("video/resolution", Form->ui.pageOptions->CBResolution->currentText());
   268         QStandardItemModel * model = DataManager::instance().colorsModel();
   287         QStandardItemModel * model = DataManager::instance().colorsModel();
   269         for(int i = model->rowCount() - 1; i >= 0; --i)
   288         for(int i = model->rowCount() - 1; i >= 0; --i)
   270             setValue(QString("colors/color%1").arg(i), model->item(i)->data());
   289             setValue(QString("colors/color%1").arg(i), model->item(i)->data());
   271     }
   290     }
   272 
   291 
   273     Form->gameSettings->sync();
   292     sync();
   274 }
   293 }
   275 
   294 
   276 void GameUIConfig::SaveVideosOptions()
   295 void GameUIConfig::SaveVideosOptions()
   277 {
   296 {
   278     QRect res = rec_Resolution();
   297     QRect res = rec_Resolution();
   279     setValue("videorec/format", AVFormat());
   298     setValue("videorec/format", AVFormat());
   280     setValue("videorec/videocodec", videoCodec());
   299     setValue("videorec/videocodec", videoCodec());
   281     setValue("videorec/audiocodec", audioCodec());
   300     setValue("videorec/audiocodec", audioCodec());
   282     setValue("videorec/fps", rec_Framerate());
   301     setValue("videorec/framerate", rec_Framerate());
   283     setValue("videorec/bitrate", rec_Bitrate());
   302     setValue("videorec/bitrate", rec_Bitrate());
   284     setValue("videorec/width", res.width());
   303     setValue("videorec/width", res.width());
   285     setValue("videorec/height", res.height());
   304     setValue("videorec/height", res.height());
   286     setValue("videorec/usegameres", Form->ui.pageVideos->checkUseGameRes->isChecked());
   305     setValue("videorec/usegameres", Form->ui.pageOptions->checkUseGameRes->isChecked());
   287     setValue("videorec/audio", recordAudio());
   306     setValue("videorec/audio", recordAudio());
   288 
   307 
   289     Form->gameSettings->sync();
   308     sync();
       
   309 }
       
   310 
       
   311 void GameUIConfig::setValue(const QString &key, const QVariant &value)
       
   312 {
       
   313     QSettings::setValue(key, value);
   290 }
   314 }
   291 
   315 
   292 QString GameUIConfig::language()
   316 QString GameUIConfig::language()
   293 {
   317 {
   294     return Form->ui.pageOptions->CBLanguage->itemData(Form->ui.pageOptions->CBLanguage->currentIndex()).toString();
   318     return Form->ui.pageOptions->CBLanguage->itemData(Form->ui.pageOptions->CBLanguage->currentIndex()).toString();
   445     return Form->ui.pageOptions->editNetPassword->text().size();
   469     return Form->ui.pageOptions->editNetPassword->text().size();
   446 }
   470 }
   447 
   471 
   448 bool GameUIConfig::netPasswordIsValid()
   472 bool GameUIConfig::netPasswordIsValid()
   449 {
   473 {
   450     return (netPasswordLength() == 0 || Form->ui.pageOptions->editNetPassword->text() != QString(netPasswordLength(), '\0'));
   474     return (netPasswordLength() == 0 || Form->ui.pageOptions->editNetPassword->text() != QString(netPasswordLength(), '*'));
   451 }
   475 }
   452 
   476 
   453 // When hedgewars launches, the password field is set with null characters. If the user tries to edit the field and there are such characters, then clear the field
   477 // When hedgewars launches, the password field is set with null characters. If the user tries to edit the field and there are such characters, then clear the field
   454 bool GameUIConfig::eventFilter(QObject *object, QEvent *event)
   478 bool GameUIConfig::eventFilter(QObject *object, QEvent *event)
   455 {
   479 {
   470 
   494 
   471 void GameUIConfig::setNetPasswordLength(int passwordLength)
   495 void GameUIConfig::setNetPasswordLength(int passwordLength)
   472 {
   496 {
   473     if (passwordLength > 0)
   497     if (passwordLength > 0)
   474     {
   498     {
   475         Form->ui.pageOptions->editNetPassword->setText(QString(passwordLength, '\0'));
   499         Form->ui.pageOptions->editNetPassword->setText(QString(passwordLength, '*'));
   476     }
   500     }
   477     else
   501     else
   478     {
   502     {
   479         Form->ui.pageOptions->editNetPassword->setText("");
   503         Form->ui.pageOptions->editNetPassword->setText("");
   480     }
   504     }
   485     return Form->ui.pageOptions->volumeBox->value() * 128 / 100;
   509     return Form->ui.pageOptions->volumeBox->value() * 128 / 100;
   486 }
   510 }
   487 
   511 
   488 QString GameUIConfig::AVFormat()
   512 QString GameUIConfig::AVFormat()
   489 {
   513 {
   490     return Form->ui.pageVideos->format();
   514     return Form->ui.pageOptions->format();
   491 }
   515 }
   492 
   516 
   493 QString GameUIConfig::videoCodec()
   517 QString GameUIConfig::videoCodec()
   494 {
   518 {
   495     return Form->ui.pageVideos->videoCodec();
   519     return Form->ui.pageOptions->videoCodec();
   496 }
   520 }
   497 
   521 
   498 QString GameUIConfig::audioCodec()
   522 QString GameUIConfig::audioCodec()
   499 {
   523 {
   500     return Form->ui.pageVideos->audioCodec();
   524     return Form->ui.pageOptions->audioCodec();
   501 }
   525 }
   502 
   526 
   503 QRect GameUIConfig::rec_Resolution()
   527 QRect GameUIConfig::rec_Resolution()
   504 {
   528 {
   505     if (Form->ui.pageVideos->checkUseGameRes->isChecked())
   529     if (Form->ui.pageOptions->checkUseGameRes->isChecked())
   506         return vid_Resolution();
   530         return vid_Resolution();
   507     QRect res(0,0,0,0);
   531     QRect res(0,0,0,0);
   508     res.setWidth(Form->ui.pageVideos->widthEdit->text().toUInt());
   532     res.setWidth(Form->ui.pageOptions->widthEdit->text().toUInt());
   509     res.setHeight(Form->ui.pageVideos->heightEdit->text().toUInt());
   533     res.setHeight(Form->ui.pageOptions->heightEdit->text().toUInt());
   510     return res;
   534     return res;
   511 }
   535 }
   512 
   536 
   513 int GameUIConfig::rec_Framerate()
   537 int GameUIConfig::rec_Framerate()
   514 {
   538 {
   515     return Form->ui.pageVideos->framerateBox->value();
   539     // remove the "fps" label
       
   540     QString fpsText = Form->ui.pageOptions->framerateBox->currentText();
       
   541     QStringList fpsList = fpsText.split(" ");
       
   542     return fpsList.first().toInt();
   516 }
   543 }
   517 
   544 
   518 int GameUIConfig::rec_Bitrate()
   545 int GameUIConfig::rec_Bitrate()
   519 {
   546 {
   520     return Form->ui.pageVideos->bitrateBox->value();
   547     return Form->ui.pageOptions->bitrateBox->value();
   521 }
   548 }
   522 
   549 
   523 bool GameUIConfig::recordAudio()
   550 bool GameUIConfig::recordAudio()
   524 {
   551 {
   525     return Form->ui.pageVideos->checkRecordAudio->isChecked();
   552     return Form->ui.pageOptions->checkRecordAudio->isChecked();
   526 }
   553 }