Add a new feature to People app: a picture can now be stored in Person file,
besides attributes. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40647 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
7a9ea6df3b
commit
84627497fb
@ -1,15 +1,19 @@
|
||||
SubDir HAIKU_TOP src apps people ;
|
||||
|
||||
UseLibraryHeaders icon ;
|
||||
UsePrivateHeaders shared ;
|
||||
|
||||
Application People : main.cpp
|
||||
Application People :
|
||||
main.cpp
|
||||
AttributeTextControl.cpp
|
||||
PeopleApp.cpp
|
||||
PersonView.cpp
|
||||
PersonWindow.cpp
|
||||
: libbe.so libtracker.so $(TARGET_LIBSUPC++) $(HAIKU_LOCALE_LIBS)
|
||||
PictureView.cpp
|
||||
: libicon.a be tracker translation
|
||||
$(TARGET_LIBSUPC++) $(HAIKU_LOCALE_LIBS)
|
||||
: People.rdef
|
||||
;
|
||||
;
|
||||
|
||||
DoCatalogs People :
|
||||
x-vnd.Be-PEPL
|
||||
@ -17,4 +21,5 @@ DoCatalogs People :
|
||||
PeopleApp.cpp
|
||||
PersonView.cpp
|
||||
PersonWindow.cpp
|
||||
# PictureView.cpp
|
||||
;
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <BitmapStream.h>
|
||||
#include <Catalog.h>
|
||||
#include <fs_attr.h>
|
||||
#include <Box.h>
|
||||
@ -27,10 +28,13 @@
|
||||
#include <MenuItem.h>
|
||||
#include <PopUpMenu.h>
|
||||
#include <Query.h>
|
||||
#include <TranslationUtils.h>
|
||||
#include <Translator.h>
|
||||
#include <VolumeRoster.h>
|
||||
#include <Window.h>
|
||||
|
||||
#include "AttributeTextControl.h"
|
||||
#include "PictureView.h"
|
||||
|
||||
|
||||
#undef B_TRANSLATE_CONTEXT
|
||||
@ -43,16 +47,27 @@ PersonView::PersonView(const char* name, const char* categoryAttribute,
|
||||
BGridView(),
|
||||
fGroups(NULL),
|
||||
fControls(20, false),
|
||||
fCategoryAttribute(categoryAttribute)
|
||||
fCategoryAttribute(categoryAttribute),
|
||||
fPictureView(NULL)
|
||||
{
|
||||
SetName(name);
|
||||
SetFlags(Flags() | B_WILL_DRAW);
|
||||
|
||||
if (ref)
|
||||
fFile = new BFile(ref, O_RDWR);
|
||||
else
|
||||
fFile = NULL;
|
||||
|
||||
float spacing = be_control_look->DefaultItemSpacing();
|
||||
GridLayout()->SetInsets(spacing, spacing, spacing, spacing);
|
||||
BGridLayout* layout = GridLayout();
|
||||
layout->SetInsets(spacing, spacing, spacing, spacing);
|
||||
|
||||
// Add picture "field"
|
||||
fPictureView = new PictureView(96, 112, ref);
|
||||
|
||||
layout->AddView(fPictureView, 0, 0, 1, 5);
|
||||
layout->ItemAt(0, 0)->SetExplicitAlignment(
|
||||
BAlignment(B_ALIGN_CENTER, B_ALIGN_TOP));
|
||||
}
|
||||
|
||||
|
||||
@ -65,13 +80,19 @@ PersonView::~PersonView()
|
||||
void
|
||||
PersonView::AddAttribute(const char* label, const char* attribute)
|
||||
{
|
||||
// TODO: We could check if this attribute has already been added.
|
||||
// Check if this attribute has already been added.
|
||||
AttributeTextControl* control = NULL;
|
||||
for (int32 i = fControls.CountItems() - 1; i >= 0; i--) {
|
||||
if (fControls.ItemAt(i)->Attribute() == attribute) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
AttributeTextControl* control = new AttributeTextControl(label, attribute);
|
||||
control = new AttributeTextControl(label, attribute);
|
||||
fControls.AddItem(control);
|
||||
|
||||
BGridLayout* layout = GridLayout();
|
||||
int32 row = layout->CountRows();
|
||||
int32 row = fControls.CountItems();
|
||||
|
||||
if (fCategoryAttribute == attribute) {
|
||||
// Special case the category attribute. The Group popup field will
|
||||
@ -82,13 +103,13 @@ PersonView::AddAttribute(const char* label, const char* attribute)
|
||||
|
||||
BMenuField* field = new BMenuField("", "", fGroups);
|
||||
field->SetEnabled(true);
|
||||
layout->AddView(field, 0, row);
|
||||
layout->AddView(field, 1, row);
|
||||
|
||||
control->SetLabel("");
|
||||
layout->AddView(control, 1, row);
|
||||
layout->AddView(control, 2, row);
|
||||
} else {
|
||||
layout->AddItem(control->CreateLabelLayoutItem(), 0, row);
|
||||
layout->AddItem(control->CreateTextViewLayoutItem(), 1, row);
|
||||
layout->AddItem(control->CreateLabelLayoutItem(), 1, row);
|
||||
layout->AddItem(control->CreateTextViewLayoutItem(), 2, row);
|
||||
}
|
||||
|
||||
SetAttribute(attribute, true);
|
||||
@ -114,6 +135,9 @@ PersonView::MessageReceived(BMessage* msg)
|
||||
break;
|
||||
|
||||
case M_REVERT:
|
||||
if (fPictureView)
|
||||
fPictureView->Revert();
|
||||
|
||||
for (int32 i = fControls.CountItems() - 1; i >= 0; i--)
|
||||
fControls.ItemAt(i)->Revert();
|
||||
break;
|
||||
@ -140,6 +164,21 @@ PersonView::MessageReceived(BMessage* msg)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PersonView::Draw(BRect updateRect)
|
||||
{
|
||||
if (!fPictureView)
|
||||
return;
|
||||
|
||||
// Draw a alert/get info-like strip
|
||||
BRect stripeRect = Bounds();
|
||||
float pictureWidth = /*fPictureView->Bounds().Width() */ 96;
|
||||
stripeRect.right = 10 + pictureWidth / 2;
|
||||
SetHighColor(tint_color(ViewColor(), B_DARKEN_1_TINT));
|
||||
FillRect(stripeRect);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PersonView::BuildGroupMenu()
|
||||
{
|
||||
@ -234,6 +273,9 @@ PersonView::CreateFile(const entry_ref* ref)
|
||||
bool
|
||||
PersonView::IsSaved() const
|
||||
{
|
||||
if (fPictureView && fPictureView->HasChanged())
|
||||
return false;
|
||||
|
||||
for (int32 i = fControls.CountItems() - 1; i >= 0; i--) {
|
||||
if (fControls.ItemAt(i)->HasChanged())
|
||||
return false;
|
||||
@ -254,6 +296,19 @@ PersonView::Save()
|
||||
value, strlen(value) + 1);
|
||||
control->Update();
|
||||
}
|
||||
|
||||
// Write the picture, if any, in the person file content
|
||||
if (fPictureView) {
|
||||
// trim previous content
|
||||
fFile->Seek(0, SEEK_SET);
|
||||
fFile->SetSize(0);
|
||||
if (fPictureView->Bitmap()) {
|
||||
BBitmapStream stream(fPictureView->Bitmap());
|
||||
BTranslatorRoster* roster = BTranslatorRoster::Default();
|
||||
roster->Translate(&stream, NULL, NULL, fFile, B_PNG_FORMAT,
|
||||
B_TRANSLATOR_BITMAP);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -327,6 +382,14 @@ PersonView::SetAttribute(const char* attribute, const char* value,
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PersonView::UpdatePicture(const entry_ref* ref)
|
||||
{
|
||||
if (fPictureView)
|
||||
fPictureView->Update(ref);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
PersonView::IsTextSelected() const
|
||||
{
|
||||
|
@ -21,6 +21,7 @@
|
||||
class AttributeTextControl;
|
||||
class BFile;
|
||||
class BPopUpMenu;
|
||||
class PictureView;
|
||||
|
||||
enum {
|
||||
M_SAVE = 'save',
|
||||
@ -39,6 +40,7 @@ public:
|
||||
|
||||
virtual void MakeFocus(bool focus = true);
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
virtual void Draw(BRect updateRect);
|
||||
|
||||
void AddAttribute(const char* label,
|
||||
const char* attribute);
|
||||
@ -55,6 +57,8 @@ public:
|
||||
void SetAttribute(const char* attribute,
|
||||
const char* value, bool update);
|
||||
|
||||
void UpdatePicture(const entry_ref* ref);
|
||||
|
||||
bool IsTextSelected() const;
|
||||
|
||||
private:
|
||||
@ -64,6 +68,7 @@ private:
|
||||
AttributeList fControls;
|
||||
|
||||
BString fCategoryAttribute;
|
||||
PictureView* fPictureView;
|
||||
};
|
||||
|
||||
#endif // PERSON_VIEW_H
|
||||
|
@ -255,6 +255,9 @@ PersonWindow::MessageReceived(BMessage* msg)
|
||||
fView->SetAttribute(attr.String(), true);
|
||||
break;
|
||||
}
|
||||
case B_STAT_CHANGED:
|
||||
fView->UpdatePicture(fRef);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
|
||||
#define TITLE_BAR_HEIGHT 25
|
||||
#define WIND_WIDTH 321
|
||||
#define WIND_WIDTH 420
|
||||
#define WIND_HEIGHT 340
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user