aboutsummaryrefslogtreecommitdiff
path: root/src/qt/askpassphrasedialog.cpp
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2011-12-12 15:03:16 -0500
committerGavin Andresen <gavinandresen@gmail.com>2011-12-12 15:03:16 -0500
commit5491c310a6c70220e32c123ba7b8ce3da3e26126 (patch)
tree9d1cb7abc7246d06a9b4f0e9218f5b331a53cade /src/qt/askpassphrasedialog.cpp
parent1d8b4cd544018814a064730ca62e9169f8456ccd (diff)
parent7298ebb432f541a6efb9d7e7a29f34da588a6b7f (diff)
Merge commit '7298ebb'v0.5.1rc1
Diffstat (limited to 'src/qt/askpassphrasedialog.cpp')
-rw-r--r--src/qt/askpassphrasedialog.cpp53
1 files changed, 52 insertions, 1 deletions
diff --git a/src/qt/askpassphrasedialog.cpp b/src/qt/askpassphrasedialog.cpp
index 24f622d637..f516169460 100644
--- a/src/qt/askpassphrasedialog.cpp
+++ b/src/qt/askpassphrasedialog.cpp
@@ -6,17 +6,25 @@
#include <QMessageBox>
#include <QPushButton>
+#include <QKeyEvent>
AskPassphraseDialog::AskPassphraseDialog(Mode mode, QWidget *parent) :
QDialog(parent),
ui(new Ui::AskPassphraseDialog),
mode(mode),
- model(0)
+ model(0),
+ fCapsLock(false)
{
ui->setupUi(this);
ui->passEdit1->setMaxLength(MAX_PASSPHRASE_SIZE);
ui->passEdit2->setMaxLength(MAX_PASSPHRASE_SIZE);
ui->passEdit3->setMaxLength(MAX_PASSPHRASE_SIZE);
+
+ // Setup Caps Lock detection.
+ ui->passEdit1->installEventFilter(this);
+ ui->passEdit2->installEventFilter(this);
+ ui->passEdit3->installEventFilter(this);
+ ui->capsLabel->clear();
switch(mode)
{
@@ -188,3 +196,46 @@ void AskPassphraseDialog::textChanged()
}
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(acceptable);
}
+
+bool AskPassphraseDialog::event(QEvent *event)
+{
+ // Detect Caps Lock key press.
+ if (event->type() == QEvent::KeyPress) {
+ QKeyEvent *ke = static_cast<QKeyEvent *>(event);
+ if (ke->key() == Qt::Key_CapsLock) {
+ fCapsLock = !fCapsLock;
+ }
+ if (fCapsLock) {
+ ui->capsLabel->setText(tr("Warning: The Caps Lock key is on."));
+ } else {
+ ui->capsLabel->clear();
+ }
+ }
+ return QWidget::event(event);
+}
+
+bool AskPassphraseDialog::eventFilter(QObject *, QEvent *event)
+{
+ /* Detect Caps Lock.
+ * There is no good OS-independent way to check a key state in Qt, but we
+ * can detect Caps Lock by checking for the following condition:
+ * Shift key is down and the result is a lower case character, or
+ * Shift key is not down and the result is an upper case character.
+ */
+ if (event->type() == QEvent::KeyPress) {
+ QKeyEvent *ke = static_cast<QKeyEvent *>(event);
+ QString str = ke->text();
+ if (str.length() != 0) {
+ const QChar *psz = str.unicode();
+ bool fShift = (ke->modifiers() & Qt::ShiftModifier) != 0;
+ if ((fShift && psz->isLower()) || (!fShift && psz->isUpper())) {
+ fCapsLock = true;
+ ui->capsLabel->setText(tr("Warning: The Caps Lock key is on."));
+ } else if (psz->isLetter()) {
+ fCapsLock = false;
+ ui->capsLabel->clear();
+ }
+ }
+ }
+ return false;
+}