Move AT91 SPI register definitions.
[bertos.git] / emul / emulwin.cpp
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 2000, 2001 Bernardo Innocenti <bernie@codewiz.org>
31  *
32  * -->
33  *
34  * \version $Id$
35  *
36  * \author Bernardo Innocenti <bernie@develer.com>
37  *
38  * \brief Main Qt window for embedded applications emulator (implementation)
39  */
40
41 /*#*
42  *#* $Log$
43  *#* Revision 1.6  2006/09/19 17:49:04  bernie
44  *#* Reindent.
45  *#*
46  *#* Revision 1.5  2006/05/28 12:17:56  bernie
47  *#* Drop almost all the Qt3 cruft.
48  *#*
49  *#* Revision 1.4  2006/02/20 02:00:39  bernie
50  *#* Port to Qt 4.1.
51  *#*
52  *#* Revision 1.3  2006/02/15 09:11:17  bernie
53  *#* Add keyboard emulator.
54  *#*
55  *#* Revision 1.2  2006/01/16 03:51:51  bernie
56  *#* Fix boilerplate.
57  *#*
58  *#* Revision 1.1  2006/01/16 03:37:12  bernie
59  *#* Add emulator skeleton.
60  *#*
61  *#*/
62
63 #include "emulwin.h"
64
65 #include <drv/lcd_gfx_qt.h>
66 #include <emul/emul.h>
67 #include <emul/emulkbd.h>
68
69 #include <cassert>
70
71 #include <QtGui/QLayout>
72 #include <QtGui/QLabel>
73 #include <QtGui/QSlider>
74 #include <QtGui/QCheckBox>
75 #include <QtGui/QMenuBar>
76 #include <QtGui/QMessageBox>
77 #include <QtCore/QDateTime>
78 #include <QtCore/QTimer>
79 #include <QtGui/QApplication>
80 #include <QtGui/QCloseEvent>
81 using namespace Qt;
82
83 EmulWin::EmulWin(Emulator *e)
84 {
85         setWindowTitle(tr("DevLib Emul Demo"));
86         setAttribute(Qt::WA_DeleteOnClose);
87
88         // Create the menu bar
89         QMenu *file_menu = menuBar()->addMenu(tr("&File"));
90         file_menu->addAction(tr("&Quit"),
91                 e->emulApp, SLOT(closeAllWindows()), CTRL+Key_Q);
92
93         menuBar()->addSeparator();
94
95         QMenu *help_menu = menuBar()->addMenu(tr("&Help"));
96         help_menu->addAction(tr("&About"),
97                 this, SLOT(about()), Key_F1);
98
99         // Make a central widget to contain the other widgets
100         QWidget *central = new QWidget(this);
101         setCentralWidget(central);
102
103         // Create a layout to position the widgets
104         QHBoxLayout *box_main = new QHBoxLayout(central);
105
106         // Main layout
107         QVBoxLayout *box_right = new QVBoxLayout();
108         box_main->addLayout(box_right);
109
110                 // LCD
111                 QHBoxLayout *lay_lcd = new QHBoxLayout();
112                 box_right->addLayout(lay_lcd);
113                         lay_lcd->addStretch();
114                         lay_lcd->addWidget(e->emulLCD = new EmulLCD(central));
115                         lay_lcd->addStretch();
116
117                 // Keyboard
118                 box_right->addWidget(e->emulKbd = new EmulKbd(central));
119
120         // Setup keyboard: Label   Keycode     Row Col MRow MCol
121         e->emulKbd->addKey("^",    Key_Up,     0,  0,  0,   0);
122         e->emulKbd->addKey("v",    Key_Down,   1,  0,  0,   1);
123         e->emulKbd->addKey("OK",   Key_Return, 0,  1,  0,   2);
124         e->emulKbd->addKey("ESC",  Key_Escape, 1,  1,  0,   3);
125 }
126
127
128 EmulWin::~EmulWin()
129 {
130         emul->quit();
131 }
132
133
134 void EmulWin::closeEvent(QCloseEvent *ce)
135 {
136         ce->accept();
137 }
138
139
140 void EmulWin::about()
141 {
142     QMessageBox::about(this,
143                 "Embedded Application Emulator",
144                 "Version 0.1\n"
145                 "Copyright 2006 Develer S.r.l. (http://www.develer.com/)\n"
146                 "Copyright 2001, 2002, 2003, 2005 Bernardo Innocenti <bernie@codewiz.org>\n"
147                 "All rights reserved."
148         );
149 }
150
151 #include "emulwin_moc.cpp"