mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-14 05:35:58 +08:00
Ensure that local votes are displayed right away
So even before an update is received, ensure that the data is updated CURA-6013
This commit is contained in:
parent
e92bd01fb2
commit
04f3601c27
@ -9,8 +9,16 @@ Item
|
|||||||
property real rating: 0
|
property real rating: 0
|
||||||
property int indexHovered: -1
|
property int indexHovered: -1
|
||||||
property string packageId: ""
|
property string packageId: ""
|
||||||
|
|
||||||
property int numRatings: 0
|
property int numRatings: 0
|
||||||
|
|
||||||
|
// If the widget was used to vote, but the vote isn't sent to remote yet, we do want to fake some things.
|
||||||
|
property int _numRatings: _localRating != 0 ? numRatings + 1 : numRatings
|
||||||
|
property int _localRating: 0
|
||||||
|
onVisibleChanged: _localRating = 0 // Reset the _localRating
|
||||||
|
|
||||||
property int userRating: 0
|
property int userRating: 0
|
||||||
|
|
||||||
width: contentRow.width
|
width: contentRow.width
|
||||||
height: contentRow.height
|
height: contentRow.height
|
||||||
MouseArea
|
MouseArea
|
||||||
@ -50,7 +58,10 @@ Item
|
|||||||
{
|
{
|
||||||
return indexHovered >= index
|
return indexHovered >= index
|
||||||
}
|
}
|
||||||
|
if(ratingWidget._localRating > 0)
|
||||||
|
{
|
||||||
|
return _localRating >= index +1
|
||||||
|
}
|
||||||
if(ratingWidget.userRating > 0)
|
if(ratingWidget.userRating > 0)
|
||||||
{
|
{
|
||||||
return userRating >= index +1
|
return userRating >= index +1
|
||||||
@ -73,7 +84,7 @@ Item
|
|||||||
{
|
{
|
||||||
return "#5a5a5a"
|
return "#5a5a5a"
|
||||||
}
|
}
|
||||||
if((ratingWidget.indexHovered >= 0 || ratingWidget.userRating > 0) && isStarFilled)
|
if((ratingWidget.indexHovered >= 0 || ratingWidget.userRating > 0 || ratingWidget._localRating > 0) && isStarFilled)
|
||||||
{
|
{
|
||||||
return UM.Theme.getColor("primary")
|
return UM.Theme.getColor("primary")
|
||||||
}
|
}
|
||||||
@ -82,19 +93,19 @@ Item
|
|||||||
}
|
}
|
||||||
onClicked:
|
onClicked:
|
||||||
{
|
{
|
||||||
if(userRating == 0)
|
// Ensure that the local rating is updated (even though it's not on the server just yet)
|
||||||
{
|
_localRating = index + 1
|
||||||
//User didn't vote yet, locally fake it
|
|
||||||
numRatings += 1
|
|
||||||
}
|
|
||||||
userRating = index + 1 // Fake local data
|
|
||||||
toolbox.ratePackage(ratingWidget.packageId, index + 1)
|
toolbox.ratePackage(ratingWidget.packageId, index + 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Label
|
Label
|
||||||
{
|
{
|
||||||
text: "(" + numRatings + ")"
|
text: "(" + _numRatings + ")"
|
||||||
|
verticalAlignment: Text.AlignVCenter
|
||||||
|
height: parent.height
|
||||||
|
color: "#5a5a5a"
|
||||||
|
font: UM.Theme.getFont("small")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,8 @@ import QtQuick.Controls 1.4
|
|||||||
import QtQuick.Controls.Styles 1.4
|
import QtQuick.Controls.Styles 1.4
|
||||||
import UM 1.1 as UM
|
import UM 1.1 as UM
|
||||||
|
|
||||||
|
import Cura 1.1 as Cura
|
||||||
|
|
||||||
Item
|
Item
|
||||||
{
|
{
|
||||||
id: page
|
id: page
|
||||||
@ -103,6 +105,12 @@ Item
|
|||||||
font: UM.Theme.getFont("default")
|
font: UM.Theme.getFont("default")
|
||||||
color: UM.Theme.getColor("text_medium")
|
color: UM.Theme.getColor("text_medium")
|
||||||
}
|
}
|
||||||
|
Label
|
||||||
|
{
|
||||||
|
text: catalog.i18nc("@label", "Rating") + ":"
|
||||||
|
font: UM.Theme.getFont("default")
|
||||||
|
color: UM.Theme.getColor("text_medium")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Column
|
Column
|
||||||
{
|
{
|
||||||
@ -160,6 +168,16 @@ Item
|
|||||||
font: UM.Theme.getFont("default")
|
font: UM.Theme.getFont("default")
|
||||||
color: UM.Theme.getColor("text")
|
color: UM.Theme.getColor("text")
|
||||||
}
|
}
|
||||||
|
RatingWidget
|
||||||
|
{
|
||||||
|
id: rating
|
||||||
|
visible: details.type == "plugin"
|
||||||
|
packageId: details.id
|
||||||
|
rating: details.average_rating
|
||||||
|
numRatings: details.num_ratings
|
||||||
|
userRating: details.user_rating
|
||||||
|
enabled: toolbox.isInstalled(details.id) && Cura.API.account.isLoggedIn
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Rectangle
|
Rectangle
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user