1
// =============================================================================
3
// --- kvi_lineedit_qt.cpp ---
5
// This file is part of the KVIrc IRC client distribution
6
// Copyright (C) 1999-2000 Szymon Stefanek (stefanek@tin.it)
8
// This program is FREE software. You can redistribute it and/or
9
// modify it under the terms of the GNU General Public License
10
// as published by the Free Software Foundation; either version 2
11
// of the License, or (at your opinion) any later version.
13
// This program is distributed in the HOPE that it will be USEFUL,
14
// but WITHOUT ANY WARRANTY; without even the implied warranty of
15
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
// See the GNU General Public License for more details.
18
// You should have received a copy of the GNU General Public License
19
// along with this program. If not, write to the Free Software Foundation,
20
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
// =============================================================================
24
#define _KVI_DEBUG_CHECK_RANGE_
25
#define _KVI_DEBUG_CLASS_NAME_ "KviLineEdit"
27
#include "kvi_lineedit_qt.h"
28
#include "kvi_malloc.h"
29
#include "kvi_mirccntrl.h"
31
KviLineEdit::KviLineEdit(QWidget *parent, const char *name)
32
: QLineEdit(parent, name)
34
setFocusPolicy(ClickFocus);
36
connect(this, SIGNAL(returnPressed(const QString &)), SLOT(slot_returnPressed(const QString &)));
39
KviLineEdit::~KviLineEdit()
44
QString KviLineEdit::text() const
46
KviStr text(QLineEdit::text());
47
char *p = (char *) kvi_malloc(text.len() + 1);
48
qstrcpy(p, text.ptr());
54
case '~': text.append(*p);
56
case 'b': text.append((char) KVI_TEXT_BOLD);
58
case 'c': text.append((char) KVI_TEXT_RESET);
60
case 'r': text.append((char) KVI_TEXT_REVERSE);
62
case 'u': text.append((char) KVI_TEXT_UNDERLINE);
65
text.append((char) KVI_TEXT_COLOR);
68
} else text.append(*p);
71
return QString(text.ptr());
74
void KviLineEdit::keyPressEvent(QKeyEvent *e)
76
if( e->state() & ControlButton ) {
79
QLineEdit::insert(QString("~b"));
82
QLineEdit::insert(QString("~"));
85
QLineEdit::insert(QString("~c"));
88
QLineEdit::insert(QString("~r"));
91
QLineEdit::insert(QString("~u"));
94
QLineEdit::keyPressEvent(e);
99
if( e->state() & AltButton ) {
100
// Qt::Key_Meta seems to substitute Key_Alt on some keyboards
101
if( (e->key() == Qt::Key_Alt) || (e->key() == Qt::Key_Meta) ) {
104
} else if( (e->ascii() >= '0') && (e->ascii() <= '9') ) {
105
m_szAltKeyCode += e->ascii();
109
QLineEdit::keyPressEvent(e);
112
void KviLineEdit::keyReleaseEvent(QKeyEvent *e)
114
if( (e->key() == Qt::Key_Alt) || (e->key() == Qt::Key_Meta) ) {
115
if( m_szAltKeyCode.hasData() ) {
117
char ch = m_szAltKeyCode.toChar(&bOk);
118
if( bOk && ch > ' ' ) {
119
insert(KviStr(ch).ptr());
128
void KviLineEdit::setText(const char *text)
142
case KVI_TEXT_REVERSE:
145
case KVI_TEXT_UNDERLINE:
156
QLineEdit::setText(QString(t.ptr()));
159
void KviLineEdit::insert(const char *newText)
173
case KVI_TEXT_REVERSE:
176
case KVI_TEXT_UNDERLINE:
187
QLineEdit::insert(QString(t.ptr()));
190
void KviLineEdit::slot_returnPressed(const QString &)
192
emit QLineEdit::returnPressed();
195
#include "m_kvi_lineedit_qt.moc"