Lesson7: Combobox
/*
+--------------------------------------------------------------------------
| 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
|
+---------------------------------------------------------------------------
*/
Lesson7: Combobox
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 seven.
We will add to our Window a Combobox and a messagebox to show the item of the list we have selected.
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 Combobox creation.
These are only a part of the listbox API. The Combobox is more complicated and it is a box containing a Listbox so we will examine here only the main calls:
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's go.
bibledemo.cpp additions:
First of all we have to add to our include files the Enigma Combobox library.
Ok Now we have to add the declaration of Combobox in our main class.
We have to add a function too:
void message1();
we will connect the execution of this function to a button.
In this way when the button is pushed this function will be called and it will show the Combobox item we have selected.
This is our new main class declaration:
Perfect !! Now we have to add the Combobox and populate it with items. We have also to add a button and to connect it
to the function that will show a messagebox:
Finally we have to add the function that will show the MessageBox with the selected item:
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:
- Retrieve the item key instead of the item text
That's all, and this is the application shot and the complete package.
(to be continued in lesson 8 ... )
+--------------------------------------------------------------------------
| 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
|
+---------------------------------------------------------------------------
*/
Lesson7: Combobox
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 seven.
We will add to our Window a Combobox and a messagebox to show the item of the list we have selected.
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 Combobox creation.
These are only a part of the listbox API. The Combobox is more complicated and it is a box containing a Listbox so we will examine here only the main calls:
Code:
// create Combobox eComboBox(eWidget* parent, int OpenEntries=5, eLabel* desc=0, int takefocus=1, const char *deco="eComboBox" ); // Functions: int setCurrent( int, bool=false ); // Listbox items: //create new item: eListBoxEntryText(eListBox<eListBoxEntryText>* lb, const char* txt=0, void *key=0, int align=0, const eString &hlptxt="", int keytype = value ); // retrieve selected item getCurrent()->getText(); // retrieve selected key getCurrent()->getKey()
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's go.
bibledemo.cpp additions:
First of all we have to add to our include files the Enigma Combobox library.
Code:
#include <lib/gui/combobox.h>
We have to add a function too:
void message1();
we will connect the execution of this function to a button.
In this way when the button is pushed this function will be called and it will show the Combobox item we have selected.
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 listbox eListBox<eListBoxEntryText> *theList; // the combobox eComboBox *Lang; // function to execute whwn button is pushed void message1(); public: // the constructor. eBibleMainWindow(); // the destructor. ~eBibleMainWindow(); };
to the function that will show a messagebox:
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 7: Combobox"); // create a label to show a text. label=new eLabel(this); // give a position label->move(ePoint(50, 50)); // set the label dimensions label->resize(eSize(400, 60)); // set the label text label->setText("Select your language"); // Create the Combobox Lang=new eComboBox(this, 4); // Populate the Combobox with a List of Items new eListBoxEntryText(*Lang, "English", (void *) (0)); new eListBoxEntryText(*Lang, "French", (void *) (1)); new eListBoxEntryText(*Lang, "Italian", (void *) (2)); new eListBoxEntryText(*Lang, "Dutch", (void *) (3)); // set Combobox position Lang->move(ePoint(50, 160)); // Combo dimensions Lang->resize(eSize(clientrect.width()-120, 35)); // set the default entry of Combobox to the first element of the list Lang->setCurrent(0); // decore Combo with a frame Lang->loadDeco(); // 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 the Combobox setFocus(Lang); }
Code:
void eBibleMainWindow::message1() { // declare variable we will use in this function eString message, message2; // assign to message2 the selected item text message2 = Lang->getCurrent()->getText(); // compose message concatenating strings message = "Your Language is:/n " + message2; // 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:
- Retrieve the item key instead of the item text
That's all, and this is the application shot and the complete package.
(to be continued in lesson 8 ... )