/*
* Hello World demo program for EZX
* Copyright (C) 2005 Sam Revitch
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* Further, this software is distributed without any warranty that it is
* free of the rightful claim of any third person regarding infringement
* or the like. Any license provided herein, whether implied or
* otherwise, applies only to this software file. Patent licenses, if
* any, provided herein do not apply to combinations of this program with
* other software, or any other product whatsoever.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stddef.h>
#include <stdio.h>
#include <qwsevent_qws.h>
#include <zapplication.h>
#include <zmainwidget.h>
#include <zmessagebox.h>
#include <ezxutilcst.h>
#include <ezxres.h>
#include <qlabel.h>
class MyWidget : public ZMainWidget
{
Q_OBJECT
public:
MyWidget(QWidget *parent)
: ZMainWidget("My first Moto EZX App", true, parent, NULL, 0) {
UTIL_CST *cp;//Moto 手机界面的下面的任务栏,左边是菜单按钮,右边是退出按钮,中间也是一个按钮
ZPushButton *wp;
QPopupMenu *pp;
lp = new QLabel("Hello, world!\n"
"Try the menu!",
this, "main_label");
setContentWidget(lp);
lp->show();
cp = new UTIL_CST(this, "Show Dialog");
setCSTWidget(cp);
cp->show();
wp = cp->getRightBtn();//右边按钮的信号为退出信号
connect(wp, SIGNAL(clicked()), qApp, SLOT(slotQuickQuit()));
wp = cp->getMidBtn();//中间按钮也处理一个信号,显示一个MessageBox对话框
connect(wp, SIGNAL(clicked()), this, SLOT(showDialog()));
pp = new QPopupMenu(cp, "Pop");
connect(pp, SIGNAL(activated(int)), this, SLOT(menuSelect(int)));
m_showdialog_menu_id = pp->insertItem("Show Dialog");
wp = cp->getLeftBtn();//左边按钮的信号为弹出一个菜单选项
wp->setPopup(pp);
}
virtual ~MyWidget() {
fprintf(stderr, "Tearing down MyWidget...\n");
}
public:
int m_showdialog_menu_id;
QLabel *lp;
public slots:
void showDialog(void)
{
RES_ICON_Reader ir;
int ret;
//返回值为ret,
//ret=0,表明点击了MessageBox左边按钮;
//ret=1,表明点击了MessageBox右边按钮
//利用这个返回值,可以做一些信号的处理工作
ret = ZMessageBox::information( //一个MessageBox,带一个图标、一行文字、两个按钮
this,
ir.getIcon(RES_ICON_DLG_EMPTY_TRASH),//垃圾站的图标
QString("Hello, World!"),//显示的信息
QString("Left on!"), //左边按钮显示的文字
QString("Screw it!"));//右边按钮显示的文字
fprintf(stderr, "information() returned %d\n", ret);
if ( 0 == ret )//点击了MessageBox左边按钮
{
fprintf(stderr, "Left button clicked!");
lp->setText("Left button clicked!\n~~zieckey");//重新设置QLable显示的文字
}
else//点击了MessageBox右边按钮
{
fprintf(stderr, "Right button clicked!");
lp->setText("Right button clicked!\n~~zieckey");
}
}
void menuSelect( int selectIndex ) //菜单栏的选择
{
if ( selectIndex == m_showdialog_menu_id )
{
showDialog();
}
}
};
//这里就不用多解释了,所以的qt程序main函数基本一样
//可以参考:http://blog.chinaunix.net/u/16292/showart_220215.html
int main(int argc, char** argv)
{
ZApplication app (argc, argv);
MyWidget *wp = new MyWidget(NULL);
app.setMainWidget(wp);
wp->show();
return app.exec();
}
#include "helloworld.moc"
|