Merge commit '7298ebb'
This commit is contained in:
commit
5491c310a6
3 changed files with 71 additions and 2 deletions
|
@ -6,18 +6,26 @@
|
||||||
|
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
#include <QKeyEvent>
|
||||||
|
|
||||||
AskPassphraseDialog::AskPassphraseDialog(Mode mode, QWidget *parent) :
|
AskPassphraseDialog::AskPassphraseDialog(Mode mode, QWidget *parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
ui(new Ui::AskPassphraseDialog),
|
ui(new Ui::AskPassphraseDialog),
|
||||||
mode(mode),
|
mode(mode),
|
||||||
model(0)
|
model(0),
|
||||||
|
fCapsLock(false)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
ui->passEdit1->setMaxLength(MAX_PASSPHRASE_SIZE);
|
ui->passEdit1->setMaxLength(MAX_PASSPHRASE_SIZE);
|
||||||
ui->passEdit2->setMaxLength(MAX_PASSPHRASE_SIZE);
|
ui->passEdit2->setMaxLength(MAX_PASSPHRASE_SIZE);
|
||||||
ui->passEdit3->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)
|
switch(mode)
|
||||||
{
|
{
|
||||||
case Encrypt: // Ask passphrase x2
|
case Encrypt: // Ask passphrase x2
|
||||||
|
@ -188,3 +196,46 @@ void AskPassphraseDialog::textChanged()
|
||||||
}
|
}
|
||||||
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(acceptable);
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -34,9 +34,12 @@ private:
|
||||||
Ui::AskPassphraseDialog *ui;
|
Ui::AskPassphraseDialog *ui;
|
||||||
Mode mode;
|
Mode mode;
|
||||||
WalletModel *model;
|
WalletModel *model;
|
||||||
|
bool fCapsLock;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void textChanged();
|
void textChanged();
|
||||||
|
bool event(QEvent *event);
|
||||||
|
bool eventFilter(QObject *, QEvent *event);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ASKPASSPHRASEDIALOG_H
|
#endif // ASKPASSPHRASEDIALOG_H
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>589</width>
|
<width>589</width>
|
||||||
<height>228</height>
|
<height>239</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
@ -83,6 +83,21 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="4" column="1">
|
||||||
|
<widget class="QLabel" name="capsLabel">
|
||||||
|
<property name="styleSheet">
|
||||||
|
<string notr="true">#capsLabel {
|
||||||
|
font: bold;
|
||||||
|
}</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>TextLabel</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
|
Loading…
Reference in a new issue