From 2c229684805ca98f31698d3013d77237b7f6c40b Mon Sep 17 00:00:00 2001 From: apprb Date: Sun, 16 Nov 2014 02:16:56 +0900 Subject: [PATCH] improved usability --- src/widget/form/settings/privacyform.cpp | 15 ++++++++++++++- src/widget/form/settings/privacyform.h | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/widget/form/settings/privacyform.cpp b/src/widget/form/settings/privacyform.cpp index 6dc38804b..101eb41b0 100644 --- a/src/widget/form/settings/privacyform.cpp +++ b/src/widget/form/settings/privacyform.cpp @@ -36,6 +36,7 @@ PrivacyForm::PrivacyForm() : connect(bodyUI->cbEncryptTox, SIGNAL(clicked()), this, SLOT(onEncryptToxUpdated())); connect(bodyUI->nospamLineEdit, SIGNAL(editingFinished()), this, SLOT(setNospam())); connect(bodyUI->randomNosapamButton, SIGNAL(clicked()), this, SLOT(generateRandomNospam())); + connect(bodyUI->nospamLineEdit, SIGNAL(textChanged(QString)), this, SLOT(onNospamEdit())); } PrivacyForm::~PrivacyForm() @@ -156,10 +157,22 @@ void PrivacyForm::generateRandomNospam() QTime time = QTime::currentTime(); qsrand((uint)time.msec()); - uint8_t *newNospam = new uint8_t[4]; + uint8_t newNospam[4]; for (int i = 0; i < 4; i++) newNospam[i] = qrand() % 256; Core::getInstance()->setNospam(*reinterpret_cast(newNospam)); bodyUI->nospamLineEdit->setText(Core::getInstance()->getSelfId().noSpam); } + +void PrivacyForm::onNospamEdit() +{ + QString str = bodyUI->nospamLineEdit->text(); + int curs = bodyUI->nospamLineEdit->cursorPosition(); + if (str.length() != 8) + { + str = QString("00000000").replace(0, str.length(), str); + bodyUI->nospamLineEdit->setText(str); + bodyUI->nospamLineEdit->setCursorPosition(curs); + }; +} diff --git a/src/widget/form/settings/privacyform.h b/src/widget/form/settings/privacyform.h index e7a844b92..fc0e4eb0d 100644 --- a/src/widget/form/settings/privacyform.h +++ b/src/widget/form/settings/privacyform.h @@ -37,7 +37,7 @@ private slots: void onTypingNotificationEnabledUpdated(); void setNospam(); void generateRandomNospam(); - + void onNospamEdit(); void onEncryptLogsUpdated(); void onEncryptToxUpdated();