HaikuDepot: Beginnings of transformation from BTabView

This commit is contained in:
Stephan Aßmus 2013-07-28 15:30:53 +02:00
parent 6c28726eab
commit cc4fa3bf29
2 changed files with 147 additions and 20 deletions

View File

@ -8,6 +8,7 @@
#include <algorithm>
#include <stdio.h>
#include <Bitmap.h>
#include <Button.h>
#include <Catalog.h>
#include <LayoutBuilder.h>
@ -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();
}

View File

@ -5,10 +5,16 @@
#ifndef PACKAGE_INFO_VIEW_H
#define PACKAGE_INFO_VIEW_H
#include <TabView.h>
#include <GroupView.h>
#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