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