diff --git a/src/apps/haiku-depot/PackageInfoView.cpp b/src/apps/haiku-depot/PackageInfoView.cpp index 662f1abb8b..9f7af16358 100644 --- a/src/apps/haiku-depot/PackageInfoView.cpp +++ b/src/apps/haiku-depot/PackageInfoView.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -18,24 +19,125 @@ #define B_TRANSLATION_CONTEXT "PackageInfoView" +class TitleView : public BView { +public: + TitleView() + : + BView("title view", B_WILL_DRAW), + fIcon(NULL), + fTitle() + { + SetViewColor(B_TRANSPARENT_COLOR); + SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + + // Title font + BFont font; + GetFont(&font); + font.SetSize(font.Size() * 2.0f); + SetFont(&font); + } + + virtual ~TitleView() + { + Clear(); + } + + virtual void Draw(BRect updateRect) + { + BPoint offset(B_ORIGIN); + BRect bounds(Bounds()); + + if (fIcon != NULL) { + // TODO: ... + } + + if (fTitle.Length() > 0) { + // TODO: Truncate title + font_height fontHeight; + GetFontHeight(&fontHeight); + + offset.y = ceilf((bounds.Height() + fontHeight.ascent) / 2.0f); + DrawString(fTitle.String(), offset); + } + } + + virtual BSize MinSize() + { + BSize size(0.0f, 0.0f); + + if (fTitle.Length() > 0) { + font_height fontHeight; + GetFontHeight(&fontHeight); + + size.width = StringWidth(fTitle.String()); + size.height = ceilf(fontHeight.ascent + fontHeight.descent); + } + + return size; + } + + void SetPackage(const PackageInfo& package) + { + // TODO: Fetch icon + fTitle = package.Title(); + InvalidateLayout(); + } + + void Clear() + { + delete fIcon; + fIcon = NULL; + fTitle = ""; + } + +private: + BBitmap* fIcon; + BString fTitle; +}; + + +class PagesView : public BView { +public: + PagesView() + : + BView("pages view", B_WILL_DRAW) + { + SetViewColor(B_TRANSPARENT_COLOR); + SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + } + + virtual ~PagesView() + { + Clear(); + } + + virtual void Draw(BRect updateRect) + { + } + + void SetPackage(const PackageInfo& package) + { + } + + void Clear() + { + } + +private: +}; + + PackageInfoView::PackageInfoView() : - BTabView("package info view", B_WIDTH_FROM_WIDEST) + BGroupView("package info view", B_VERTICAL) { - fDescriptionView = new BView("about", 0); - AddTab(fDescriptionView); + fTitleView = new TitleView(); + fPagesView = new PagesView(); - fRatingAndCommentsView = new BView("rating and comments", 0); - AddTab(fRatingAndCommentsView); - - fChangeLogView = new BView("changelog", 0); - AddTab(fChangeLogView); - - TabAt(0)->SetLabel(B_TRANSLATE("About")); - TabAt(1)->SetLabel(B_TRANSLATE("Rating & comments")); - TabAt(2)->SetLabel(B_TRANSLATE("Changelog")); - - Select(0); + BLayoutBuilder::Group<>(this) + .Add(fTitleView) + .Add(fPagesView) + ; } @@ -55,7 +157,24 @@ PackageInfoView::MessageReceived(BMessage* message) { switch (message->what) { default: - BTabView::MessageReceived(message); + BGroupView::MessageReceived(message); break; } } + + +void +PackageInfoView::SetPackage(const PackageInfo& package) +{ + fTitleView->SetPackage(package); + fPagesView->SetPackage(package); +} + + +void +PackageInfoView::Clear() +{ + fTitleView->Clear(); + fPagesView->Clear(); +} + diff --git a/src/apps/haiku-depot/PackageInfoView.h b/src/apps/haiku-depot/PackageInfoView.h index d1749887c6..683c28eea7 100644 --- a/src/apps/haiku-depot/PackageInfoView.h +++ b/src/apps/haiku-depot/PackageInfoView.h @@ -5,10 +5,16 @@ #ifndef PACKAGE_INFO_VIEW_H #define PACKAGE_INFO_VIEW_H -#include +#include + +#include "PackageInfo.h" -class PackageInfoView : public BTabView { +class TitleView; +class PagesView; + + +class PackageInfoView : public BGroupView { public: PackageInfoView(); virtual ~PackageInfoView(); @@ -16,10 +22,12 @@ public: virtual void AttachedToWindow(); virtual void MessageReceived(BMessage* message); + void SetPackage(const PackageInfo& package); + void Clear(); + private: - BView* fDescriptionView; - BView* fRatingAndCommentsView; - BView* fChangeLogView; + TitleView* fTitleView; + PagesView* fPagesView; }; #endif // PACKAGE_INFO_VIEW_H