Lesson5: Checkbox
/*
+--------------------------------------------------------------------------
| 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
|
+---------------------------------------------------------------------------
*/
Lesson5: Checkbox
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 lesson number five.
We will add to our Window a Checkbox and a messagebox to show the in a message if the checkbox is checked or not.
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 Checkbox creation.
These are the main Api about TextInput creation and managing:
Ok now that we have listed the main API we can write the code.
You can find 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 Checkbox library:
Ok Now we have to add the declaration of echeckbox in our main class.
We have to add a function too:
void message1();
we will connect the execution of this function to the button.
In this way when the butto will be pressed this function will be called and it will show one messagebox with the result.
This is our new main class declaration:
Perfect !! Now we have to add the checkbox and the button in our main function code to call the function that will show the messagebox with the result.
This is our new main Function:
Finally we have to add the function that will show the MessageBox with the result:
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:
- Set a default unchecked status to the checkbox
That's all, and this is the application shot and the complete package.
(to be continued in lesson 6 ... )
+--------------------------------------------------------------------------
| 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
|
+---------------------------------------------------------------------------
*/
Lesson5: Checkbox
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 lesson number five.
We will add to our Window a Checkbox and a messagebox to show the in a message if the checkbox is checked or not.
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 Checkbox creation.
These are the main Api about TextInput creation and managing:
Code:
// create Checkbox eCheckbox(eWidget *parent, int checked=0, int takefocus=1, bool swapTxtPixmap=false, const char *deco="eCheckBox" ); // Functions: setCheck(int c); int isChecked() { return ischecked; }
You can find 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 Checkbox library:
Code:
#include <lib/gui/echeckbox.h>
We have to add a function too:
void message1();
we will connect the execution of this function to the button.
In this way when the butto will be pressed this function will be called and it will show one messagebox with the result.
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 Checkbox eCheckbox *mycheck; // function to execute when button is pushed void message1(); 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 5: CheckBox"); // Create checkbox mycheck=new eCheckbox(this, 1); // give position mycheck->move(ePoint(10, 200)); // give dimensions (x and y) mycheck->resize(eSize(clientrect.width() - 20, 50)); // Text to display near the checkbox mycheck->setText("Check / Uncheck Box"); // create button and set properties eButton * ok = new eButton(this); ok->setText("Show"); ok->move(ePoint((clientrect.width() - 90)/2, clientrect.height() - 60)); ok->resize(eSize(100, 40)); ok->setShortcut("green"); ok->setShortcutPixmap("green"); ok->loadDeco(); // function to call when button is pushed CONNECT(ok->selected, eBibleMainWindow::message1); //set focus to checkbox setFocus(mycheck); }
Code:
void eBibleMainWindow::message1() { // declare variable we will use in this function eString message; // assign message to variable message = "The Box is Unchecked"; // assign another message in case the box is checked if (mycheck->isChecked()) { message = "The Box is Checked"; } // Create, show and execute the messagebox to display the message eMessageBox msg((message), "Info", eMessageBox::iconInfo|eMessageBox::btOK); msg.show(); msg.exec(); msg.hide(); }
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:
- Set a default unchecked status to the checkbox
That's all, and this is the application shot and the complete package.
(to be continued in lesson 6 ... )