~timo-jyrinki/ubuntu/trusty/maliit-framework/fix_qt52

« back to all changes in this revision

Viewing changes to examples/apps/twofields/actionkeyfilter.cpp

  • Committer: Package Import Robot
  • Author(s): Ricardo Salveti de Araujo, Sergio Schvezov, Ricardo Salveti de Araujo
  • Date: 2013-07-23 19:47:04 UTC
  • mfrom: (1.1.2) (1.2.1 experimental)
  • Revision ID: package-import@ubuntu.com-20130723194704-1lsy1kmlda069cea
Tags: 0.99.0+git20130615+97e8335-0ubuntu1
[ Sergio Schvezov ]
* New build from HEAD 97e8335.
* Packaging import from lp:phablet-extras/maliit-framework.

[ Ricardo Salveti de Araujo ]
* debian/control: adding vcs and fixing dependencies
* General package cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <QKeyEvent>
2
 
#include <QLineEdit>
3
 
#include <QMessageBox>
4
 
#include <QString>
5
 
 
6
 
#include "actionkeyfilter.h"
7
 
 
8
 
ActionKeyFilter::ActionKeyFilter(QLineEdit *login, QLineEdit *password, QObject *parent)
9
 
:   QObject(parent),
10
 
    m_loginEdit(login),
11
 
    m_passwordEdit(password),
12
 
    m_enterLoginAccepts(true),
13
 
    m_enterPasswordAccepts(true)
14
 
{
15
 
    // EMPTY
16
 
}
17
 
 
18
 
bool ActionKeyFilter::enterLoginAccepts() const
19
 
{
20
 
    return m_enterLoginAccepts;
21
 
}
22
 
 
23
 
bool ActionKeyFilter::enterPasswordAccepts() const
24
 
{
25
 
    return m_enterPasswordAccepts;
26
 
}
27
 
 
28
 
void ActionKeyFilter::setEnterLoginAccepts(bool accepts)
29
 
{
30
 
    m_enterLoginAccepts = accepts;
31
 
}
32
 
 
33
 
void ActionKeyFilter::setEnterPasswordAccepts(bool accepts)
34
 
{
35
 
    m_enterPasswordAccepts = accepts;
36
 
}
37
 
 
38
 
bool ActionKeyFilter::eventFilter(QObject *obj, QEvent *event)
39
 
{
40
 
    if (not event) {
41
 
        return false;
42
 
    }
43
 
    if (event->type() != QEvent::KeyPress) {
44
 
        return false;
45
 
    }
46
 
 
47
 
    QKeyEvent* keyEvent(static_cast<QKeyEvent*>(event));
48
 
 
49
 
    if (keyEvent->key() != Qt::Key_Return) {
50
 
        return false;
51
 
    }
52
 
 
53
 
    if ((obj == m_loginEdit) and m_enterLoginAccepts) {
54
 
        m_passwordEdit->setFocus(Qt::OtherFocusReason);
55
 
        return true;
56
 
    } else if ((obj == m_passwordEdit) and m_enterPasswordAccepts) {
57
 
        QString message;
58
 
        QMessageBox::Icon icon;
59
 
 
60
 
        if (m_loginEdit->text().isEmpty() || m_passwordEdit->text().isEmpty()) {
61
 
            message = "Please enter your credentials.";
62
 
            icon = QMessageBox::Warning;
63
 
        } else {
64
 
            message = "Login successfull!";
65
 
            icon = QMessageBox::Information;
66
 
        }
67
 
 
68
 
        QMessageBox messageBox;
69
 
 
70
 
        messageBox.setText(message);
71
 
        messageBox.addButton("OK", QMessageBox::AcceptRole);
72
 
        messageBox.setIcon(icon);
73
 
        messageBox.exec();
74
 
        return true;
75
 
    }
76
 
    return false;
77
 
}