Make QMenuItem a derived class of QAction (to minimize its implementation)

This commit is contained in:
Viranch Mehta 2011-08-17 20:30:53 +05:30
parent c34d4ea456
commit 220cae4242
5 changed files with 8 additions and 78 deletions

View File

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

View File

@ -18,7 +18,6 @@
***************************************************************************/ ***************************************************************************/
#include "qmenu.h" #include "qmenu.h"
#include <QMenu>
#include <QApplication> #include <QApplication>
QMenuProxy::QMenuProxy (QObject *parent) QMenuProxy::QMenuProxy (QObject *parent)
@ -51,7 +50,7 @@ void QMenuProxy::showMenu(int x, int y)
{ {
m_menu->clear(); m_menu->clear();
foreach(QMenuItem* item, m_actions) { foreach(QMenuItem* item, m_actions) {
m_menu->addAction(item->nativeAction()); m_menu->addAction (item);
} }
QPoint screenPos = QApplication::activeWindow()->mapToGlobal(QPoint(x, y)); QPoint screenPos = QApplication::activeWindow()->mapToGlobal(QPoint(x, y));

View File

@ -20,6 +20,7 @@
#ifndef QMENU_PROXY_H #ifndef QMENU_PROXY_H
#define QMENU_PROXY_H #define QMENU_PROXY_H
#include <QMenu>
#include <QDeclarativeListProperty> #include <QDeclarativeListProperty>
#include "qmenuitem.h" #include "qmenuitem.h"

View File

@ -1,41 +0,0 @@
/***************************************************************************
* 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 "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"

View File

@ -22,45 +22,17 @@
#include <QAction> #include <QAction>
class QMenuItem : public QObject class QMenuItem : public QAction
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(bool checkable READ checkable WRITE setCheckable) Q_PROPERTY(bool separator READ isSeparator WRITE setSeparator)
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)
public: public:
QMenuItem(QObject *parent = 0); QMenuItem(QObject *parent = 0)
~QMenuItem(); : QAction(parent)
{
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;
}; };
#endif // QMENUITEM_H #endif // QMENUITEM_H