From a6c0fea79c170d7ac8a68d95f9a63eacdb1710d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sun, 12 Jan 2014 22:04:07 +0100 Subject: [PATCH] HaikuDepot: Some preparations for adding rating comments * The package info area toggles a package's rating to a "Rate package..." button when the mouse hovers it. * Clicking that button opens a window where one can enter a rating. * Totally not working yet, but I want this in VCS. --- src/apps/haiku-depot/Jamfile | 2 + src/apps/haiku-depot/MainWindow.cpp | 12 ++ src/apps/haiku-depot/PackageInfoView.cpp | 147 +++++++++++++++++++-- src/apps/haiku-depot/PackageInfoView.h | 1 + src/apps/haiku-depot/RatePackageWindow.cpp | 106 +++++++++++++++ src/apps/haiku-depot/RatePackageWindow.h | 37 ++++++ 6 files changed, 291 insertions(+), 14 deletions(-) create mode 100644 src/apps/haiku-depot/RatePackageWindow.cpp create mode 100644 src/apps/haiku-depot/RatePackageWindow.h diff --git a/src/apps/haiku-depot/Jamfile b/src/apps/haiku-depot/Jamfile index 899aa608ce..ddbe9de5f1 100644 --- a/src/apps/haiku-depot/Jamfile +++ b/src/apps/haiku-depot/Jamfile @@ -49,6 +49,7 @@ Application HaikuDepot : PackageInfoView.cpp PackageListView.cpp PackageManager.cpp + RatePackageWindow.cpp support.cpp # package_daemon @@ -73,6 +74,7 @@ DoCatalogs HaikuDepot : PackageInfoView.cpp PackageListView.cpp PackageManager.cpp + UserRatingWindow.cpp ; Application TextDocumentTest : diff --git a/src/apps/haiku-depot/MainWindow.cpp b/src/apps/haiku-depot/MainWindow.cpp index c9455b8bb7..910cd83b54 100644 --- a/src/apps/haiku-depot/MainWindow.cpp +++ b/src/apps/haiku-depot/MainWindow.cpp @@ -44,6 +44,7 @@ #include "PackageInfoView.h" #include "PackageListView.h" #include "PackageManager.h" +#include "RatePackageWindow.h" #undef B_TRANSLATION_CONTEXT @@ -259,6 +260,17 @@ MainWindow::MessageReceived(BMessage* message) PackageInfoRef ref(info, true); fModel.SetPackageState(ref, ref->State()); } + break; + } + + case MSG_RATE_PACKAGE: + { + // TODO: Allow only one RatingWindow + // TODO: Mechanism for remembering the window frame + RatePackageWindow* window = new RatePackageWindow(this, + BRect(0, 0, 500, 400)); + window->Show(); + break; } default: diff --git a/src/apps/haiku-depot/PackageInfoView.cpp b/src/apps/haiku-depot/PackageInfoView.cpp index 6c4e87d648..0790955f6b 100644 --- a/src/apps/haiku-depot/PackageInfoView.cpp +++ b/src/apps/haiku-depot/PackageInfoView.cpp @@ -390,6 +390,73 @@ private: enum { MSG_PACKAGE_ACTION = 'pkga', + MSG_MOUSE_ENTERED_RATING = 'menr', + MSG_MOUSE_EXITED_RATING = 'mexr', +}; + + +class TransitReportingButton : public BButton { +public: + TransitReportingButton(const char* name, const char* label, + BMessage* message) + : + BButton(name, label, message), + fTransitMessage(NULL) + { + } + + virtual ~TransitReportingButton() + { + SetTransitMessage(NULL); + } + + virtual void MouseMoved(BPoint point, uint32 transit, + const BMessage* dragMessage) + { + BButton::MouseMoved(point, transit, dragMessage); + + if (fTransitMessage != NULL && transit == B_EXITED_VIEW) + Invoke(fTransitMessage); + } + + void SetTransitMessage(BMessage* message) + { + if (fTransitMessage != message) { + delete fTransitMessage; + fTransitMessage = message; + } + } + +private: + BMessage* fTransitMessage; +}; + + +class TransitReportingRatingView : public RatingView, public BInvoker { +public: + TransitReportingRatingView(BMessage* transitMessage) + : + RatingView(), + fTransitMessage(transitMessage) + { + } + + virtual ~TransitReportingRatingView() + { + delete fTransitMessage; + } + + virtual void MouseMoved(BPoint point, uint32 transit, + const BMessage* dragMessage) + { + RatingView::MouseMoved(point, transit, dragMessage); + + if (fTransitMessage != NULL && transit == B_ENTERED_VIEW) + Invoke(fTransitMessage); + } + +private: + BMessage* fTransitMessage; }; @@ -432,7 +499,8 @@ public: fVersionInfo->SetHighColor(kLightBlack); // Rating view - fRatingView = new RatingView(); + fRatingView = new TransitReportingRatingView( + new BMessage(MSG_MOUSE_ENTERED_RATING)); fAvgRating = new BStringView("package average rating", ""); fAvgRating->SetFont(&font); @@ -445,6 +513,33 @@ public: fVoteInfo->SetFont(&font); fVoteInfo->SetHighColor(kLightBlack); + // Rate button + fRateButton = new TransitReportingButton("rate", + B_TRANSLATE("Rate package" B_UTF8_ELLIPSIS), + new BMessage(MSG_RATE_PACKAGE)); + fRateButton->SetTransitMessage(new BMessage(MSG_MOUSE_EXITED_RATING)); + fRateButton->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, + B_ALIGN_VERTICAL_CENTER)); + + // Rating group + BView* ratingStack = new BView("rating stack", 0); + fRatingLayout = new BCardLayout(); + ratingStack->SetLayout(fRatingLayout); + ratingStack->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); + ratingStack->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + + BGroupView* ratingGroup = new BGroupView(B_HORIZONTAL, + B_USE_SMALL_SPACING); + BLayoutBuilder::Group<>(ratingGroup) + .Add(fRatingView) + .Add(fAvgRating) + .Add(fVoteInfo) + ; + + ratingStack->AddChild(ratingGroup); + ratingStack->AddChild(fRateButton); + fRatingLayout->SetVisibleItem((int32)0); + BLayoutBuilder::Group<>(this) .Add(fIconView) .AddGroup(B_VERTICAL, 1.0f, 2.2f) @@ -453,12 +548,7 @@ public: .SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)) .End() .AddGlue(0.1f) - .AddGroup(B_HORIZONTAL, B_USE_SMALL_SPACING, 0.8f) - .Add(fRatingView) - .Add(fAvgRating) - .Add(fVoteInfo) - .SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)) - .End() + .Add(ratingStack, 0.8f) .AddGlue(0.2f) .AddGroup(B_HORIZONTAL, B_USE_SMALL_SPACING, 2.0f) .Add(fVersionInfo) @@ -474,6 +564,31 @@ public: { } + virtual void AttachedToWindow() + { + fRateButton->SetTarget(this); + fRatingView->SetTarget(this); + } + + virtual void MessageReceived(BMessage* message) + { + switch (message->what) { + case MSG_RATE_PACKAGE: + // Forward to window (The button has us as target so + // we receive the message below.) + Window()->PostMessage(MSG_RATE_PACKAGE); + break; + + case MSG_MOUSE_ENTERED_RATING: + fRatingLayout->SetVisibleItem(1); + break; + + case MSG_MOUSE_EXITED_RATING: + fRatingLayout->SetVisibleItem((int32)0); + break; + } + } + void SetPackage(const PackageInfo& package) { if (package.Icon().Get() != NULL) @@ -527,16 +642,20 @@ public: } private: - BitmapView* fIconView; + BitmapView* fIconView; - BStringView* fTitleView; - BStringView* fPublisherView; + BStringView* fTitleView; + BStringView* fPublisherView; - BStringView* fVersionInfo; + BStringView* fVersionInfo; - RatingView* fRatingView; - BStringView* fAvgRating; - BStringView* fVoteInfo; + BCardLayout* fRatingLayout; + + TransitReportingRatingView* fRatingView; + BStringView* fAvgRating; + BStringView* fVoteInfo; + + TransitReportingButton* fRateButton; }; diff --git a/src/apps/haiku-depot/PackageInfoView.h b/src/apps/haiku-depot/PackageInfoView.h index eb2848f346..de03f5eed7 100644 --- a/src/apps/haiku-depot/PackageInfoView.h +++ b/src/apps/haiku-depot/PackageInfoView.h @@ -21,6 +21,7 @@ class PagesView; enum { MSG_VOTE_UP = 'vtup', MSG_VOTE_DOWN = 'vtdn', + MSG_RATE_PACKAGE = 'rate', }; diff --git a/src/apps/haiku-depot/RatePackageWindow.cpp b/src/apps/haiku-depot/RatePackageWindow.cpp new file mode 100644 index 0000000000..2a7833aeff --- /dev/null +++ b/src/apps/haiku-depot/RatePackageWindow.cpp @@ -0,0 +1,106 @@ +/* + * Copyright 2014, Stephan Aßmus . + * All rights reserved. Distributed under the terms of the MIT License. + */ + +#include "RatePackageWindow.h" + +#include +#include + +#include +#include +#include +#include +#include + +#include "MarkupParser.h" +#include "TextDocumentView.h" + + +#undef B_TRANSLATION_CONTEXT +#define B_TRANSLATION_CONTEXT "RatePackageWindow" + + +enum { + MSG_SEND = 'send' +}; + + +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() +{ + AddToSubset(parent); + CenterIn(parent->Frame()); + + TextDocumentView* textView = new TextDocumentView(); + BScrollView* textScrollView = new BScrollView("rating scroll view", + textView); + + MarkupParser parser; + fRatingText = parser.CreateDocumentFromMarkup( + "Here is where you ''could'' type your awesome rating comment, " + "if only this were already implemented."); + + textView->SetInsets(10.0f); + textView->SetTextDocument(fRatingText); + textView->SetTextEditor(TextEditorRef(new TextEditor(), true)); + + fSendButton = new BButton("send", B_TRANSLATE("Send"), + new BMessage(MSG_SEND)); + + // Build layout + BLayoutBuilder::Group<>(this, B_VERTICAL) + .Add(textScrollView) + .AddGroup(B_HORIZONTAL) + .AddGlue() + .Add(fSendButton) + .End() + .SetInsets(B_USE_DEFAULT_SPACING) + ; +} + + +RatePackageWindow::~RatePackageWindow() +{ +} + + +void +RatePackageWindow::MessageReceived(BMessage* message) +{ + switch (message->what) { + case MSG_SEND: + _SendRating(); + break; + + default: + BWindow::MessageReceived(message); + break; + } +} + + +void +RatePackageWindow::SetPackage(const PackageInfoRef& package) +{ + // TODO: Just remember which package the rating is for. +} + + +void +RatePackageWindow::_SendRating() +{ + // TODO: Implement... + BAlert* alert = new BAlert("Not implemented", + "Sorry, the web application is not yet finished and " + "this functionality is not implemented.", + "Thanks for telling me after I typed all this!"); + alert->Go(NULL); + + PostMessage(B_QUIT_REQUESTED); +} diff --git a/src/apps/haiku-depot/RatePackageWindow.h b/src/apps/haiku-depot/RatePackageWindow.h new file mode 100644 index 0000000000..c3082a1b62 --- /dev/null +++ b/src/apps/haiku-depot/RatePackageWindow.h @@ -0,0 +1,37 @@ +/* + * Copyright 2014, Stephan Aßmus . + * All rights reserved. Distributed under the terms of the MIT License. + */ +#ifndef RATE_PACKAGE_WINDOW_H +#define RATE_PACKAGE_WINDOW_H + +#include + +#include "PackageInfo.h" +#include "TextDocument.h" + + +class BButton; +class TextDocumentView; + + +class RatePackageWindow : public BWindow { +public: + RatePackageWindow(BWindow* parent, BRect frame); + virtual ~RatePackageWindow(); + + virtual void MessageReceived(BMessage* message); + + void SetPackage(const PackageInfoRef& package); + +private: + void _SendRating(); + +private: + TextDocumentRef fRatingText; + BButton* fSendButton; + PackageInfoRef fPackage; +}; + + +#endif // RATE_PACKAGE_WINDOW_H