Add emulator skeleton.
authorbernie <bernie@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 16 Jan 2006 03:37:12 +0000 (03:37 +0000)
committerbernie <bernie@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 16 Jan 2006 03:37:12 +0000 (03:37 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@467 38d2e660-2303-0410-9eaa-f027e97ec537

emul/emul.cpp [new file with mode: 0755]
emul/emul.h [new file with mode: 0755]
emul/emulwin.cpp [new file with mode: 0755]
emul/emulwin.h [new file with mode: 0755]

diff --git a/emul/emul.cpp b/emul/emul.cpp
new file mode 100755 (executable)
index 0000000..c68fa8d
--- /dev/null
@@ -0,0 +1,81 @@
+/**
+ * \file
+ * <!--
+ * Copyright 2006 Develer S.r.l. (http://www.develer.com/)
+ * Copyright 2000, 2001 Bernardo Innocenti <bernie@codewiz.org>
+ * All Rights Reserved.
+ * -->
+ *
+ * \version $Id$
+ *
+ * \author Bernardo Innocenti <bernie@develer.com>
+ *
+ * \brief Qt-based emulator framework for embedded applications (implementation)
+ */
+
+/*#*
+ *#* $Log$
+ *#* Revision 1.1  2006/01/16 03:37:12  bernie
+ *#* Add emulator skeleton.
+ *#*
+ *#*/
+
+#include "emul.h"
+#include "emulwin.h"
+
+#include <qapplication.h>
+#include <cstdlib> // std::exit()
+
+/// The global emulator instance.
+Emulator *emul;
+
+Emulator::Emulator(int &argc, char **argv) :
+       emulApp(new QApplication(argc, argv)),
+       emulWin(new EmulWin(this))
+{
+       emulApp->setMainWidget(emulWin);
+       emulWin->show();
+}
+
+
+Emulator::~Emulator()
+{
+       // we don't delete emulWin because it automatically
+       // deletes itself when closed
+       delete emulApp;
+}
+
+
+void Emulator::quit()
+{
+       // WHAT A KLUDGE!
+       this->~Emulator();
+       emul = NULL;
+
+       // do we have a better way to shut down the emulation?
+       exit(0);
+}
+
+
+/// Main emulator entry point.
+extern "C" void emul_init(int *argc, char *argv[])
+{
+       ASSERT(!emul);
+
+       // setup global emulator pointer
+       emul = new Emulator(*argc, argv);
+}
+
+extern "C" void emul_cleanup()
+{
+       ASSERT(emul);
+       delete emul;
+       emul = NULL;
+}
+
+extern "C" void emul_idle()
+{
+       // We process GUI events when the application is idle.
+       emul->emulApp->processEvents();
+}
+
diff --git a/emul/emul.h b/emul/emul.h
new file mode 100755 (executable)
index 0000000..b6631e1
--- /dev/null
@@ -0,0 +1,68 @@
+/**
+ * \file
+ * <!--
+ * Copyright 2006 Develer S.r.l. (http://www.develer.com/)
+ * Copyright 2000, 2001 Bernardo Innocenti <bernie@codewiz.org>
+ * All Rights Reserved.
+ * -->
+ *
+ * \version $Id$
+ *
+ * \author Bernardo Innocenti <bernie@develer.com>
+ *
+ * \brief Qt-based emulator framework for embedded applications (interface)
+ */
+
+/*#*
+ *#* $Log$
+ *#* Revision 1.1  2006/01/16 03:37:12  bernie
+ *#* Add emulator skeleton.
+ *#*
+ *#*/
+
+#ifndef EMUL_EMUL_H
+#define EMUL_EMUL_H
+
+#include <cfg/compiler.h>
+
+#ifdef __cplusplus
+
+// fwd decls
+class QApplication;
+class EmulWin;
+class EmulPRT;
+class EmulLCD;
+class EmulKBD;
+class QCheckBox;
+class QSlider;
+class QLabel;
+
+class Emulator
+{
+// data members
+public:
+       QApplication    *emulApp;       ///< QT Application.
+       EmulWin                 *emulWin;       ///< Main window.
+
+       EmulLCD                 *emulLCD;       ///< Display emulator.
+       EmulKBD                 *emulKBD;       ///< Keyboard emulator.
+
+// construction
+       Emulator(int &argc, char **argv);
+       ~Emulator();
+
+// public methods
+       int exec(void (*entry)(void));
+       void quit();
+};
+
+extern Emulator *emul;
+
+#endif /* __cplusplus */
+
+EXTERN_C void emul_init(int *argc, char *argv[]);
+EXTERN_C void emul_cleanup();
+EXTERN_C void emul_idle();
+
+#endif /* EMUL_EMUL_H */
+
diff --git a/emul/emulwin.cpp b/emul/emulwin.cpp
new file mode 100755 (executable)
index 0000000..9f9ff5e
--- /dev/null
@@ -0,0 +1,95 @@
+/**
+ * \file
+ * <!--
+ * Copyright 2006 Develer S.r.l. (http://www.develer.com/)
+ * Copyright 2000, 2001 Bernardo Innocenti <bernie@codewiz.org>
+ * All Rights Reserved.
+ * -->
+ *
+ * \version $Id$
+ *
+ * \author Bernardo Innocenti <bernie@develer.com>
+ *
+ * \brief Main Qt window for embedded applications emulator (implementation)
+ */
+
+/*#*
+ *#* $Log$
+ *#* Revision 1.1  2006/01/16 03:37:12  bernie
+ *#* Add emulator skeleton.
+ *#*
+ *#*/
+
+#include "emulwin.h"
+
+#include <drv/lcd_gfx_qt.h>
+#include <emul/emul.h>
+
+#include <cassert>
+#include <qlayout.h>
+#include <qlabel.h>
+#include <qslider.h>
+#include <qcheckbox.h>
+#include <qpopupmenu.h>
+#include <qmenubar.h>
+#include <qmessagebox.h>
+#include <qdatetime.h>
+#include <qtimer.h>
+#include <qapplication.h>
+
+EmulWin::EmulWin(Emulator *e) : QMainWindow(0, "SarfEmul", WDestructiveClose)
+{
+       // "File" menu
+       QPopupMenu * file = new QPopupMenu(this);
+       file->insertItem("&Quit", static_cast<QObject *>(e->emulApp), SLOT(closeAllWindows()), CTRL+Key_Q);
+
+       // "Help" menu
+       QPopupMenu * help = new QPopupMenu(this);
+       help->insertItem("&About", this, SLOT(about()), Key_F1);
+
+       // Menu bar
+       QMenuBar * menu = new QMenuBar(this);
+       menu->insertItem("&File", file);
+       menu->insertSeparator();
+       menu->insertItem("&Help", help);
+
+       // Make a central widget to contain the other widgets
+       QWidget *central = new QWidget(this);
+       setCentralWidget(central);
+
+       // Create a layout to position the widgets
+       QHBoxLayout *box_main = new QHBoxLayout(central, 4);
+
+       // Main layout
+       QVBoxLayout *box_right = new QVBoxLayout(box_main, 4);
+
+               // LCD
+               QHBoxLayout *lay_lcd = new QHBoxLayout(box_right, 4);
+               lay_lcd->addWidget(e->emulLCD = new EmulLCD(central));
+}
+
+
+EmulWin::~EmulWin()
+{
+       emul->quit();
+}
+
+
+void EmulWin::closeEvent(QCloseEvent *ce)
+{
+       ce->accept();
+}
+
+
+void EmulWin::about()
+{
+    QMessageBox::about(this,
+               "Embedded Application Emulator",
+               "Version 0.1\n"
+               "Copyright 2006 Develer S.r.l. (http://www.develer.com/)\n"
+               "Copyright 2001, 2002, 2003, 2005 Bernardo Innocenti <bernie@codewiz.org>\n"
+               "All rights reserved."
+       );
+}
+
+#include "emulwin_moc.cpp"
diff --git a/emul/emulwin.h b/emul/emulwin.h
new file mode 100755 (executable)
index 0000000..b47d30f
--- /dev/null
@@ -0,0 +1,48 @@
+/**
+ * \file
+ * <!--
+ * Copyright 2006 Develer S.r.l. (http://www.develer.com/)
+ * Copyright 2000, 2001 Bernardo Innocenti <bernie@codewiz.org>
+ * All Rights Reserved.
+ * -->
+ *
+ * \version $Id$
+ *
+ * \author Bernardo Innocenti <bernie@develer.com>
+ *
+ * \brief Main Qt window for embedded applications emulator (interface)
+ */
+
+/*#*
+ *#* $Log$
+ *#* Revision 1.1  2006/01/16 03:37:12  bernie
+ *#* Add emulator skeleton.
+ *#*
+ *#*/
+
+#ifndef EMUL_EMULWIN_H
+#define EMUL_EMULWIN_H
+
+#include <qmainwindow.h>
+
+// fwd decls
+class Emulator;
+
+class EmulWin : public QMainWindow
+{
+       Q_OBJECT
+
+// construction
+public:
+       EmulWin(Emulator *emul);
+       ~EmulWin();
+
+protected:
+       void closeEvent(QCloseEvent *);
+
+private slots:
+       void about();
+};
+
+#endif // EMUL_EMULWIN_H
+