From 2c6677aaf464f5c24f1773c7d55f4e9a27f45f11 Mon Sep 17 00:00:00 2001 From: Viranch Mehta Date: Tue, 2 Aug 2011 19:43:48 +0530 Subject: [PATCH] QMenu QML binding (with test 'hello','world' menu entries) --- .../qtextracomponents/CMakeLists.txt | 1 + .../qtextracomponents/qmenu.cpp | 43 +++++++++++++++++++ declarativeimports/qtextracomponents/qmenu.h | 41 ++++++++++++++++++ .../qtextracomponentsplugin.cpp | 2 + 4 files changed, 87 insertions(+) create mode 100644 declarativeimports/qtextracomponents/qmenu.cpp create mode 100644 declarativeimports/qtextracomponents/qmenu.h diff --git a/declarativeimports/qtextracomponents/CMakeLists.txt b/declarativeimports/qtextracomponents/CMakeLists.txt index 3264ae8e2..7c3f5c5c9 100644 --- a/declarativeimports/qtextracomponents/CMakeLists.txt +++ b/declarativeimports/qtextracomponents/CMakeLists.txt @@ -7,6 +7,7 @@ set(qtextracomponents_SRCS qpixmapitem.cpp qimageitem.cpp qiconitem.cpp + qmenu.cpp ) INCLUDE_DIRECTORIES( diff --git a/declarativeimports/qtextracomponents/qmenu.cpp b/declarativeimports/qtextracomponents/qmenu.cpp new file mode 100644 index 000000000..e94767460 --- /dev/null +++ b/declarativeimports/qtextracomponents/qmenu.cpp @@ -0,0 +1,43 @@ +/*************************************************************************** + * Copyright 2011 Viranch Mehta * + * * + * 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" + diff --git a/declarativeimports/qtextracomponents/qmenu.h b/declarativeimports/qtextracomponents/qmenu.h new file mode 100644 index 000000000..0a708da96 --- /dev/null +++ b/declarativeimports/qtextracomponents/qmenu.h @@ -0,0 +1,41 @@ +/*************************************************************************** + * Copyright 2011 Viranch Mehta * + * * + * 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 +#include + +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 + diff --git a/declarativeimports/qtextracomponents/qtextracomponentsplugin.cpp b/declarativeimports/qtextracomponents/qtextracomponentsplugin.cpp index 7d6b61f82..e8c8eb327 100644 --- a/declarativeimports/qtextracomponents/qtextracomponentsplugin.cpp +++ b/declarativeimports/qtextracomponents/qtextracomponentsplugin.cpp @@ -26,6 +26,7 @@ #include "qpixmapitem.h" #include "qimageitem.h" #include "qiconitem.h" +#include "qmenu.h" void QtExtraComponentsPlugin::registerTypes(const char *uri) { @@ -34,6 +35,7 @@ void QtExtraComponentsPlugin::registerTypes(const char *uri) qmlRegisterType(uri, 0, 1, "QPixmapItem"); qmlRegisterType(uri, 0, 1, "QImageItem"); qmlRegisterType(uri, 0, 1, "QIconItem"); + qmlRegisterType(uri, 0, 1, "QMenu"); }