Save weights of the chat view's SplitViews

This commit is contained in:
Jaidyn Ann 2021-07-31 11:15:51 -05:00
parent 7ec20a45ad
commit 51dc12236c
5 changed files with 79 additions and 15 deletions

View File

@ -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)

View File

@ -37,6 +37,11 @@ public:
float MainWindowListWeight;
float MainWindowChatWeight;
float ChatViewHorizChatWeight;
float ChatViewHorizListWeight;
float ChatViewVertChatWeight;
float ChatViewVertSendWeight;
BRect MainWindowRect;
private:

View File

@ -14,6 +14,7 @@
#include <LayoutBuilder.h>
#include <ListView.h>
#include <ScrollView.h>
#include <SplitView.h>
#include <StringList.h>
#include <StringView.h>
@ -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()

View File

@ -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

View File

@ -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)