Preface
Since i bought my ROKR E6 3-4 months ago, i need to develop the native app for the phone.
But look bad, the MOTOROLA have not been released anything about native SDK for EZX platform.
Yes, Java is be good but does everybody wants this ?
After hard searching on the net, i found the weakness SDK by yan0 and samr,
but seem it not ready to develop native app on the E6/A1200.
Well, i try to put and cutoff method on any class of that weak SDK.. but still can not work.
It can not derive or inherit class for extend the capability of the class which is the main important thing of the C++ programming.
After hard trying i have found the technic which brought me to handling the widget events, paint it etc.
So i made the new class with this technic, this technic may call "WRAPPER".
The Wrapper technic
The main function of this technic is
void QObject::installEventFilter ( const QObject * obj )
Let see the following code of the
QEObject class HEADER - qeobject.h:
PHP Code:
/***************************************************************************
* *
* (c) 2007, Thanomsub Noppaburana <donga.nb@gmail.com> *
* *
* 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 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. *
* *
* 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. *
***************************************************************************/
#ifndef __QEOBJECT_H__
#define __QEOBJECT_H__
#include <qobject.h>
#include <qwidget.h>
/**
***********************************************
Base Object for handle Widget's events
***********************************************
*/
class QEObject : public QObject
{
Q_OBJECT
public:
QEObject(QWidget *parent, const char *name = 0);
QEObject(const char *name = 0);
virtual ~QEObject();
QWidget *widget() const { return m_Widget; };
/**
hook Widget events
please call this after init and show object already
*/
void hookEvents(bool hook = TRUE);
virtual void requestDestroy() {};
void setMouseBlocked(bool block = FALSE);
virtual void setGeometry(int x, int y, int w, int h);
virtual void move(int x, int y);
virtual void resize(int w, int h);
virtual void show();
virtual void hide();
virtual void showNormal();
virtual void showFullScreen();
virtual QSize sizeHint() const { return QSize(m_width, m_height); };
int ix() const { return m_ix; };
int iy() const { return m_iy; };
int x() const { return m_x; };
int y() const { return m_y; };
int left() const { return m_x; };
int top() const { return m_y; };
int width() const { return m_width; };
int height() const { return m_height; };
QRect rect() const { return QRect(m_x, m_y, m_width, m_height); };
/** GUI creation */
virtual void setupGUI() {};
virtual void setupContent() {};
protected:
void setHookObject(QWidget *);
virtual void setupCST() {};
virtual void setupTitleBar() {};
/** event handles */
virtual bool eventFilter(QObject *, QEvent *);
/** Event handling method */
virtual bool mousePressEvent(QMouseEvent *) { return FALSE; };
virtual bool mouseReleaseEvent(QMouseEvent *) { return FALSE; };
virtual bool mouseMoveEvent(QMouseEvent *) { return FALSE; };
virtual bool mouseDblClickEvent(QMouseEvent *) { return FALSE; };
virtual bool mouseEnterEvent(QMouseEvent *) { return FALSE; };
virtual bool mouseLeaveEvent(QMouseEvent *) { return FALSE; };
virtual bool keyPressEvent(QKeyEvent *) { return FALSE; };
virtual bool keyReleaseEvent(QKeyEvent *) { return FALSE; };
virtual bool focusInEvent(QFocusEvent *) { return FALSE; };
virtual bool focusOutEvent(QFocusEvent *) { return FALSE; };
virtual bool paintEvent(QPaintEvent *) { return FALSE; };
virtual bool resizeEvent(QResizeEvent *) { return FALSE; };
virtual bool windowActivateEvent(QEvent *) { return FALSE; };
virtual bool windowDeactivateEvent(QEvent *) { return FALSE; };
virtual bool closeEvent(QCloseEvent *ev) { ev->accept(); return FALSE; };
protected:
int m_ix;
int m_iy;
int m_x;
int m_y;
int m_width;
int m_height;
bool m_isFullScreen;
bool m_isOnHookEvent;
bool m_isMouseBlocked;
QWidget *m_Widget;
};
#endif // __QEWIDGET_H__
CPP BODY - qeobject.cpp:
PHP Code:
/***************************************************************************
* *
* (c) 2007, Thanomsub Noppaburana <donga.nb@gmail.com> *
* *
* 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 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. *
* *
* 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 <stdio.h>
#include "qeobject.h"
/**
===========================================================================
QEObject class implementations
===========================================================================
*/
QEObject::QEObject(const char *name)
: QObject(0, name),
m_ix(0), m_iy(0), m_x(0), m_y(0), m_width(0), m_height(0),
m_isFullScreen(FALSE), m_isOnHookEvent(FALSE), m_isMouseBlocked(FALSE),
m_Widget(0)
{
}
QEObject::QEObject(QWidget *parent, const char *name)
: QObject(parent, name),
m_ix(0), m_iy(0), m_x(0), m_y(0), m_width(0), m_height(0),
m_isFullScreen(FALSE), m_isOnHookEvent(FALSE), m_isMouseBlocked(FALSE),
m_Widget(parent)
{
}
QEObject::~QEObject()
{
hookEvents(FALSE);
requestDestroy();
killTimers();
if (m_Widget) m_Widget->close(TRUE);
printf("(%s)->QEObject<-::destroy()\n", name());
}
void QEObject::setHookObject(QWidget *widget)
{
m_Widget = widget;
}
void QEObject::setMouseBlocked(bool block)
{
m_isMouseBlocked = block;
}
void QEObject::hookEvents(bool hook)
{
if (m_isOnHookEvent == hook) return;
m_isOnHookEvent = hook;
if (hook)
if (m_Widget) m_Widget->installEventFilter(this);
else
if (m_Widget) m_Widget->removeEventFilter(this);
}
/** event handles */
bool QEObject::eventFilter(QObject *obj, QEvent *ev)
{
bool endEvent = FALSE;
switch (ev->type())
{
case QEvent::MouseButtonPress:
if (m_isMouseBlocked) return TRUE;
endEvent = mousePressEvent((QMouseEvent *) ev);
break;
case QEvent::MouseButtonRelease:
if (m_isMouseBlocked) return TRUE;
endEvent = mouseReleaseEvent((QMouseEvent *) ev);
break;
case QEvent::MouseButtonDblClick:
if (m_isMouseBlocked) return TRUE;
endEvent = mouseDblClickEvent((QMouseEvent *) ev);
break;
case QEvent::MouseMove:
if (m_isMouseBlocked) return TRUE;
endEvent = mouseMoveEvent((QMouseEvent *) ev);
break;
case QEvent::Enter:
if (m_isMouseBlocked) return TRUE;
endEvent = mouseEnterEvent((QMouseEvent *) ev);
break;
case QEvent::Leave:
if (m_isMouseBlocked) return TRUE;
endEvent = mouseLeaveEvent((QMouseEvent *) ev);
break;
case QEvent::KeyPress:
endEvent = keyPressEvent((QKeyEvent *) ev);
break;
case QEvent::KeyRelease:
endEvent = keyReleaseEvent((QKeyEvent *) ev);
break;
case QEvent::FocusIn:
endEvent = focusInEvent((QFocusEvent *) ev);
break;
case QEvent::FocusOut:
endEvent = focusInEvent((QFocusEvent *) ev);
break;
case QEvent::Paint:
endEvent = paintEvent((QPaintEvent *) ev);
break;
case QEvent::Resize:
endEvent = resizeEvent((QResizeEvent *) ev);
break;
case QEvent::WindowActivate:
endEvent = windowActivateEvent((QEvent *) ev);
break;
case QEvent::WindowDeactivate:
endEvent = windowDeactivateEvent((QEvent *) ev);
break;
case QEvent::Close:
endEvent = closeEvent((QCloseEvent *) ev);
break;
default:
endEvent = obj->eventFilter(obj, ev);
break;
}
return (endEvent) ? endEvent : obj->eventFilter(obj, ev);
}
void QEObject::setGeometry(int x, int y, int w, int h)
{
if (m_Widget) m_Widget->setGeometry(x, y, w, h);
m_ix = m_x = x;
m_iy = m_y = y;
m_width = w;
m_height = h;
}
void QEObject::move(int x, int y)
{
if (m_Widget) m_Widget->move(x, y);
m_x = x;
m_y = y;
}
void QEObject::resize(int w, int h)
{
if (m_Widget) m_Widget->resize(w, h);
m_width = w;
m_height = h;
}
void QEObject::show()
{
if (m_Widget) m_Widget->show();
}
void QEObject::hide()
{
if (m_Widget) m_Widget->hide();
}
void QEObject::showNormal()
{
if (m_Widget) m_Widget->showNormal();
m_isFullScreen = FALSE;
}
void QEObject::showFullScreen()
{
if (m_Widget) m_Widget->showFullScreen();
m_isFullScreen = TRUE;
}
With the above try i had try to implement another class especialy the
QWidget but it seem can not work.
Ok, i found the
ZMainWidget can work with my technic, so i used it to my main widget for implement anothers.
QEWidget class HEADER - qewidget.h PHP Code:
/***************************************************************************
* *
* (c) 2007, Thanomsub Noppaburana <donga.nb@gmail.com> *
* *
* 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 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. *
* *
* 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. *
***************************************************************************/
#ifndef __QEWIDGET_H__
#define __QEWIDGET_H__
#include <stdio.h>
#include <qimage.h>
#include <qpixmap.h>
#include <qwidget.h>
#include <zmainwidget.h>
#include "qeglobal.h"
#include "qeobject.h"
/**
*****************************************************************************
class QEWidget definition
*****************************************************************************
*/
class QEWidget : public QEObject
{
Q_OBJECT
public:
QEWidget(const QString &title, QWidget *parent=0, const char *name = 0, WFlags f=0);
QEWidget(QWidget *parent, const char *name = 0, WFlags f=0);
QEWidget(const char *name = 0);
QEWidget(bool editorMode, QWidget *parent=0, const char *name=0, WFlags f=0);
virtual ~QEWidget();
ZMainWidget *widget() const { return (ZMainWidget*) m_Widget; };
WId winId() const { return (m_Widget) ? m_Widget->winId() : (unsigned int)-1; };
virtual void setBackgroundPixmap(const QPixmap &pix) { if (m_Widget) m_Widget->setBackgroundPixmap(pix); };
virtual void setBackgroundMode(const QWidget::BackgroundMode &);
virtual void setBackgroundColor(const QColor &clr) { if (m_Widget) m_Widget->setBackgroundColor(clr); };
protected:
WFlags m_WFlags;
};
#endif // __QEWIDGET_H__
and the
BODY - qewidget.cpp PHP Code:
/***************************************************************************
* *
* (c) 2007, Thanomsub Noppaburana <donga.nb@gmail.com> *
* *
* 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 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. *
* *
* 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 <qpainter.h>
#include "qewidget.h"
/**
*****************************************************************************
class QEWidget implementation
*****************************************************************************
*/
QEWidget::QEWidget(const QString &title, QWidget *parent, const char *name, WFlags f)
: QEObject(parent, name), m_WFlags(f)
{
m_Widget = new ZMainWidget(title, FALSE, parent, name, f);
CHECK_PTR(m_Widget);
widget()->getTitleBarWidget()->hide();
}
QEWidget::QEWidget(QWidget *parent, const char *name, WFlags f)
: QEObject(parent, name), m_WFlags(f)
{
m_Widget = new ZMainWidget("", FALSE, parent, name, f);
CHECK_PTR(m_Widget);
widget()->getTitleBarWidget()->hide();
}
QEWidget::QEWidget(const char *name)
: QEObject(0, name)
{
m_Widget = new ZMainWidget(name, FALSE, 0, name);
CHECK_PTR(m_Widget);
widget()->getTitleBarWidget()->hide();
}
QEWidget::QEWidget(bool editorMode, QWidget *parent, const char *name, WFlags f)
: QEObject(parent, name), m_WFlags(f)
{
m_Widget = new ZMainWidget(editorMode, parent, name, f);
CHECK_PTR(m_Widget);
widget()->getTitleBarWidget()->hide();
}
QEWidget::~QEWidget()
{
if (m_Widget) {
delete m_Widget;
m_Widget = 0;
}
printf("(%s)->QEWidget<-::destroy()\n", name());
}
void QEWidget::setBackgroundMode(const QWidget::BackgroundMode &bgm)
{
if (m_Widget) m_Widget->setBackgroundMode(bgm);
}
Because the ZMainWidget object have the title bar, then i hide it in the constructor of the class.
Well, lets go to the next section.