Correct spacing and sizes of main window views

Removes explicit setting of sizes in ConversationView and StatusView,
allowing them to be resized appropriately. Also rearranges StatusView
somewhat, so that it's more friendly to smaller sizes. (The avatar is
moved from being beside the status menu field to being beside the
nickname textbox.)
This commit is contained in:
Jaidyn Ann 2021-05-30 12:30:26 -05:00
parent f0492a995d
commit 641e8b1fb4
6 changed files with 126 additions and 127 deletions

View File

@ -12,26 +12,19 @@
#include <Alert.h> #include <Alert.h>
#include <LayoutBuilder.h> #include <LayoutBuilder.h>
#include <MenuBar.h> #include <MenuBar.h>
#include <MenuItem.h>
#include <Notification.h>
#include <ScrollView.h> #include <ScrollView.h>
#include <StringView.h>
#include <TextControl.h>
#include <TranslationUtils.h> #include <TranslationUtils.h>
#include <libinterface/BitmapUtils.h>
#include "AccountManager.h" #include "AccountManager.h"
#include "CayaConstants.h"
#include "CayaMessages.h" #include "CayaMessages.h"
#include "CayaProtocolMessages.h"
#include "CayaPreferences.h" #include "CayaPreferences.h"
#include "CayaProtocolMessages.h"
#include "ConversationItem.h" #include "ConversationItem.h"
#include "ConversationListView.h" #include "ConversationListView.h"
#include "ConversationView.h" #include "ConversationView.h"
#include "EditingFilter.h" #include "EditingFilter.h"
#include "NotifyMessage.h"
#include "MainWindow.h" #include "MainWindow.h"
#include "NotifyMessage.h"
#include "PreferencesDialog.h" #include "PreferencesDialog.h"
#include "ReplicantStatusView.h" #include "ReplicantStatusView.h"
#include "RosterWindow.h" #include "RosterWindow.h"
@ -47,63 +40,16 @@ MainWindow::MainWindow()
BWindow(BRect(0, 0, 300, 400), "Caya", B_TITLED_WINDOW, 0), BWindow(BRect(0, 0, 300, 400), "Caya", B_TITLED_WINDOW, 0),
fWorkspaceChanged(false) fWorkspaceChanged(false)
{ {
fStatusView = new StatusView("statusView"); _InitInterface();
// Menubar
BMenuBar* menuBar = new BMenuBar("MenuBar");
BMenu* programMenu = new BMenu("Program");
programMenu->AddItem(new BMenuItem("About" B_UTF8_ELLIPSIS,
new BMessage(B_ABOUT_REQUESTED)));
programMenu->AddItem(new BMenuItem("Preferences" B_UTF8_ELLIPSIS,
new BMessage(CAYA_SHOW_SETTINGS), ',', B_COMMAND_KEY));
programMenu->AddItem(new BSeparatorItem());
programMenu->AddItem(new BMenuItem("Quit",
new BMessage(B_QUIT_REQUESTED), 'Q', B_COMMAND_KEY));
programMenu->SetTargetForItems(this);
BMenu* chatMenu = new BMenu("Chat");
chatMenu->AddItem(new BMenuItem("New chat" B_UTF8_ELLIPSIS,
new BMessage(CAYA_NEW_CHAT)));
chatMenu->SetTargetForItems(this);
menuBar->AddItem(programMenu);
menuBar->AddItem(chatMenu);
fListView = new ConversationListView("roomList");
fChatView = new ConversationView();
fSendView = new BTextView("fSendView");
fSendScroll = new BScrollView("fSendScroll", fSendView,
B_WILL_DRAW, false, true);
fSendView->SetWordWrap(true);
AddCommonFilter(new EditingFilter(fSendView));
fSendView->MakeFocus(true);
fRightView = new BGroupView("rightView", B_VERTICAL);
fRightView->AddChild(fChatView);
fRightView->AddChild(fSendScroll);
BLayoutBuilder::Group<>(this, B_VERTICAL)
.Add(menuBar)
.AddGroup(B_HORIZONTAL)
.SetInsets(5, 5, 5, 10)
.AddGroup(B_VERTICAL)
.Add(fListView)
.Add(fStatusView)
.End()
.Add(fRightView)
.End()
.End();
// Filter messages using Server // Filter messages using Server
fServer = new Server(); fServer = new Server();
AddFilter(fServer); AddFilter(fServer);
// Also through the editing filter (enter to send)
AddCommonFilter(new EditingFilter(fSendView));
fSendView->MakeFocus(true);
CenterOnScreen(); CenterOnScreen();
//TODO check for errors here //TODO check for errors here
@ -216,26 +162,6 @@ MainWindow::MessageReceived(BMessage* message)
} }
void
MainWindow::ImError(BMessage* msg)
{
const char* error = NULL;
const char* detail = msg->FindString("detail");
if (msg->FindString("error", &error) != B_OK)
return;
// Format error message
BString errMsg(error);
if (detail)
errMsg << "\n" << detail;
BAlert* alert = new BAlert("Error", errMsg.String(), "OK", NULL, NULL,
B_WIDTH_AS_USUAL, B_STOP_ALERT);
alert->Go();
}
void void
MainWindow::ImMessage(BMessage* msg) MainWindow::ImMessage(BMessage* msg)
{ {
@ -270,16 +196,22 @@ MainWindow::ImMessage(BMessage* msg)
void void
MainWindow::SetConversation(Conversation* chat) MainWindow::ImError(BMessage* msg)
{ {
BView* current = fRightView->FindView("chatView"); const char* error = NULL;
fRightView->RemoveChild(fRightView->FindView("chatView")); const char* detail = msg->FindString("detail");
fRightView->RemoveChild(fRightView->FindView("fSendScroll"));
fChatView = chat->GetView(); if (msg->FindString("error", &error) != B_OK)
return;
fRightView->AddChild(fChatView); // Format error message
fRightView->AddChild(fSendScroll); BString errMsg(error);
if (detail)
errMsg << "\n" << detail;
BAlert* alert = new BAlert("Error", errMsg.String(), "OK", NULL, NULL,
B_WIDTH_AS_USUAL, B_STOP_ALERT);
alert->Go();
} }
@ -294,16 +226,6 @@ MainWindow::ObserveInteger(int32 what, int32 val)
} }
void
MainWindow::UpdateListItem(ConversationItem* item)
{
if (fListView->HasItem(item) == true)
fListView->InvalidateItem(fListView->IndexOf(item));
else
fListView->AddItem(item);
}
void void
MainWindow::WorkspaceActivated(int32 workspace, bool active) MainWindow::WorkspaceActivated(int32 workspace, bool active)
{ {
@ -314,6 +236,79 @@ MainWindow::WorkspaceActivated(int32 workspace, bool active)
} }
void
MainWindow::SetConversation(Conversation* chat)
{
fRightView->RemoveChild(fRightView->FindView("chatView"));
fRightView->RemoveChild(fRightView->FindView("fSendScroll"));
if (chat != NULL)
fChatView = chat->GetView();
fRightView->AddChild(fChatView, 9);
fRightView->AddChild(fSendScroll, 1);
}
void
MainWindow::_InitInterface()
{
// Left side of window, Roomlist + Status
fListView = new ConversationListView("roomList");
fStatusView = new StatusView("statusView");
// Right-side of window, Chat + Textbox
fRightView = new BSplitView(B_VERTICAL, 0);
fChatView = new ConversationView();
fSendView = new BTextView("fSendView");
fSendScroll = new BScrollView("fSendScroll", fSendView,
B_WILL_DRAW, false, true);
fSendView->SetWordWrap(true);
BLayoutBuilder::Group<>(this, B_VERTICAL)
.Add(_CreateMenuBar())
.AddGroup(B_HORIZONTAL)
.SetInsets(5, 5, 0, 10)
.AddSplit(B_HORIZONTAL, 0)
.AddGroup(B_VERTICAL)
.Add(fListView, 1)
.Add(fStatusView)
.End()
.Add(fRightView, 5)
.End()
.End()
.End();
SetConversation(NULL);
}
BMenuBar*
MainWindow::_CreateMenuBar()
{
BMenuBar* menuBar = new BMenuBar("MenuBar");
BMenu* programMenu = new BMenu("Program");
programMenu->AddItem(new BMenuItem("About" B_UTF8_ELLIPSIS,
new BMessage(B_ABOUT_REQUESTED)));
programMenu->AddItem(new BMenuItem("Preferences" B_UTF8_ELLIPSIS,
new BMessage(CAYA_SHOW_SETTINGS), ',', B_COMMAND_KEY));
programMenu->AddItem(new BSeparatorItem());
programMenu->AddItem(new BMenuItem("Quit",
new BMessage(B_QUIT_REQUESTED), 'Q', B_COMMAND_KEY));
programMenu->SetTargetForItems(this);
BMenu* chatMenu = new BMenu("Chat");
chatMenu->AddItem(new BMenuItem("New chat" B_UTF8_ELLIPSIS,
new BMessage(CAYA_NEW_CHAT)));
chatMenu->SetTargetForItems(this);
menuBar->AddItem(programMenu);
menuBar->AddItem(chatMenu);
return menuBar;
}
ConversationItem* ConversationItem*
MainWindow::_EnsureConversationItem(BMessage* msg) MainWindow::_EnsureConversationItem(BMessage* msg)
{ {
@ -325,7 +320,7 @@ MainWindow::_EnsureConversationItem(BMessage* msg)
if (chat != NULL) { if (chat != NULL) {
ConversationItem* item = chat->GetConversationItem(); ConversationItem* item = chat->GetConversationItem();
if (fListView->HasItem(item)) { if (fListView->HasItem(item)) {
UpdateListItem(item); _UpdateListItem(item);
} }
else if (item != NULL) { else if (item != NULL) {
fListView->AddItem(item); fListView->AddItem(item);
@ -337,3 +332,13 @@ MainWindow::_EnsureConversationItem(BMessage* msg)
} }
void
MainWindow::_UpdateListItem(ConversationItem* item)
{
if (fListView->HasItem(item) == true)
fListView->InvalidateItem(fListView->IndexOf(item));
else
fListView->AddItem(item);
}

View File

@ -10,17 +10,16 @@
#include "Observer.h" #include "Observer.h"
class BGroupView; class BSplitView;
class BTextControl;
class BTextView; class BTextView;
class Conversation; class Conversation;
class ConversationItem; class ConversationItem;
class ConversationListView; class ConversationListView;
class ConversationView; class ConversationView;
class RosterItem;
class Server; class Server;
class StatusView; class StatusView;
class RosterItem;
class MainWindow: public BWindow, public Observer { class MainWindow: public BWindow, public Observer {
@ -28,27 +27,28 @@ public:
MainWindow(); MainWindow();
void Start(); void Start();
virtual bool QuitRequested();
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage* message);
void ImMessage(BMessage* msg); void ImMessage(BMessage* msg);
void ImError(BMessage* msg); void ImError(BMessage* msg);
virtual bool QuitRequested();
// Observer inheritance
void ObserveInteger(int32 what, int32 val);
virtual void WorkspaceActivated(int32 workspace, virtual void WorkspaceActivated(int32 workspace,
bool active); bool active);
void ObserveInteger(int32 what, int32 val);
void SetConversation(Conversation* chat); void SetConversation(Conversation* chat);
Server* GetServer() const { return fServer; } Server* GetServer() const { return fServer; }
void UpdateListItem(ConversationItem* item);
int32 CountItems() const;
RosterItem* ItemAt(int index);
private: private:
void _InitInterface();
BMenuBar* _CreateMenuBar();
ConversationItem* _EnsureConversationItem(BMessage* msg); ConversationItem* _EnsureConversationItem(BMessage* msg);
void _UpdateListItem(ConversationItem* item);
Server* fServer; Server* fServer;
bool fWorkspaceChanged; bool fWorkspaceChanged;
@ -58,11 +58,12 @@ private:
StatusView* fStatusView; StatusView* fStatusView;
// Right panel, chat // Right panel, chat
BGroupView* fRightView; BSplitView* fRightView;
BScrollView* fSendScroll; BScrollView* fSendScroll;
BTextView* fSendView; BTextView* fSendView;
ConversationView* fChatView; ConversationView* fChatView;
}; };
#endif // _MAIN_WINDOW_H #endif // _MAIN_WINDOW_H

View File

@ -19,7 +19,7 @@ const uint32 kLeaveSelectedChat = 'CVcs';
ConversationListView::ConversationListView(const char* name) ConversationListView::ConversationListView(const char* name)
: BOutlineListView(name) : BListView(name)
{ {
} }
@ -39,7 +39,7 @@ ConversationListView::MessageReceived(BMessage* msg)
} }
default: default:
BOutlineListView::MessageReceived(msg); BListView::MessageReceived(msg);
} }
} }
@ -69,7 +69,8 @@ BPopUpMenu*
ConversationListView::_ConversationPopUp() ConversationListView::_ConversationPopUp()
{ {
BPopUpMenu* menu = new BPopUpMenu("chatPopUp"); BPopUpMenu* menu = new BPopUpMenu("chatPopUp");
menu->AddItem(new BMenuItem("Open chat…", new BMessage(kOpenSelectedChat))); menu->AddItem(new BMenuItem("Open chat" B_UTF8_ELLIPSIS,
new BMessage(kOpenSelectedChat)));
menu->AddItem(new BMenuItem("Leave chat", new BMessage(kLeaveSelectedChat))); menu->AddItem(new BMenuItem("Leave chat", new BMessage(kLeaveSelectedChat)));
menu->SetTargetForItems(this); menu->SetTargetForItems(this);

View File

@ -10,7 +10,7 @@
class BPopUpMenu; class BPopUpMenu;
class ConversationListView : public BOutlineListView { class ConversationListView : public BListView {
public: public:
ConversationListView(const char* name); ConversationListView(const char* name);

View File

@ -41,15 +41,12 @@ ConversationView::ConversationView()
BAlignment(B_ALIGN_LEFT, B_ALIGN_MIDDLE)); BAlignment(B_ALIGN_LEFT, B_ALIGN_MIDDLE));
fPersonalMessage->SetText(""); fPersonalMessage->SetText("");
fPersonalMessage->SetExplicitMaxSize(BSize(400, 200));
fPersonalMessage->MakeEditable(false); fPersonalMessage->MakeEditable(false);
fPersonalMessage->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); fPersonalMessage->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
fStatus = new BStringView("status", ""); fStatus = new BStringView("status", "");
fStatus->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_MIDDLE));
fAvatar = new BitmapView("ContactIcon"); fAvatar = new BitmapView("ContactIcon");
fAvatar->SetExplicitMaxSize(BSize(50, 50));
fAvatar->SetExplicitMinSize(BSize(50, 50)); fAvatar->SetExplicitMinSize(BSize(50, 50));
fAvatar->SetExplicitPreferredSize(BSize(50, 50)); fAvatar->SetExplicitPreferredSize(BSize(50, 50));
fAvatar->SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT, B_ALIGN_MIDDLE)); fAvatar->SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT, B_ALIGN_MIDDLE));
@ -62,9 +59,8 @@ ConversationView::ConversationView()
.Add(fPersonalMessage) .Add(fPersonalMessage)
.Add(fAvatar) .Add(fAvatar)
.End() .End()
.Add(scrollViewReceive, 3) .Add(scrollViewReceive, 3);
.Add(fStatus, 4) // .Add(fStatus, 4)
.SetInsets(5, 5, 5, 5);
} }

View File

@ -37,9 +37,6 @@ StatusView::StatusView(const char* name)
fNickname = new NicknameTextControl("Nickname", fNickname = new NicknameTextControl("Nickname",
new BMessage(kSetNickname)); new BMessage(kSetNickname));
BStringView* nicknameLabel = new BStringView("Nickname",
"Nickname:", B_WILL_DRAW);
// Status menu // Status menu
fStatusMenu = new BPopUpMenu("-"); fStatusMenu = new BPopUpMenu("-");
@ -78,11 +75,10 @@ StatusView::StatusView(const char* name)
.AddGroup(B_VERTICAL) .AddGroup(B_VERTICAL)
.Add(statusField) .Add(statusField)
.AddGroup(B_HORIZONTAL) .AddGroup(B_HORIZONTAL)
.Add(nicknameLabel)
.Add(fNickname) .Add(fNickname)
.End()
.End()
.Add(fAvatar) .Add(fAvatar)
.End()
.End()
.End(); .End();
} }