hrev45969 adds 2 changesets to branch 'master' old head: 74577830da3777d2e0e7e9d391f2710055e24c30 new head: 057633446b66dc02915884ed0d51af4c30a373e5 overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=0576334+%5E7457783 ---------------------------------------------------------------------------- 4f434bc: HaikuDepot: Added up and down vote count to UserRating 0576334: HaikuDepot: Added ratings summary view [ Stephan Aßmus <superstippi@xxxxxx> ] ---------------------------------------------------------------------------- 4 files changed, 183 insertions(+), 17 deletions(-) src/apps/haiku-depot/MainWindow.cpp | 14 +-- src/apps/haiku-depot/PackageInfo.cpp | 21 ++-- src/apps/haiku-depot/PackageInfo.h | 9 +- src/apps/haiku-depot/PackageInfoView.cpp | 156 ++++++++++++++++++++++++++- ############################################################################ Commit: 4f434bc67ac6d5d49985226f5ec0f1e9b7ff5572 URL: http://cgit.haiku-os.org/haiku/commit/?id=4f434bc Author: Stephan Aßmus <superstippi@xxxxxx> Date: Sat Aug 17 10:13:27 2013 UTC HaikuDepot: Added up and down vote count to UserRating ---------------------------------------------------------------------------- diff --git a/src/apps/haiku-depot/MainWindow.cpp b/src/apps/haiku-depot/MainWindow.cpp index 04deaba..4015947 100644 --- a/src/apps/haiku-depot/MainWindow.cpp +++ b/src/apps/haiku-depot/MainWindow.cpp @@ -199,11 +199,11 @@ MainWindow::_InitDummyModel() "2.1.2 - Initial Haiku release."); wonderbrush.AddUserRating( UserRating(UserInfo("humdinger"), 4.5f, - "Awesome!", "en", "2.1.2") + "Awesome!", "en", "2.1.2", 0, 0) ); wonderbrush.AddUserRating( UserRating(UserInfo("bonefish"), 5.0f, - "The best!", "en", "2.1.2") + "The best!", "en", "2.1.2", 3, 1) ); wonderbrush.AddScreenshot( BitmapRef(new SharedBitmap(603), true)); @@ -231,17 +231,17 @@ MainWindow::_InitDummyModel() paladin.AddUserRating( UserRating(UserInfo("stippi"), 3.5f, "Could be more integrated from the sounds of it.", - "en", "1.2.0") + "en", "1.2.0", 0, 1) ); paladin.AddUserRating( UserRating(UserInfo("mmadia"), 5.0f, "It rocks! Give a try", - "en", "1.1.0") + "en", "1.1.0", 1, 0) ); paladin.AddUserRating( UserRating(UserInfo("bonefish"), 2.0f, "It just needs to use my jam-rewrite 'ham' and it will be great.", - "en", "1.1.0") + "en", "1.1.0", 3, 1) ); paladin.AddScreenshot( BitmapRef(new SharedBitmap(605), true)); @@ -321,14 +321,14 @@ MainWindow::_InitDummyModel() "custom installed sound fonts? Reading through this comment I find " "that I did not until now. Hopefully there are enough lines now to " "please the programmer with the text layouting and scrolling of " - "long ratings!", "en", "2.1.0") + "long ratings!", "en", "2.1.0", 4, 1) ); sequitur.AddUserRating( UserRating(UserInfo("stippi"), 3.5f, "It seems very capable. Still runs fine on Haiku. The interface " "is composed of many small, hard to click items. But you can " "configure a tool for each mouse button, which is great for the " - "work flow.", "en", "2.1.0") + "work flow.", "en", "2.1.0", 2, 1) ); sequitur.AddCategory(fModel.CategoryAudio()); diff --git a/src/apps/haiku-depot/PackageInfo.cpp b/src/apps/haiku-depot/PackageInfo.cpp index 7f1fdde..7172b80 100644 --- a/src/apps/haiku-depot/PackageInfo.cpp +++ b/src/apps/haiku-depot/PackageInfo.cpp @@ -242,21 +242,24 @@ UserRating::UserRating() fRating(0.0f), fComment(), fLanguage(), - fPackageVersion() + fPackageVersion(), + fUpVotes(0), + fDownVotes(0) { } UserRating::UserRating(const UserInfo& userInfo, float rating, const BString& comment, const BString& language, - const BString& packageVersion) + const BString& packageVersion, int32 upVotes, int32 downVotes) : fUserInfo(userInfo), fRating(rating), fComment(comment), fLanguage(language), - fPackageVersion(packageVersion) - + fPackageVersion(packageVersion), + fUpVotes(upVotes), + fDownVotes(downVotes) { } @@ -267,7 +270,9 @@ UserRating::UserRating(const UserRating& other) fRating(other.fRating), fComment(other.fComment), fLanguage(other.fLanguage), - fPackageVersion(other.fPackageVersion) + fPackageVersion(other.fPackageVersion), + fUpVotes(other.fUpVotes), + fDownVotes(other.fDownVotes) { } @@ -280,6 +285,8 @@ UserRating::operator=(const UserRating& other) fComment = other.fComment; fLanguage = other.fLanguage; fPackageVersion = other.fPackageVersion; + fUpVotes = other.fUpVotes; + fDownVotes = other.fDownVotes; return *this; } @@ -291,7 +298,9 @@ UserRating::operator==(const UserRating& other) const && fRating == other.fRating && fComment == other.fComment && fLanguage == other.fLanguage - && fPackageVersion == other.fPackageVersion; + && fPackageVersion == other.fPackageVersion + && fUpVotes == other.fUpVotes + && fDownVotes == other.fDownVotes; } diff --git a/src/apps/haiku-depot/PackageInfo.h b/src/apps/haiku-depot/PackageInfo.h index 7461a07..c66aecd 100644 --- a/src/apps/haiku-depot/PackageInfo.h +++ b/src/apps/haiku-depot/PackageInfo.h @@ -76,7 +76,8 @@ public: float rating, const BString& comment, const BString& language, - const BString& packageVersion); + const BString& packageVersion, + int32 upVotes, int32 downVotes); UserRating(const UserRating& other); UserRating& operator=(const UserRating& other); @@ -94,12 +95,18 @@ public: const BString& PackageVersion() const { return fPackageVersion; } + int32 UpVotes() const + { return fUpVotes; } + int32 DownVotes() const + { return fDownVotes; } private: UserInfo fUserInfo; float fRating; BString fComment; BString fLanguage; BString fPackageVersion; + int32 fUpVotes; + int32 fDownVotes; }; ############################################################################ Revision: hrev45969 Commit: 057633446b66dc02915884ed0d51af4c30a373e5 URL: http://cgit.haiku-os.org/haiku/commit/?id=0576334 Author: Stephan Aßmus <superstippi@xxxxxx> Date: Sat Aug 17 11:33:08 2013 UTC HaikuDepot: Added ratings summary view ---------------------------------------------------------------------------- diff --git a/src/apps/haiku-depot/PackageInfoView.cpp b/src/apps/haiku-depot/PackageInfoView.cpp index 12435da..d97f613 100644 --- a/src/apps/haiku-depot/PackageInfoView.cpp +++ b/src/apps/haiku-depot/PackageInfoView.cpp @@ -13,6 +13,7 @@ #include <CardLayout.h> #include <Catalog.h> #include <Font.h> +#include <GridView.h> #include <LayoutBuilder.h> #include <LayoutUtils.h> #include <Message.h> @@ -328,6 +329,72 @@ private: }; +class DiagramBarView : public BView { +public: + DiagramBarView() + : + BView("diagram bar view", B_WILL_DRAW), + fValue(0.0f) + { + SetViewColor(B_TRANSPARENT_COLOR); + SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + SetHighColor(tint_color(LowColor(), B_DARKEN_2_TINT)); + } + + virtual ~DiagramBarView() + { + } + + virtual void AttachedToWindow() + { + BView* parent = Parent(); + if (parent != NULL) { + SetLowColor(parent->ViewColor()); + SetHighColor(tint_color(LowColor(), B_DARKEN_2_TINT)); + } + } + + virtual void Draw(BRect updateRect) + { + FillRect(updateRect, B_SOLID_LOW); + + if (fValue <= 0.0f) + return; + + BRect rect(Bounds()); + rect.right = ceilf(rect.left + fValue * rect.Width()); + + FillRect(rect, B_SOLID_HIGH); + } + + virtual BSize MinSize() + { + return BSize(64, 10); + } + + virtual BSize PreferredSize() + { + return MinSize(); + } + + virtual BSize MaxSize() + { + return BSize(64, 10); + } + + void SetValue(float value) + { + if (fValue != value) { + fValue = value; + Invalidate(); + } + } + +private: + float fValue; +}; + + // #pragma mark - TitleView @@ -814,15 +881,83 @@ protected: }; +class RatingSummaryView : public BGridView { +public: + RatingSummaryView() + : + BGridView("rating summary view", B_USE_HALF_ITEM_SPACING, 0.0f) + { + SetViewColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), + kContentTint - 0.1)); + + BLayoutBuilder::Grid<> layoutBuilder(this); + + BFont smallFont; + GetFont(&smallFont); + smallFont.SetSize(std::max(9.0f, floorf(smallFont.Size() * 0.85f))); + + for (int32 i = 0; i < 5; i++) { + BString label; + label.SetToFormat("%ld", 5 - i); + fLabelViews[i] = new BStringView("", label); + fLabelViews[i]->SetFont(&smallFont); + fLabelViews[i]->SetHighColor(kLightBlack); + layoutBuilder.Add(fLabelViews[i], 0, i); + + fDiagramBarViews[i] = new DiagramBarView(); + layoutBuilder.Add(fDiagramBarViews[i], 1, i); + + fCountViews[i] = new BStringView("", ""); + fCountViews[i]->SetFont(&smallFont); + fCountViews[i]->SetHighColor(kLightBlack); + fCountViews[i]->SetAlignment(B_ALIGN_RIGHT); + layoutBuilder.Add(fCountViews[i], 2, i); + } + + layoutBuilder.SetInsets(5); + } + + void SetToSummary(const RatingSummary& summary) { + for (int32 i = 0; i < 5; i++) { + int count = summary.ratingCountByStar[4 - i]; + + BString label; + label.SetToFormat("%ld", count); + fCountViews[i]->SetText(label); + + if (summary.ratingCount > 0) { + fDiagramBarViews[i]->SetValue( + (float)count / summary.ratingCount); + } else + fDiagramBarViews[i]->SetValue(0.0f); + } + } + + void Clear() { + for (int32 i = 0; i < 5; i++) { + fCountViews[i]->SetText(""); + fDiagramBarViews[i]->SetValue(0.0f); + } + } + +private: + BStringView* fLabelViews[5]; + DiagramBarView* fDiagramBarViews[5]; + BStringView* fCountViews[5]; +}; + + class UserRatingsView : public BGroupView { public: UserRatingsView() : - BGroupView("package ratings view", B_VERTICAL) + BGroupView("package ratings view", B_HORIZONTAL) { SetViewColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), kContentTint)); + fRatingSummaryView = new RatingSummaryView(); + RatingContainerView* ratingsContainerView = new RatingContainerView(); fRatingContainerLayout = ratingsContainerView->GroupLayout(); @@ -830,6 +965,11 @@ public: "ratings scroll view", ratingsContainerView); BLayoutBuilder::Group<>(this) + .AddGroup(B_VERTICAL) + .Add(fRatingSummaryView, 0.0f) + .AddGlue() + .SetInsets(0.0f, B_USE_DEFAULT_SPACING, 0.0f, 0.0f) + .End() .Add(scrollView, 1.0f) .SetInsets(B_USE_DEFAULT_SPACING, -1.0f, -1.0f, -1.0f) ; @@ -842,7 +982,10 @@ public: void SetPackage(const PackageInfo& package) { - Clear(); + ClearRatings(); + + // TODO: Re-use rating summary already used for TitleView... + fRatingSummaryView->SetToSummary(package.CalculateRatingSummary()); const UserRatingList& userRatings = package.UserRatings(); @@ -858,6 +1001,12 @@ public: void Clear() { + fRatingSummaryView->Clear(); + ClearRatings(); + } + + void ClearRatings() + { for (int32 i = fRatingContainerLayout->CountItems() - 1; BLayoutItem* item = fRatingContainerLayout->ItemAt(i); i--) { RatingItemView* view = dynamic_cast<RatingItemView*>( @@ -870,7 +1019,8 @@ public: } private: - BGroupLayout* fRatingContainerLayout; + BGroupLayout* fRatingContainerLayout; + RatingSummaryView* fRatingSummaryView; };