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

View File

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

View File

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

View File

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

View File

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