Zachary Hall
8fdf30878b
Some checks failed
Build / build-gentoo (push) Successful in 1m22s
Build / download-system-deps (push) Successful in 1m37s
Build / get-source-code (push) Successful in 4m30s
Build / build-appimage (push) Successful in 1m15s
Build / build-android (push) Failing after 4m34s
Build / build-windows (push) Failing after 4m33s
74 lines
3.2 KiB
C++
74 lines
3.2 KiB
C++
#include "aboutwindow.h"
|
|
#include <SplitView.h>
|
|
#include <license.hpp>
|
|
#include <GroupLayout.h>
|
|
#include <SplitView.h>
|
|
#include <StringView.h>
|
|
#include <ScrollView.h>
|
|
#include "main_window.h"
|
|
#define CMD_LOAD_LICENSE 0x40
|
|
LicenseItem::LicenseItem(const LicenseData license) : BStringItem("") {
|
|
SetText(fmt::format("{} ({})", license.Project, license.Spdx).c_str());
|
|
this->license_text = license.LicenseContents;
|
|
}
|
|
|
|
AboutWindow::AboutWindow() : BWindow(BRect(100, 100, 600, 400), "About Looper", B_TITLED_WINDOW, B_AUTO_UPDATE_SIZE_LIMITS) {
|
|
BGroupLayout *root_layout = new BGroupLayout(B_VERTICAL);
|
|
float minW, minH, maxW, maxH;
|
|
GetSizeLimits(&minW, &maxW, &minH, &maxH);
|
|
SetLayout(root_layout);
|
|
root_layout->SetSpacing(0.0);
|
|
BFont *title_font = new BFont();
|
|
title_font->SetSize(title_font->Size() * 4.0);
|
|
BStringView *looper_title = new BStringView("about:title", "Looper");
|
|
looper_title->SetAlignment(B_ALIGN_HORIZONTAL_CENTER);
|
|
looper_title->SetFont(title_font);
|
|
float title_height, version_height;
|
|
looper_title->GetPreferredSize(NULL, &title_height);
|
|
looper_title->SetExplicitMaxSize(BSize(maxW, title_height));
|
|
looper_title->ResizeToPreferred();
|
|
BStringView *version_text = new BStringView("about:version_text", fmt::format("Version {}", TAG).c_str());
|
|
version_text->SetAlignment(B_ALIGN_HORIZONTAL_CENTER);
|
|
version_text->GetPreferredSize(NULL, &version_height);
|
|
version_text->SetExplicitMaxSize(BSize(maxW, version_height));
|
|
version_text->ResizeToPreferred();
|
|
BLayoutItem *title_item = root_layout->AddView(looper_title);
|
|
BLayoutItem *version_item = root_layout->AddView(version_text);
|
|
title_item->SetExplicitAlignment(BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER));
|
|
version_item->SetExplicitAlignment(BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER));
|
|
BSplitView *view = new BSplitView();
|
|
view->SetExplicitMaxSize(BSize(maxW, maxH));
|
|
root_layout->AddView(view);
|
|
license_list = new BListView();
|
|
license_list->SetTarget(this);
|
|
for (auto &license : get_license_data()) {
|
|
license_list->AddItem(new LicenseItem(license));
|
|
}
|
|
license_list->SetSelectionMessage(new BMessage(CMD_LOAD_LICENSE));
|
|
BScrollView *license_list_scroller = new BScrollView("about:license-list-scroller", license_list, B_FOLLOW_ALL_SIDES, B_SUPPORTS_LAYOUT|B_FRAME_EVENTS, false, true);
|
|
license_text = new BTextView("about:license-text");
|
|
license_text->MakeEditable(false);
|
|
BScrollView *license_text_scroller = new BScrollView("about:license-text-scroller", license_text, B_FOLLOW_ALL_SIDES, B_SUPPORTS_LAYOUT|B_FRAME_EVENTS, false, true);
|
|
view->AddChild(license_list_scroller);
|
|
view->AddChild(license_text_scroller);
|
|
license_list->Select(0);
|
|
InvalidateLayout(true);
|
|
UpdateIfNeeded();
|
|
}
|
|
void AboutWindow::Show() {
|
|
BWindow::Show();
|
|
}
|
|
bool AboutWindow::QuitRequested() {
|
|
Hide();
|
|
return quitting;
|
|
}
|
|
void AboutWindow::MessageReceived(BMessage *msg) {
|
|
if (msg->IsSystem()) return;
|
|
if (msg->what == CMD_LOAD_LICENSE) {
|
|
auto selection = license_list->ItemAt(msg->GetInt32("index", 0));
|
|
std::string str = ((LicenseItem*)selection)->license_text;
|
|
|
|
license_text->SetText(str.c_str());
|
|
|
|
}
|
|
}
|