positioning for context menu

This commit is contained in:
Sebastian Kügler 2013-03-26 22:17:25 +01:00
parent aedfc3a580
commit 0ef4080e4f
5 changed files with 29 additions and 13 deletions

View File

@ -22,8 +22,7 @@
#include <QApplication>
#include <QDebug>
#include <QDesktopWidget>
// #include <QQuickItem>
// #include <QGraphicsView>
#include <QQuickWindow>
#include <QQuickItem>
#include "plasmacomponentsplugin.h"
@ -174,6 +173,12 @@ void QMenuProxy::open(int x, int y)
} else {
parentItem = qobject_cast<QQuickItem *>(parent());
}
QPointF pos = parentItem->mapToScene(QPointF(x, y));
//qDebug() << "I've an Item at " << pos;
if (parentItem->window() && parentItem->window()->screen()) {
pos = parentItem->window()->mapToGlobal(pos.toPoint());
}
screenPos = pos.toPoint();
/*
if (!parentItem || !parentItem->scene()) {
m_menu->popup(QPoint(0, 0));
@ -235,6 +240,7 @@ void QMenuProxy::open()
} else {
parentItem = qobject_cast<QQuickItem *>(parent());
}
/*
if (!parentItem || !parentItem->scene()) {
m_menu->popup(QPoint(0, 0));

View File

@ -19,6 +19,7 @@
#include "qmenuitem.h"
QMenuItem::QMenuItem(QQuickItem *parent)
: QQuickItem(parent),
m_action(0)
@ -43,15 +44,17 @@ void QMenuItem::setAction(QAction* a)
}
}
QIcon QMenuItem::icon() const
QString QMenuItem::icon() const
{
return m_action->icon();
return m_icon;
}
void QMenuItem::setIcon(const QIcon& i)
void QMenuItem::setIcon(const QString& i)
{
m_action->setIcon(i);
emit iconChanged();
if (i != m_icon) {
m_action->setIcon(QIcon::fromTheme(i));
emit iconChanged();
}
}
bool QMenuItem::separator() const

View File

@ -38,7 +38,7 @@ class QMenuItem : public QQuickItem
*/
Q_PROPERTY(bool separator READ separator WRITE setSeparator NOTIFY separatorChanged)
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
Q_PROPERTY(QIcon icon READ icon WRITE setIcon NOTIFY iconChanged)
Q_PROPERTY(QString icon READ icon WRITE setIcon NOTIFY iconChanged)
Q_PROPERTY(QAction* action READ action WRITE setAction NOTIFY actionChanged)
public:
@ -46,8 +46,8 @@ public:
QAction* action() const;
void setAction(QAction* a);
QIcon icon() const;
void setIcon(const QIcon& i);
QString icon() const;
void setIcon(const QString& i);
bool separator() const;
void setSeparator(bool s);
QString text() const;
@ -63,6 +63,7 @@ Q_SIGNALS:
private:
QAction* m_action;
QString m_icon;
};
#endif // QMENUITEM_H

View File

@ -58,7 +58,6 @@ PlasmaComponents.Page {
if (checked) plasmoid.backgroundHints = 2;
}
}
}
PlasmaComponents.Button {
@ -71,6 +70,7 @@ PlasmaComponents.Page {
}
PlasmaComponents.Button {
id: ctxButton
height: theme.iconSizes.desktop
text: "Context Menu"
Loader {
@ -80,8 +80,9 @@ PlasmaComponents.Page {
if (menuLoader.source == "") {
menuLoader.source = "TestMenu.qml"
} else {
menuLoader.source = ""
//menuLoader.source = ""
}
menuLoader.item.open(0, height);
}
}

View File

@ -39,9 +39,14 @@ PlasmaComponents.Menu {
onClicked: print(" Clicked on : " + text)
}
PlasmaComponents.MenuItem {
text: "White Tip Reef Shark"
icon: "kmag"
onClicked: print(" Clicked on : " + text)
}
Component.onCompleted:{
print("TestMenu.qml served .. opening");
testMenu.open();
}
}