Use a tabview instead of an iconrule (without icons) in the notification preflet.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@43161 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Adrien Destugues 2011-11-03 13:41:23 +00:00
parent 08f7f5744a
commit 7034a82597
7 changed files with 16 additions and 568 deletions

View File

@ -1,117 +0,0 @@
/*
* Copyright 2010, Haiku, Inc. All Rights Reserved.
* Copyright 2009, Pier Luigi Fiorini.
* Distributed under the terms of the MIT License.
*
* Authors:
* Pier Luigi Fiorini, pierluigi.fiorini@gmail.com
*/
#include <stdio.h>
#include <Bitmap.h>
#include "IconItem.h"
#include "IconRule.h"
const int32 kEdgeOffset = 4;
BIconItem::BIconItem(BView* owner, const char* label, BBitmap* icon)
:
fLabel(label),
fIcon(icon),
fSelected(false),
fOwner(owner)
{
}
BIconItem::~BIconItem()
{
delete fIcon;
}
void BIconItem::Draw()
{
if (IsSelected()) {
rgb_color color;
rgb_color origHigh;
origHigh = fOwner->HighColor();
if (IsSelected())
color = ui_color(B_CONTROL_HIGHLIGHT_COLOR);
else
color = fOwner->ViewColor();
fOwner->SetHighColor(color);
fOwner->FillRect(fFrame);
fOwner->SetHighColor(origHigh);
}
if (fIcon)
{
fOwner->SetDrawingMode(B_OP_ALPHA);
fOwner->DrawBitmap(fIcon, BPoint(fFrame.top + kEdgeOffset,
fFrame.left + kEdgeOffset));
fOwner->SetDrawingMode(B_OP_COPY);
}
if (IsSelected())
fOwner->SetDrawingMode(B_OP_OVER);
#if 0
fOwner->MovePenTo(frame.left + kEdgeOffset + fIconWidth + kEdgeOffset,
frame.bottom - fFontOffset);
#else
fOwner->MovePenTo(fFrame.left, fFrame.bottom - 10);
#endif
fOwner->SetHighColor(ui_color(B_CONTROL_TEXT_COLOR));
fOwner->DrawString(" ");
fOwner->DrawString(fLabel.String());
}
const char*
BIconItem::Label() const
{
return fLabel.String();
}
void
BIconItem::SetFrame(BRect frame)
{
fFrame = frame;
}
BRect
BIconItem::Frame() const
{
return fFrame;
}
void
BIconItem::Select()
{
fSelected = true;
Draw();
}
void
BIconItem::Deselect()
{
fSelected = false;
Draw();
}
bool
BIconItem::IsSelected() const
{
return fSelected;
}

View File

@ -1,38 +0,0 @@
/*
* Copyright 2010, Haiku, Inc. All Rights Reserved.
* Copyright 2009, Pier Luigi Fiorini.
* Distributed under the terms of the MIT License.
*/
#ifndef _ICON_ITEM_H
#define _ICON_ITEM_H
#include <View.h>
#include <String.h>
class BBitmap;
class BIconItem {
public:
BIconItem(BView* owner, const char* label, BBitmap* icon);
virtual ~BIconItem();
void Draw();
const char* Label() const;
void SetFrame(BRect frame);
BRect Frame() const;
void Select();
void Deselect();
bool IsSelected() const;
private:
BString fLabel;
BBitmap* fIcon;
bool fSelected;
BView* fOwner;
BRect fFrame;
};
#endif // _ICON_ITEM_H

View File

@ -1,262 +0,0 @@
/*
* Copyright 2010, Haiku, Inc. All Rights Reserved.
* Copyright 2009, Pier Luigi Fiorini.
* Distributed under the terms of the MIT License.
*
* Authors:
* Pier Luigi Fiorini, pierluigi.fiorini@gmail.com
*/
#include <stdio.h>
#include <Message.h>
#include <Bitmap.h>
#include <Window.h>
#include "IconRule.h"
const int32 kEdgeOffset = 8;
const int32 kBorderOffset = 1;
// TODO: Do we need to inherit from BControl?
BIconRule::BIconRule(const char* name)
:
BView(name, B_WILL_DRAW),
fIcons(5, true),
fSelIndex(-1),
fMessage(NULL)
{
}
BIconRule::~BIconRule()
{
}
status_t
BIconRule::Invoke(BMessage* message)
{
bool notify = false;
uint32 kind = InvokeKind(&notify);
BMessage clone(kind);
status_t err = B_BAD_VALUE;
if (!message && !notify)
message = Message();
if (!message) {
if (!IsWatched())
return err;
} else
clone = *message;
clone.AddInt64("when", (int64)system_time());
clone.AddPointer("source", this);
clone.AddMessenger("be:sender", BMessenger(this));
clone.AddInt32("index", fSelIndex);
if (message)
err = BInvoker::Invoke(&clone);
SendNotices(kind, &clone);
return err;
}
void
BIconRule::AttachedToWindow()
{
BView::AttachedToWindow();
if (!Messenger().IsValid())
SetTarget(Window(), NULL);
}
void
BIconRule::MouseDown(BPoint point)
{
if (!IsFocus()) {
MakeFocus();
Sync();
Window()->UpdateIfNeeded();
}
int32 index = IndexOf(point);
if (index > -1)
SlideToIcon(index);
}
void
BIconRule::Draw(BRect updateRect)
{
int32 count = CountIcons();
if (count == 0)
return;
rgb_color panelColor = ui_color(B_PANEL_BACKGROUND_COLOR);
rgb_color lightColor = tint_color(panelColor, B_DARKEN_1_TINT);
rgb_color darkColor = tint_color(lightColor, B_DARKEN_2_TINT);
SetHighColor(darkColor);
StrokeLine(Bounds().LeftTop(), Bounds().RightTop());
StrokeLine(Bounds().LeftTop(), Bounds().LeftBottom());
SetHighColor(lightColor);
StrokeLine(Bounds().LeftBottom(), Bounds().RightBottom());
StrokeLine(Bounds().RightTop(), Bounds().RightBottom());
BRect itemFrame(kEdgeOffset, kBorderOffset, -1, kBorderOffset + 64);
for (int32 i = 0; i < count; i++) {
BIconItem* item = fIcons.ItemAt(i);
float width = StringWidth(item->Label()) + StringWidth(" ") * 2;
if (width < 64.0f)
width = 64.0f;
itemFrame.right = itemFrame.left + width - 1;
if (itemFrame.Intersects(updateRect)) {
item->SetFrame(itemFrame);
item->Draw();
}
itemFrame.left = itemFrame.right + kEdgeOffset + 1;
}
}
BMessage*
BIconRule::SelectionMessage() const
{
return fMessage;
}
void
BIconRule::SetSelectionMessage(BMessage* message)
{
delete fMessage;
fMessage = message;
}
void
BIconRule::AddIcon(const char* label, const BBitmap* icon)
{
BIconItem* item = new BIconItem(this, label, (BBitmap*)icon);
if (CountIcons() == 0) {
item->Select();
fSelIndex = 0;
}
fIcons.AddItem(item);
}
void
BIconRule::RemoveIconAt(int32 index)
{
delete fIcons.RemoveItemAt(index);
}
void
BIconRule::RemoveAllIcons()
{
fIcons.MakeEmpty();
}
int32
BIconRule::CountIcons() const
{
return fIcons.CountItems();
}
void
BIconRule::SlideToIcon(int32 index)
{
BIconItem* item = fIcons.ItemAt(index);
if (item) {
// Deselect previously selected item
if (fSelIndex > -1) {
BIconItem* selItem = fIcons.ItemAt(fSelIndex);
selItem->Deselect();
}
// Select this item
item->Select();
fSelIndex = index;
Invalidate();
// Invoke notification
InvokeNotify(fMessage, B_CONTROL_MODIFIED);
}
}
void
BIconRule::SlideToNext()
{
SlideToIcon(fSelIndex + 1);
}
void
BIconRule::SlideToPrevious()
{
SlideToIcon(fSelIndex - 1);
}
int32
BIconRule::IndexOf(BPoint point)
{
int32 low = 0;
int32 high = fIcons.CountItems() - 1;
int32 mid = -1;
float frameLeft = -1.0f;
float frameRight = 1.0f;
// Binary search the list
while (high >= low) {
mid = (low + high) / 2;
BIconItem* item = fIcons.ItemAt(mid);
frameLeft = item->Frame().left;
frameRight = item->Frame().right;
if (point.x < frameLeft)
high = mid - 1;
else if (point.x > frameRight)
low = mid + 1;
else
return mid;
}
return -1;
}
BSize
BIconRule::MinSize()
{
BSize minSize(BView::MinSize());
minSize.height = 64 + (kBorderOffset * 2);
return minSize;
}
BSize
BIconRule::MaxSize()
{
return BView::MaxSize();
}
BSize
BIconRule::PreferredSize()
{
return BView::PreferredSize();
}

View File

@ -1,57 +0,0 @@
/*
* Copyright 2010, Haiku, Inc. All Rights Reserved.
* Copyright 2009, Pier Luigi Fiorini.
* Distributed under the terms of the MIT License.
*/
#ifndef _ICON_RULE_H
#define _ICON_RULE_H
#include <Invoker.h>
#include <ObjectList.h>
#include <View.h>
#include "IconItem.h"
class BMessage;
class BIconRule : public BView, public BInvoker {
public:
BIconRule(const char* name);
virtual ~BIconRule();
status_t Invoke(BMessage* message);
virtual void AttachedToWindow();
virtual void MouseDown(BPoint point);
virtual void Draw(BRect updateRect);
BMessage* SelectionMessage() const;
void SetSelectionMessage(BMessage* message);
void AddIcon(const char* label, const BBitmap* icon);
void RemoveIconAt(int32 index);
void RemoveAllIcons();
int32 CountIcons() const;
void SlideToIcon(int32 index);
void SlideToNext();
void SlideToPrevious();
int32 IndexOf(BPoint point);
virtual BSize MinSize();
virtual BSize MaxSize();
virtual BSize PreferredSize();
private:
typedef BObjectList<BIconItem> IconItems;
IconItems fIcons;
int32 fSelIndex;
BMessage* fMessage;
};
#endif // _ICON_RULE_H

View File

@ -12,8 +12,6 @@ Application Notifications :
GeneralView.cpp
DisplayView.cpp
NotificationsView.cpp
IconRule.cpp
IconItem.cpp
: be translation libcolumnlistview.a libnotification.a $(TARGET_LIBSTDC++) $(HAIKU_LOCALE_LIBS)
: Notifications.rdef
;

View File

@ -16,7 +16,6 @@
#include "SettingsHost.h"
#include "PrefletView.h"
#include "IconRule.h"
#include "GeneralView.h"
#include "DisplayView.h"
#include "NotificationsView.h"
@ -31,111 +30,44 @@ const int32 kPageSelected = '_LCH';
PrefletView::PrefletView(SettingsHost* host)
:
BView("pages", B_WILL_DRAW)
BTabView("pages")
{
// Page selector
fRule = new BIconRule("icon_rule");
fRule->SetSelectionMessage(new BMessage(kPageSelected));
fRule->AddIcon(B_TRANSLATE("General"), NULL);
fRule->AddIcon(B_TRANSLATE("Display"), NULL);
//fRule->AddIcon(B_TRANSLATE("Notifications"), NULL);
// View for card layout
fPagesView = new BView("pages", B_WILL_DRAW);
// Pages
GeneralView* general = new GeneralView(host);
DisplayView* display = new DisplayView(host);
NotificationsView* apps = new NotificationsView();
// Calculate inset
float inset = ceilf(be_plain_font->Size() * 0.7f);
// Page selector
BTab* tab = new BTab();
AddTab(general, tab);
tab->SetLabel(B_TRANSLATE("General"));
// Build the layout
SetLayout(new BGroupLayout(B_VERTICAL));
tab = new BTab();
AddTab(display, tab);
tab->SetLabel(B_TRANSLATE("Display"));
// Card layout for pages
BCardLayout* layout = new BCardLayout();
fPagesView->SetLayout(layout);
layout->AddView(general);
layout->AddView(display);
layout->AddView(apps);
// Add childs
AddChild(BGroupLayoutBuilder(B_VERTICAL, inset)
.Add(fRule)
.Add(fPagesView)
);
// Select the first view
Select(0);
}
void
PrefletView::AttachedToWindow()
{
fRule->SetTarget(this);
}
void
PrefletView::MessageReceived(BMessage* message)
{
switch (message->what) {
case kPageSelected:
{
int32 index = B_ERROR;
if (message->FindInt32("index", &index) != B_OK)
return;
Select(index);
break;
}
default:
BView::MessageReceived(message);
}
}
void
PrefletView::Select(int32 index)
{
BCardLayout* layout
= dynamic_cast<BCardLayout*>(fPagesView->GetLayout());
if (layout)
layout->SetVisibleItem(index);
tab = new BTab();
AddTab(apps, tab);
tab->SetLabel(B_TRANSLATE("Notifications"));
}
BView*
PrefletView::CurrentPage()
{
BCardLayout* layout
= dynamic_cast<BCardLayout*>(fPagesView->GetLayout());
if (layout)
return layout->VisibleItem()->View();
return NULL;
return PageAt(FocusTab());
}
int32
PrefletView::CountPages() const
{
BCardLayout* layout
= dynamic_cast<BCardLayout*>(fPagesView->GetLayout());
if (layout)
return layout->CountItems();
return 0;
return 3;
}
BView*
PrefletView::PageAt(int32 index)
{
BCardLayout* layout
= dynamic_cast<BCardLayout*>(fPagesView->GetLayout());
if (layout)
return layout->ItemAt(index)->View();
return NULL;
return TabAt(index)->View();
}

View File

@ -6,27 +6,19 @@
#ifndef _PREFLET_VIEW_H
#define _PREFLET_VIEW_H
#include <View.h>
#include <TabView.h>
class BIconRule;
class SettingsHost;
class PrefletView : public BView {
class PrefletView : public BTabView {
public:
PrefletView(SettingsHost* host);
virtual void AttachedToWindow();
virtual void MessageReceived(BMessage* message);
void Select(int32 index);
BView* CurrentPage();
int32 CountPages() const;
BView* PageAt(int32 index);
private:
BIconRule* fRule;
BView* fPagesView;
};
#endif // PREFLETVIEW_H