QTfrontend/gameuiconfig.cpp
changeset 5294 67278f1cba2c
parent 5262 505a90cfa377
child 5390 f41e87de8989
equal deleted inserted replaced
5247:bf6d4bc531d2 5294:67278f1cba2c
    18 
    18 
    19 #include <QMessageBox>
    19 #include <QMessageBox>
    20 #include <QCheckBox>
    20 #include <QCheckBox>
    21 #include <QLineEdit>
    21 #include <QLineEdit>
    22 #include <QDesktopWidget>
    22 #include <QDesktopWidget>
    23 #include <QApplication>
       
    24 #include <QInputDialog>
    23 #include <QInputDialog>
    25 #include <QCryptographicHash>
    24 #include <QCryptographicHash>
    26 
    25 
    27 #include "gameuiconfig.h"
    26 #include "gameuiconfig.h"
    28 #include "hwform.h"
    27 #include "hwform.h"
    29 #include "pageoptions.h"
    28 #include "pageoptions.h"
    30 #include "pagenetserver.h"
    29 #include "pagenetserver.h"
    31 #include "hwconsts.h"
    30 #include "hwconsts.h"
    32 #include "fpsedit.h"
    31 #include "fpsedit.h"
       
    32 #include "HWApplication.h"
    33 
    33 
    34 GameUIConfig::GameUIConfig(HWForm * FormWidgets, const QString & fileName)
    34 GameUIConfig::GameUIConfig(HWForm * FormWidgets, const QString & fileName)
    35     : QSettings(fileName, QSettings::IniFormat)
    35     : QSettings(fileName, QSettings::IniFormat)
    36 {
    36 {
    37     Form = FormWidgets;
    37     Form = FormWidgets;
    73                 QLineEdit::Normal,
    73                 QLineEdit::Normal,
    74                 QDir::home().dirName());
    74                 QDir::home().dirName());
    75 
    75 
    76     Form->ui.pageOptions->editNetNick->setText(netNick);
    76     Form->ui.pageOptions->editNetNick->setText(netNick);
    77     
    77     
       
    78     Form->ui.pageOptions->editNetPassword->installEventFilter(this);
       
    79     
    78     int passLength = value("net/passwordlength", 0).toInt();
    80     int passLength = value("net/passwordlength", 0).toInt();
    79     setNetPasswordLength(passLength);
    81     setNetPasswordLength(passLength);
    80 
    82 
    81     delete netHost;
    83     delete netHost;
    82     netHost = new QString(value("net/ip", "").toString());
    84     netHost = new QString(value("net/ip", "").toString());
    95         Form->ui.pageOptions->CBAutoUpdate->setChecked(value("misc/autoUpdate", true).toBool());
    97         Form->ui.pageOptions->CBAutoUpdate->setChecked(value("misc/autoUpdate", true).toBool());
    96 #endif
    98 #endif
    97 
    99 
    98     Form->ui.pageOptions->CBLanguage->setCurrentIndex(Form->ui.pageOptions->CBLanguage->findData(value("misc/locale", "").toString()));
   100     Form->ui.pageOptions->CBLanguage->setCurrentIndex(Form->ui.pageOptions->CBLanguage->findData(value("misc/locale", "").toString()));
    99 
   101 
   100     depth = QApplication::desktop()->depth();
   102     depth = HWApplication::desktop()->depth();
   101     if (depth < 16) depth = 16;
   103     if (depth < 16) depth = 16;
   102     else if (depth > 16) depth = 32;
   104     else if (depth > 16) depth = 32;
   103 }
   105 }
   104 
   106 
   105 QStringList GameUIConfig::GetTeamsList()
   107 QStringList GameUIConfig::GetTeamsList()
   325 bool GameUIConfig::netPasswordIsValid()
   327 bool GameUIConfig::netPasswordIsValid()
   326 {
   328 {
   327     return (netPasswordLength() == 0 || Form->ui.pageOptions->editNetPassword->text() != QString(netPasswordLength(), '\0'));
   329     return (netPasswordLength() == 0 || Form->ui.pageOptions->editNetPassword->text() != QString(netPasswordLength(), '\0'));
   328 }
   330 }
   329 
   331 
       
   332 // 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
       
   333 bool GameUIConfig::eventFilter(QObject *object, QEvent *event)
       
   334 {
       
   335     if (event->type() == QEvent::FocusIn)
       
   336     {
       
   337         if ((QLineEdit *)object == Form->ui.pageOptions->editNetPassword)
       
   338         {
       
   339             if (!netPasswordIsValid())
       
   340             {
       
   341                 Form->ui.pageOptions->editNetPassword->clear();
       
   342             }
       
   343         }
       
   344     }
       
   345     
       
   346     // Don't filter anything
       
   347     return false;
       
   348 }
       
   349 
   330 void GameUIConfig::setNetPasswordLength(int passwordLength)
   350 void GameUIConfig::setNetPasswordLength(int passwordLength)
   331 {
   351 {
   332     if (passwordLength > 0)
   352     if (passwordLength > 0)
   333     {
   353     {
   334         Form->ui.pageOptions->editNetPassword->setText(QString(passwordLength, '\0'));
   354         Form->ui.pageOptions->editNetPassword->setText(QString(passwordLength, '\0'));