From e677aafcadcf9c1fff764c669d360e75b63b5050 Mon Sep 17 00:00:00 2001 From: Viranch Mehta Date: Wed, 17 Aug 2011 23:21:04 +0530 Subject: [PATCH] Rename QMenuItem to QMenuAction, QMenuItem was already defined. Add support for separators in QMenus --- .../qtextracomponents/CMakeLists.txt | 1 + declarativeimports/qtextracomponents/qmenu.cpp | 8 ++++---- declarativeimports/qtextracomponents/qmenu.h | 14 ++++++-------- .../qtextracomponents/qmenuaction.cpp | 8 ++++++++ .../{qmenuitem.h => qmenuaction.h} | 8 +++----- .../qtextracomponents/qtextracomponentsplugin.cpp | 4 ++-- 6 files changed, 24 insertions(+), 19 deletions(-) create mode 100644 declarativeimports/qtextracomponents/qmenuaction.cpp rename declarativeimports/qtextracomponents/{qmenuitem.h => qmenuaction.h} (93%) diff --git a/declarativeimports/qtextracomponents/CMakeLists.txt b/declarativeimports/qtextracomponents/CMakeLists.txt index 7c3f5c5c9..7b4bc7450 100644 --- a/declarativeimports/qtextracomponents/CMakeLists.txt +++ b/declarativeimports/qtextracomponents/CMakeLists.txt @@ -8,6 +8,7 @@ set(qtextracomponents_SRCS qimageitem.cpp qiconitem.cpp qmenu.cpp + qmenuaction.cpp ) INCLUDE_DIRECTORIES( diff --git a/declarativeimports/qtextracomponents/qmenu.cpp b/declarativeimports/qtextracomponents/qmenu.cpp index 54203829c..1a6004e1d 100644 --- a/declarativeimports/qtextracomponents/qmenu.cpp +++ b/declarativeimports/qtextracomponents/qmenu.cpp @@ -31,9 +31,9 @@ QMenuProxy::~QMenuProxy() delete m_menu; } -QDeclarativeListProperty QMenuProxy::actions() +QDeclarativeListProperty QMenuProxy::actions() { - return QDeclarativeListProperty(this, m_actions); + return QDeclarativeListProperty(this, m_actions); } int QMenuProxy::actionCount() const @@ -41,7 +41,7 @@ int QMenuProxy::actionCount() const return m_actions.count(); } -QMenuItem *QMenuProxy::action(int index) const +QMenuAction *QMenuProxy::action(int index) const { return m_actions.at(index); } @@ -49,7 +49,7 @@ QMenuItem *QMenuProxy::action(int index) const void QMenuProxy::showMenu(int x, int y) { m_menu->clear(); - foreach(QMenuItem* item, m_actions) { + foreach(QMenuAction* item, m_actions) { m_menu->addAction (item); } diff --git a/declarativeimports/qtextracomponents/qmenu.h b/declarativeimports/qtextracomponents/qmenu.h index af16f45c9..66511c0ba 100644 --- a/declarativeimports/qtextracomponents/qmenu.h +++ b/declarativeimports/qtextracomponents/qmenu.h @@ -20,32 +20,30 @@ #ifndef QMENU_PROXY_H #define QMENU_PROXY_H +#include #include #include -#include "qmenuitem.h" +#include "qmenuaction.h" class QMenuProxy : public QObject { Q_OBJECT - Q_PROPERTY(QDeclarativeListProperty actions READ actions) + Q_PROPERTY(QDeclarativeListProperty actions READ actions) Q_CLASSINFO("DefaultProperty", "actions") public: QMenuProxy(QObject *parent = 0); ~QMenuProxy(); - QDeclarativeListProperty actions(); + QDeclarativeListProperty actions(); int actionCount() const; - QMenuItem *action(int) const; + QMenuAction *action(int) const; Q_INVOKABLE void showMenu(int x, int y); -Q_SIGNALS: - void actionTriggered(QString itemName); - private: - QList m_actions; + QList m_actions; QMenu *m_menu; }; diff --git a/declarativeimports/qtextracomponents/qmenuaction.cpp b/declarativeimports/qtextracomponents/qmenuaction.cpp new file mode 100644 index 000000000..bffc3a389 --- /dev/null +++ b/declarativeimports/qtextracomponents/qmenuaction.cpp @@ -0,0 +1,8 @@ +#include "qmenuaction.h" + +QMenuAction::QMenuAction(QObject *parent) : QAction(parent) +{ +} + +#include "qmenuaction.moc" + diff --git a/declarativeimports/qtextracomponents/qmenuitem.h b/declarativeimports/qtextracomponents/qmenuaction.h similarity index 93% rename from declarativeimports/qtextracomponents/qmenuitem.h rename to declarativeimports/qtextracomponents/qmenuaction.h index df14b85c7..c1032750a 100644 --- a/declarativeimports/qtextracomponents/qmenuitem.h +++ b/declarativeimports/qtextracomponents/qmenuaction.h @@ -21,18 +21,16 @@ #define QMENUITEM_H #include +#include -class QMenuItem : public QAction +class QMenuAction : public QAction { Q_OBJECT Q_PROPERTY(bool separator READ isSeparator WRITE setSeparator) public: - QMenuItem(QObject *parent = 0) - : QAction(parent) - { - } + QMenuAction(QObject *parent = 0); }; #endif // QMENUITEM_H diff --git a/declarativeimports/qtextracomponents/qtextracomponentsplugin.cpp b/declarativeimports/qtextracomponents/qtextracomponentsplugin.cpp index 5bb8529dc..07eb59c32 100644 --- a/declarativeimports/qtextracomponents/qtextracomponentsplugin.cpp +++ b/declarativeimports/qtextracomponents/qtextracomponentsplugin.cpp @@ -27,7 +27,7 @@ #include "qimageitem.h" #include "qiconitem.h" #include "qmenu.h" -#include "qmenuitem.h" +#include "qmenuaction.h" void QtExtraComponentsPlugin::registerTypes(const char *uri) { @@ -37,7 +37,7 @@ void QtExtraComponentsPlugin::registerTypes(const char *uri) qmlRegisterType(uri, 0, 1, "QImageItem"); qmlRegisterType(uri, 0, 1, "QIconItem"); qmlRegisterType(uri, 0, 1, "QMenu"); - qmlRegisterType(uri, 0, 1, "QMenuItem"); + qmlRegisterType(uri, 0, 1, "QMenuAction"); }