From 220cae4242d1664de8c2c18d921017a802b903af Mon Sep 17 00:00:00 2001 From: Viranch Mehta Date: Wed, 17 Aug 2011 20:30:53 +0530 Subject: [PATCH] Make QMenuItem a derived class of QAction (to minimize its implementation) --- .../qtextracomponents/CMakeLists.txt | 1 - .../qtextracomponents/qmenu.cpp | 3 +- declarativeimports/qtextracomponents/qmenu.h | 1 + .../qtextracomponents/qmenuitem.cpp | 41 ------------------- .../qtextracomponents/qmenuitem.h | 40 +++--------------- 5 files changed, 8 insertions(+), 78 deletions(-) delete mode 100644 declarativeimports/qtextracomponents/qmenuitem.cpp diff --git a/declarativeimports/qtextracomponents/CMakeLists.txt b/declarativeimports/qtextracomponents/CMakeLists.txt index f395e632f..7c3f5c5c9 100644 --- a/declarativeimports/qtextracomponents/CMakeLists.txt +++ b/declarativeimports/qtextracomponents/CMakeLists.txt @@ -8,7 +8,6 @@ set(qtextracomponents_SRCS qimageitem.cpp qiconitem.cpp qmenu.cpp - qmenuitem.cpp ) INCLUDE_DIRECTORIES( diff --git a/declarativeimports/qtextracomponents/qmenu.cpp b/declarativeimports/qtextracomponents/qmenu.cpp index a6a41ff1b..54203829c 100644 --- a/declarativeimports/qtextracomponents/qmenu.cpp +++ b/declarativeimports/qtextracomponents/qmenu.cpp @@ -18,7 +18,6 @@ ***************************************************************************/ #include "qmenu.h" -#include #include QMenuProxy::QMenuProxy (QObject *parent) @@ -51,7 +50,7 @@ void QMenuProxy::showMenu(int x, int y) { m_menu->clear(); foreach(QMenuItem* item, m_actions) { - m_menu->addAction(item->nativeAction()); + m_menu->addAction (item); } QPoint screenPos = QApplication::activeWindow()->mapToGlobal(QPoint(x, y)); diff --git a/declarativeimports/qtextracomponents/qmenu.h b/declarativeimports/qtextracomponents/qmenu.h index 489e4d5c6..af16f45c9 100644 --- a/declarativeimports/qtextracomponents/qmenu.h +++ b/declarativeimports/qtextracomponents/qmenu.h @@ -20,6 +20,7 @@ #ifndef QMENU_PROXY_H #define QMENU_PROXY_H +#include #include #include "qmenuitem.h" diff --git a/declarativeimports/qtextracomponents/qmenuitem.cpp b/declarativeimports/qtextracomponents/qmenuitem.cpp deleted file mode 100644 index bf4ba9b30..000000000 --- a/declarativeimports/qtextracomponents/qmenuitem.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/*************************************************************************** - * 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 "qmenuitem.h" - -QMenuItem::QMenuItem(QObject *parent) - : QObject(parent) -{ - m_action = new QAction(0); - connect (m_action, SIGNAL(triggered(bool)), - this, SLOT(emitTriggered(bool))); -} - -QMenuItem::~QMenuItem() -{ - delete m_action; -} - -void QMenuItem::emitTriggered(bool checked) -{ - emit triggered(); -} - -#include "qmenuitem.moc" - diff --git a/declarativeimports/qtextracomponents/qmenuitem.h b/declarativeimports/qtextracomponents/qmenuitem.h index 2cd12b0b3..df14b85c7 100644 --- a/declarativeimports/qtextracomponents/qmenuitem.h +++ b/declarativeimports/qtextracomponents/qmenuitem.h @@ -22,45 +22,17 @@ #include -class QMenuItem : public QObject +class QMenuItem : public QAction { Q_OBJECT - Q_PROPERTY(bool checkable READ checkable WRITE setCheckable) - Q_PROPERTY(bool checked READ checked WRITE setChecked) - Q_PROPERTY(bool enabled READ enabled WRITE setEnabled) - Q_PROPERTY(QString text READ text WRITE setText) - Q_PROPERTY(QIcon icon READ icon WRITE setIcon) + Q_PROPERTY(bool separator READ isSeparator WRITE setSeparator) public: - QMenuItem(QObject *parent = 0); - ~QMenuItem(); - - bool enabled() const { return m_action->isEnabled(); } - void setEnabled(const bool enabled) { m_action->setEnabled(enabled); } - - bool checkable() const { return m_action->isCheckable(); } - void setCheckable(const bool checkable) { m_action->setCheckable(checkable); } - - bool checked() const { return m_action->isChecked(); } - void setChecked(const bool checked) { m_action->setChecked(checked); } - - QString text() const { return m_action->text(); } - void setText(const QString &text) { m_action->setText(text); } - - QIcon icon() const { return m_action->icon(); } - void setIcon(const QIcon &icon) { m_action->setIcon(icon); } - - QAction *nativeAction() { return m_action; } - -public Q_SLOTS: - void emitTriggered(bool checked); - -Q_SIGNALS: - void triggered(); - -private: - QAction *m_action; + QMenuItem(QObject *parent = 0) + : QAction(parent) + { + } }; #endif // QMENUITEM_H