first commit

This commit is contained in:
2025-10-20 00:32:01 +08:00
parent edac742f6a
commit 6ad03fc44f
106 changed files with 52165 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
//
// Created by Lenn on 2025/10/17.
//
#include "heatmap.hh"
#include "heatmap.impl.hh"
BasicPlot::BasicPlot()
: pimpl {std::make_unique<Impl>(*this)} {}
void BasicPlot::set_matrix_size(const QSize &) {
}

View File

@@ -0,0 +1,57 @@
//
// Created by Lenn on 2025/10/17.
//
#ifndef TOUCHSENSOR_HEATMAP_H
#define TOUCHSENSOR_HEATMAP_H
#include "modern-qt/utility/theme/theme.hh"
#include "modern-qt/utility/wrapper/pimpl.hh"
#include "qcustomplot/qcustomplot.h"
namespace creeper {
class heatmap;
namespace plot_widget::internal {
class BasicPlot : public QCustomPlot {
CREEPER_PIMPL_DEFINITION(BasicPlot);
friend heatmap;
public:
struct ColorSpace {
};
void load_theme_manager(ThemeManager&);
void set_xlabel_text(const QString&);
void set_ylabel_text(const QString&);
void set_matrix_size(const QSize&);
private:
friend class Impl;
};
}
namespace plot_widget::pro {
using Token = common::Token<internal::BasicPlot>;
using XLabelText = common::pro::String<Token, [](auto& self, const auto& string) {
self.set_xlabel_text(string);
}>;
using YLabelText = common::pro::String<Token, [](auto& self, const auto& string) {
self.set_ylabel_text(string);
}>;
struct MatrixSize : Token {
QSize size;
explicit MatrixSize(const int& w, const int& h) : size {w, h} {}
void apply(auto& self) const {
}
}
}
}
#endif //TOUCHSENSOR_HEATMAP_H

View File

@@ -0,0 +1,22 @@
//
// Created by Lenn on 2025/10/17.
//
#ifndef TOUCHSENSOR_HEATMAP_IMPL_HH
#define TOUCHSENSOR_HEATMAP_IMPL_HH
#include "heatmap.hh"
using namespace creeper::plot_widget::internal;
struct BasicPlot::Impl {
explicit Impl(BasicSelect& self) noexcept
: self{self} {
}
private:
BasicPlot& self;
};
#endif //TOUCHSENSOR_HEATMAP_IMPL_HH

103
components/nav.cc Normal file
View File

@@ -0,0 +1,103 @@
#include "component.hh"
#include "modern-qt/core/application.hh"
#include "modern-qt/layout/group.hh"
#include "modern-qt/layout/linear.hh"
#include "modern-qt/layout/mutual-exclusion-group.hh"
#include "modern-qt/utility/material-icon.hh"
#include "modern-qt/utility/theme/theme.hh"
#include "modern-qt/widget/buttons/icon-button.hh"
#include "modern-qt/widget/cards/filled-card.hh"
#include "modern-qt/widget/image.hh"
using namespace creeper;
namespace fc = filled_card::pro;
namespace sg = select_group::pro;
namespace ln = linear::pro;
namespace im = image::pro;
namespace ic = icon_button::pro;
auto NavComponent(NavComponentState& state) noexcept -> raw_pointer<QWidget> {
const auto AvatarComponent = new Image {
im::FixedSize {60, 60},
im::Radius {-1},
im::ContentScale {ContentScale::CROP},
im::BorderWidth {3},
im::PainterResource {
":/images/images/logo.png",
// "./images/logo.png",
},
};
state.manager.append_handler(AvatarComponent, [AvatarComponent](const ThemeManager& manager) {
const auto colorscheme = manager.color_scheme();
const auto colorborder = colorscheme.secondary_container;
AvatarComponent->set_border_color(colorborder);
});
const auto navigation_icons_config = std::tuple {
ic::ThemeManager {state.manager},
ic::ColorStandard,
ic::ShapeRound,
ic::TypesToggleUnselected,
ic::WidthDefault,
ic::Font {material::regular::font_1},
ic::FixedSize {IconButton::kSmallContainerSize},
};
return new FilledCard {
fc::ThemeManager {state.manager},
fc::Radius {0},
fc::Level {CardLevel::HIGHEST},
fc::Layout<Col> {
ln::Spacing {10},
ln::Margin {15},
ln::Item {
{0, Qt::AlignHCenter},
AvatarComponent,
},
ln::SpacingItem {20},
ln::Item<SelectGroup<Col, IconButton>> {
{0, Qt::AlignHCenter},
ln::Margin {0},
ln::SpacingItem {10},
sg::Compose {
state.buttons_context | std::views::enumerate,
[&](int index, const auto& context) {
const auto& [name, icon] = context;
const auto status = (index == 0)
? ic::TypesToggleSelected
: ic::TypesToggleUnselected;
return new IconButton {
navigation_icons_config,
status,
ic::FontIcon(icon.data()),
ic::Clickable {[=]{state.switch_callback(index, name);}},
};
},
Qt::AlignHCenter,
},
sg::SignalInjection{&IconButton::clicked},
},
ln::SpacingItem {40},
ln::Stretch {255},
ln::Item<IconButton> {
{0, Qt::AlignHCenter},
navigation_icons_config,
ic::TypesDefault,
ic::FontIcon {material::icon::kLogout},
ic::Clickable {&app::quit},
},
ln::Item<IconButton> {
{0, Qt::AlignHCenter},
navigation_icons_config,
ic::ColorFilled,
ic::FontIcon {material::icon::kDarkMode},
ic::Clickable{[&]{state.manager.toggle_color_mode();state.manager.apply_theme();}},
}
}
};
}

178
components/view.cc Normal file
View File

@@ -0,0 +1,178 @@
//
// Created by Lenn on 2025/10/14.
//
#include <random>
#include "component.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;
static auto ComConfigComponent(ThemeManager& manager, auto&& callback) {
auto slogen_context = std::make_shared<MutableValue<QString>>();
slogen_context->set_silent("BanG Bream! It's MyGo!!!");
// 创建一个MutableValue<QStringList>来存储MatSelect的选项
auto select_com_context = std::make_shared<MutableValue<QStringList>>();
select_com_context->set_silent(QStringList {});
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"},
},
lnpro::Item<MatSelect> {
slpro::ThemeManager {manager },
slpro::LeadingIcon { material::icon::kArrowDropDown, material::regular::font},
slpro::IndexChanged {[&](auto& self){ qDebug() << self.currentIndex();}},
slpro::LeadingText {"Baud"},
// slpro::MutableItems {select_baud_context},
MutableForward {
slpro::SelectItems {},
select_baud_context,
}
},
// lnpro::Item<MatSelect> {
// // slpro::ThemeManager {manager},
// // slpro::LeadingIcon {material::icon::kArrowDropDown, material::regular::font},
// // slpro::IndexChanged {}
// // }
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::kFavorite },
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);
}
}
qDebug() << new_options;
// 更新选项列表MatSelect会自动刷新
*select_baud_context = new_options;
}},
},
};
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);
}
}),
},
},
};
}