Enigma1 THE BIBLE - Lesson3: MessageBox

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

}
Ok Now we have to add the function that will show the first MessageBox (Simply messagebox with only one button):
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();
}
Finally we have to add the function that will show the second MessageBox (modal messagebox with two buttons):
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 ... )
Attached Images
File Type: pngosdshot.png (14.1 KB, 62 views)
Attached Files
File Type: ziplesson3.zip (9.4 KB, 45 views)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值