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.
This commit is contained in:
Stephan Aßmus
2014-01-12 22:06:37 +01:00
parent 448c87fb4e
commit a6c0fea79c
6 changed files with 291 additions and 14 deletions
+2
View File
@@ -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 :
+12
View File
@@ -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:
+133 -14
View File
@@ -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;
};
+1
View File
@@ -21,6 +21,7 @@ class PagesView;
enum {
MSG_VOTE_UP = 'vtup',
MSG_VOTE_DOWN = 'vtdn',
MSG_RATE_PACKAGE = 'rate',
};
+106
View File
@@ -0,0 +1,106 @@
/*
* Copyright 2014, Stephan Aßmus <superstippi@gmx.de>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "RatePackageWindow.h"
#include <algorithm>
#include <stdio.h>
#include <Alert.h>
#include <Catalog.h>
#include <Button.h>
#include <LayoutBuilder.h>
#include <ScrollView.h>
#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);
}
+37
View File
@@ -0,0 +1,37 @@
/*
* Copyright 2014, Stephan Aßmus <superstippi@gmx.de>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#ifndef RATE_PACKAGE_WINDOW_H
#define RATE_PACKAGE_WINDOW_H
#include <Window.h>
#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