From bcc3ba4109e4138550d62f58e54f47f29d531817 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sat, 10 Aug 2013 22:40:40 +0200 Subject: [PATCH] HaikuDepot: Added item count view to package list --- src/apps/haiku-depot/PackageListView.cpp | 85 ++++++++++++++++++++++++ src/apps/haiku-depot/PackageListView.h | 4 ++ 2 files changed, 89 insertions(+) diff --git a/src/apps/haiku-depot/PackageListView.cpp b/src/apps/haiku-depot/PackageListView.cpp index f1a2050fabe..eb7edf44304 100644 --- a/src/apps/haiku-depot/PackageListView.cpp +++ b/src/apps/haiku-depot/PackageListView.cpp @@ -9,6 +9,7 @@ #include #include +#include #include @@ -402,6 +403,85 @@ PackageRow::PackageRow(const PackageInfo& package) } +// #pragma mark - ItemCountView + + +class PackageListView::ItemCountView : public BView { +public: + ItemCountView() + : + BView("item count view", B_WILL_DRAW), + fItemCount(0) + { + BFont font(be_plain_font); + font.SetSize(9.0f); + SetFont(&font); + + SetViewColor(B_TRANSPARENT_COLOR); + SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + } + + virtual BSize MinSize() + { + BString label(_GetLabel()); + return BSize(StringWidth(label) + 10, B_H_SCROLL_BAR_HEIGHT); + } + + virtual BSize PreferredSize() + { + return MinSize(); + } + + virtual BSize MaxSize() + { + return MinSize(); + } + + virtual void Draw(BRect updateRect) + { + FillRect(updateRect, B_SOLID_LOW); + + BString label(_GetLabel()); + + font_height fontHeight; + GetFontHeight(&fontHeight); + + BRect bounds(Bounds()); + float width = StringWidth(label); + + BPoint offset; + offset.x = bounds.left + (bounds.Width() - width) / 2.0f; + offset.y = bounds.top + (bounds.Height() + - (fontHeight.ascent + fontHeight.descent)) / 2.0f + + fontHeight.ascent; + + DrawString(label, offset); + } + + void SetItemCount(int32 count) + { + if (count == fItemCount) + return; + fItemCount = count; + InvalidateLayout(); + Invalidate(); + } + +private: + BString _GetLabel() const + { + BString label; + if (fItemCount == 1) + label = B_TRANSLATE("1 item"); + else + label.SetToFormat(B_TRANSLATE("%ld items"), fItemCount); + return label; + } + + int32 fItemCount; +}; + + // #pragma mark - PackageListView @@ -421,6 +501,9 @@ PackageListView::PackageListView() B_TRUNCATE_END), kStatusColumn); SetSortingEnabled(true); + + fItemCountView = new ItemCountView(); + AddStatusView(fItemCountView); } @@ -481,6 +564,8 @@ PackageListView::AddPackage(const PackageInfo& package) // make sure the row is initially expanded ExpandOrCollapse(packageRow, true); + + fItemCountView->SetItemCount(CountRows()); } diff --git a/src/apps/haiku-depot/PackageListView.h b/src/apps/haiku-depot/PackageListView.h index 05c57a3da2c..9ffd5760c1e 100644 --- a/src/apps/haiku-depot/PackageListView.h +++ b/src/apps/haiku-depot/PackageListView.h @@ -34,6 +34,10 @@ class PackageListView : public BColumnListView { private: PackageRow* _FindRow(const PackageInfo& package, PackageRow* parent = NULL); +private: + class ItemCountView; + + ItemCountView* fItemCountView; }; #endif // PACKAGE_LIST_VIEW_H