diff --git a/src/apps/haikudepot/Jamfile b/src/apps/haikudepot/Jamfile index e40c09c962..b90445eac7 100644 --- a/src/apps/haikudepot/Jamfile +++ b/src/apps/haikudepot/Jamfile @@ -41,6 +41,7 @@ Application HaikuDepot : DecisionProvider.cpp FilterView.cpp JobStateListener.cpp + LinkView.cpp main.cpp MainWindow.cpp Model.cpp @@ -54,6 +55,7 @@ Application HaikuDepot : RatePackageWindow.cpp RatingView.cpp support.cpp + ScrollableGroupView.cpp SharedBitmap.cpp UserLoginWindow.cpp WebAppInterface.cpp diff --git a/src/apps/haikudepot/ui/PackageInfoView.cpp b/src/apps/haikudepot/ui/PackageInfoView.cpp index 1cce6914ee..1502814e4a 100644 --- a/src/apps/haikudepot/ui/PackageInfoView.cpp +++ b/src/apps/haikudepot/ui/PackageInfoView.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2013-214, Stephan Aßmus . + * Copyright 2013-2014, Stephan Aßmus . * All rights reserved. Distributed under the terms of the MIT License. */ @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -30,10 +29,12 @@ #include "BitmapButton.h" #include "BitmapView.h" +#include "LinkView.h" #include "MarkupParser.h" #include "PackageActionHandler.h" #include "PackageManager.h" #include "RatingView.h" +#include "ScrollableGroupView.h" #include "TextDocumentView.h" #include "TextView.h" @@ -167,94 +168,6 @@ private: }; -class LinkView : public BStringView, public BInvoker { -public: - LinkView(const char* name, const char* string, BMessage* message, - rgb_color color) - : - BStringView(name, string), - BInvoker(message, NULL), - fNormalColor(color), - fHoverColor(make_color(1, 141, 211)), - fEnabled(true), - fMouseInside(false) - { - SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); - SetExplicitMinSize(BSize(120, B_SIZE_UNSET)); - _UpdateLinkColor(); - } - - virtual void MouseMoved(BPoint where, uint32 transit, - const BMessage* dragMessage) - { - if (transit == B_ENTERED_VIEW) { - fMouseInside = true; - _UpdateLinkColor(); - } else if (transit == B_EXITED_VIEW) { - fMouseInside = false; - _UpdateLinkColor(); - } - } - - virtual void MouseDown(BPoint where) - { - if (fEnabled) - Invoke(Message()); - } - - virtual void Draw(BRect updateRect) - { - if (Text() == NULL) - return; - - SetLowColor(ViewColor()); - - font_height fontHeight; - GetFontHeight(&fontHeight); - - BRect bounds = Bounds(); - - float y = (bounds.top + bounds.bottom - ceilf(fontHeight.ascent) - - ceilf(fontHeight.descent)) / 2.0 + ceilf(fontHeight.ascent); - float x = 0.0f; - - BString text(Text()); - TruncateString(&text, B_TRUNCATE_END, bounds.Width()); - DrawString(text, BPoint(x, y)); - } - - void SetEnabled(bool enabled) - { - if (fEnabled != enabled) { - fEnabled = enabled; - _UpdateLinkColor(); - } - } - -private: - void _UpdateLinkColor() - { - if (fEnabled && fMouseInside) { - SetHighColor(fHoverColor); - BCursor cursor(B_CURSOR_ID_FOLLOW_LINK); - SetViewCursor(&cursor, true); - Invalidate(); - } else { - SetHighColor(fNormalColor); - SetViewCursor(NULL); - Invalidate(); - } - } - -private: - rgb_color fNormalColor; - rgb_color fHoverColor; - - bool fEnabled; - bool fMouseInside; -}; - - // #pragma mark - rating stats @@ -1098,53 +1011,6 @@ private: }; -class RatingContainerView : public BGroupView { -public: - RatingContainerView() - : - BGroupView(B_VERTICAL, 0.0) - { - SetViewColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), - kContentTint)); - AddChild(BSpaceLayoutItem::CreateGlue()); - } - - virtual BSize MinSize() - { - BSize minSize = BGroupView::MinSize(); - return BSize(minSize.width, 80); - } - -protected: - virtual void DoLayout() - { - BGroupView::DoLayout(); - if (BScrollBar* scrollBar = ScrollBar(B_VERTICAL)) { - BRect layoutArea = GroupLayout()->LayoutArea(); - float layoutHeight = layoutArea.Height(); - // Min size is not reliable with HasHeightForWidth() children, - // since it does not reflect how thos children are currently - // laid out, but what their theoretical minimum size would be. - - BLayoutItem* lastItem = GroupLayout()->ItemAt( - GroupLayout()->CountItems() - 1); - if (lastItem != NULL) { - layoutHeight = lastItem->Frame().bottom; - } - - float viewHeight = Bounds().Height(); - - float max = layoutHeight- viewHeight; - scrollBar->SetRange(0, max); - if (layoutHeight > 0) - scrollBar->SetProportion(viewHeight / layoutHeight); - else - scrollBar->SetProportion(1); - } - } -}; - - class RatingSummaryView : public BGridView { public: RatingSummaryView() @@ -1224,7 +1090,9 @@ public: fRatingSummaryView = new RatingSummaryView(); - RatingContainerView* ratingsContainerView = new RatingContainerView(); + ScrollableGroupView* ratingsContainerView = new ScrollableGroupView(); + ratingsContainerView->SetViewColor( + tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), kContentTint)); fRatingContainerLayout = ratingsContainerView->GroupLayout(); BScrollView* scrollView = new RatingsScrollView( diff --git a/src/apps/haikudepot/ui_generic/LinkView.cpp b/src/apps/haikudepot/ui_generic/LinkView.cpp new file mode 100644 index 0000000000..66495886be --- /dev/null +++ b/src/apps/haikudepot/ui_generic/LinkView.cpp @@ -0,0 +1,96 @@ +/* + * Copyright 2014, Stephan Aßmus . + * All rights reserved. Distributed under the terms of the MIT License. + */ + + +#include "LinkView.h" + +#include +#include + + +LinkView::LinkView(const char* name, const char* string, BMessage* message, + rgb_color color) + : + BStringView(name, string), + BInvoker(message, NULL), + fNormalColor(color), + fHoverColor(make_color(1, 141, 211)), + fEnabled(true), + fMouseInside(false) +{ + SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); + SetExplicitMinSize(BSize(120, B_SIZE_UNSET)); + _UpdateLinkColor(); +} + + +void +LinkView::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage) +{ + if (transit == B_ENTERED_VIEW) { + fMouseInside = true; + _UpdateLinkColor(); + } else if (transit == B_EXITED_VIEW) { + fMouseInside = false; + _UpdateLinkColor(); + } +} + + +void +LinkView::MouseDown(BPoint where) +{ + if (fEnabled) + Invoke(Message()); +} + + +void +LinkView::Draw(BRect updateRect) +{ + if (Text() == NULL) + return; + + SetLowColor(ViewColor()); + + font_height fontHeight; + GetFontHeight(&fontHeight); + + BRect bounds = Bounds(); + + float y = (bounds.top + bounds.bottom - ceilf(fontHeight.ascent) + - ceilf(fontHeight.descent)) / 2.0 + ceilf(fontHeight.ascent); + float x = 0.0f; + + BString text(Text()); + TruncateString(&text, B_TRUNCATE_END, bounds.Width()); + DrawString(text, BPoint(x, y)); +} + + +void +LinkView::SetEnabled(bool enabled) +{ + if (fEnabled != enabled) { + fEnabled = enabled; + _UpdateLinkColor(); + } +} + + +void +LinkView::_UpdateLinkColor() +{ + if (fEnabled && fMouseInside) { + SetHighColor(fHoverColor); + BCursor cursor(B_CURSOR_ID_FOLLOW_LINK); + SetViewCursor(&cursor, true); + Invalidate(); + } else { + SetHighColor(fNormalColor); + SetViewCursor(NULL); + Invalidate(); + } +} diff --git a/src/apps/haikudepot/ui_generic/LinkView.h b/src/apps/haikudepot/ui_generic/LinkView.h new file mode 100644 index 0000000000..059b954c7c --- /dev/null +++ b/src/apps/haikudepot/ui_generic/LinkView.h @@ -0,0 +1,38 @@ +/* + * Copyright 2014, Stephan Aßmus . + * All rights reserved. Distributed under the terms of the MIT License. + */ +#ifndef LINK_VIEW_H +#define LINK_VIEW_H + + +#include +#include + + +class LinkView : public BStringView, public BInvoker { +public: + LinkView(const char* name, const char* string, + BMessage* message, rgb_color color); + + virtual void MouseMoved(BPoint where, uint32 transit, + const BMessage* dragMessage); + virtual void MouseDown(BPoint where); + + virtual void Draw(BRect updateRect); + + void SetEnabled(bool enabled); + +private: + void _UpdateLinkColor(); + +private: + rgb_color fNormalColor; + rgb_color fHoverColor; + + bool fEnabled; + bool fMouseInside; +}; + + +#endif // LINK_VIEW_H diff --git a/src/apps/haikudepot/ui_generic/ScrollableGroupView.cpp b/src/apps/haikudepot/ui_generic/ScrollableGroupView.cpp new file mode 100644 index 0000000000..9be7cf4689 --- /dev/null +++ b/src/apps/haikudepot/ui_generic/ScrollableGroupView.cpp @@ -0,0 +1,58 @@ +/* + * Copyright 2013-2014, Stephan Aßmus . + * All rights reserved. Distributed under the terms of the MIT License. + */ + + +#include "ScrollableGroupView.h" + +#include +#include + + +ScrollableGroupView::ScrollableGroupView() + : + BGroupView(B_VERTICAL, 0.0) +{ + AddChild(BSpaceLayoutItem::CreateGlue()); +} + + +BSize +ScrollableGroupView::MinSize() +{ + BSize minSize = BGroupView::MinSize(); + return BSize(minSize.width, 80); +} + + +void +ScrollableGroupView::DoLayout() +{ + BGroupView::DoLayout(); + + BScrollBar* scrollBar = ScrollBar(B_VERTICAL); + + if (scrollBar == NULL) + return; + + BRect layoutArea = GroupLayout()->LayoutArea(); + float layoutHeight = layoutArea.Height(); + // Min size is not reliable with HasHeightForWidth() children, + // since it does not reflect how those children are currently + // laid out, but what their theoretical minimum size would be. + + BLayoutItem* lastItem = GroupLayout()->ItemAt( + GroupLayout()->CountItems() - 1); + if (lastItem != NULL) + layoutHeight = lastItem->Frame().bottom; + + float viewHeight = Bounds().Height(); + + float max = layoutHeight- viewHeight; + scrollBar->SetRange(0, max); + if (layoutHeight > 0) + scrollBar->SetProportion(viewHeight / layoutHeight); + else + scrollBar->SetProportion(1); +} diff --git a/src/apps/haikudepot/ui_generic/ScrollableGroupView.h b/src/apps/haikudepot/ui_generic/ScrollableGroupView.h new file mode 100644 index 0000000000..2446be08f6 --- /dev/null +++ b/src/apps/haikudepot/ui_generic/ScrollableGroupView.h @@ -0,0 +1,25 @@ +/* + * Copyright 2013-2014, Stephan Aßmus . + * All rights reserved. Distributed under the terms of the MIT License. + */ +#ifndef SCROLLABLE_GROUP_VIEW_H +#define SCROLLABLE_GROUP_VIEW_H + + +#include + +//! A group view to hold items in a vertically scrollable area. Needs to +// be embedded into a BScrollView with vertical scrollbar to work. Get the +// BGroupLayout with GroupLayout() and add or remove items/views to the layout. +class ScrollableGroupView : public BGroupView { +public: + ScrollableGroupView(); + + virtual BSize MinSize(); + +protected: + virtual void DoLayout(); +}; + + +#endif // SCROLLABLE_GROUP_VIEW_H