Roster list tweaks, auto-deselect

This commit is contained in:
Jaidyn Ann 2021-07-25 17:27:04 -05:00
parent bba3d3d866
commit bea52c14be
5 changed files with 26 additions and 16 deletions

View File

@ -5,6 +5,7 @@
* Authors: * Authors:
* Andrea Anzani, andrea.anzani@gmail.com * Andrea Anzani, andrea.anzani@gmail.com
* Pier Luigi Fiorini, pierluigi.fiorini@gmail.com * Pier Luigi Fiorini, pierluigi.fiorini@gmail.com
* Jaidyn Levesque, jadedctrl@teknik.io
*/ */
#include <ListView.h> #include <ListView.h>
@ -21,11 +22,11 @@
RosterItem::RosterItem(const char* name, Contact* contact) RosterItem::RosterItem(const char* name, Contact* contact)
: BStringItem(name), : BStringItem(name),
fBitmap(contact->AvatarBitmap()), fBitmap(contact->AvatarBitmap()),
fStatus(STATUS_OFFLINE), fStatus(contact->GetNotifyStatus()),
contactLinker(contact), fContact(contact),
fVisible(true) fVisible(true)
{ {
rgb_color highlightColor = ui_color(B_CONTROL_HIGHLIGHT_COLOR); rgb_color highlightColor = ui_color(B_LIST_SELECTED_BACKGROUND_COLOR);
rgb_color darkenHighlightColor = tint_color(highlightColor, B_DARKEN_1_TINT); rgb_color darkenHighlightColor = tint_color(highlightColor, B_DARKEN_1_TINT);
fGradient.AddColor(highlightColor, 0); fGradient.AddColor(highlightColor, 0);
@ -154,18 +155,19 @@ RosterItem::DrawItem(BView* owner, BRect frame, bool complete)
// Draw contact status string // Draw contact status string
owner->MovePenTo(frame.left + 48, frame.top + fBaselineOffset + owner->MovePenTo(frame.left + 48, frame.top + fBaselineOffset +
fBaselineOffset + 3); fBaselineOffset + 3);
owner->SetHighColor(tint_color(lowColor, B_DARKEN_2_TINT)); owner->SetHighColor(TintColor(owner->HighColor(), 2));
if (fPersonalStatus.Length() == 0) if (fPersonalStatus.Length() == 0)
owner->DrawString(UserStatusToString(fStatus)); owner->DrawString(UserStatusToString(fStatus));
else else
owner->DrawString(fPersonalStatus); owner->DrawString(fPersonalStatus);
// Draw separator between items // Draw separator between items
owner->SetHighColor(tint_color(lowColor, B_DARKEN_2_TINT));
owner->StrokeLine(BPoint(frame.left, frame.bottom), owner->StrokeLine(BPoint(frame.left, frame.bottom),
BPoint(frame.right, frame.bottom)); BPoint(frame.right, frame.bottom));
// Draw protocol bitmpap // Draw protocol bitmpap
BBitmap* protocolBitmap = contactLinker->ProtocolBitmap(); BBitmap* protocolBitmap = fContact->ProtocolBitmap();
if (protocolBitmap != NULL) { if (protocolBitmap != NULL) {
BRect rect(frame.right - 19, frame.top + 2, BRect rect(frame.right - 19, frame.top + 2,
@ -175,7 +177,6 @@ RosterItem::DrawItem(BView* owner, BRect frame, bool complete)
owner->DrawBitmap(protocolBitmap, protocolBitmap->Bounds(), owner->DrawBitmap(protocolBitmap, protocolBitmap->Bounds(),
rect, B_FILTER_BITMAP_BILINEAR); rect, B_FILTER_BITMAP_BILINEAR);
} }
owner->SetHighColor(highColor); owner->SetHighColor(highColor);
owner->SetLowColor(lowColor); owner->SetLowColor(lowColor);
} }

View File

@ -28,7 +28,7 @@ public:
void Update(BView *owner, const BFont *font); void Update(BView *owner, const BFont *font);
Contact* GetContact() { return contactLinker;} Contact* GetContact() { return fContact;}
UserStatus Status() const { return fStatus; } UserStatus Status() const { return fStatus; }
void SetStatus(UserStatus status); void SetStatus(UserStatus status);
@ -45,7 +45,7 @@ protected:
void ObserveInteger(int32 what, int32 val); void ObserveInteger(int32 what, int32 val);
private: private:
Contact* contactLinker; Contact* fContact;
float fBaselineOffset; float fBaselineOffset;
BString fPersonalStatus; BString fPersonalStatus;
UserStatus fStatus; UserStatus fStatus;

View File

@ -224,16 +224,25 @@ RosterListView::Draw(BRect updateRect)
bool bool
RosterListView::AddRosterItem(RosterItem* item) RosterListView::AddItem(RosterItem* item)
{ {
item->Deselect();
bool ret = false; bool ret = false;
if (HasItem(item) == false) if (HasItem(item) == false)
ret = AddItem(item); ret = BListView::AddItem(item);
Sort(); Sort();
return ret; return ret;
} }
void
RosterListView::RemoveItem(RosterItem* item)
{
item->Deselect();
BListView::RemoveItem(item);
}
RosterItem* RosterItem*
RosterListView::RosterItemAt(int32 index) RosterListView::RosterItemAt(int32 index)
{ {

View File

@ -23,7 +23,8 @@ public:
virtual void Draw(BRect updateRect); virtual void Draw(BRect updateRect);
virtual void AttachedToWindow(); virtual void AttachedToWindow();
bool AddRosterItem(RosterItem* item); bool AddItem(RosterItem* item);
void RemoveItem(RosterItem* item);
RosterItem* RosterItemAt(int32 index); RosterItem* RosterItemAt(int32 index);
void Sort(); void Sort();

View File

@ -42,7 +42,6 @@ RosterView::RosterView(const char* title, Server* server, bigtime_t account)
new BMessage(kSearchContact)); new BMessage(kSearchContact));
fSearchBox->SetModificationMessage(new BMessage(kSearchContact)); fSearchBox->SetModificationMessage(new BMessage(kSearchContact));
fListView = new RosterListView("buddyView"); fListView = new RosterListView("buddyView");
BScrollView* scrollView = new BScrollView("scrollview", fListView, BScrollView* scrollView = new BScrollView("scrollview", fListView,
B_WILL_DRAW, false, true); B_WILL_DRAW, false, true);
@ -74,11 +73,11 @@ RosterView::MessageReceived(BMessage* message)
// otherwise remove the item in order to show only items // otherwise remove the item in order to show only items
// that matches the search criteria // that matches the search criteria
if (strcmp(fSearchBox->Text(), "") == 0) if (strcmp(fSearchBox->Text(), "") == 0)
fListView->AddRosterItem(item); fListView->AddItem(item);
else if (linker->GetName().IFindFirst(fSearchBox->Text()) == B_ERROR) else if (linker->GetName().IFindFirst(fSearchBox->Text()) == B_ERROR)
fListView->RemoveItem(item); fListView->RemoveItem(item);
else else
fListView->AddRosterItem(item); fListView->AddItem(item);
UpdateListItem(item); UpdateListItem(item);
} }
break; break;
@ -128,7 +127,7 @@ RosterView::ImMessage(BMessage* msg)
return;*/ return;*/
default: default:
// Add item because it has a non-offline status // Add item because it has a non-offline status
fListView->AddRosterItem(rosterItem); fListView->AddItem(rosterItem);
break; break;
} }
@ -233,7 +232,7 @@ RosterView::SetAccount(bigtime_t instance_id)
fListView->MakeEmpty(); fListView->MakeEmpty();
for (int i = 0; i < contacts.CountItems(); i++) for (int i = 0; i < contacts.CountItems(); i++)
fListView->AddRosterItem(contacts.ValueAt(i)->GetRosterItem()); fListView->AddItem(contacts.ValueAt(i)->GetRosterItem());
} }