4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright 2006 Develer S.r.l. (http://www.develer.com/)
30 * Copyright 2001 Bernie Innocenti <bernie@codewiz.org>
35 * \author Bernie Innocenti <bernie@codewiz.org>
37 * \brief QT-based widget for keyboard emulation (implementation)
43 #include <QtGui/QPainter>
44 #include <QtGui/QPixmap>
45 #include <QtGui/QSizePolicy>
46 #include <QtGui/QLayout>
47 #include <QtGui/QKeyEvent>
48 #include <QtCore/QEvent>
49 #include <QtCore/QSize>
50 #include <QtCore/QRect>
53 EmulKey::EmulKey(EmulKbd *kbd, const char *label, int _keycode, int _row, int _col) :
54 QPushButton(label, kbd),
58 // don't let the widget get focus
59 setFocusPolicy(Qt::NoFocus);
62 connect(this, SIGNAL(pressed()), this, SLOT(keyPressed()));
63 connect(this, SIGNAL(released()), this, SLOT(keyReleased()));
74 * Override standad QButton behaviour: we must also emit the signals.
77 void EmulKey::setDown(bool enable)
79 // let our superclass do everything else
80 QPushButton::setDown(enable);
90 void EmulKey::keyPressed(void)
92 static_cast<EmulKbd *>(parent())->setKey(row, col, true);
97 void EmulKey::keyReleased(void)
99 static_cast<EmulKbd *>(parent())->setKey(row, col, false);
103 EmulKbd::EmulKbd(QWidget *parent, Qt::WFlags f) :
105 layout(new QGridLayout(this)),
108 setFrameStyle(QFrame::Box | QFrame::Sunken);
110 setFocusPolicy(Qt::StrongFocus);
111 frame_width = frameWidth();
121 QSizePolicy EmulKbd::sizePolicy() const
123 return QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
127 void EmulKbd::resizeEvent(QResizeEvent *event)
129 // Let our superclass process the event first
130 QFrame::resizeEvent(event);
134 // handle key presses for all keys in keyboard
135 bool EmulKbd::event(QEvent *_e)
139 case QEvent::KeyPress:
140 case QEvent::KeyRelease:
142 QKeyEvent *e = static_cast<QKeyEvent *>(_e);
143 int keycode = e->key();
146 // ignore repeated keys
147 if (!e->isAutoRepeat())
150 for (QObjectList::const_iterator it(children().begin()); it != children().end(); ++it)
152 // only keys, not other children!
153 if ((*it)->metaObject() == &EmulKey::staticMetaObject)
154 // if ((key = dynamic_cast<EmulKey *>(*it)))
156 key = static_cast<EmulKey *>(*it);
159 if (key->keycode == keycode)
161 // yes, tell key to go down (or up)
162 key->setDown(_e->type() == QEvent::KeyPress);
172 // let superclass process this event
173 return QFrame::event(_e);
175 } // end switch(_e->type())
179 void EmulKbd::addKey(const char *label, int keycode, int row, int col, int matrix_row, int matrix_col)
181 if (matrix_row == -1)
183 if (matrix_col == -1)
186 layout->addWidget(new EmulKey(this, label, keycode, matrix_row, matrix_col), row, col);
191 void EmulKbd::setKey(int /*row*/, int /*col*/, bool /*on*/)
196 void EmulKbd::setRow(int r)
201 int EmulKbd::readCols(void)
207 for (int i = 0; (item = layout->itemAt(i)); ++i)
209 key = static_cast<EmulKey *>(item->widget());
210 if (key->row == active_row)
213 cols |= (1<<key->col);
219 extern "C" void emul_kbdSetRows(int r)
221 emul->emulKbd->setRow(r);
225 extern "C" int emul_kbdReadCols(void)
227 return emul->emulKbd->readCols();
230 #include "emulkbd_moc.cpp"