HaikuDepot: Beginnings of transformation from BTabView
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <Bitmap.h>
|
||||||
#include <Button.h>
|
#include <Button.h>
|
||||||
#include <Catalog.h>
|
#include <Catalog.h>
|
||||||
#include <LayoutBuilder.h>
|
#include <LayoutBuilder.h>
|
||||||
@@ -18,24 +19,125 @@
|
|||||||
#define B_TRANSLATION_CONTEXT "PackageInfoView"
|
#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()
|
PackageInfoView::PackageInfoView()
|
||||||
:
|
:
|
||||||
BTabView("package info view", B_WIDTH_FROM_WIDEST)
|
BGroupView("package info view", B_VERTICAL)
|
||||||
{
|
{
|
||||||
fDescriptionView = new BView("about", 0);
|
fTitleView = new TitleView();
|
||||||
AddTab(fDescriptionView);
|
fPagesView = new PagesView();
|
||||||
|
|
||||||
fRatingAndCommentsView = new BView("rating and comments", 0);
|
BLayoutBuilder::Group<>(this)
|
||||||
AddTab(fRatingAndCommentsView);
|
.Add(fTitleView)
|
||||||
|
.Add(fPagesView)
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -55,7 +157,24 @@ PackageInfoView::MessageReceived(BMessage* message)
|
|||||||
{
|
{
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
default:
|
default:
|
||||||
BTabView::MessageReceived(message);
|
BGroupView::MessageReceived(message);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PackageInfoView::SetPackage(const PackageInfo& package)
|
||||||
|
{
|
||||||
|
fTitleView->SetPackage(package);
|
||||||
|
fPagesView->SetPackage(package);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PackageInfoView::Clear()
|
||||||
|
{
|
||||||
|
fTitleView->Clear();
|
||||||
|
fPagesView->Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,10 +5,16 @@
|
|||||||
#ifndef PACKAGE_INFO_VIEW_H
|
#ifndef PACKAGE_INFO_VIEW_H
|
||||||
#define 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:
|
public:
|
||||||
PackageInfoView();
|
PackageInfoView();
|
||||||
virtual ~PackageInfoView();
|
virtual ~PackageInfoView();
|
||||||
@@ -16,10 +22,12 @@ public:
|
|||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
virtual void MessageReceived(BMessage* message);
|
virtual void MessageReceived(BMessage* message);
|
||||||
|
|
||||||
|
void SetPackage(const PackageInfo& package);
|
||||||
|
void Clear();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BView* fDescriptionView;
|
TitleView* fTitleView;
|
||||||
BView* fRatingAndCommentsView;
|
PagesView* fPagesView;
|
||||||
BView* fChangeLogView;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PACKAGE_INFO_VIEW_H
|
#endif // PACKAGE_INFO_VIEW_H
|
||||||
|
|||||||
Reference in New Issue
Block a user