Ticket #9: let the demo application close gracefully when choosing File->Quit or...
[bertos.git] / emul / emulwin.cpp
old mode 100755 (executable)
new mode 100644 (file)
index f03fc06..b5f57cd
@@ -1,9 +1,34 @@
 /**
  * \file
  * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction.  Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License.  This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
  * Copyright 2006 Develer S.r.l. (http://www.develer.com/)
  * Copyright 2000, 2001 Bernardo Innocenti <bernie@codewiz.org>
- * This file is part of DevLib - See README.devlib for information.
+ *
  * -->
  *
  * \version $Id$
  * \brief Main Qt window for embedded applications emulator (implementation)
  */
 
-/*#*
- *#* $Log$
- *#* Revision 1.2  2006/01/16 03:51:51  bernie
- *#* Fix boilerplate.
- *#*
- *#* 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 <emul/emulkbd.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)
+
+#include <QtGui/QLayout>
+#include <QtGui/QLabel>
+#include <QtGui/QSlider>
+#include <QtGui/QCheckBox>
+#include <QtGui/QMenuBar>
+#include <QtGui/QMessageBox>
+#include <QtCore/QDateTime>
+#include <QtCore/QTimer>
+#include <QtGui/QApplication>
+#include <QtGui/QCloseEvent>
+using namespace Qt;
+
+EmulWin::EmulWin(Emulator *e)
 {
-       // "File" menu
-       QPopupMenu * file = new QPopupMenu(this);
-       file->insertItem("&Quit", static_cast<QObject *>(e->emulApp), SLOT(closeAllWindows()), CTRL+Key_Q);
+       setWindowTitle(tr("BeRTOS Emul Demo"));
+       setAttribute(Qt::WA_DeleteOnClose);
 
-       // "Help" menu
-       QPopupMenu * help = new QPopupMenu(this);
-       help->insertItem("&About", this, SLOT(about()), Key_F1);
+       // Create the menu bar
+       QMenu *file_menu = menuBar()->addMenu(tr("&File"));
+       file_menu->addAction(tr("&Quit"),
+               e->emulApp, SLOT(closeAllWindows()), CTRL+Key_Q);
 
-       // Menu bar
-       QMenuBar * menu = new QMenuBar(this);
-       menu->insertItem("&File", file);
-       menu->insertSeparator();
-       menu->insertItem("&Help", help);
+       menuBar()->addSeparator();
+
+       QMenu *help_menu = menuBar()->addMenu(tr("&Help"));
+       help_menu->addAction(tr("&About"),
+               this, SLOT(about()), Key_F1);
 
        // 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);
+       QHBoxLayout *box_main = new QHBoxLayout(central);
 
        // Main layout
-       QVBoxLayout *box_right = new QVBoxLayout(box_main, 4);
+       QVBoxLayout *box_right = new QVBoxLayout();
+       box_main->addLayout(box_right);
 
                // LCD
-               QHBoxLayout *lay_lcd = new QHBoxLayout(box_right, 4);
-               lay_lcd->addWidget(e->emulLCD = new EmulLCD(central));
+               QHBoxLayout *lay_lcd = new QHBoxLayout();
+               box_right->addLayout(lay_lcd);
+                       lay_lcd->addStretch();
+                       lay_lcd->addWidget(e->emulLCD = new EmulLCD(central));
+                       lay_lcd->addStretch();
+
+               // Keyboard
+               box_right->addWidget(e->emulKbd = new EmulKbd(central));
+
+       // Setup keyboard: Label   Keycode     Row Col MRow MCol
+       e->emulKbd->addKey("^",    Key_Up,     0,  0,  0,   0);
+       e->emulKbd->addKey("v",    Key_Down,   1,  0,  0,   1);
+       e->emulKbd->addKey("OK",   Key_Return, 0,  1,  0,   2);
+       e->emulKbd->addKey("ESC",  Key_Escape, 1,  1,  0,   3);
 }
 
 
@@ -80,6 +111,7 @@ EmulWin::~EmulWin()
 
 void EmulWin::closeEvent(QCloseEvent *ce)
 {
+       emul->quit();
        ce->accept();
 }
 
@@ -87,9 +119,9 @@ void EmulWin::closeEvent(QCloseEvent *ce)
 void EmulWin::about()
 {
     QMessageBox::about(this,
-               "Embedded Application Emulator",
+               "BeRTOS Embedded Application Emulator",
                "Version 0.1\n"
-               "Copyright 2006 Develer S.r.l. (http://www.develer.com/)\n"
+               "Copyright 2006, 2008 Develer S.r.l. (http://www.develer.com/)\n"
                "Copyright 2001, 2002, 2003, 2005 Bernardo Innocenti <bernie@codewiz.org>\n"
                "All rights reserved."
        );