File: simelineedit.cpp

package info (click to toggle)
guidedog 1.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 372 kB
  • ctags: 161
  • sloc: cpp: 2,118; sh: 84; makefile: 14
file content (86 lines) | stat: -rw-r--r-- 2,717 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/***************************************************************************
                               simelineedit.cpp  -
                             -------------------
    begin                : Sat May 12 23:25:00 CET 2001
    copyright            : (C) 2000-2001 by Simon Edwards
    email                : simon@simonzone.com
 ***************************************************************************/
/***************************************************************************
    Converted to a pure Qt5 application
    begin                : December 2014
    by                   : Antonio Martins
    email                : digiplan.pt@gmail.com
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "simelineedit.h"

#include <QValidator>
#include <QKeyEvent>


/*!
 * \brief SimeLineEdit::SimeLineEdit Constructor
 * \param parent
 */
SimeLineEdit::SimeLineEdit(QWidget *parent) : QLineEdit(parent) {
}


/*!
 * \brief SimeLineEdit::~SimeLineEdit
 */
SimeLineEdit::~SimeLineEdit() {
}


/*!
 * \brief SimeLineEdit::keyPressEvent
 * \param e
 * This is just a small modification for when the user hits the return key.
 * We just give the focus back to the parent widget.
 */
void SimeLineEdit::keyPressEvent(QKeyEvent *e) {
    QString t;
    
    t = text();
    QLineEdit::keyPressEvent(e);
    if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) {
        e->accept();
        if (t != text()) {
            emit textChanged(text());   // This is bullshit. If keyPressEvent() changed the text
            // then I expect a textChanged() signal to be emitted. I should not have to DIY.
        }
        if (parentWidget() != 0) {
            parentWidget()->setFocus();
        }
    }
}


/*!
 * \brief SimeLineEdit::focusOutEvent
 */
void SimeLineEdit::focusOutEvent() {
    const QValidator *v;
    QString t;
    int pos;

    v = validator();
    if (v != 0) {
        t = text();
        pos = 0;
        if (v->validate(t, pos) != QValidator::Acceptable) {
            v->fixup(t);
            setText(t);
        }
    }
}