aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2013-06-05 13:50:12 -0400
committerLars Uebernickel <lars.uebernickel@canonical.com>2013-06-05 13:50:12 -0400
commite735d95e613e2ee6170799002183e0770d34590e (patch)
treed8f823bb8f17a9db0f4105f0566cf4b862e5476d
parent692926cb12c8f8e6d3969c249dbf924a0bd1499b (diff)
downloadqmenumodel-e735d95e613e2ee6170799002183e0770d34590e.tar.gz
qmenumodel-e735d95e613e2ee6170799002183e0770d34590e.tar.bz2
qmenumodel-e735d95e613e2ee6170799002183e0770d34590e.zip
unitymenumodel: add activate()
-rw-r--r--examples/unityqmlmenumodel.qml9
-rw-r--r--libqmenumodel/src/unitymenumodel.cpp17
-rw-r--r--libqmenumodel/src/unitymenumodel.h3
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<int, QByteArray> UnityMenuModel::roleNames() const
return names;
}
+
+#include <QDebug>
+
+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<int, QByteArray> 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);