QMenu QML binding (with test 'hello','world' menu entries)

This commit is contained in:
Viranch Mehta 2011-08-02 19:43:48 +05:30
parent e8432fe351
commit 2c6677aaf4
4 changed files with 87 additions and 0 deletions

View File

@ -7,6 +7,7 @@ set(qtextracomponents_SRCS
qpixmapitem.cpp qpixmapitem.cpp
qimageitem.cpp qimageitem.cpp
qiconitem.cpp qiconitem.cpp
qmenu.cpp
) )
INCLUDE_DIRECTORIES( INCLUDE_DIRECTORIES(

View File

@ -0,0 +1,43 @@
/***************************************************************************
* Copyright 2011 Viranch Mehta <viranch.mehta@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., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/
#include "qmenu.h"
QMenuProxy::QMenuProxy (QObject *parent)
: QObject (parent)
{
m_menu = new QMenu();
/* Test entries, should be removed later */
m_menu->addAction ("hello");
m_menu->addAction ("world");
}
QMenuProxy::~QMenuProxy()
{
delete m_menu;
}
void QMenuProxy::showMenu(int x, int y)
{
m_menu->popup(QPoint(x,y));
}
#include "qmenu.moc"

View File

@ -0,0 +1,41 @@
/***************************************************************************
* Copyright 2011 Viranch Mehta <viranch.mehta@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., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/
#ifndef QMENU_PROXY_H
#define QMENU_PROXY_H
#include <QObject>
#include <QMenu>
class QMenuProxy : public QObject
{
Q_OBJECT
public:
QMenuProxy(QObject *parent = 0);
~QMenuProxy();
Q_INVOKABLE void showMenu(int x, int y);
private:
QMenu *m_menu;
};
#endif //QMENU_PROXY_H

View File

@ -26,6 +26,7 @@
#include "qpixmapitem.h" #include "qpixmapitem.h"
#include "qimageitem.h" #include "qimageitem.h"
#include "qiconitem.h" #include "qiconitem.h"
#include "qmenu.h"
void QtExtraComponentsPlugin::registerTypes(const char *uri) void QtExtraComponentsPlugin::registerTypes(const char *uri)
{ {
@ -34,6 +35,7 @@ void QtExtraComponentsPlugin::registerTypes(const char *uri)
qmlRegisterType<QPixmapItem>(uri, 0, 1, "QPixmapItem"); qmlRegisterType<QPixmapItem>(uri, 0, 1, "QPixmapItem");
qmlRegisterType<QImageItem>(uri, 0, 1, "QImageItem"); qmlRegisterType<QImageItem>(uri, 0, 1, "QImageItem");
qmlRegisterType<QIconItem>(uri, 0, 1, "QIconItem"); qmlRegisterType<QIconItem>(uri, 0, 1, "QIconItem");
qmlRegisterType<QMenuProxy>(uri, 0, 1, "QMenu");
} }