-
Notifications
You must be signed in to change notification settings - Fork 0
/
SettingsWindow.h
125 lines (103 loc) · 3.82 KB
/
SettingsWindow.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#pragma once
#include "rfc/rfc.h"
#include "AppSettings.h"
class SettingsWindow : public KDialog, public KButtonListener
{
KTextBox txtCmdline;
KScopedClassPointer<KFont> fontSegoeUI;
KLabel lblCmdline;
KCheckBox chkRemoveMarkdown;
KCheckBox chkShowInit;
KCheckBox chkShowVecDBResp;
KGlyphButton btnOK, btnReset;
public:
AppSettings* appSettings;
KFont* fontWingdings;
SettingsWindow()
{
appSettings = nullptr;
this->SetText(L"Settings");
this->SetCloseOperation(KCloseOperation::Hide);
}
bool Create(bool requireInitialMessages = false) override
{
KDialog::Create();
const int clientWidth = KDPIUtility::ScaleToNewDPI(600, this->GetDPI());
const int clientHeight = KDPIUtility::ScaleToNewDPI(145, this->GetDPI());
this->SetClientAreaSize(clientWidth, clientHeight);
this->CenterOnSameMonitor(compParentHWND);
fontSegoeUI = new KFont(L"Segoe UI", 14, false, false, false, true, this->GetDPI());
lblCmdline.SetText(L"Commandline");
lblCmdline.SetFont(fontSegoeUI);
lblCmdline.SetPosition(10, 22);
lblCmdline.SetSize(80, lblCmdline.GetHeight());
txtCmdline.SetSize(490, txtCmdline.GetHeight());
txtCmdline.SetFont(fontSegoeUI);
txtCmdline.SetPosition(lblCmdline.GetX() + lblCmdline.GetWidth() + 5, 20);
chkRemoveMarkdown.SetText(L"Remove Markdown");
chkRemoveMarkdown.SetFont(fontSegoeUI);
chkRemoveMarkdown.SetSize(120, chkRemoveMarkdown.GetHeight());
chkRemoveMarkdown.SetPosition(txtCmdline.GetX(), txtCmdline.GetY() + txtCmdline.GetHeight() + 15);
chkShowInit.SetText(L"Show Initialization");
chkShowInit.SetFont(fontSegoeUI);
chkShowInit.SetSize(120, chkShowInit.GetHeight());
chkShowInit.SetPosition(txtCmdline.GetX() + 170, chkRemoveMarkdown.GetY());
chkShowVecDBResp.SetText(L"Show VecDB Result");
chkShowVecDBResp.SetFont(fontSegoeUI);
chkShowVecDBResp.SetSize(120, chkShowVecDBResp.GetHeight());
chkShowVecDBResp.SetPosition(chkShowInit.GetX() + 170, chkRemoveMarkdown.GetY());
btnOK.SetText(L"Save");
btnOK.SetFont(fontSegoeUI);
btnOK.SetGlyph(L"\x3C", fontWingdings, RGB(0, 0, 255), 13);
btnOK.SetPosition(txtCmdline.GetX() + txtCmdline.GetWidth() - 100, txtCmdline.GetY() + txtCmdline.GetHeight() + 60);
btnOK.SetListener(this);
btnReset.SetText(L"Reset");
btnReset.SetFont(fontSegoeUI);
btnReset.SetGlyph(L"\xC3", fontWingdings, RGB(0, 180, 0), 13);
btnReset.SetPosition(btnOK.GetX() - (btnReset.GetWidth() + 5), txtCmdline.GetY() + txtCmdline.GetHeight() + 60);
btnReset.SetListener(this);
this->AddComponent(&lblCmdline);
this->AddComponent(&txtCmdline);
this->AddComponent(&chkRemoveMarkdown);
this->AddComponent(&chkShowInit);
this->AddComponent(&chkShowVecDBResp);
this->AddComponent(&btnReset);
this->AddComponent(&btnOK);
return true;
}
void OnButtonPress(KButton* button) override
{
if (button == &btnOK)
{
KString cmdline(txtCmdline.GetText());
if (cmdline.GetLength() > 0)
{
appSettings->commandline = cmdline;
appSettings->removeMarkdown = chkRemoveMarkdown.IsChecked();
appSettings->showInitLog = chkShowInit.IsChecked();
appSettings->showVecDBResponse = chkShowVecDBResp.IsChecked();
appSettings->SaveSettings();
this->SetVisible(false);
}
}
else if (button == &btnReset)
{
appSettings->ResetConfig();
txtCmdline.SetText(appSettings->commandline);
chkRemoveMarkdown.SetCheckedState(appSettings->removeMarkdown);
chkShowInit.SetCheckedState(appSettings->showInitLog);
chkShowVecDBResp.SetCheckedState(appSettings->showVecDBResponse);
}
}
void ShowSettings()
{
if (this->IsVisible())
return;
// apply settings
txtCmdline.SetText(appSettings->commandline);
chkRemoveMarkdown.SetCheckedState(appSettings->removeMarkdown);
chkShowInit.SetCheckedState(appSettings->showInitLog);
chkShowVecDBResp.SetCheckedState(appSettings->showVecDBResponse);
this->SetVisible(true);
}
};