82048367bf54f26551d3bd55dd9c40b4f28f0e22
[bertos.git] / emul / emulkbd.h
1 /**
2  * \file
3  * <!--
4  * This file is part of BeRTOS.
5  *
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.
10  *
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.
15  *
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
19  *
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.
28  *
29  * Copyright 2006 Develer S.r.l. (http://www.develer.com/)
30  * Copyright 2001 Bernardo Innocenti <bernie@codewiz.org>
31  *
32  * -->
33  *
34  * \version $Id$
35  *
36  * \author Bernardo Innocenti <bernie@develer.com>
37  *
38  * \brief QT-based widget for leyboard emulation (interface)
39  */
40
41 #if !defined(EMULKBD_H)
42 #define EMULKBD_H
43
44 #if defined (_MSC_VER) && (_MSC_VER > 1000)
45 #pragma once
46 #endif // _MSC_VER > 1000
47
48 #include <QtGui/QFrame>
49
50 // fwd decl
51 class QGridLayout;
52 class EmulKey;
53
54 class EmulKbd : public QFrame
55 {
56         Q_OBJECT
57
58 // Data members
59 protected:
60         QGridLayout *layout;
61         int frame_width;
62         int active_row;
63
64 // Construction
65 public:
66         EmulKbd(QWidget *parent = 0, Qt::WFlags f = 0);
67         virtual ~EmulKbd();
68
69 // Public methods
70         void addKey(const char *label, int keycode, int row, int col, int matrix_row = -1, int matrix_col = -1);
71         void setRow(int row);
72         int readCols(void);
73
74 // Protected methods
75 protected:
76         void setKey(int row, int col, bool on);
77
78 // Base class overrides
79 protected:
80         virtual QSizePolicy sizePolicy() const;
81         virtual void resizeEvent(QResizeEvent *e);
82         virtual bool event(QEvent *e);
83
84 // Friends
85         friend class EmulKey;
86 };
87
88
89 // Private helper class for EmulKbd
90 // NOTE: with protected inheritance, dynamic_cast<> does not work (gcc 2.96)
91 #include <QtGui/qpushbutton.h>
92 class EmulKey : public QPushButton
93 {
94         Q_OBJECT
95
96 // Data members
97 protected:
98         int row, col;
99         int keycode;
100
101 // Construction
102 public:
103         EmulKey(EmulKbd *parent, const char *label, int keycode, int _row, int _col);
104         virtual ~EmulKey();
105
106 // superclass overrides
107         void setDown(bool enable);
108
109 protected slots:
110         void keyPressed(void);
111         void keyReleased(void);
112
113 // Friends
114 public:
115         friend class EmulKbd;
116 };
117
118 #endif // !defined(EMULKBD_H)
119