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