Skip to content

Commit

Permalink
HaikuDepot: Add actual rating to RatePackageWindow.
Browse files Browse the repository at this point in the history
Implemented SetRatingView based on RatingView. It previews the rating
when hovering and makes it permanent when clicked.
  • Loading branch information
stippi committed Sep 27, 2014
1 parent 63269a6 commit c28b830
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 5 deletions.
74 changes: 69 additions & 5 deletions src/apps/haikudepot/ui/RatePackageWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
#include <MenuItem.h>
#include <PopUpMenu.h>
#include <ScrollView.h>
#include <StringView.h>

#include "MarkupParser.h"
#include "RatingView.h"
#include "TextDocumentView.h"


Expand All @@ -27,6 +29,7 @@

enum {
MSG_SEND = 'send',
MSG_PACKAGE_RATED = 'rpkg',
MSG_STABILITY_SELECTED = 'stbl'
};

Expand Down Expand Up @@ -84,6 +87,51 @@ class ScrollView : public BScrollView {
};


class SetRatingView : public RatingView {
public:
SetRatingView()
:
RatingView("rate package view"),
fPermanentRating(0.0f)
{
SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
SetRating(fPermanentRating);
}

virtual void MouseMoved(BPoint where, uint32 transit,
const BMessage* dragMessage)
{
if (dragMessage != NULL)
return;

if ((transit != B_INSIDE_VIEW && transit != B_ENTERED_VIEW)
|| where.x > MinSize().width) {
SetRating(fPermanentRating);
return;
}

float hoverRating = _RatingForMousePos(where);
SetRating(hoverRating);
}

virtual void MouseDown(BPoint where)
{
fPermanentRating = _RatingForMousePos(where);
BMessage message(MSG_PACKAGE_RATED);
message.AddFloat("rating", fPermanentRating);
Window()->PostMessage(&message, Window());
}

private:
float _RatingForMousePos(BPoint where)
{
return std::min(5.0f, ceilf(5.0f * where.x / MinSize().width));
}

float fPermanentRating;
};


static void
add_stabilities_to_menu(const StabilityRatingList& stabilities, BMenu* menu)
{
Expand All @@ -102,10 +150,15 @@ RatePackageWindow::RatePackageWindow(BWindow* parent, BRect frame)
BWindow(frame, B_TRANSLATE_SYSTEM_NAME("Your rating"),
B_FLOATING_WINDOW_LOOK, B_FLOATING_SUBSET_WINDOW_FEEL,
B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS),
fRatingText()
fRatingText(),
fRating(-1.0f)
{
AddToSubset(parent);
CenterIn(parent->Frame());

BStringView* ratingLabel = new BStringView("rating label",
B_TRANSLATE("Your rating:"));

SetRatingView* setRatingView = new SetRatingView();

TextDocumentView* textView = new TextDocumentView();
ScrollView* textScrollView = new ScrollView(
Expand Down Expand Up @@ -154,8 +207,12 @@ RatePackageWindow::RatePackageWindow(BWindow* parent, BRect frame)

// Build layout
BLayoutBuilder::Group<>(this, B_VERTICAL)
.AddGrid()
.Add(ratingLabel, 0, 0)
.Add(setRatingView, 1, 0)
.AddMenuField(stabilityRatingField, 0, 1)
.End()
.Add(textScrollView)
.Add(stabilityRatingField)
.AddGroup(B_HORIZONTAL)
.AddGlue()
.Add(cancelButton)
Expand All @@ -166,6 +223,8 @@ RatePackageWindow::RatePackageWindow(BWindow* parent, BRect frame)

// NOTE: Do not make Send the default button. The user might want
// to type line-breaks instead of sending when hitting RETURN.

CenterIn(parent->Frame());
}


Expand All @@ -178,13 +237,18 @@ void
RatePackageWindow::MessageReceived(BMessage* message)
{
switch (message->what) {
case MSG_SEND:
_SendRating();
case MSG_PACKAGE_RATED:
message->FindFloat("rating", &fRating);
break;

case MSG_STABILITY_SELECTED:
message->FindString("name", &fStability);
break;

case MSG_SEND:
_SendRating();
break;

default:
BWindow::MessageReceived(message);
break;
Expand Down
1 change: 1 addition & 0 deletions src/apps/haikudepot/ui/RatePackageWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class RatePackageWindow : public BWindow {

private:
TextDocumentRef fRatingText;
float fRating;
BString fStability;
PackageInfoRef fPackage;
};
Expand Down

0 comments on commit c28b830

Please sign in to comment.