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 <LayoutBuilder.h>
#include <MenuBar.h>
#include <MenuItem.h>
#include <Notification.h>
#include <ScrollView.h>
#include <StringView.h>
#include <TextControl.h>
#include <TranslationUtils.h>
#include <libinterface/BitmapUtils.h>
#include "AccountManager.h"
#include "CayaConstants.h"
#include "CayaMessages.h"
#include "CayaProtocolMessages.h"
#include "CayaPreferences.h"
#include "CayaProtocolMessages.h"
#include "ConversationItem.h"
#include "ConversationListView.h"
#include "ConversationView.h"
#include "EditingFilter.h"
#include "NotifyMessage.h"
#include "MainWindow.h"
#include "NotifyMessage.h"
#include "PreferencesDialog.h"
#include "ReplicantStatusView.h"
#include "RosterWindow.h"
@ -47,63 +40,16 @@ MainWindow::MainWindow()
BWindow(BRect(0, 0, 300, 400), "Caya", B_TITLED_WINDOW, 0),
fWorkspaceChanged(false)
{
fStatusView = new StatusView("statusView");
// 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();
_InitInterface();
// Filter messages using Server
fServer = new Server();
AddFilter(fServer);
// Also through the editing filter (enter to send)
AddCommonFilter(new EditingFilter(fSendView));
fSendView->MakeFocus(true);
CenterOnScreen();
//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
MainWindow::ImMessage(BMessage* msg)
{
@ -270,16 +196,22 @@ MainWindow::ImMessage(BMessage* msg)
void
MainWindow::SetConversation(Conversation* chat)
MainWindow::ImError(BMessage* msg)
{
BView* current = fRightView->FindView("chatView");
fRightView->RemoveChild(fRightView->FindView("chatView"));
fRightView->RemoveChild(fRightView->FindView("fSendScroll"));
const char* error = NULL;
const char* detail = msg->FindString("detail");
fChatView = chat->GetView();
if (msg->FindString("error", &error) != B_OK)
return;
fRightView->AddChild(fChatView);
fRightView->AddChild(fSendScroll);
// 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();
}
@ -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
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*
MainWindow::_EnsureConversationItem(BMessage* msg)
{
@ -325,7 +320,7 @@ MainWindow::_EnsureConversationItem(BMessage* msg)
if (chat != NULL) {
ConversationItem* item = chat->GetConversationItem();
if (fListView->HasItem(item)) {
UpdateListItem(item);
_UpdateListItem(item);
}
else if (item != NULL) {
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"
class BGroupView;
class BTextControl;
class BSplitView;
class BTextView;
class Conversation;
class ConversationItem;
class ConversationListView;
class ConversationView;
class RosterItem;
class Server;
class StatusView;
class RosterItem;
class MainWindow: public BWindow, public Observer {
@ -28,27 +27,28 @@ public:
MainWindow();
void Start();
virtual bool QuitRequested();
virtual void MessageReceived(BMessage* message);
void ImMessage(BMessage* msg);
void ImError(BMessage* msg);
virtual bool QuitRequested();
// Observer inheritance
void ObserveInteger(int32 what, int32 val);
virtual void WorkspaceActivated(int32 workspace,
bool active);
void ObserveInteger(int32 what, int32 val);
void SetConversation(Conversation* chat);
Server* GetServer() const { return fServer; }
void UpdateListItem(ConversationItem* item);
int32 CountItems() const;
RosterItem* ItemAt(int index);
private:
ConversationItem* _EnsureConversationItem(BMessage* msg);
void _InitInterface();
BMenuBar* _CreateMenuBar();
ConversationItem* _EnsureConversationItem(BMessage* msg);
void _UpdateListItem(ConversationItem* item);
Server* fServer;
bool fWorkspaceChanged;
@ -58,11 +58,12 @@ private:
StatusView* fStatusView;
// Right panel, chat
BGroupView* fRightView;
BSplitView* fRightView;
BScrollView* fSendScroll;
BTextView* fSendView;
ConversationView* fChatView;
};
#endif // _MAIN_WINDOW_H

View File

@ -19,7 +19,7 @@ const uint32 kLeaveSelectedChat = 'CVcs';
ConversationListView::ConversationListView(const char* name)
: BOutlineListView(name)
: BListView(name)
{
}
@ -39,7 +39,7 @@ ConversationListView::MessageReceived(BMessage* msg)
}
default:
BOutlineListView::MessageReceived(msg);
BListView::MessageReceived(msg);
}
}
@ -69,7 +69,8 @@ BPopUpMenu*
ConversationListView::_ConversationPopUp()
{
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->SetTargetForItems(this);

View File

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

View File

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

View File

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