Save weights of the chat view's SplitViews
This commit is contained in:
parent
7ec20a45ad
commit
51dc12236c
|
@ -49,6 +49,11 @@ AppPreferences::Load()
|
||||||
MainWindowListWeight = settings.GetFloat("MainWindowListWeight", 1);
|
MainWindowListWeight = settings.GetFloat("MainWindowListWeight", 1);
|
||||||
MainWindowChatWeight = settings.GetFloat("MainWindowChatWeight", 5);
|
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));
|
MainWindowRect = settings.GetRect("MainWindowRect", BRect(0, 0, 600, 400));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,6 +81,11 @@ AppPreferences::Save()
|
||||||
settings.AddFloat("MainWindowListWeight", MainWindowListWeight);
|
settings.AddFloat("MainWindowListWeight", MainWindowListWeight);
|
||||||
settings.AddFloat("MainWindowChatWeight", MainWindowChatWeight);
|
settings.AddFloat("MainWindowChatWeight", MainWindowChatWeight);
|
||||||
|
|
||||||
|
settings.AddFloat("ChatViewHorizChatWeight", ChatViewHorizChatWeight);
|
||||||
|
settings.AddFloat("ChatViewHorizListWeight", ChatViewHorizListWeight);
|
||||||
|
settings.AddFloat("ChatViewVertChatWeight", ChatViewVertChatWeight);
|
||||||
|
settings.AddFloat("ChatViewVertSendWeight", ChatViewVertSendWeight);
|
||||||
|
|
||||||
settings.AddRect("MainWindowRect", MainWindowRect);
|
settings.AddRect("MainWindowRect", MainWindowRect);
|
||||||
|
|
||||||
if (file.InitCheck() == B_OK)
|
if (file.InitCheck() == B_OK)
|
||||||
|
|
|
@ -37,6 +37,11 @@ public:
|
||||||
float MainWindowListWeight;
|
float MainWindowListWeight;
|
||||||
float MainWindowChatWeight;
|
float MainWindowChatWeight;
|
||||||
|
|
||||||
|
float ChatViewHorizChatWeight;
|
||||||
|
float ChatViewHorizListWeight;
|
||||||
|
float ChatViewVertChatWeight;
|
||||||
|
float ChatViewVertSendWeight;
|
||||||
|
|
||||||
BRect MainWindowRect;
|
BRect MainWindowRect;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include <LayoutBuilder.h>
|
#include <LayoutBuilder.h>
|
||||||
#include <ListView.h>
|
#include <ListView.h>
|
||||||
#include <ScrollView.h>
|
#include <ScrollView.h>
|
||||||
|
#include <SplitView.h>
|
||||||
#include <StringList.h>
|
#include <StringList.h>
|
||||||
#include <StringView.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
|
void
|
||||||
ConversationView::_InitInterface()
|
ConversationView::_InitInterface()
|
||||||
{
|
{
|
||||||
|
@ -337,6 +360,9 @@ ConversationView::_InitInterface()
|
||||||
BScrollView* scrollViewUsers = new BScrollView("userScrollView",
|
BScrollView* scrollViewUsers = new BScrollView("userScrollView",
|
||||||
fUserList, B_WILL_DRAW, false, true);
|
fUserList, B_WILL_DRAW, false, true);
|
||||||
|
|
||||||
|
fHorizSplit = new BSplitView(B_HORIZONTAL, 0);
|
||||||
|
fVertSplit = new BSplitView(B_VERTICAL, 0);
|
||||||
|
|
||||||
BLayoutBuilder::Group<>(this, B_VERTICAL)
|
BLayoutBuilder::Group<>(this, B_VERTICAL)
|
||||||
.AddGroup(B_HORIZONTAL)
|
.AddGroup(B_HORIZONTAL)
|
||||||
.Add(fIcon)
|
.Add(fIcon)
|
||||||
|
@ -346,11 +372,13 @@ ConversationView::_InitInterface()
|
||||||
.End()
|
.End()
|
||||||
.Add(fProtocolView)
|
.Add(fProtocolView)
|
||||||
.End()
|
.End()
|
||||||
.AddSplit(B_HORIZONTAL, 0)
|
.AddSplit(fHorizSplit, 0.0)
|
||||||
.AddGroup(B_VERTICAL, B_USE_HALF_ITEM_SPACING, 8)
|
.AddGroup(B_VERTICAL)
|
||||||
|
.AddSplit(fVertSplit, 8.0)
|
||||||
.Add(scrollViewReceive, 20)
|
.Add(scrollViewReceive, 20)
|
||||||
.Add(fSendView, 1)
|
.Add(fSendView, 1)
|
||||||
.End()
|
.End()
|
||||||
|
.End()
|
||||||
.Add(scrollViewUsers, 1)
|
.Add(scrollViewUsers, 1)
|
||||||
.End()
|
.End()
|
||||||
.End();
|
.End();
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2009-2011, Andrea Anzani. All rights reserved.
|
* Copyright 2009-2011, Andrea Anzani. All rights reserved.
|
||||||
|
* Copyright 2021, Jaidyn Levesque. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef _CHAT_VIEW_H
|
#ifndef _CHAT_VIEW_H
|
||||||
|
@ -13,6 +14,7 @@
|
||||||
#include "Observer.h"
|
#include "Observer.h"
|
||||||
|
|
||||||
class BStringView;
|
class BStringView;
|
||||||
|
class BSplitView;
|
||||||
|
|
||||||
class BitmapView;
|
class BitmapView;
|
||||||
class EnterTextView;
|
class EnterTextView;
|
||||||
|
@ -42,7 +44,10 @@ public:
|
||||||
|
|
||||||
void ObserveString(int32 what, BString str);
|
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:
|
private:
|
||||||
void _InitInterface();
|
void _InitInterface();
|
||||||
|
@ -69,8 +74,8 @@ private:
|
||||||
RenderView* fReceiveView;
|
RenderView* fReceiveView;
|
||||||
UserListView* fUserList;
|
UserListView* fUserList;
|
||||||
SendTextView* fSendView;
|
SendTextView* fSendView;
|
||||||
|
BSplitView* fHorizSplit;
|
||||||
|
BSplitView* fVertSplit;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // _CHAT_VIEW_H
|
#endif // _CHAT_VIEW_H
|
||||||
|
|
||||||
|
|
|
@ -86,9 +86,9 @@ MainWindow::QuitRequested()
|
||||||
button_index = alert->Go();
|
button_index = alert->Go();
|
||||||
}
|
}
|
||||||
|
|
||||||
AppPreferences::Get()->MainWindowRect = Frame();
|
|
||||||
AppPreferences::Get()->MainWindowListWeight = fSplitView->ItemWeight(0);
|
AppPreferences::Get()->MainWindowListWeight = fSplitView->ItemWeight(0);
|
||||||
AppPreferences::Get()->MainWindowChatWeight = fSplitView->ItemWeight(1);
|
AppPreferences::Get()->MainWindowChatWeight = fSplitView->ItemWeight(1);
|
||||||
|
AppPreferences::Get()->MainWindowRect = Frame();
|
||||||
|
|
||||||
if(button_index == 0) {
|
if(button_index == 0) {
|
||||||
fServer->Quit();
|
fServer->Quit();
|
||||||
|
@ -324,9 +324,11 @@ MainWindow::WorkspaceActivated(int32 workspace, bool active)
|
||||||
void
|
void
|
||||||
MainWindow::SetConversation(Conversation* chat)
|
MainWindow::SetConversation(Conversation* chat)
|
||||||
{
|
{
|
||||||
// Save current size of chat and textbox
|
// Save split weights
|
||||||
float weightChat = fRightView->ItemWeight((int32)0);
|
float weightChat = fRightView->ItemWeight((int32)0);
|
||||||
float weightSend = fRightView->ItemWeight((int32)1);
|
float weightSend = fRightView->ItemWeight((int32)1);
|
||||||
|
float horizChat, horizList, vertChat, vertSend;
|
||||||
|
fChatView->GetWeights(&horizChat, &horizList, &vertChat, &vertSend);
|
||||||
|
|
||||||
fRightView->RemoveChild(fRightView->FindView("chatView"));
|
fRightView->RemoveChild(fRightView->FindView("chatView"));
|
||||||
|
|
||||||
|
@ -343,12 +345,6 @@ MainWindow::SetConversation(Conversation* chat)
|
||||||
|
|
||||||
fRightView->AddChild(fChatView, 9);
|
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
|
// Remove "Protocol" menu
|
||||||
BMenuItem* chatMenuItem = fMenuBar->FindItem("Protocol");
|
BMenuItem* chatMenuItem = fMenuBar->FindItem("Protocol");
|
||||||
BMenu* chatMenu;
|
BMenu* chatMenu;
|
||||||
|
@ -379,8 +375,20 @@ MainWindow::SetConversation(Conversation* chat)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply saved weights
|
||||||
fSplitView->SetItemWeight(0, AppPreferences::Get()->MainWindowListWeight, true);
|
fSplitView->SetItemWeight(0, AppPreferences::Get()->MainWindowListWeight, true);
|
||||||
fSplitView->SetItemWeight(1, AppPreferences::Get()->MainWindowChatWeight, 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);
|
fRightView = new BSplitView(B_VERTICAL, 0);
|
||||||
fChatView = new ConversationView();
|
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)
|
BLayoutBuilder::Group<>(this, B_VERTICAL)
|
||||||
.Add((fMenuBar = _CreateMenuBar()))
|
.Add((fMenuBar = _CreateMenuBar()))
|
||||||
.AddGroup(B_HORIZONTAL)
|
.AddGroup(B_HORIZONTAL)
|
||||||
|
|
Ŝarĝante…
Reference in New Issue