Lesson4: TextInput
/*
+--------------------------------------------------------------------------
| 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
|
+---------------------------------------------------------------------------
*/
Lesson4: TextInput
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 4 lesson.
We will add to our Window a TextInput and a messagebox to show the text we digit in the textinput.
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 TextInput 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 TextInput library:
Ok Now we have to add the declaration of textinput 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 text we have inserted.
This is our new main class declaration:
Perfect !! Now we have to add the button in our main function code to call the function that will show the messagebox with the text.
This is our new main Function:
Finally we have to add the function that will show the MessageBox with the text we have inserted in the textinput:
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 text in the textinput
- Set the characters that are allowed in the textinput
- Set the Max number of characters allowed in the textinput
That's all, and this is the application shot and the complete package.
(to be continued in lesson 5 ... )
+--------------------------------------------------------------------------
| 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
|
+---------------------------------------------------------------------------
*/
Lesson4: TextInput
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 4 lesson.
We will add to our Window a TextInput and a messagebox to show the text we digit in the textinput.
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 TextInput creation.
These are the main Api about TextInput creation and managing:
Code:
// create TextInput eTextInputField( eWidget* parent, eLabel *descr=0, eTextInputFieldHelpWidget* hlp=0, const char *deco="eNumber" ); // Functions: setText(eString); setMaxChars( int i ) setUseableChars( const char* );
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 TextInput library:
Code:
#include <lib/gui/textinput.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 text we have inserted.
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 textinput eTextInputField *mytext; // 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 4: TextInput"); // 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 Ok Button and digit your text."); // create textinput mytext=new eTextInputField(this); // give position mytext->move(ePoint(20, 150)); // give size mytext->resize(eSize(400, 40)); // set max number of characters mytext->setMaxChars(100); //mytext->setUseableChars("1234567890"); //mytext->setText(codeentry); // show a frame decoration mytext->loadDeco(); // create buttons 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 textinput setFocus(mytext); }
Code:
void eBibleMainWindow::message1() { // declare variable we will use in this function eString message, message2; // assign to message2 the textinput content message2 = mytext->getText(); // compose message concatenating strings message = "You wrote: " + 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:
- Set a default text in the textinput
- Set the characters that are allowed in the textinput
- Set the Max number of characters allowed in the textinput
That's all, and this is the application shot and the complete package.
(to be continued in lesson 5 ... )