Commit 1486b2e2 authored by Richard Moe Gustavsen's avatar Richard Moe Gustavsen
Browse files

ComboBox: add support for onSelected etc inside MenuItem

parent cdd99115
Branches
Tags
No related merge requests found
Showing with 21 additions and 1 deletion
...@@ -42,7 +42,7 @@ import "custom" as Custom ...@@ -42,7 +42,7 @@ import "custom" as Custom
* text: "Pineapple" * text: "Pineapple"
* } * }
* MenuItem { * MenuItem {
* text: "Grapes" * text: "Grape"
* } * }
* } * }
* *
......
...@@ -19,6 +19,16 @@ MenuBase { ...@@ -19,6 +19,16 @@ MenuBase {
onModelChanged: if (Component.status === Component.Ready) rebuildMenu() onModelChanged: if (Component.status === Component.Ready) rebuildMenu()
Component.onCompleted: rebuildMenu() Component.onCompleted: rebuildMenu()
onHighlightedIndexChanged: {
if (highlightedIndex < menuItems.length)
menuItems[highlightedIndex].emitHighlighted()
}
onSelectedIndexChanged: {
if (highlightedIndex < menuItems.length)
menuItems[highlightedIndex].emitSelected()
}
onVisibleChanged: { onVisibleChanged: {
if (visible) { if (visible) {
var globalPos = parent.mapToItem(null, x, y) var globalPos = parent.mapToItem(null, x, y)
......
...@@ -38,6 +38,12 @@ class QtMenu : public QDeclarativeItem ...@@ -38,6 +38,12 @@ class QtMenu : public QDeclarativeItem
Q_PROPERTY(QString title READ title WRITE setTitle) Q_PROPERTY(QString title READ title WRITE setTitle)
Q_PROPERTY(int selectedIndex READ selectedIndex WRITE setSelectedIndex NOTIFY selectedIndexChanged) Q_PROPERTY(int selectedIndex READ selectedIndex WRITE setSelectedIndex NOTIFY selectedIndexChanged)
Q_PROPERTY(int highlightedIndex READ highlightedIndex WRITE setHighlightedIndex NOTIFY highlightedIndexChanged) Q_PROPERTY(int highlightedIndex READ highlightedIndex WRITE setHighlightedIndex NOTIFY highlightedIndexChanged)
// The only reason we declare a list of menu items here, is so we can make it a default
// property from within QML, if needed. The reason we don't implement the code for using
// the list here, is that we expect the QML code to mix both ListModel and MenuItems API for
// adding menu items. And we don't wan't to decide how to mix those two API-s from here. So the only
// API in his class will be 'addMenuItem' and 'clearMenuItems'.
Q_PROPERTY(QDeclarativeListProperty<QtMenuItem> menuItems READ menuItems NOTIFY menuItemsChanged) Q_PROPERTY(QDeclarativeListProperty<QtMenuItem> menuItems READ menuItems NOTIFY menuItemsChanged)
Q_CLASSINFO("DefaultProperty", "menuItems") Q_CLASSINFO("DefaultProperty", "menuItems")
public: public:
......
...@@ -54,8 +54,12 @@ public: ...@@ -54,8 +54,12 @@ public:
void setText(const QString &text); void setText(const QString &text);
QString text(); QString text();
Q_INVOKABLE void emitHighlighted() { emit highlighted(); }
Q_INVOKABLE void emitSelected() { emit selected(); }
Q_SIGNALS: Q_SIGNALS:
void selected(); void selected();
void highlighted();
void textChanged(); void textChanged();
private: private:
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment