Lesson3: MessageBox
/*
+--------------------------------------------------------------------------
| The Bible Enigma1 Tutorial
| ========================================
| By: Bacicciosat aka Meo aka Luponero
|
| Enigma 1 API GUI tutorial with Sources Code and Comments
| (c) august 2006 by Meo
|
+---------------------------------------------------------------------------
*/
Lesson3: MessageBox
You can find in attach:
- the cfg file (Bibledemo.cfg)
- the compiled and working plugin (Bibledemo.so)
- the source file (bibledemo.cpp)
- the makefile (nedeed to compile code if you want to modify source)
Ok this is the third lesson.
We will add to our window two buttons to call two different messageboxes.
You can see the example in the screenshot.
You can test this application simply uploading in your dreambox (/var/tuxbox/plugins) the files that you can find in attach: Bibledemo.cfg and Bibledemo.so
You can modify this application editing the source file bibledemo.cpp and recompiling it to have a new Bibledemo.so file.
The Enigma API we will explain in this lesson is the messaagebox creation.
These are the main Api about messagebox creation and managing:
Ok now that we have listed the main API we can write the code.
You can fnd the complete application code in the attach package
(bibledemo.cpp). Here i will comment only the code added in this
lesson.
Let'go.
bibledemo.cpp additions:
First of all we have to add to our include files the Enigma button library:
Ok Now we have to add two functions to our main class:
void message1();
void message2();
we will connect the execution of these functions to the buttons.
In this way when a butto will be pressed one of these functions will be called and it will show one messagebox.
This is our new main class declaration:
Perfect !! Now we have to add the two buttons in our main function code to call the functions that will show the messageboxes.
This is our new main Function:
Ok Now we have to add the function that will show the first MessageBox (Simply messagebox with only one button):
Finally we have to add the function that will show the second MessageBox (modal messagebox with two buttons):
As you can see is very simply.
You can now exercise to compile source you find in the attach package and to modify it.
Exercises:
- Change the icons text and buttons of MessageBoxes
- Add another Messagebox
That's all, and this is the application shot and the complete package.
(to be continued in lesson 4 ... )
+--------------------------------------------------------------------------
| The Bible Enigma1 Tutorial
| ========================================
| By: Bacicciosat aka Meo aka Luponero
|
| Enigma 1 API GUI tutorial with Sources Code and Comments
| (c) august 2006 by Meo
|
+---------------------------------------------------------------------------
*/
Lesson3: MessageBox
You can find in attach:
- the cfg file (Bibledemo.cfg)
- the compiled and working plugin (Bibledemo.so)
- the source file (bibledemo.cpp)
- the makefile (nedeed to compile code if you want to modify source)
Ok this is the third lesson.
We will add to our window two buttons to call two different messageboxes.
You can see the example in the screenshot.
You can test this application simply uploading in your dreambox (/var/tuxbox/plugins) the files that you can find in attach: Bibledemo.cfg and Bibledemo.so
You can modify this application editing the source file bibledemo.cpp and recompiling it to have a new Bibledemo.so file.
The Enigma API we will explain in this lesson is the messaagebox creation.
These are the main Api about messagebox creation and managing:
Code:
// create messagebox eMessageBox(eString string, eString caption, int flags=btOK, int def=btOK, int timeout=0 ); // Flags: Buttons btOK=1, btCancel=2, btYes=4, btNo=8, btMax // Flags: Icons iconInfo=16, iconWarning=32, iconQuestion=64, iconError=128 // Functions: show(); exec(); hide();
You can fnd the complete application code in the attach package
(bibledemo.cpp). Here i will comment only the code added in this
lesson.
Let'go.
bibledemo.cpp additions:
First of all we have to add to our include files the Enigma button library:
Code:
#include <lib/gui/emessage.h>
void message1();
void message2();
we will connect the execution of these functions to the buttons.
In this way when a butto will be pressed one of these functions will be called and it will show one messagebox.
This is our new main class declaration:
Code:
// The Class declaration of our Main Window class eBibleMainWindow: public eWindow { // the label to show the text eLabel *label; // the function to call when button 1 is pushed void message1(); // the function to call when button 2 is pushed void message2(); public: // the constructor. eBibleMainWindow(); // the destructor. ~eBibleMainWindow(); };
This is our new main Function:
Code:
eBibleMainWindow::eBibleMainWindow(): eWindow(1) { // move our dialog to 100.100... cmove(ePoint(100, 100)); // ...and give x and y dimensions. cresize(eSize(520, 376)); // set a title. setText("Enigma Bible Lesson 3: MessageBox"); // create a label to show a text. label=new eLabel(this); // give a position label->move(ePoint(20, 50)); // set the label dimensions label->resize(eSize(400, 100)); // set the label text label->setText("Push a button to show a MessageBox"); // create buttons and set properties eButton * ok = new eButton(this); ok->setText("Simply"); ok->move(ePoint((clientrect.width() - 200)/2, clientrect.height() - 60)); ok->resize(eSize(90, 40)); ok->loadDeco(); // function to call when button1 is pushed CONNECT(ok->selected, eBibleMainWindow::message1); eButton * ok2 = new eButton(this); ok2->setText("Inter"); ok2->move(ePoint((clientrect.width())/2, clientrect.height() - 60)); ok2->resize(eSize(90, 40)); ok2->loadDeco(); // function to call when button2 is pushed CONNECT(ok2->selected, eBibleMainWindow::message2); // set focus on 1 button setFocus(ok); }
Code:
void eBibleMainWindow::message1() { // create messagebox eMessageBox msg("Hi by Bacicciosat :-)", "Info", eMessageBox::iconInfo|eMessageBox::btOK); // show it msg.show(); // execute msg.exec(); // hide after execution (button pressed) msg.hide(); }
Code:
void eBibleMainWindow::message2() { // create messagebox (two buttons yes/no) eMessageBox box("Do you want to exit?", "Question", eMessageBox::btYes|eMessageBox::btNo|eMessageBox::iconQuestion, eMessageBox::btYes); // show it box.show(); // execute code and store in the variable button the result (button pressed) int button = box.exec(); // hide it after execution box.hide(); // exit if button yes was pushed. if (button == eMessageBox::btYes) { eWidget::accept(); } }
As you can see is very simply.
You can now exercise to compile source you find in the attach package and to modify it.
Exercises:
- Change the icons text and buttons of MessageBoxes
- Add another Messagebox
That's all, and this is the application shot and the complete package.
(to be continued in lesson 4 ... )