export status

This commit is contained in:
Marco Martin 2011-10-28 19:40:04 +02:00
parent 5788424702
commit 4970198392
2 changed files with 27 additions and 10 deletions

View File

@ -24,7 +24,8 @@
#include <QGraphicsView>
QMenuProxy::QMenuProxy (QObject *parent)
: QObject (parent)
: QObject(parent),
m_status(DialogStatus::Closed)
{
m_menu = new QMenu(0);
}
@ -34,30 +35,37 @@ QMenuProxy::~QMenuProxy()
delete m_menu;
}
QDeclarativeListProperty<QMenuItem> QMenuProxy::actions()
QDeclarativeListProperty<QMenuItem> QMenuProxy::items()
{
return QDeclarativeListProperty<QMenuItem>(this, m_actions);
return QDeclarativeListProperty<QMenuItem>(this, m_items);
}
int QMenuProxy::actionCount() const
{
return m_actions.count();
return m_items.count();
}
QMenuItem *QMenuProxy::action(int index) const
{
return m_actions.at(index);
return m_items.at(index);
}
DialogStatus::Status QMenuProxy::status() const
{
return m_status;
}
void QMenuProxy::showMenu(int x, int y)
{
m_menu->clear();
foreach(QMenuItem* item, m_actions) {
foreach(QMenuItem* item, m_items) {
m_menu->addAction (item);
}
QPoint screenPos = QApplication::activeWindow()->mapToGlobal(QPoint(x, y));
m_menu->popup(screenPos);
m_status = DialogStatus::Open;
emit statusChanged();
}
void QMenuProxy::open()
@ -107,6 +115,8 @@ void QMenuProxy::open()
void QMenuProxy::close()
{
m_menu->hide();
m_status = DialogStatus::Closed;
emit statusChanged();
}
#include "qmenu.moc"

View File

@ -24,29 +24,36 @@
#include <QMenu>
#include <QDeclarativeListProperty>
#include "qmenuitem.h"
#include "enums.h"
class QMenuProxy : public QObject
{
Q_OBJECT
Q_PROPERTY(QDeclarativeListProperty<QMenuItem> actions READ actions)
Q_CLASSINFO("DefaultProperty", "actions")
Q_PROPERTY(QDeclarativeListProperty<QMenuItem> items READ items CONSTANT)
Q_CLASSINFO("DefaultProperty", "items")
Q_PROPERTY(DialogStatus::Status status READ status NOTIFY statusChanged)
public:
QMenuProxy(QObject *parent = 0);
~QMenuProxy();
QDeclarativeListProperty<QMenuItem> actions();
QDeclarativeListProperty<QMenuItem> items();
int actionCount() const;
QMenuItem *action(int) const;
DialogStatus::Status status() const;
void showMenu(int x, int y);
Q_INVOKABLE void open();
Q_INVOKABLE void close();
Q_SIGNALS:
void statusChanged();
private:
QList<QMenuItem*> m_actions;
QList<QMenuItem*> m_items;
QMenu *m_menu;
DialogStatus::Status m_status;
};
#endif //QMENU_PROXY_H