support visualParent property
This commit is contained in:
parent
b3597331f7
commit
c0de261ccc
@ -24,6 +24,7 @@
|
||||
#include <QDesktopWidget>
|
||||
#include <QGraphicsObject>
|
||||
#include <QGraphicsView>
|
||||
#include <QDeclarativeItem>
|
||||
|
||||
QMenuProxy::QMenuProxy (QObject *parent)
|
||||
: QObject(parent),
|
||||
@ -57,6 +58,21 @@ DialogStatus::Status QMenuProxy::status() const
|
||||
return m_status;
|
||||
}
|
||||
|
||||
QDeclarativeItem *QMenuProxy::visualParent() const
|
||||
{
|
||||
return m_visualParent.data();
|
||||
}
|
||||
|
||||
void QMenuProxy::setVisualParent(QDeclarativeItem *parent)
|
||||
{
|
||||
if (m_visualParent.data() == parent) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_visualParent = parent;
|
||||
emit visualParentChanged();
|
||||
}
|
||||
|
||||
void QMenuProxy::showMenu(int x, int y)
|
||||
{
|
||||
m_menu->clear();
|
||||
@ -79,7 +95,12 @@ void QMenuProxy::open()
|
||||
}
|
||||
m_menu->updateGeometry();
|
||||
|
||||
QGraphicsObject *parentItem = qobject_cast<QGraphicsObject *>(parent());
|
||||
QGraphicsObject *parentItem;
|
||||
if (m_visualParent) {
|
||||
parentItem = qobject_cast<QGraphicsObject *>(parent());
|
||||
} else {
|
||||
parentItem = m_visualParent.data();
|
||||
}
|
||||
|
||||
if (!parentItem || !parentItem->scene()) {
|
||||
showMenu(0, 0);
|
||||
|
@ -26,12 +26,15 @@
|
||||
#include "qmenuitem.h"
|
||||
#include "enums.h"
|
||||
|
||||
class QDeclarativeItem;
|
||||
|
||||
class QMenuProxy : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(QDeclarativeListProperty<QMenuItem> items READ items CONSTANT)
|
||||
Q_CLASSINFO("DefaultProperty", "items")
|
||||
Q_PROPERTY(QDeclarativeItem *visualParent READ visualParent WRITE setVisualParent NOTIFY visualParentChanged())
|
||||
Q_PROPERTY(DialogStatus::Status status READ status NOTIFY statusChanged)
|
||||
|
||||
public:
|
||||
@ -43,17 +46,22 @@ public:
|
||||
QMenuItem *action(int) const;
|
||||
DialogStatus::Status status() const;
|
||||
|
||||
QDeclarativeItem *visualParent() const;
|
||||
void setVisualParent(QDeclarativeItem *parent);
|
||||
|
||||
void showMenu(int x, int y);
|
||||
Q_INVOKABLE void open();
|
||||
Q_INVOKABLE void close();
|
||||
|
||||
Q_SIGNALS:
|
||||
void statusChanged();
|
||||
void visualParentChanged();
|
||||
|
||||
private:
|
||||
QList<QMenuItem*> m_items;
|
||||
QMenu *m_menu;
|
||||
DialogStatus::Status m_status;
|
||||
QWeakPointer<QDeclarativeItem> m_visualParent;
|
||||
};
|
||||
|
||||
#endif //QMENU_PROXY_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user