From 4934660da34319bd2678d45cc706e654af576cba Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Sat, 24 Jul 2021 20:54:46 -0500 Subject: [PATCH] Redesign/scalability of UserInfoWindow --- application/ImageCache.cpp | 7 +++- application/Utils.cpp | 16 ++++++++ application/Utils.h | 4 ++ application/windows/UserInfoWindow.cpp | 51 +++++++++++++++++++------- application/windows/UserInfoWindow.h | 3 +- 5 files changed, 65 insertions(+), 16 deletions(-) diff --git a/application/ImageCache.cpp b/application/ImageCache.cpp index 3dabd1b..c6a0423 100644 --- a/application/ImageCache.cpp +++ b/application/ImageCache.cpp @@ -27,6 +27,11 @@ ImageCache* ImageCache::fInstance = NULL; ImageCache::ImageCache() { _LoadResource(kPersonIcon, "kPersonIcon"); + + _LoadResource(kAwayReplicant, "kAwayReplicant"); + _LoadResource(kBusyReplicant, "kBusyReplicant"); + _LoadResource(kOfflineReplicant, "kOfflineReplicant"); + _LoadResource(kOnlineReplicant, "kOnlineReplicant"); } @@ -98,5 +103,3 @@ ImageCache::_LoadResource(int identifier, const char* key) if (bitmap != NULL && bitmap->IsValid() == true) fBitmaps.AddItem(BString(key), bitmap); } - - diff --git a/application/Utils.cpp b/application/Utils.cpp index 5cc7803..f22c3ab 100644 --- a/application/Utils.cpp +++ b/application/Utils.cpp @@ -49,6 +49,22 @@ UserStatusToString(UserStatus status) } +const char* +UserStatusToImageKey(UserStatus status) +{ + switch (status) { + case STATUS_ONLINE: + return "kOnlineReplicant"; + case STATUS_AWAY: + return "kAwayReplicant"; + case STATUS_OFFLINE: + return "kOfflineReplicant"; + default: + return "kBusyReplicant"; + } +} + + bool IsCommand(BString line) { diff --git a/application/Utils.h b/application/Utils.h index 913967a..f5f6087 100644 --- a/application/Utils.h +++ b/application/Utils.h @@ -19,8 +19,12 @@ class BMenu; +// For display purposes const char* UserStatusToString(UserStatus status); +// For use with the ImageCache +const char* UserStatusToImageKey(UserStatus status); + bool IsCommand(BString line); BString CommandName(BString line); BString CommandArgs(BString line); diff --git a/application/windows/UserInfoWindow.cpp b/application/windows/UserInfoWindow.cpp index 5996672..c7b0d76 100644 --- a/application/windows/UserInfoWindow.cpp +++ b/application/windows/UserInfoWindow.cpp @@ -11,19 +11,25 @@ #include "UserInfoWindow.h" #include +#include #include #include #include -#include "Utils.h" +#include "ImageCache.h" #include "User.h" +#include "Utils.h" + + +#undef B_TRANSLATION_CONTEXT +#define B_TRANSLATION_CONTEXT "UserInfoWindow" UserInfoWindow::UserInfoWindow(User* user) : - BWindow(BRect(200, 200, 500, 400), - "User information", B_FLOATING_WINDOW, + BWindow(BRect(200, 200, 300, 400), + B_TRANSLATE("User information"), B_FLOATING_WINDOW, B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS), fUser(user) { @@ -47,16 +53,32 @@ void UserInfoWindow::_InitInterface() { fNameLabel = new BStringView("nameLabel", fUser->GetName().String()); - fStatusLabel = new BStringView("statusLabel", - UserStatusToString(fUser->GetNotifyStatus())); + fNameLabel->SetFont(be_bold_font); + + UserStatus status = fUser->GetNotifyStatus(); + fStatusLabel = new BStringView("statusLabel", UserStatusToString(status)); + + float iconSize = be_plain_font->Size() + 5; + BBitmap* statusBitmap = + ImageCache::Get()->GetImage(UserStatusToImageKey(status)); + fStatusIcon = new BitmapView("statusIcon"); + fStatusIcon->SetExplicitMaxSize(BSize(iconSize, iconSize)); + fStatusIcon->SetBitmap(statusBitmap); + fTextStatusLabel = new BStringView("statusMessageLabel", fUser->GetNotifyPersonalStatus()); - BString idText("["); - idText << fUser->GetId().String() << "]"; - fIdLabel = new BStringView("idLabel", idText.String()); + const char* userId = fUser->GetId().String(); + fIdLabel = new BTextView("idLabel"); + fIdLabel->SetText(userId); + fIdLabel->SetFont(be_fixed_font); + fIdLabel->SetWordWrap(false); + fIdLabel->SetViewUIColor(B_PANEL_BACKGROUND_COLOR); + fIdLabel->MakeEditable(false); + fIdLabel->SetExplicitMinSize( + BSize(be_fixed_font->StringWidth(userId), B_SIZE_UNSET)); - fAvatar = new BitmapView("UserIcon"); + fAvatar = new BitmapView("userIcon"); fAvatar->SetExplicitMaxSize(BSize(70, 70)); fAvatar->SetExplicitMinSize(BSize(50, 50)); fAvatar->SetExplicitPreferredSize(BSize(50, 50)); @@ -65,8 +87,9 @@ UserInfoWindow::_InitInterface() // Centering is lyfeee fNameLabel->SetExplicitAlignment(BAlignment(B_ALIGN_CENTER, B_ALIGN_TOP)); fIdLabel->SetExplicitAlignment(BAlignment(B_ALIGN_CENTER, B_ALIGN_TOP)); - fStatusLabel->SetExplicitAlignment(BAlignment(B_ALIGN_CENTER, B_ALIGN_TOP)); - fAvatar->SetExplicitAlignment(BAlignment(B_ALIGN_CENTER, B_ALIGN_TOP)); + fStatusIcon->SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT, B_ALIGN_TOP)); + fStatusLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_TOP)); + fAvatar->SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT, B_ALIGN_TOP)); BLayoutBuilder::Group<>(this, B_HORIZONTAL, 10) .SetInsets(B_USE_DEFAULT_SPACING) @@ -79,8 +102,10 @@ UserInfoWindow::_InitInterface() .AddGroup(B_VERTICAL) .AddGroup(B_VERTICAL) .Add(fAvatar) - .Add(fStatusLabel) - .AddGlue() + .AddGroup(B_HORIZONTAL) + .Add(fStatusIcon) + .Add(fStatusLabel) + .End() .End() .End(); } diff --git a/application/windows/UserInfoWindow.h b/application/windows/UserInfoWindow.h index 354660d..829d6f1 100644 --- a/application/windows/UserInfoWindow.h +++ b/application/windows/UserInfoWindow.h @@ -32,7 +32,8 @@ private: BitmapView* fAvatar; BStringView* fNameLabel; - BStringView* fIdLabel; + BTextView* fIdLabel; + BitmapView* fStatusIcon; BStringView* fStatusLabel; BStringView* fTextStatusLabel; };