Enigma1 THE BIBLE - Lesson5: Checkbox

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:
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; }
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:
Code:
#include <lib/gui/echeckbox.h>
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:
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();
};
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:
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);

}
Finally we have to add the function that will show the MessageBox with the result:
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 ... )
Attached Images
File Type: pngosdshot.png (11.1 KB, 43 views)
Attached Files
File Type: ziplesson5.zip (9.2 KB, 41 views)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值