QTfrontend/gameuiconfig.cpp
changeset 8183 9b1c206a6cf2
parent 8151 25b95d6224fc
parent 8179 a1ffcb559f99
child 8190 92792d48574b
equal deleted inserted replaced
8151:25b95d6224fc 8183:9b1c206a6cf2
    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();
   268         QStandardItemModel * model = DataManager::instance().colorsModel();
   270         QStandardItemModel * model = DataManager::instance().colorsModel();
   269         for(int i = model->rowCount() - 1; i >= 0; --i)
   271         for(int i = model->rowCount() - 1; i >= 0; --i)
   270             setValue(QString("colors/color%1").arg(i), model->item(i)->data());
   272             setValue(QString("colors/color%1").arg(i), model->item(i)->data());
   271     }
   273     }
   272 
   274 
   273     Form->gameSettings->sync();
   275     sync();
   274 }
   276 }
   275 
   277 
   276 void GameUIConfig::SaveVideosOptions()
   278 void GameUIConfig::SaveVideosOptions()
   277 {
   279 {
   278     QRect res = rec_Resolution();
   280     QRect res = rec_Resolution();
   284     setValue("videorec/width", res.width());
   286     setValue("videorec/width", res.width());
   285     setValue("videorec/height", res.height());
   287     setValue("videorec/height", res.height());
   286     setValue("videorec/usegameres", Form->ui.pageOptions->checkUseGameRes->isChecked());
   288     setValue("videorec/usegameres", Form->ui.pageOptions->checkUseGameRes->isChecked());
   287     setValue("videorec/audio", recordAudio());
   289     setValue("videorec/audio", recordAudio());
   288 
   290 
   289     Form->gameSettings->sync();
   291     sync();
       
   292 }
       
   293 
       
   294 void GameUIConfig::setValue(const QString &key, const QVariant &value)
       
   295 {
       
   296     qDebug() << "[settings]" << key << value;
       
   297     QSettings::setValue(key, value);
   290 }
   298 }
   291 
   299 
   292 QString GameUIConfig::language()
   300 QString GameUIConfig::language()
   293 {
   301 {
   294     return Form->ui.pageOptions->CBLanguage->itemData(Form->ui.pageOptions->CBLanguage->currentIndex()).toString();
   302     return Form->ui.pageOptions->CBLanguage->itemData(Form->ui.pageOptions->CBLanguage->currentIndex()).toString();
   445     return Form->ui.pageOptions->editNetPassword->text().size();
   453     return Form->ui.pageOptions->editNetPassword->text().size();
   446 }
   454 }
   447 
   455 
   448 bool GameUIConfig::netPasswordIsValid()
   456 bool GameUIConfig::netPasswordIsValid()
   449 {
   457 {
   450     return (netPasswordLength() == 0 || Form->ui.pageOptions->editNetPassword->text() != QString(netPasswordLength(), '\0'));
   458     return (netPasswordLength() == 0 || Form->ui.pageOptions->editNetPassword->text() != QString(netPasswordLength(), '*'));
   451 }
   459 }
   452 
   460 
   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
   461 // 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)
   462 bool GameUIConfig::eventFilter(QObject *object, QEvent *event)
   455 {
   463 {
   470 
   478 
   471 void GameUIConfig::setNetPasswordLength(int passwordLength)
   479 void GameUIConfig::setNetPasswordLength(int passwordLength)
   472 {
   480 {
   473     if (passwordLength > 0)
   481     if (passwordLength > 0)
   474     {
   482     {
   475         Form->ui.pageOptions->editNetPassword->setText(QString(passwordLength, '\0'));
   483         Form->ui.pageOptions->editNetPassword->setText(QString(passwordLength, '*'));
   476     }
   484     }
   477     else
   485     else
   478     {
   486     {
   479         Form->ui.pageOptions->editNetPassword->setText("");
   487         Form->ui.pageOptions->editNetPassword->setText("");
   480     }
   488     }