QTfrontend/gameuiconfig.cpp
changeset 5294 67278f1cba2c
parent 5262 505a90cfa377
child 5390 f41e87de8989
--- a/QTfrontend/gameuiconfig.cpp	Tue Jun 21 16:43:05 2011 +0400
+++ b/QTfrontend/gameuiconfig.cpp	Thu Jun 23 21:19:43 2011 +0400
@@ -20,7 +20,6 @@
 #include <QCheckBox>
 #include <QLineEdit>
 #include <QDesktopWidget>
-#include <QApplication>
 #include <QInputDialog>
 #include <QCryptographicHash>
 
@@ -30,6 +29,7 @@
 #include "pagenetserver.h"
 #include "hwconsts.h"
 #include "fpsedit.h"
+#include "HWApplication.h"
 
 GameUIConfig::GameUIConfig(HWForm * FormWidgets, const QString & fileName)
     : QSettings(fileName, QSettings::IniFormat)
@@ -75,6 +75,8 @@
 
     Form->ui.pageOptions->editNetNick->setText(netNick);
     
+    Form->ui.pageOptions->editNetPassword->installEventFilter(this);
+    
     int passLength = value("net/passwordlength", 0).toInt();
     setNetPasswordLength(passLength);
 
@@ -97,7 +99,7 @@
 
     Form->ui.pageOptions->CBLanguage->setCurrentIndex(Form->ui.pageOptions->CBLanguage->findData(value("misc/locale", "").toString()));
 
-    depth = QApplication::desktop()->depth();
+    depth = HWApplication::desktop()->depth();
     if (depth < 16) depth = 16;
     else if (depth > 16) depth = 32;
 }
@@ -327,6 +329,24 @@
     return (netPasswordLength() == 0 || Form->ui.pageOptions->editNetPassword->text() != QString(netPasswordLength(), '\0'));
 }
 
+// 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
+bool GameUIConfig::eventFilter(QObject *object, QEvent *event)
+{
+    if (event->type() == QEvent::FocusIn)
+    {
+        if ((QLineEdit *)object == Form->ui.pageOptions->editNetPassword)
+        {
+            if (!netPasswordIsValid())
+            {
+                Form->ui.pageOptions->editNetPassword->clear();
+            }
+        }
+    }
+    
+    // Don't filter anything
+    return false;
+}
+
 void GameUIConfig::setNetPasswordLength(int passwordLength)
 {
     if (passwordLength > 0)