setting.cc预留导入导出配置文件

This commit is contained in:
2025-11-27 15:02:39 +08:00
parent 98dcfa1520
commit c86c24488c
2 changed files with 99 additions and 48 deletions

View File

@@ -244,6 +244,28 @@ static auto AddProfileLongItem(creeper::ThemeManager& manager) {
fbpro::Clickable {[]{ ShowAddProfileDialog(); }},
};
}
static auto ImportProfileLongItem(creeper::ThemeManager& manager) {
return new FilledButton {
fbpro::ThemeManager {manager},
fbpro::Text {QStringLiteral("导入配置")},
widget::pro::SizePolicy {QSizePolicy::Fixed, QSizePolicy::Expanding},
widget::pro::MinimumHeight {40},
widget::pro::MinimumWidth {320},
fbpro::Radius {12},
fbpro::Clickable {[]{ qDebug() << "ImportProfileLongItem"; }},
};
}
static auto ExportProfileLongItem(creeper::ThemeManager& manager) {
return new FilledButton {
fbpro::ThemeManager {manager},
fbpro::Text {QStringLiteral("导出配置")},
widget::pro::SizePolicy {QSizePolicy::Fixed, QSizePolicy::Expanding},
widget::pro::MinimumHeight {40},
widget::pro::MinimumWidth {320},
fbpro::Radius {12},
fbpro::Clickable {[]{ qDebug() << "ExportProfileLongItem"; }},
};
}
static auto ProfileItemComponent(creeper::ThemeManager& manager, ConfigProfile& profile,
const std::shared_ptr<MutableValue<std::vector<ConfigProfile>>>& profiles_store) {
QString matrix_size = "规格:" + QString{ "%1 * %2" }.arg(profile.matrix_width).arg(profile.matrix_height);
@@ -421,9 +443,19 @@ auto SettingComponent(SettingComponentState& state) noexcept -> raw_pointer<QWid
lnpro::Alignment {Qt::AlignTop},
lnpro::Margin {10},
lnpro::Spacing {10},
lnpro::Item<Row> {
lnpro::Item{
AddProfileLongItem(state.manager)
},
lnpro::Item {
ImportProfileLongItem(state.manager)
},
lnpro::Item {
ExportProfileLongItem(state.manager)
}
},
col::pro::Item<ScrollArea>{
scroll::pro::ThemeManager { state.manager },
scroll::pro::HorizontalScrollBarPolicy { Qt::ScrollBarAlwaysOff },

View File

@@ -28,6 +28,7 @@
#include <qsize.h>
#include <qsizepolicy.h>
#include <chrono>
#include <QEvent>
#include <iomanip>
#include <iostream>
#include <sstream>
@@ -509,6 +510,45 @@ SensorUiState& sensor_state() {
return state;
}
static void RefreshPortsForView(SensorUiState& sensor) {
QStringList ports_list;
const auto ports = ffmsep::CPStreamCore::list_available_ports();
ports_list.reserve(static_cast<qsizetype>(ports.size()));
for (const auto& info: ports) {
ports_list.emplace_back(QString::fromStdString(info.port));
}
if (!sensor.selected_port.isEmpty()) {
const bool exists = ports_list.contains(sensor.selected_port);
if (!exists) {
sensor.selected_port = ports_list.isEmpty() ? QString{} : ports_list.front();
}
}
else if (!ports_list.isEmpty()) {
sensor.selected_port = ports_list.front();
}
sensor.port_items->set(std::move(ports_list));
RefreshProfilesForView();
}
class PortHoverRefreshFilter final : public QObject {
public:
explicit PortHoverRefreshFilter(SensorUiState& sensor, QObject* parent = nullptr)
: QObject(parent)
, sensor_(sensor) { }
protected:
bool eventFilter(QObject* watched, QEvent* event) override {
if (event && event->type() == QEvent::Enter) {
RefreshPortsForView(sensor_);
}
return QObject::eventFilter(watched, event);
}
private:
SensorUiState& sensor_;
};
} // namespace
void RefreshProfilesForView() {
@@ -581,6 +621,12 @@ static auto ComConfigComponent(ThemeManager& manager) {
dmpro::Items{},
sensor.port_items,
},
dmpro::Apply{ [&sensor](dropdown_menu::internal::DropdownMenu& self) {
if (!self.property("portHoverRefreshAttached").toBool()) {
self.installEventFilter(new PortHoverRefreshFilter(sensor, &self));
self.setProperty("portHoverRefreshAttached", true);
}
} },
},
lnpro::Item<FilledDropdownMenu>{
dmpro::ThemeManager{ manager },
@@ -642,33 +688,6 @@ static auto ComConfigComponent(ThemeManager& manager) {
}
}
} } },
lnpro::Item<IconButton>{
ibpro::ThemeManager{ manager },
ibpro::FixedSize{ 40, 40 },
ibpro::Color{ IconButton::Color::TONAL },
ibpro::Font{ material::kRegularExtraSmallFont },
ibpro::FontIcon{ material::icon::kRefresh },
ibpro::Clickable{ [&sensor] {
QStringList ports_list;
const auto ports = ffmsep::CPStreamCore::list_available_ports();
ports_list.reserve(static_cast<qsizetype>(ports.size()));
for (const auto& info: ports) {
ports_list.emplace_back(QString::fromStdString(info.port));
}
if (!sensor.selected_port.isEmpty()) {
const bool exists = ports_list.contains(sensor.selected_port);
if (!exists) {
sensor.selected_port = ports_list.isEmpty() ? QString{} : ports_list.front();
}
}
else if (!ports_list.isEmpty()) {
sensor.selected_port = ports_list.front();
}
sensor.port_items->set(std::move(ports_list));
RefreshProfilesForView();
} },
},
lnpro::Item<FilledButton>{
fbpro::ThemeManager{ manager },
fbpro::FixedSize{ 40, 40 },