diff --git a/application/preferences/AppPreferences.cpp b/application/preferences/AppPreferences.cpp index ccd3670..f7a1e7b 100644 --- a/application/preferences/AppPreferences.cpp +++ b/application/preferences/AppPreferences.cpp @@ -49,6 +49,11 @@ AppPreferences::Load() MainWindowListWeight = settings.GetFloat("MainWindowListWeight", 1); MainWindowChatWeight = settings.GetFloat("MainWindowChatWeight", 5); + ChatViewHorizChatWeight = settings.GetFloat("ChatViewHorizChatWeight", 8); + ChatViewHorizListWeight = settings.GetFloat("ChatViewHorizListWeight", 1); + ChatViewVertChatWeight = settings.GetFloat("ChatViewVertChatWeight", 20); + ChatViewVertSendWeight = settings.GetFloat("ChatViewVertSendWeight", 1); + MainWindowRect = settings.GetRect("MainWindowRect", BRect(0, 0, 600, 400)); } @@ -76,6 +81,11 @@ AppPreferences::Save() settings.AddFloat("MainWindowListWeight", MainWindowListWeight); settings.AddFloat("MainWindowChatWeight", MainWindowChatWeight); + settings.AddFloat("ChatViewHorizChatWeight", ChatViewHorizChatWeight); + settings.AddFloat("ChatViewHorizListWeight", ChatViewHorizListWeight); + settings.AddFloat("ChatViewVertChatWeight", ChatViewVertChatWeight); + settings.AddFloat("ChatViewVertSendWeight", ChatViewVertSendWeight); + settings.AddRect("MainWindowRect", MainWindowRect); if (file.InitCheck() == B_OK) diff --git a/application/preferences/AppPreferences.h b/application/preferences/AppPreferences.h index 30bae19..2f7481e 100644 --- a/application/preferences/AppPreferences.h +++ b/application/preferences/AppPreferences.h @@ -37,6 +37,11 @@ public: float MainWindowListWeight; float MainWindowChatWeight; + float ChatViewHorizChatWeight; + float ChatViewHorizListWeight; + float ChatViewVertChatWeight; + float ChatViewVertSendWeight; + BRect MainWindowRect; private: diff --git a/application/views/ConversationView.cpp b/application/views/ConversationView.cpp index 2bfd8a7..4880a2c 100644 --- a/application/views/ConversationView.cpp +++ b/application/views/ConversationView.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -305,6 +306,28 @@ ConversationView::ObserveString(int32 what, BString str) } +void +ConversationView::GetWeights(float* horizChat, float* horizList, + float* vertChat, float* vertSend) +{ + *horizChat = fHorizSplit->ItemWeight(0); + *horizList = fHorizSplit->ItemWeight(1); + *vertChat = fVertSplit->ItemWeight(0); + *vertSend = fVertSplit->ItemWeight(1); +} + + +void +ConversationView::SetWeights(float horizChat, float horizList, float vertChat, + float vertSend) +{ + fHorizSplit->SetItemWeight(0, horizChat, true); + fHorizSplit->SetItemWeight(1, horizList, true); + fVertSplit->SetItemWeight(0, vertChat, true); + fVertSplit->SetItemWeight(1, vertSend, true); +} + + void ConversationView::_InitInterface() { @@ -337,6 +360,9 @@ ConversationView::_InitInterface() BScrollView* scrollViewUsers = new BScrollView("userScrollView", fUserList, B_WILL_DRAW, false, true); + fHorizSplit = new BSplitView(B_HORIZONTAL, 0); + fVertSplit = new BSplitView(B_VERTICAL, 0); + BLayoutBuilder::Group<>(this, B_VERTICAL) .AddGroup(B_HORIZONTAL) .Add(fIcon) @@ -346,10 +372,12 @@ ConversationView::_InitInterface() .End() .Add(fProtocolView) .End() - .AddSplit(B_HORIZONTAL, 0) - .AddGroup(B_VERTICAL, B_USE_HALF_ITEM_SPACING, 8) - .Add(scrollViewReceive, 20) - .Add(fSendView, 1) + .AddSplit(fHorizSplit, 0.0) + .AddGroup(B_VERTICAL) + .AddSplit(fVertSplit, 8.0) + .Add(scrollViewReceive, 20) + .Add(fSendView, 1) + .End() .End() .Add(scrollViewUsers, 1) .End() diff --git a/application/views/ConversationView.h b/application/views/ConversationView.h index 6267fbb..f463ead 100644 --- a/application/views/ConversationView.h +++ b/application/views/ConversationView.h @@ -1,5 +1,6 @@ /* * Copyright 2009-2011, Andrea Anzani. All rights reserved. + * Copyright 2021, Jaidyn Levesque. All rights reserved. * Distributed under the terms of the MIT License. */ #ifndef _CHAT_VIEW_H @@ -13,6 +14,7 @@ #include "Observer.h" class BStringView; +class BSplitView; class BitmapView; class EnterTextView; @@ -42,7 +44,10 @@ public: void ObserveString(int32 what, BString str); - void AvoidFocus(bool avoid); + void GetWeights(float* horizChat, float* horizList, + float* vertChat, float* vertSend); + void SetWeights(float horizChat, float horizList, + float vertChat, float vertSend); private: void _InitInterface(); @@ -69,8 +74,8 @@ private: RenderView* fReceiveView; UserListView* fUserList; SendTextView* fSendView; + BSplitView* fHorizSplit; + BSplitView* fVertSplit; }; - #endif // _CHAT_VIEW_H - diff --git a/application/windows/MainWindow.cpp b/application/windows/MainWindow.cpp index ab0bf64..691ce3a 100644 --- a/application/windows/MainWindow.cpp +++ b/application/windows/MainWindow.cpp @@ -86,9 +86,9 @@ MainWindow::QuitRequested() button_index = alert->Go(); } - AppPreferences::Get()->MainWindowRect = Frame(); AppPreferences::Get()->MainWindowListWeight = fSplitView->ItemWeight(0); AppPreferences::Get()->MainWindowChatWeight = fSplitView->ItemWeight(1); + AppPreferences::Get()->MainWindowRect = Frame(); if(button_index == 0) { fServer->Quit(); @@ -324,9 +324,11 @@ MainWindow::WorkspaceActivated(int32 workspace, bool active) void MainWindow::SetConversation(Conversation* chat) { - // Save current size of chat and textbox + // Save split weights float weightChat = fRightView->ItemWeight((int32)0); float weightSend = fRightView->ItemWeight((int32)1); + float horizChat, horizList, vertChat, vertSend; + fChatView->GetWeights(&horizChat, &horizList, &vertChat, &vertSend); fRightView->RemoveChild(fRightView->FindView("chatView")); @@ -343,12 +345,6 @@ MainWindow::SetConversation(Conversation* chat) fRightView->AddChild(fChatView, 9); - // Apply saved chat and textbox size to new views - if (weightChat * weightSend != 0) { - fRightView->SetItemWeight(0, weightChat, true); - fRightView->SetItemWeight(1, weightSend, true); - } - // Remove "Protocol" menu BMenuItem* chatMenuItem = fMenuBar->FindItem("Protocol"); BMenu* chatMenu; @@ -379,8 +375,20 @@ MainWindow::SetConversation(Conversation* chat) } } + // Apply saved weights fSplitView->SetItemWeight(0, AppPreferences::Get()->MainWindowListWeight, true); fSplitView->SetItemWeight(1, AppPreferences::Get()->MainWindowChatWeight, true); + fChatView->SetWeights(horizChat, horizList, vertChat, vertSend); + if (weightChat * weightSend != 0) { + fRightView->SetItemWeight(0, weightChat, true); + fRightView->SetItemWeight(1, weightSend, true); + } + + // Save ChatView weights to settings + AppPreferences::Get()->ChatViewHorizChatWeight = horizChat; + AppPreferences::Get()->ChatViewHorizListWeight = horizList; + AppPreferences::Get()->ChatViewVertChatWeight = vertChat; + AppPreferences::Get()->ChatViewVertSendWeight = vertSend; } @@ -422,6 +430,14 @@ MainWindow::_InitInterface() fRightView = new BSplitView(B_VERTICAL, 0); fChatView = new ConversationView(); + // Load weights from settings + float horizChat, horizList, vertChat, vertSend; + horizChat = AppPreferences::Get()->ChatViewHorizChatWeight; + horizList = AppPreferences::Get()->ChatViewHorizListWeight; + vertChat = AppPreferences::Get()->ChatViewVertChatWeight; + vertSend = AppPreferences::Get()->ChatViewVertSendWeight; + fChatView->SetWeights(horizChat, horizList, vertChat, vertSend); + BLayoutBuilder::Group<>(this, B_VERTICAL) .Add((fMenuBar = _CreateMenuBar())) .AddGroup(B_HORIZONTAL)