ui fixes
This commit is contained in:
parent
2e82ca6791
commit
720dcbb381
3 changed files with 69 additions and 71 deletions
BIN
DumBer
BIN
DumBer
Binary file not shown.
139
MainWindow.cpp
139
MainWindow.cpp
|
@ -3,7 +3,6 @@
|
||||||
* All rights reserved. Distributed under the terms of the MIT license.
|
* All rights reserved. Distributed under the terms of the MIT license.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
|
|
||||||
#include <Url.h>
|
#include <Url.h>
|
||||||
|
@ -14,7 +13,8 @@
|
||||||
#include <LayoutBuilder.h>
|
#include <LayoutBuilder.h>
|
||||||
#include <Menu.h>
|
#include <Menu.h>
|
||||||
#include <MenuBar.h>
|
#include <MenuBar.h>
|
||||||
#include <StringView.h>
|
#include <ScrollView.h>
|
||||||
|
#include <StringView.h>
|
||||||
|
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
|
|
||||||
|
@ -38,37 +38,32 @@ MainWindow::MainWindow()
|
||||||
: BWindow(BRect(100, 100, 600, 400), B_TRANSLATE("BeDumb"), B_TITLED_WINDOW,
|
: BWindow(BRect(100, 100, 600, 400), B_TRANSLATE("BeDumb"), B_TITLED_WINDOW,
|
||||||
B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE) {
|
B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE) {
|
||||||
|
|
||||||
|
|
||||||
BMenuBar *menuBar = _BuildMenu();
|
BMenuBar *menuBar = _BuildMenu();
|
||||||
|
|
||||||
BLayoutBuilder::Group<>(this, B_VERTICAL, 0).Add(menuBar).AddGlue().End();
|
BLayoutBuilder::Group<>(this, B_VERTICAL, 0).Add(menuBar).AddGlue().End();
|
||||||
|
|
||||||
_inputField =
|
_inputField = new BTextControl("", "What is the matrix ?",
|
||||||
new BTextControl("", "What is the matrix ?", new BMessage(kQuestionChanged));
|
new BMessage(kQuestionChanged));
|
||||||
|
|
||||||
|
|
||||||
_progress = new BStatusBar("prog");
|
_progress = new BStatusBar("prog");
|
||||||
_progress->SetMaxValue(100);
|
_progress->SetMaxValue(100);
|
||||||
_progress->SetTo(0);
|
_progress->SetTo(0);
|
||||||
_progress->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
_progress->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
|
|
||||||
|
|
||||||
_answerView = new BTextView("answer");
|
BStringView *header = new BStringView("biglabel", "Let's Be Dumber!");
|
||||||
|
BFont font;
|
||||||
BStringView* header = new BStringView("biglabel", "Let's Be Dumber!");
|
header->GetFont(&font);
|
||||||
BFont font;
|
font.SetSize(20);
|
||||||
header->GetFont(&font);
|
header->SetFont(&font);
|
||||||
font.SetSize(20);
|
|
||||||
header->SetFont(&font);
|
|
||||||
|
|
||||||
// Info view, only one line high
|
// Info view, only one line high
|
||||||
_infoView = new BTextView("info");
|
_infoView = new BTextView("info");
|
||||||
_infoView->SetText("...");
|
_infoView->SetText("...");
|
||||||
_infoView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
_infoView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
_infoView->MakeEditable(false);
|
_infoView->MakeEditable(false);
|
||||||
_infoView->MakeSelectable(false);
|
_infoView->MakeSelectable(false);
|
||||||
_infoView->SetWordWrap(false);
|
_infoView->SetWordWrap(false);
|
||||||
|
|
||||||
float lineHeight = _infoView->LineHeight(0);
|
float lineHeight = _infoView->LineHeight(0);
|
||||||
_infoView->SetExplicitMinSize(BSize(B_SIZE_UNSET, lineHeight));
|
_infoView->SetExplicitMinSize(BSize(B_SIZE_UNSET, lineHeight));
|
||||||
_infoView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, lineHeight));
|
_infoView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, lineHeight));
|
||||||
|
@ -81,9 +76,20 @@ MainWindow::MainWindow()
|
||||||
new BButton("send", B_TRANSLATE("Send"), new BMessage(kSendPrompt),
|
new BButton("send", B_TRANSLATE("Send"), new BMessage(kSendPrompt),
|
||||||
B_WILL_DRAW | B_NAVIGABLE);
|
B_WILL_DRAW | B_NAVIGABLE);
|
||||||
|
|
||||||
|
_answerView = new BTextView("answer", B_WILL_DRAW | B_FOLLOW_ALL);
|
||||||
|
_answerView->MakeEditable(false); // Disable editing
|
||||||
|
_answerView->MakeSelectable(true); // Enable text selection
|
||||||
|
|
||||||
|
//_answerView->SetWordWrap(true);
|
||||||
|
BScrollView *scrollView =
|
||||||
|
new BScrollView("scroll_view", _answerView, 0, 0, false,
|
||||||
|
true); // horizontal and vertical scrollbars
|
||||||
|
|
||||||
BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
|
BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
|
||||||
|
|
||||||
.Add(header)
|
.AddGlue(0.1)
|
||||||
|
.Add(header)
|
||||||
|
.AddGlue(0.1)
|
||||||
|
|
||||||
.AddGroup(B_HORIZONTAL, 0, 1)
|
.AddGroup(B_HORIZONTAL, 0, 1)
|
||||||
.Add(_inputField)
|
.Add(_inputField)
|
||||||
|
@ -92,9 +98,10 @@ MainWindow::MainWindow()
|
||||||
.End()
|
.End()
|
||||||
.End()
|
.End()
|
||||||
|
|
||||||
|
.AddGlue(0.1)
|
||||||
|
.Add(scrollView)
|
||||||
.Add(_progress)
|
.Add(_progress)
|
||||||
.Add(_infoView)
|
.Add(_infoView)
|
||||||
.Add(_answerView)
|
|
||||||
|
|
||||||
.SetInsets(5, 5, 5, 5)
|
.SetInsets(5, 5, 5, 5)
|
||||||
|
|
||||||
|
@ -106,7 +113,7 @@ MainWindow::~MainWindow() {}
|
||||||
void MainWindow::MessageReceived(BMessage *message) {
|
void MainWindow::MessageReceived(BMessage *message) {
|
||||||
|
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
|
|
||||||
// case kMsgNewFile: {
|
// case kMsgNewFile: {
|
||||||
// fSaveMenuItem->SetEnabled(false);
|
// fSaveMenuItem->SetEnabled(false);
|
||||||
// printf("New\n");
|
// printf("New\n");
|
||||||
|
@ -123,9 +130,9 @@ void MainWindow::MessageReceived(BMessage *message) {
|
||||||
|
|
||||||
case kQuestionChanged: {
|
case kQuestionChanged: {
|
||||||
printf("Question Changed\n");
|
printf("Question Changed\n");
|
||||||
_progress->SetTo(2);
|
_progress->SetTo(2);
|
||||||
|
|
||||||
// sendQuery();
|
// sendQuery();
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
|
@ -138,8 +145,8 @@ void MainWindow::MessageReceived(BMessage *message) {
|
||||||
|
|
||||||
case UrlEvent::HostNameResolved: {
|
case UrlEvent::HostNameResolved: {
|
||||||
printf("Host name resolved\n");
|
printf("Host name resolved\n");
|
||||||
auto name = message->GetString(UrlEventData::HostName);
|
auto name = message->GetString(UrlEventData::HostName);
|
||||||
message->PrintToStream();
|
message->PrintToStream();
|
||||||
|
|
||||||
_infoView->SetText("Hostname resolve...");
|
_infoView->SetText("Hostname resolve...");
|
||||||
_infoView->SetText(name);
|
_infoView->SetText(name);
|
||||||
|
@ -158,34 +165,31 @@ void MainWindow::MessageReceived(BMessage *message) {
|
||||||
_progress->SetTo(14);
|
_progress->SetTo(14);
|
||||||
_infoView->SetText("ResponseStarted...");
|
_infoView->SetText("ResponseStarted...");
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case UrlEvent::HttpRedirect: {
|
case UrlEvent::HttpRedirect: {
|
||||||
printf("HttpRedirect\n");
|
printf("HttpRedirect\n");
|
||||||
_progress->SetTo(16);
|
_progress->SetTo(16);
|
||||||
_infoView->SetText("HttpRedirect...");
|
_infoView->SetText("HttpRedirect...");
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
case UrlEvent::RequestCompleted: {
|
case UrlEvent::RequestCompleted: {
|
||||||
printf("RequestCompleted\n");
|
printf("RequestCompleted\n");
|
||||||
auto identifier = message->GetInt32(UrlEventData::Id, -1);
|
auto identifier = message->GetInt32(UrlEventData::Id, -1);
|
||||||
if (_lastResult->Identity() == identifier) {
|
if (_lastResult->Identity() == identifier) {
|
||||||
// The following call will not block, because we have been notified
|
// The following call will not block, because we have been notified
|
||||||
// that the request is done.
|
// that the request is done.
|
||||||
BHttpBody body = _lastResult->Body();
|
BHttpBody body = _lastResult->Body();
|
||||||
if (body.text.has_value())
|
if (body.text.has_value())
|
||||||
_answerView->SetText(body.text.value());
|
_answerView->SetText(body.text.value());
|
||||||
else
|
else
|
||||||
_answerView->SetText("nuthin'");
|
_answerView->SetText("nuthin'");
|
||||||
}
|
}
|
||||||
|
|
||||||
_infoView->SetText("Completed");
|
|
||||||
_progress->SetMaxValue(100);
|
|
||||||
_progress->SetTo(100);
|
|
||||||
|
|
||||||
} break;
|
_infoView->SetText("Completed");
|
||||||
|
_progress->SetMaxValue(100);
|
||||||
|
_progress->SetTo(100);
|
||||||
|
|
||||||
|
} break;
|
||||||
|
|
||||||
case UrlEvent::HttpStatus: {
|
case UrlEvent::HttpStatus: {
|
||||||
|
|
||||||
|
@ -199,49 +203,45 @@ void MainWindow::MessageReceived(BMessage *message) {
|
||||||
_infoView->SetText("Some bytes written..");
|
_infoView->SetText("Some bytes written..");
|
||||||
auto identifier = message->GetInt32(UrlEventData::Id, -1);
|
auto identifier = message->GetInt32(UrlEventData::Id, -1);
|
||||||
if (_lastResult->Identity() == identifier) {
|
if (_lastResult->Identity() == identifier) {
|
||||||
off_t numBytes = message->GetInt64(UrlEventData::NumBytes, 0);
|
off_t numBytes = message->GetInt64(UrlEventData::NumBytes, 0);
|
||||||
off_t totalBytes = message->GetInt64(UrlEventData::TotalBytes, 0);
|
off_t totalBytes = message->GetInt64(UrlEventData::TotalBytes, 0);
|
||||||
_progress->SetTo(numBytes);
|
_progress->SetTo(numBytes);
|
||||||
_progress->SetMaxValue(totalBytes);
|
_progress->SetMaxValue(totalBytes);
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case UrlEvent::DownloadProgress: {
|
case UrlEvent::DownloadProgress: {
|
||||||
auto identifier = message->GetInt32(UrlEventData::Id, -1);
|
auto identifier = message->GetInt32(UrlEventData::Id, -1);
|
||||||
if (_lastResult->Identity() == identifier) {
|
if (_lastResult->Identity() == identifier) {
|
||||||
off_t nn = message->GetInt64(UrlEventData::NumBytes, 0);
|
off_t nn = message->GetInt64(UrlEventData::NumBytes, 0);
|
||||||
off_t totalBytes = message->GetInt64(UrlEventData::TotalBytes, 0);
|
off_t totalBytes = message->GetInt64(UrlEventData::TotalBytes, 0);
|
||||||
_progress->SetTo(nn);
|
_progress->SetTo(nn);
|
||||||
_progress->SetMaxValue(totalBytes);
|
_progress->SetMaxValue(totalBytes);
|
||||||
_infoView->SetText("Download Progress..");
|
_infoView->SetText("Download Progress..");
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
//message->PrintToStream();
|
// message->PrintToStream();
|
||||||
BWindow::MessageReceived(message); // call the parent handler for other messages
|
BWindow::MessageReceived(
|
||||||
|
message); // call the parent handler for other messages
|
||||||
// _infoView->SetText(message->FindMessage());
|
// _infoView->SetText(message->FindMessage());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}//end switch
|
|
||||||
|
|
||||||
} //end function
|
|
||||||
|
|
||||||
|
} // end switch
|
||||||
|
|
||||||
|
} // end function
|
||||||
|
|
||||||
void MainWindow::sendQuery() {
|
void MainWindow::sendQuery() {
|
||||||
|
|
||||||
if (_lastResult)
|
if (_lastResult)
|
||||||
_sharedSession.Cancel(_lastResult->Identity());
|
_sharedSession.Cancel(_lastResult->Identity());
|
||||||
|
|
||||||
_progress->SetMaxValue(100);
|
_progress->SetMaxValue(100);
|
||||||
_progress->SetTo(0);
|
_progress->SetTo(0);
|
||||||
|
|
||||||
auto url = BUrl("https://www.link-u.com/ip/");
|
auto url = BUrl("https://www.lema.org/");
|
||||||
BHttpRequest request = BHttpRequest(url);
|
BHttpRequest request = BHttpRequest(url);
|
||||||
|
|
||||||
printf("Sending Prompt to server: %s\n", url.UrlString().String());
|
printf("Sending Prompt to server: %s\n", url.UrlString().String());
|
||||||
|
@ -250,17 +250,14 @@ void MainWindow::sendQuery() {
|
||||||
if (_lastResult) {
|
if (_lastResult) {
|
||||||
printf("Result has identity: %d\n", _lastResult->Identity());
|
printf("Result has identity: %d\n", _lastResult->Identity());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BMenuBar *MainWindow::_BuildMenu() {
|
BMenuBar *MainWindow::_BuildMenu() {
|
||||||
|
|
||||||
BMenuBar *menuBar = new BMenuBar("menubar");
|
BMenuBar *menuBar = new BMenuBar("menubar");
|
||||||
BMenu *menu;
|
BMenu *menu;
|
||||||
BMenuItem *item;
|
BMenuItem *item;
|
||||||
|
|
||||||
// menu 'File'
|
// menu 'File'
|
||||||
menu = new BMenu(B_TRANSLATE("File"));
|
menu = new BMenu(B_TRANSLATE("File"));
|
||||||
|
|
||||||
|
@ -277,17 +274,17 @@ BMenuBar *MainWindow::_BuildMenu() {
|
||||||
// menu->AddItem(fSaveMenuItem);
|
// menu->AddItem(fSaveMenuItem);
|
||||||
|
|
||||||
// menu->AddSeparatorItem();
|
// menu->AddSeparatorItem();
|
||||||
|
|
||||||
item = new BMenuItem(B_TRANSLATE("About" B_UTF8_ELLIPSIS),
|
item = new BMenuItem(B_TRANSLATE("About" B_UTF8_ELLIPSIS),
|
||||||
new BMessage(B_ABOUT_REQUESTED));
|
new BMessage(B_ABOUT_REQUESTED));
|
||||||
item->SetTarget(be_app);
|
item->SetTarget(be_app);
|
||||||
menu->AddItem(item);
|
menu->AddItem(item);
|
||||||
|
|
||||||
item = new BMenuItem(B_TRANSLATE("Quit"), new BMessage(B_QUIT_REQUESTED), 'Q');
|
item =
|
||||||
|
new BMenuItem(B_TRANSLATE("Quit"), new BMessage(B_QUIT_REQUESTED), 'Q');
|
||||||
menu->AddItem(item);
|
menu->AddItem(item);
|
||||||
|
|
||||||
menuBar->AddItem(menu);
|
menuBar->AddItem(menu);
|
||||||
|
|
||||||
return menuBar;
|
return menuBar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,7 @@ private:
|
||||||
BTextView * _infoView;
|
BTextView * _infoView;
|
||||||
BTextControl* _inputField;
|
BTextControl* _inputField;
|
||||||
BStatusBar* _progress;
|
BStatusBar* _progress;
|
||||||
|
|
||||||
BMenuItem *fSaveMenuItem;
|
BMenuItem *fSaveMenuItem;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue