Commit b7a70ec7 authored by Aurélien Gâteau's avatar Aurélien Gâteau
Browse files

Make favoriteId role non mandatory

parent 6ba7a961
......@@ -10,7 +10,7 @@ Item text
Name of the item icon
### string favoriteId
- mandatory: yes
- mandatory: no
Unique Id used to favorite this item. Its value depends on the item type:
- item cannot be favorited: ""
......
......@@ -25,10 +25,9 @@ Item {
id: main
property int iconWidth: 64
property string favoriteIcon
property alias currentText: resultLabel.text
property alias currentIcon: resultIcon.icon;
property alias favoriteIcon: favoriteIcon.icon
property alias showFavoriteIcon: favoriteIcon.visible
property alias truncated: resultLabel.truncated
property bool containsMouse: itemMouseArea.containsMouse || favoriteMouseArea.containsMouse
......@@ -72,7 +71,7 @@ Item {
}
function showFeedback() {
favoriteFeedbackComponent.createObject(favoriteIcon);
favoriteFeedbackComponent.createObject(favoriteIconItem);
}
Behavior on opacity {
......@@ -117,7 +116,7 @@ Item {
}
QtExtra.QIconItem {
id: favoriteIcon
id: favoriteIconItem
anchors {
right: parent.right
......@@ -132,7 +131,11 @@ Item {
easing.type: Easing.OutQuad
}
}
icon: "bookmarks"
icon: main.favoriteIcon
// Use "main.favoriteIcon" and not "icon" because right now "icon"
// is a non-notifiable property
visible: main.favoriteIcon != ""
opacity: favoriteMouseArea.containsMouse ? 1 : (main.highlighted ? 0.5 : 0)
width: 22
......@@ -146,10 +149,10 @@ Item {
}
MouseArea {
// If MouseArea were a child of favoriteIcon it would not work
// when favoriteIcon.opacity is 0. That's why it is a sibling.
// If MouseArea were a child of favoriteIconItem it would not work
// when favoriteIconItem.opacity is 0. That's why it is a sibling.
id: favoriteMouseArea
anchors.fill: favoriteIcon
anchors.fill: favoriteIconItem
hoverEnabled: true
}
}
......@@ -61,7 +61,6 @@ FocusScope {
id: main
currentText: model.label
currentIcon: model.icon
showFavoriteIcon: model.favoriteId != ""
favoriteIcon: {
var favoriteModel = favoriteModelForFavoriteId(model.favoriteId);
if (favoriteModel === null) {
......@@ -225,13 +224,16 @@ FocusScope {
// Code
function favoriteModelForFavoriteId(favoriteId) {
if (favoriteId === undefined || favoriteId === "") {
return null;
}
var lst = favoriteId.split(":");
if (lst.length === 0) {
return null;
}
var model = favoriteModels[lst[0]];
if (model === undefined) {
console.log("No favorite model for favoriteId '" + favoriteId + "'");
console.log("favoriteModelForFavoriteId(): No favorite model for favoriteId '" + favoriteId + "'");
return null;
} else {
return model;
......
Markdown is supported
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