From e735d95e613e2ee6170799002183e0770d34590e Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Wed, 5 Jun 2013 13:50:12 -0400 Subject: unitymenumodel: add activate() --- examples/unityqmlmenumodel.qml | 9 +++++++-- libqmenumodel/src/unitymenumodel.cpp | 17 +++++++++++++++++ libqmenumodel/src/unitymenumodel.h | 3 +++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/examples/unityqmlmenumodel.qml b/examples/unityqmlmenumodel.qml index d38d6e5..a66ba8e 100644 --- a/examples/unityqmlmenumodel.qml +++ b/examples/unityqmlmenumodel.qml @@ -14,6 +14,7 @@ Item { } ListView { + id: listview anchors.fill: parent anchors.margins: 10 spacing: 3 @@ -25,7 +26,7 @@ Item { Component { id: separator Rectangle { - width: parent.width + width: listview.width height: 4 color: "blue" } @@ -34,7 +35,7 @@ Item { Component { id: menuitem Rectangle { - width: parent.width + width: listview.width height: 40 color: "#ddd" Text { @@ -44,6 +45,10 @@ Item { color: sensitive ? "black" : "#aaa"; text: label } + MouseArea { + anchors.fill: parent + onClicked: listview.model.activate(index); + } } } } diff --git a/libqmenumodel/src/unitymenumodel.cpp b/libqmenumodel/src/unitymenumodel.cpp index 336b72a..8000222 100644 --- a/libqmenumodel/src/unitymenumodel.cpp +++ b/libqmenumodel/src/unitymenumodel.cpp @@ -37,6 +37,7 @@ public: int nrItems(); QVariant data(int position, int role); + void activate(int position); private: UnityMenuModel *model; @@ -127,6 +128,14 @@ QVariant UnityMenuModelPrivate::data(int position, int role) } } +void UnityMenuModelPrivate::activate(int position) +{ + GtkMenuTrackerItem *item; + + item = (GtkMenuTrackerItem *) g_sequence_get (g_sequence_get_iter_at_pos (this->items, position)); + gtk_menu_tracker_item_activated (item); +} + void UnityMenuModelPrivate::freeMenuItem (gpointer data, gpointer user_data) { GSequenceIter *it = (GSequenceIter *) data; @@ -282,3 +291,11 @@ QHash UnityMenuModel::roleNames() const return names; } + +#include + +void UnityMenuModel::activate(int index) +{ + if (priv) + priv->activate(index); +} diff --git a/libqmenumodel/src/unitymenumodel.h b/libqmenumodel/src/unitymenumodel.h index 75af13a..38dd472 100644 --- a/libqmenumodel/src/unitymenumodel.h +++ b/libqmenumodel/src/unitymenumodel.h @@ -45,6 +45,9 @@ public: QModelIndex parent(const QModelIndex &index) const; QHash roleNames() const; +public Q_SLOTS: + void activate(int index); + protected: UnityMenuModel(QObject *parent = NULL); void init(const QByteArray &busName, const QByteArray &actionGroupObjectPath, const QByteArray &menuObjectPath); -- cgit v1.2.3