setting.cc预留导入导出配置文件
This commit is contained in:
@@ -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{
|
||||
AddProfileLongItem(state.manager)
|
||||
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 },
|
||||
|
||||
@@ -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() {
|
||||
@@ -570,17 +610,23 @@ static auto ComConfigComponent(ThemeManager& manager) {
|
||||
lnpro::Item<FilledDropdownMenu>{
|
||||
dmpro::ThemeManager{ manager },
|
||||
dmpro::LeadingIcon{ material::icon::kArrowDropDown, material::regular::font },
|
||||
dmpro::TextChanged{ [sensor_ptr = &sensor](QString text) {
|
||||
// const auto text = self.currentText();
|
||||
if (!text.isEmpty()) {
|
||||
sensor_ptr->selected_port = text;
|
||||
}
|
||||
} },
|
||||
dmpro::LabelText{ "COM" },
|
||||
MutableForward{
|
||||
dmpro::TextChanged{ [sensor_ptr = &sensor](QString text) {
|
||||
// const auto text = self.currentText();
|
||||
if (!text.isEmpty()) {
|
||||
sensor_ptr->selected_port = text;
|
||||
}
|
||||
} },
|
||||
dmpro::LabelText{ "COM" },
|
||||
MutableForward{
|
||||
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 },
|
||||
@@ -619,11 +665,11 @@ static auto ComConfigComponent(ThemeManager& manager) {
|
||||
icon_button::pro::FontIcon{},
|
||||
link_icon_context,
|
||||
},
|
||||
ibpro::Clickable{ [sensor_ptr = &sensor, link_icon_context] {
|
||||
auto& sensor = *sensor_ptr;
|
||||
if (!sensor.controller) {
|
||||
return;
|
||||
}
|
||||
ibpro::Clickable{ [sensor_ptr = &sensor, link_icon_context] {
|
||||
auto& sensor = *sensor_ptr;
|
||||
if (!sensor.controller) {
|
||||
return;
|
||||
}
|
||||
if (sensor.controller->is_connected()) {
|
||||
sensor.controller->stop();
|
||||
link_icon_context->set(QString::fromLatin1(material::icon::kAddLink));
|
||||
@@ -639,41 +685,14 @@ static auto ComConfigComponent(ThemeManager& manager) {
|
||||
std::cerr << "Failed to start sensor stream: "
|
||||
<< sensor.controller->last_error().toStdString()
|
||||
<< "\n";
|
||||
}
|
||||
}
|
||||
} } },
|
||||
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 },
|
||||
fbpro::Radius{ 8.0 },
|
||||
// fbpro::Color { IconButton::Color::TONAL },
|
||||
} } },
|
||||
lnpro::Item<FilledButton>{
|
||||
fbpro::ThemeManager{ manager },
|
||||
fbpro::FixedSize{ 40, 40 },
|
||||
fbpro::Radius{ 8.0 },
|
||||
// fbpro::Color { IconButton::Color::TONAL },
|
||||
fbpro::Font{ material::kRegularExtraSmallFont },
|
||||
fbpro::Text{ "drive_file_move" },
|
||||
fbpro::Clickable{ [&sensor] {
|
||||
|
||||
Reference in New Issue
Block a user