after test with ZPushButton in http://www.motorolafans.com/forums/showthread.php?p=132847#post132847
Now I try another widget. here is a memCheck application. main widget is ZMultiLineEdit. application doing an easy job by execute command cat /proc/meminfo and dispaly result in ZMultiLineEdit.
ZMultiLineEdit is a text box that can have 1 or more lines. and it can expandable in both size.
you can create ZMultiLineEdit by
memStatus = new ZMultiLineEdit( this, false, 12 );
this = parent widget. can be content widget, QVBox, QBox. but can not create ZMultiLineEdit on ZScrollView it cause a segmentation fault.
false = ezx style. I found no different between true and false. report me If you found it.
12 = number of lines.
After create it ZMultiLineEdit need to config many properties such as
setWordWrap for define wraping text.
setSizePolicy for define expanding in horizontal and vertical when text length is out of it's area.
setReadOnly to make it read only but can copy text inside it.
setMaxLength for define number of characters for user input.
and we can define filter for input by
QRegExp mFilter = QRegExp("[^0-9]");
mPhoneNumberEdit->setFilter(mFilter);
see QRegExp for more detail.
Here is a full source code of memCheck demo.
Code:
//-------------------------------------------------------------------------------------------------
//
// Header Name: MemCheck.cpp
//
// General Description: MemCheck class implement file.
//
//-------------------------------------------------------------------------------------------------
//
// Eakrin Confidential Proprietary
// Template ID and version: 20080308 Version 0.1
// (c) Copyright eakrin 2008, All Rights Reserved
//
//-------------------------------------------------------------------------------------------------
#include <ZApplication.h>
#include <ZMainWidget.h>
#include <ZPushButton.h>
#include <ZMessageBox.h>
#include <ZScrollView.h>
#include <ezxutilcst.h>
#include <ZMultiLineEdit.h>
// UTIL_MemInfo always return undefine type. can not convert to QString.
//#include <UTIL_MemInfo.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qfile.h>
#include <qtextstream.h>
#include <stdlib.h>
#include "MemCheck.h"
MemCheck::MemCheck( void )
: ZMainWidget( FALSE, NULL, NULL, 0 )
{
// Create Title bar.
title = new QLabel( tr( "Memory Status" ), this );
title->setScaledContents( TRUE );
setTitleBarWidget( title );
title->show();
// Create CST Widget.
cst = new UTIL_CST( this, tr( "Refresh" ) );
setCSTWidget( cst );
cst->show();
// Create CST Right Button.
ZPushButton *btn = cst->getRightBtn();
connect( btn, SIGNAL( clicked() ), qApp, SLOT( slotQuickQuit() ) );
// Create CST Mid Button.
btn = cst->getMidBtn();
connect( btn, SIGNAL( clicked() ), this, SLOT( refresh() ) );
// Create CST Left Button with popup menu.
cstMenu = new QPopupMenu( cst, NULL );
cstMenu->insertItem( tr( "About.." ) );
connect( cstMenu, SIGNAL( activated( int ) ), this, SLOT( selectCSTMenu( int ) ) );
btn =cst->getLeftBtn();
btn->setPopup( cstMenu );
// Create content widget.
//QWidget *contentWidget = this->getContentWidget( TRUE );
/*
ZScrollView *contentWidget = new ZScrollView( this );
setContentWidget( contentWidget );
contentWidget->show();
*/
//QVBoxLayout *contentLayout = new QVBoxLayout( contentWidget );
memStatus = new ZMultiLineEdit( this, false, 12 );
memStatus->setWordWrap( ZMultiLineEdit::WidgetWidth );
memStatus->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding));
memStatus->setReadOnly( TRUE );
setContentWidget( memStatus );
// refresh memory status.
this->refresh();
}
MemCheck::~MemCheck( void )
{
}
void MemCheck::refresh( void )
{
system( "cat /proc/meminfo > /tmp/MemInfo.txt" );
QFile ft( "/tmp/MemInfo.txt" );
if ( ft.open( IO_ReadOnly ) )
{
QTextStream ts ( &ft );
ts.readLine();
ts.readLine();
ts.readLine();
QString mem;
for (int row = 0; row < 15; row++)
{
mem = ts.readLine();
memStatus->insertLine( mem );
}
ft.close();
}
system( "rm /tmp/MemInfo.txt" );
}
void MemCheck::selectCSTMenu( int menuId )
{
showAboutDialog();
}
void MemCheck::showAboutDialog( void )
{
ZMessageBox::information(this, NULL,
QString::fromUtf8("<qt><p><b>MemCheck %1</b></p>eakrin @ MotorolaFans.com</qt>").arg(VERSION),
QString::fromUtf8("Ok"));
}
Code:
//-------------------------------------------------------------------------------------------------
//
// Header Name: MemCheck.h
//
// General Description: MemCheck header file.
//
//-------------------------------------------------------------------------------------------------
//
// Eakrin Confidential Proprietary
// Template ID and version: 20080308 Version 0.1
// (c) Copyright eakrin 2008, All Rights Reserved
//
//-------------------------------------------------------------------------------------------------
#ifndef __MEM_CHECK_H__
#define __MEM_CHECK_H__
#ifndef __cplusplus
#error "This is a C++ header file;it requires C++ to compile."
#endif
#include <ZMainWidget.h>
#define VERSION "0.1"
#define RELEASE "Mar 9, 2008"
class QLabel;
class ZMultiLineEdit;
class UTIL_CST;
class QPopupMenu;
//class UTIL_MemInfo;
class MemCheck : public ZMainWidget
{
Q_OBJECT
public:
MemCheck( void );
~MemCheck( void );
public slots:
void refresh( void );
void selectCSTMenu( int menuId );
void showAboutDialog( void );
private:
QLabel *title;
UTIL_CST *cst;
QPopupMenu *cstMenu;
//UTIL_MemInfo *mi;
ZMultiLineEdit *memStatus;
};
#endif // #ifndef __MEM_CHECK_H__
Code:
//-------------------------------------------------------------------------------------------------
//
// Header Name: main.cpp
//
// General Description: main file for Ezx Mem Check
//
//-------------------------------------------------------------------------------------------------
//
// Eakrin Confidential Proprietary
// Template ID and version: 20080308 Version 0.1
// (c) Copyright eakrin 2008, All Rights Reserved
//
//-------------------------------------------------------------------------------------------------
#include <ZApplication.h>
#include "MemCheck.h"
int main( int argc, char** argv )
{
ZApplication app( argc, argv );
MemCheck *mw = new MemCheck();
app.showMainWidget(mw);
return app.exec();
}
and you can set startup keyboard by setInputMethods.
setInputMethods( mPhoneNumberEdit, IMID_NUMBER_KB, 0, 0 );
IMID_NUMBER_KB is a keyboard constant id defined in ZIMethod.h. IMID_NUMBER_KB is Quuid not a string. I tested only number keyboard. didn't test with symbol, thai, china board. And There have no another language keyboard id in ZIMethod.h may be we can use them from *.kdb in EMEA_LP.
And need to replace ZMainWidget.h with my update from this post for setInputMethod.
http://www.motorolafans.com/forums/s...2&postcount=63
thanks for blackhawk about setInputMethods.
cheer!
eakrin