Rename myself
[bertos.git] / bertos / 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 Bernie Innocenti <bernie@codewiz.org>
31  *
32  * -->
33  *
34  * \version $Id$
35  *
36  * \author Bernie Innocenti <bernie@codewiz.org>
37  *
38  * \brief Main Qt window for embedded applications emulator (implementation)
39  */
40
41 #include "emulwin.h"
42
43 #include <drv/lcd_gfx_qt.h>
44 #include <emul/emul.h>
45 #include <emul/emulkbd.h>
46
47 #include <cassert>
48
49 #include <QtGui/QLayout>
50 #include <QtGui/QLabel>
51 #include <QtGui/QSlider>
52 #include <QtGui/QCheckBox>
53 #include <QtGui/QMenuBar>
54 #include <QtGui/QMessageBox>
55 #include <QtCore/QDateTime>
56 #include <QtCore/QTimer>
57 #include <QtGui/QApplication>
58 #include <QtGui/QCloseEvent>
59 using namespace Qt;
60
61 EmulWin::EmulWin(Emulator *e)
62 {
63         setWindowTitle(tr("BeRTOS Emul Demo"));
64         setAttribute(Qt::WA_DeleteOnClose);
65         setFixedSize(280,240);
66
67         // Create the menu bar
68         QMenu *file_menu = menuBar()->addMenu(tr("&File"));
69         file_menu->addAction(tr("&Quit"),
70                 e->emulApp, SLOT(closeAllWindows()), CTRL+Key_Q);
71
72         menuBar()->addSeparator();
73
74         QMenu *help_menu = menuBar()->addMenu(tr("&Help"));
75         help_menu->addAction(tr("&About"),
76                 this, SLOT(about()), Key_F1);
77
78         // Make a central widget to contain the other widgets
79         QWidget *central = new QWidget(this);
80         setCentralWidget(central);
81
82         // Create a layout to position the widgets
83         QHBoxLayout *box_main = new QHBoxLayout(central);
84
85         // Main layout
86         QVBoxLayout *box_right = new QVBoxLayout();
87         box_main->addLayout(box_right);
88
89                 // LCD
90                 QHBoxLayout *lay_lcd = new QHBoxLayout();
91                 box_right->addLayout(lay_lcd);
92                         lay_lcd->addStretch();
93                         lay_lcd->addWidget(e->emulLCD = new EmulLCD(central));
94                         lay_lcd->addStretch();
95
96                 // Keyboard
97                 box_right->addWidget(e->emulKbd = new EmulKbd(central));
98
99         // Setup keyboard: Label   Keycode     Row Col MRow MCol
100         e->emulKbd->addKey("^",    Key_Up,     0,  0,  0,   0);
101         e->emulKbd->addKey("v",    Key_Down,   1,  0,  0,   1);
102         e->emulKbd->addKey("OK",   Key_Return, 0,  1,  0,   2);
103         e->emulKbd->addKey("ESC",  Key_Escape, 1,  1,  0,   3);
104 }
105
106
107 EmulWin::~EmulWin()
108 {
109         emul->quit();
110 }
111
112
113 void EmulWin::closeEvent(QCloseEvent *ce)
114 {
115         emul->quit();
116         ce->accept();
117 }
118
119
120 void EmulWin::about()
121 {
122     QMessageBox::about(this,
123                 "BeRTOS Embedded Application Emulator",
124                 "Version 0.1\n"
125                 "Copyright 2006, 2008 Develer S.r.l. (http://www.develer.com/)\n"
126                 "Copyright 2001, 2002, 2003, 2005 Bernie Innocenti <bernie@codewiz.org>\n"
127                 "All rights reserved."
128         );
129 }
130
131 #include "emulwin_moc.cpp"