From aab9cedf451aea884aba8f126fe0c4ff3fda160b Mon Sep 17 00:00:00 2001
From: Richard Moe Gustavsen <richard.gustavsen@nokia.com>
Date: Fri, 10 Jun 2011 15:01:58 +0200
Subject: [PATCH] ComboBox: change highlighted to hovered

---
 components/ComboBox.qml           | 11 +++++++----
 components/Menu.qml               | 14 +++++++-------
 components/styleitem/qtmenu.cpp   | 12 ++++++------
 components/styleitem/qtmenu.h     | 10 +++++-----
 components/styleitem/qtmenuitem.h |  4 ++--
 5 files changed, 27 insertions(+), 24 deletions(-)

diff --git a/components/ComboBox.qml b/components/ComboBox.qml
index 8eb55f6e7..62c4e2108 100644
--- a/components/ComboBox.qml
+++ b/components/ComboBox.qml
@@ -16,9 +16,9 @@ import "custom" as Custom
 *   create items inside the popup menu
 * bool popupOpen - setting this property to 'true' will open the popup.
 * int selectedIndex - the index of the selected item in the popup menu.
-* int highlightedIndex - the index of the highlighted item in the popup menu.
+* int hoveredIndex - the index of the highlighted item in the popup menu.
 * string selectedText - the text of the selected menu item.
-* string highlightedText - the text of the highlighted menu item.
+* string hoveredText - the text of the highlighted menu item.
 *
 * Example 1:
 *
@@ -40,9 +40,12 @@ import "custom" as Custom
 *        width: 200
 *        MenuItem {
 *            text: "Pineapple"
+*            onSelected: console.debug(text)
+*
 *        }
 *        MenuItem {
 *            text: "Grape"
+*            onSelected: console.debug(text)
 *        }
 *    }
 *
@@ -56,9 +59,9 @@ Custom.BasicButton {
     property alias popupOpen: popup.visible
 
     property alias selectedIndex: popup.selectedIndex
-    property alias highlightedIndex: popup.highlightedIndex
+    property alias hoveredIndex: popup.hoveredIndex
     property alias selectedText: popup.selectedText
-    property alias highlightedText: popup.highlightedText
+    property alias hoveredText: popup.hoveredText
 
     background: QStyleItem {
         anchors.fill: parent
diff --git a/components/Menu.qml b/components/Menu.qml
index c005db719..b30121f46 100644
--- a/components/Menu.qml
+++ b/components/Menu.qml
@@ -6,8 +6,8 @@ MenuBase {
 
     property string selectedText: (selectedIndex < menuItems.length) ?
             menuItems[selectedIndex].text : model.get(selectedIndex - menuItems.length).text
-    property string highlightedText: (highlightedIndex < menuItems.length) ?
-            menuItems[highlightedIndex].text : model.get(highlightedIndex - menuItems.length).text
+    property string hoveredText: (hoveredIndex < menuItems.length) ?
+            menuItems[hoveredIndex].text : model.get(hoveredIndex - menuItems.length).text
 
     // 'centerSelectedText' means that the menu will be positioned
     //  so that the selected text' top left corner will be at x, y.
@@ -19,14 +19,14 @@ MenuBase {
     onModelChanged: if (Component.status === Component.Ready) rebuildMenu()
     Component.onCompleted: rebuildMenu()
 
-    onHighlightedIndexChanged: {
-        if (highlightedIndex < menuItems.length)
-            menuItems[highlightedIndex].emitHighlighted()
+    onHoveredIndexChanged: {
+        if (hoveredIndex < menuItems.length)
+            menuItems[hoveredIndex].emitHovered()
     }
 
     onSelectedIndexChanged: {
-        if (highlightedIndex < menuItems.length)
-            menuItems[highlightedIndex].emitSelected()
+        if (hoveredIndex < menuItems.length)
+            menuItems[hoveredIndex].emitSelected()
     }
 
     onVisibleChanged: {
diff --git a/components/styleitem/qtmenu.cpp b/components/styleitem/qtmenu.cpp
index 77ea063e2..15233f60e 100644
--- a/components/styleitem/qtmenu.cpp
+++ b/components/styleitem/qtmenu.cpp
@@ -59,13 +59,13 @@ void QtMenu::setSelectedIndex(int index)
     emit selectedIndexChanged();
 }
 
-void QtMenu::setHighlightedIndex(int index)
+void QtMenu::setHoveredIndex(int index)
 {
     m_highlightedIndex = index;
     QList<QAction *> actionList = m_menu->actions();
     if (m_highlightedIndex >= 0 && m_highlightedIndex < actionList.size())
         m_menu->setActiveAction(actionList[m_highlightedIndex]);
-    emit highlightedIndexChanged();
+    emit hoveredIndexChanged();
 }
 
 QDeclarativeListProperty<QtMenuItem> QtMenu::menuItems()
@@ -93,7 +93,7 @@ void QtMenu::showPopup(qreal x, qreal y, int atActionIndex)
     // ### activeWindow hack
     QPoint screenPosition = QApplication::activeWindow()->mapToGlobal(QPoint(x, y));
 
-    setHighlightedIndex(m_selectedIndex);
+    setHoveredIndex(m_selectedIndex);
     m_menu->popup(screenPosition, atAction);
 }
 
@@ -106,7 +106,7 @@ void QtMenu::addMenuItem(const QString &text)
 {
     QAction *action = new QAction(text, m_menu);
     connect(action, SIGNAL(triggered()), this, SLOT(emitSelected()));
-    connect(action, SIGNAL(hovered()), this, SLOT(emitHighlighted()));
+    connect(action, SIGNAL(hovered()), this, SLOT(emitHovered()));
     m_menu->insertAction(0, action);
 }
 
@@ -119,12 +119,12 @@ void QtMenu::emitSelected()
     emit selectedIndexChanged();
 }
 
-void QtMenu::emitHighlighted()
+void QtMenu::emitHovered()
 {
     QAction *act = qobject_cast<QAction *>(sender());
     if (!act)
         return;
     m_highlightedIndex = m_menu->actions().indexOf(act);
-    emit highlightedIndexChanged();
+    emit hoveredIndexChanged();
 }
 
diff --git a/components/styleitem/qtmenu.h b/components/styleitem/qtmenu.h
index 6b769ce63..23543e61c 100644
--- a/components/styleitem/qtmenu.h
+++ b/components/styleitem/qtmenu.h
@@ -37,7 +37,7 @@ class QtMenu : public QDeclarativeItem
     Q_OBJECT
     Q_PROPERTY(QString title READ title WRITE setTitle)
     Q_PROPERTY(int selectedIndex READ selectedIndex WRITE setSelectedIndex NOTIFY selectedIndexChanged)
-    Q_PROPERTY(int highlightedIndex READ highlightedIndex WRITE setHighlightedIndex NOTIFY highlightedIndexChanged)
+    Q_PROPERTY(int hoveredIndex READ hoveredIndex WRITE setHoveredIndex NOTIFY hoveredIndexChanged)
 
     // 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
@@ -54,8 +54,8 @@ public:
     QString title() const;
     int selectedIndex() const { return m_selectedIndex; }
     void setSelectedIndex(int index);
-    int highlightedIndex() const { return m_highlightedIndex; }
-    void setHighlightedIndex(int index);
+    int hoveredIndex() const { return m_highlightedIndex; }
+    void setHoveredIndex(int index);
     QDeclarativeListProperty<QtMenuItem> menuItems();
 
     Q_INVOKABLE void showPopup(qreal x, qreal y, int atActionIndex = -1);
@@ -65,12 +65,12 @@ public:
 
 Q_SIGNALS:
     void selectedIndexChanged();
-    void highlightedIndexChanged();
+    void hoveredIndexChanged();
     void menuClosed();
     void menuItemsChanged();
 private Q_SLOTS:
     void emitSelected();
-    void emitHighlighted();
+    void emitHovered();
 private:
     QString m_title;
     int m_selectedIndex;
diff --git a/components/styleitem/qtmenuitem.h b/components/styleitem/qtmenuitem.h
index 95f95c6fc..4bc60409f 100644
--- a/components/styleitem/qtmenuitem.h
+++ b/components/styleitem/qtmenuitem.h
@@ -54,12 +54,12 @@ public:
     void setText(const QString &text);
     QString text();
 
-    Q_INVOKABLE void emitHighlighted() { emit highlighted(); }
+    Q_INVOKABLE void emitHovered() { emit hovered(); }
     Q_INVOKABLE void emitSelected() { emit selected(); }
 
 Q_SIGNALS:
     void selected();
-    void highlighted();
+    void hovered();
     void textChanged();
 
 private:
-- 
GitLab