feat:完成设置界面和主界面的参数配置

This commit is contained in:
2025-11-25 15:58:04 +08:00
parent b2350a3b35
commit 0ec07218ab
192 changed files with 1404 additions and 56345 deletions

View File

@@ -1,16 +1,17 @@
//
// Created by Lenn on 2025/10/17.
//
#ifndef TOUCHSENSOR_HEATMAP_IMPL_HH
#define TOUCHSENSOR_HEATMAP_IMPL_HH
#include "heatmap.hh"
#include "modern-qt/utility/theme/theme.hh"
#include "modern-qt/widget/sliders.hh"
#include "qcustomplot/qcustomplot.h"
//
// Created by Lenn on 2025/10/17.
//
#ifndef TOUCHSENSOR_HEATMAP_IMPL_HH
#define TOUCHSENSOR_HEATMAP_IMPL_HH
#include "heatmap.hh"
#include "creeper-qt/utility/theme/theme.hh"
#include "creeper-qt/widget/sliders.hh"
#include "qcustomplot/qcustomplot.h"
#include <algorithm>
#include <memory>
#include <optional>
#include <qcolor.h>
#include <qdebug.h>
#include <qfont.h>
@@ -19,42 +20,45 @@ using namespace creeper::plot_widget::internal;
struct BasicPlot::Impl {
explicit Impl(BasicPlot& self) noexcept : self{self}, initialized(false), matrix_size(QSize{3, 4}) {}
public:
auto set_xlabel_text(const QString& text) -> void {
xlabel = text;
if (initialized) {
self.xAxis->setLabel(text);
self.replot();
}
}
auto set_ylabel_text(const QString& text) -> void {
ylabel = text;
if (initialized) {
self.yAxis->setLabel(text);
self.replot();
}
}
auto set_matrix_size(const QSize& size) -> void {
matrix_size = size;
if (initialized) {
reset_plot();
if (!data_points.isEmpty()) {
set_data(data_points);
}
}
}
auto load_theme_manager(ThemeManager& mgr) -> void {
mgr.append_handler(&self, [this](const ThemeManager& mgr) {
if (initialized) {
self.replot();
}
});
}
public:
std::optional<creeper::ColorScheme> scheme;
auto set_xlabel_text(const QString& text) -> void {
xlabel = text;
if (initialized) {
self.xAxis->setLabel(text);
self.replot();
}
}
auto set_ylabel_text(const QString& text) -> void {
ylabel = text;
if (initialized) {
self.yAxis->setLabel(text);
self.replot();
}
}
auto set_matrix_size(const QSize& size) -> void {
matrix_size = size;
if (initialized) {
reset_plot();
if (!data_points.isEmpty()) {
set_data(data_points);
}
}
}
auto load_theme_manager(ThemeManager& mgr) -> void {
mgr.append_handler(&self, [this](const ThemeManager& mgr) {
scheme = mgr.color_scheme();
apply_color_scheme();
if (initialized) {
self.replot();
}
});
}
auto set_color_gradient_range(const double& min, const double& max) -> void {
if (initialized && color_map) {
color_map->setDataRange(QCPRange(min, max));
@@ -62,8 +66,8 @@ public:
}
color_min = min;
color_max = max;
}
}
auto set_data(const QVector<PointData>& data) -> void {
data_points = data;
if (initialized && color_map) {
@@ -80,33 +84,33 @@ public:
cpmp->data()->setRange(QCPRange(0.5, matrix_size.width() - 0.5),
QCPRange(0.5, matrix_size.height() - 0.5));
QSharedPointer<QCPAxisTickerText> xticker(new QCPAxisTickerText);
QSharedPointer<QCPAxisTickerText> yticker(new QCPAxisTickerText);
xticker->setSubTickCount(1);
yticker->setSubTickCount(1);
self.xAxis->setVisible(false);
self.yAxis->setVisible(false);
self.xAxis->setTicker(xticker);
self.yAxis->setTicker(yticker);
self.xAxis->grid()->setPen(Qt::NoPen);
self.yAxis->grid()->setPen(Qt::NoPen);
self.xAxis->grid()->setSubGridVisible(true);
self.yAxis->grid()->setSubGridVisible(true);
self.xAxis->setSubTicks(true);
self.yAxis->setSubTicks(true);
self.xAxis->setTickLength(0);
self.yAxis->setTickLength(0);
self.xAxis->setSubTickLength(6);
self.yAxis->setSubTickLength(6);
self.xAxis->setRange(0, matrix_size.width());
self.yAxis->setRange(0, matrix_size.height());
if (!xlabel.isEmpty()) self.xAxis->setLabel(xlabel);
if (!ylabel.isEmpty()) self.yAxis->setLabel(ylabel);
QSharedPointer<QCPAxisTickerText> xticker(new QCPAxisTickerText);
QSharedPointer<QCPAxisTickerText> yticker(new QCPAxisTickerText);
xticker->setSubTickCount(1);
yticker->setSubTickCount(1);
self.xAxis->setVisible(false);
self.yAxis->setVisible(false);
self.xAxis->setTicker(xticker);
self.yAxis->setTicker(yticker);
self.xAxis->grid()->setPen(Qt::NoPen);
self.yAxis->grid()->setPen(Qt::NoPen);
self.xAxis->grid()->setSubGridVisible(true);
self.yAxis->grid()->setSubGridVisible(true);
self.xAxis->setSubTicks(true);
self.yAxis->setSubTicks(true);
self.xAxis->setTickLength(0);
self.yAxis->setTickLength(0);
self.xAxis->setSubTickLength(6);
self.yAxis->setSubTickLength(6);
self.xAxis->setRange(0, matrix_size.width());
self.yAxis->setRange(0, matrix_size.height());
if (!xlabel.isEmpty()) self.xAxis->setLabel(xlabel);
if (!ylabel.isEmpty()) self.yAxis->setLabel(ylabel);
if (!color_scale) {
color_scale = new QCPColorScale(&self);
color_scale->setType(QCPAxis::atBottom);
@@ -125,24 +129,25 @@ public:
QCPColorGradient gradient;
gradient.setColorStopAt(0.0, QColor(240, 246, 255)); // 低值淡色
gradient.setColorStopAt(0.35, QColor(142, 197, 252));
gradient.setColorStopAt(0.7, QColor(56, 128, 199));
gradient.setColorStopAt(1.0, QColor(8, 36, 95)); // 高值深色
cpmp->setGradient(gradient);
cpmp->setDataRange(QCPRange(color_min, color_max));
cpmp->setInterpolate(false);
gradient.setColorStopAt(0.7, QColor(56, 128, 199));
gradient.setColorStopAt(1.0, QColor(8, 36, 95)); // 高值深色
cpmp->setGradient(gradient);
cpmp->setDataRange(QCPRange(color_min, color_max));
cpmp->setInterpolate(false);
QCPMarginGroup *margin_group = new QCPMarginGroup(&self);
self.axisRect()->setMarginGroup(QCP::msLeft | QCP::msRight, margin_group);
color_scale->setMarginGroup(QCP::msLeft | QCP::msRight, margin_group);
initialized = true;
if (!data_points.isEmpty()) {
update_plot_data();
}
}
initialized = true;
apply_color_scheme();
if (!data_points.isEmpty()) {
update_plot_data();
}
}
auto reset_plot() -> void {
// 清除所有绘图元素
self.clearPlottables();
@@ -183,19 +188,19 @@ public:
// 重绘
self.replot();
}
auto is_plot_initialized() const -> bool {
return initialized;
}
auto get_matrix_size() const -> QSize {
return matrix_size;
}
private:
QString xlabel;
QString ylabel;
QSize matrix_size;
auto is_plot_initialized() const -> bool {
return initialized;
}
auto get_matrix_size() const -> QSize {
return matrix_size;
}
private:
QString xlabel;
QString ylabel;
QSize matrix_size;
QVector<PointData> data_points;
double color_min = 0.0;
double color_max = 800.0;
@@ -204,6 +209,40 @@ private:
QCPColorScale* color_scale = nullptr;
QCPColorMap* color_map = nullptr;
QVector<QCPItemText*> cell_labels;
QColor label_text_color = QColor(0, 0, 0);
void apply_color_scheme() {
QColor text_color = QColor(30, 30, 30);
if (scheme.has_value()) {
if (scheme->on_surface.isValid()) {
text_color = scheme->on_surface;
}
}
label_text_color = QColor(0, 0, 0); // 固定黑色
const auto pen = QPen(text_color);
self.xAxis->setTickLabelColor(text_color);
self.yAxis->setTickLabelColor(text_color);
self.xAxis->setLabelColor(text_color);
self.yAxis->setLabelColor(text_color);
self.xAxis->setBasePen(pen);
self.yAxis->setBasePen(pen);
self.xAxis->setTickPen(pen);
self.yAxis->setTickPen(pen);
if (color_scale && color_scale->axis()) {
color_scale->axis()->setTickLabelColor(text_color);
color_scale->axis()->setLabelColor(text_color);
color_scale->axis()->setBasePen(pen);
color_scale->axis()->setTickPen(pen);
}
// 已有标签更新
for (auto* label : cell_labels) {
if (!label) continue;
label->setColor(label_text_color);
}
}
void clear_labels() {
for (auto* label : cell_labels) {
@@ -245,7 +284,7 @@ private:
font.setPointSize(8);
}
label->setFont(font);
label->setColor(Qt::black);
label->setColor(label_text_color);
label->setSelectable(false);
cell_labels.push_back(label);
}
@@ -266,12 +305,6 @@ private:
? values[static_cast<std::size_t>(idx)]
: 0.0;
label->setText(QString::number(value, 'f', 0));
const double normalized = std::clamp((value - color_min) / range, 0.0, 1.0);
if (normalized > 0.55) {
label->setColor(Qt::white);
} else {
label->setColor(QColor(25, 25, 25));
}
const int x = idx % width;
const int y = idx / width;
label->position->setCoords(x + 0.5, y + 0.5);