214 lines
8.1 KiB
C++
214 lines
8.1 KiB
C++
//
|
|
// Created by Lenn on 2025/10/14.
|
|
//
|
|
|
|
#include <qsize.h>
|
|
#include <qsizepolicy.h>
|
|
#include <random>
|
|
|
|
#include "component.hh"
|
|
#include "modern-qt/utility/theme/theme.hh"
|
|
#include "modern-qt/utility/wrapper/layout.hh"
|
|
#include "modern-qt/utility/wrapper/widget.hh"
|
|
#include "components/charts/heatmap.hh"
|
|
#include <modern-qt/layout/flow.hh>
|
|
#include <modern-qt/layout/linear.hh>
|
|
#include <modern-qt/utility/material-icon.hh>
|
|
#include <modern-qt/utility/wrapper/mutable-value.hh>
|
|
#include <modern-qt/widget/buttons/icon-button.hh>
|
|
#include <modern-qt/widget/cards/filled-card.hh>
|
|
#include <modern-qt/widget/cards/outlined-card.hh>
|
|
#include <modern-qt/widget/image.hh>
|
|
#include <modern-qt/widget/shape/wave-circle.hh>
|
|
#include <modern-qt/widget/sliders.hh>
|
|
#include <modern-qt/widget/switch.hh>
|
|
#include <modern-qt/widget/text-fields.hh>
|
|
#include <modern-qt/widget/text.hh>
|
|
#include <modern-qt/widget/select.hh>
|
|
|
|
using namespace creeper;
|
|
namespace capro = card::pro;
|
|
namespace lnpro = linear::pro;
|
|
namespace impro = image::pro;
|
|
namespace ibpro = icon_button::pro;
|
|
namespace slpro = select_widget::pro;
|
|
namespace pwpro = plot_widget::pro;
|
|
|
|
static auto ComConfigComponent(ThemeManager& manager, auto&& callback) {
|
|
auto slogen_context = std::make_shared<MutableValue<QString>>();
|
|
slogen_context->set_silent("BanG Bream! It's MyGo!!!");
|
|
|
|
auto select_com_context = std::make_shared<MutableValue<QStringList>>();
|
|
select_com_context->set_silent(QStringList {"COM1", "COM2", "COM3", "COM4", "COM5"});
|
|
|
|
auto select_baud_context = std::make_shared<MutableValue<QStringList>>();
|
|
select_baud_context->set_silent(QStringList {"9600", "115200"});
|
|
|
|
|
|
|
|
const auto row = new Row {
|
|
// lnpro::Item<FilledTextField> {
|
|
// text_field::pro::ThemeManager {manager},
|
|
// text_field::pro::LeadingIcon {material::icon::kSearch, material::regular::font},
|
|
// MutableForward {
|
|
// text_field::pro::LabelText {},
|
|
// slogen_context,
|
|
// },
|
|
// },
|
|
lnpro::Item<MatSelect> {
|
|
slpro::ThemeManager {manager},
|
|
slpro::LeadingIcon {material::icon::kArrowDropDown, material::regular::font},
|
|
slpro::IndexChanged {[&](auto& self){ qDebug() << self.currentIndex();}},
|
|
slpro::LeadingText {"COM"},
|
|
MutableForward {
|
|
slpro::SelectItems {},
|
|
select_com_context,
|
|
}
|
|
},
|
|
lnpro::Item<MatSelect> {
|
|
slpro::ThemeManager {manager },
|
|
slpro::LeadingIcon { material::icon::kArrowDropDown, material::regular::font},
|
|
slpro::IndexChanged {[&](auto& self){ qDebug() << self.currentIndex();}},
|
|
slpro::LeadingText {"Baud"},
|
|
MutableForward {
|
|
slpro::SelectItems {},
|
|
select_baud_context,
|
|
}
|
|
},
|
|
lnpro::SpacingItem {20},
|
|
lnpro::Item<IconButton> {
|
|
ibpro::ThemeManager {manager},
|
|
ibpro::FixedSize {40, 40},
|
|
ibpro::Color { IconButton::Color::TONAL },
|
|
ibpro::Font { material::kRoundSmallFont },
|
|
ibpro::FontIcon { material::icon::kAddLink },
|
|
ibpro::Clickable {[slogen_context] {
|
|
constexpr auto random_slogen = [] {
|
|
constexpr auto slogens = std::array {
|
|
"为什么要演奏《春日影》!",
|
|
"我从来不觉得玩乐队开心过。",
|
|
"我好想…成为人啊!",
|
|
"那你愿意……跟我组一辈子的乐队吗?",
|
|
"过去软弱的我…已经死了。",
|
|
};
|
|
static std::random_device rd;
|
|
static std::mt19937 gen(rd());
|
|
std::uniform_int_distribution<> dist(0, slogens.size() - 1);
|
|
return QString::fromUtf8(slogens[dist(gen)]);
|
|
};
|
|
*slogen_context = random_slogen();
|
|
}},
|
|
},
|
|
lnpro::Item<IconButton> {
|
|
ibpro::ThemeManager { manager },
|
|
ibpro::FixedSize { 40, 40 },
|
|
ibpro::Color { IconButton::Color::TONAL },
|
|
ibpro::Font { material::kRoundSmallFont },
|
|
ibpro::FontIcon { material::icon::kRefresh },
|
|
ibpro::Clickable {[select_baud_context] {
|
|
|
|
static constexpr auto options_group1 = std::array {
|
|
"第一组选项1", "第一组选项2", "第一组选项3"
|
|
};
|
|
static constexpr auto options_group2 = std::array {
|
|
"第二组选项A", "第二组选项B", "第二组选项C", "第二组选项D"
|
|
};
|
|
|
|
static std::random_device rd;
|
|
static std::mt19937 gen(rd());
|
|
std::uniform_int_distribution<> dist(0, 1);
|
|
|
|
QStringList new_options;
|
|
if (dist(gen) == 0) {
|
|
for (const auto& option : options_group1) {
|
|
new_options << QString::fromUtf8(option);
|
|
}
|
|
} else {
|
|
for (const auto& option : options_group2) {
|
|
new_options << QString::fromUtf8(option);
|
|
}
|
|
}
|
|
*select_baud_context = new_options;
|
|
}},
|
|
},
|
|
|
|
};
|
|
return new Widget {
|
|
widget::pro::Layout {row},
|
|
};
|
|
}
|
|
|
|
static auto DisplayComponent(ThemeManager& manager, int index = 0) noexcept {
|
|
auto heatmap_context = std::make_shared<MutableValue<QVector<PointData>>>();
|
|
heatmap_context->set_silent(QVector<PointData>{
|
|
PointData{0, 0, 1}, PointData{1, 0, 2}, PointData{2, 0, 3},
|
|
PointData{0, 1, 3}, PointData{1, 1, 4}, PointData{2, 1, 5},
|
|
PointData{0, 2, 6}, PointData{1, 2, 7}, PointData{2, 2, 8},
|
|
PointData{0, 3, 9}, PointData{1, 3, 10}, PointData{2, 3, 11},
|
|
});
|
|
const auto row = new Row{
|
|
lnpro::Item<HeatMapPlot> {
|
|
plot_widget::pro::SizePolicy {
|
|
QSizePolicy::Expanding,
|
|
},
|
|
MutableForward {
|
|
plot_widget::pro::PlotData {},
|
|
heatmap_context,
|
|
},
|
|
pwpro::MatrixSize {
|
|
QSize{3, 4}
|
|
},
|
|
},
|
|
};
|
|
return new Widget {
|
|
widget::pro::Layout{row},
|
|
};
|
|
}
|
|
auto ViewComponent(ViewComponentState& state) noexcept -> raw_pointer<QWidget> {
|
|
const auto texts = std::array {
|
|
std::make_shared<MutableValue<QString>>("0.500"),
|
|
std::make_shared<MutableValue<QString>>("0.500"),
|
|
std::make_shared<MutableValue<QString>>("0.500"),
|
|
};
|
|
const auto progresses = std::array {
|
|
std::make_shared<MutableValue<double>>(0.5),
|
|
std::make_shared<MutableValue<double>>(0.5),
|
|
std::make_shared<MutableValue<double>>(0.5),
|
|
};
|
|
return new FilledCard {
|
|
capro::ThemeManager { state.manager },
|
|
capro::SizePolicy {QSizePolicy::Expanding},
|
|
capro::Layout<Col> {
|
|
lnpro::Alignment {Qt::AlignTop},
|
|
lnpro::Margin {10},
|
|
lnpro::Spacing {10},
|
|
|
|
lnpro::Item {
|
|
ComConfigComponent(state.manager,
|
|
[texts, progresses] {
|
|
constexpr auto random_unit = []() {
|
|
static std::random_device rd;
|
|
static std::mt19937 gen(rd());
|
|
static std::uniform_real_distribution<double> dist(0.0, 1.0);
|
|
return dist(gen);
|
|
};
|
|
for (auto&& [string, number] : std::views::zip(texts, progresses)) {
|
|
auto v = random_unit();
|
|
*number = v;
|
|
*string = QString::number(v, 'f', 3);
|
|
}
|
|
}),
|
|
},
|
|
|
|
lnpro::Item<Row> {
|
|
lnpro::Item {
|
|
DisplayComponent(state.manager),
|
|
},
|
|
lnpro::Item {
|
|
DisplayComponent(state.manager),
|
|
},
|
|
},
|
|
},
|
|
};
|
|
}
|