From 70ef586aed3922433460eaf19125378f8c996743 Mon Sep 17 00:00:00 2001 From: bernie Date: Mon, 16 Jan 2006 03:37:12 +0000 Subject: [PATCH] Add emulator skeleton. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@467 38d2e660-2303-0410-9eaa-f027e97ec537 --- emul/emul.cpp | 81 +++++++++++++++++++++++++++++++++++++++++ emul/emul.h | 68 ++++++++++++++++++++++++++++++++++ emul/emulwin.cpp | 95 ++++++++++++++++++++++++++++++++++++++++++++++++ emul/emulwin.h | 48 ++++++++++++++++++++++++ 4 files changed, 292 insertions(+) create mode 100755 emul/emul.cpp create mode 100755 emul/emul.h create mode 100755 emul/emulwin.cpp create mode 100755 emul/emulwin.h diff --git a/emul/emul.cpp b/emul/emul.cpp new file mode 100755 index 00000000..c68fa8d6 --- /dev/null +++ b/emul/emul.cpp @@ -0,0 +1,81 @@ +/** + * \file + * + * + * \version $Id$ + * + * \author Bernardo Innocenti + * + * \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 +#include // 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 index 00000000..b6631e1a --- /dev/null +++ b/emul/emul.h @@ -0,0 +1,68 @@ +/** + * \file + * + * + * \version $Id$ + * + * \author Bernardo Innocenti + * + * \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 + +#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 index 00000000..9f9ff5e8 --- /dev/null +++ b/emul/emulwin.cpp @@ -0,0 +1,95 @@ +/** + * \file + * + * + * \version $Id$ + * + * \author Bernardo Innocenti + * + * \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 +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +EmulWin::EmulWin(Emulator *e) : QMainWindow(0, "SarfEmul", WDestructiveClose) +{ + // "File" menu + QPopupMenu * file = new QPopupMenu(this); + file->insertItem("&Quit", static_cast(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 \n" + "All rights reserved." + ); +} + +#include "emulwin_moc.cpp" diff --git a/emul/emulwin.h b/emul/emulwin.h new file mode 100755 index 00000000..b47d30f2 --- /dev/null +++ b/emul/emulwin.h @@ -0,0 +1,48 @@ +/** + * \file + * + * + * \version $Id$ + * + * \author Bernardo Innocenti + * + * \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 + +// 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 + -- 2.25.1