setting.cc预留导入导出配置文件
This commit is contained in:
@@ -244,6 +244,28 @@ static auto AddProfileLongItem(creeper::ThemeManager& manager) {
|
|||||||
fbpro::Clickable {[]{ ShowAddProfileDialog(); }},
|
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,
|
static auto ProfileItemComponent(creeper::ThemeManager& manager, ConfigProfile& profile,
|
||||||
const std::shared_ptr<MutableValue<std::vector<ConfigProfile>>>& profiles_store) {
|
const std::shared_ptr<MutableValue<std::vector<ConfigProfile>>>& profiles_store) {
|
||||||
QString matrix_size = "规格:" + QString{ "%1 * %2" }.arg(profile.matrix_width).arg(profile.matrix_height);
|
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::Alignment {Qt::AlignTop},
|
||||||
lnpro::Margin {10},
|
lnpro::Margin {10},
|
||||||
lnpro::Spacing {10},
|
lnpro::Spacing {10},
|
||||||
lnpro::Item{
|
lnpro::Item<Row> {
|
||||||
AddProfileLongItem(state.manager)
|
lnpro::Item{
|
||||||
|
AddProfileLongItem(state.manager)
|
||||||
|
},
|
||||||
|
lnpro::Item {
|
||||||
|
ImportProfileLongItem(state.manager)
|
||||||
|
},
|
||||||
|
lnpro::Item {
|
||||||
|
ExportProfileLongItem(state.manager)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
col::pro::Item<ScrollArea>{
|
col::pro::Item<ScrollArea>{
|
||||||
scroll::pro::ThemeManager { state.manager },
|
scroll::pro::ThemeManager { state.manager },
|
||||||
scroll::pro::HorizontalScrollBarPolicy { Qt::ScrollBarAlwaysOff },
|
scroll::pro::HorizontalScrollBarPolicy { Qt::ScrollBarAlwaysOff },
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
#include <qsize.h>
|
#include <qsize.h>
|
||||||
#include <qsizepolicy.h>
|
#include <qsizepolicy.h>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <QEvent>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@@ -509,6 +510,45 @@ SensorUiState& sensor_state() {
|
|||||||
return 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
|
} // namespace
|
||||||
|
|
||||||
void RefreshProfilesForView() {
|
void RefreshProfilesForView() {
|
||||||
@@ -570,17 +610,23 @@ static auto ComConfigComponent(ThemeManager& manager) {
|
|||||||
lnpro::Item<FilledDropdownMenu>{
|
lnpro::Item<FilledDropdownMenu>{
|
||||||
dmpro::ThemeManager{ manager },
|
dmpro::ThemeManager{ manager },
|
||||||
dmpro::LeadingIcon{ material::icon::kArrowDropDown, material::regular::font },
|
dmpro::LeadingIcon{ material::icon::kArrowDropDown, material::regular::font },
|
||||||
dmpro::TextChanged{ [sensor_ptr = &sensor](QString text) {
|
dmpro::TextChanged{ [sensor_ptr = &sensor](QString text) {
|
||||||
// const auto text = self.currentText();
|
// const auto text = self.currentText();
|
||||||
if (!text.isEmpty()) {
|
if (!text.isEmpty()) {
|
||||||
sensor_ptr->selected_port = text;
|
sensor_ptr->selected_port = text;
|
||||||
}
|
}
|
||||||
} },
|
} },
|
||||||
dmpro::LabelText{ "COM" },
|
dmpro::LabelText{ "COM" },
|
||||||
MutableForward{
|
MutableForward{
|
||||||
dmpro::Items{},
|
dmpro::Items{},
|
||||||
sensor.port_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>{
|
lnpro::Item<FilledDropdownMenu>{
|
||||||
dmpro::ThemeManager{ manager },
|
dmpro::ThemeManager{ manager },
|
||||||
@@ -619,11 +665,11 @@ static auto ComConfigComponent(ThemeManager& manager) {
|
|||||||
icon_button::pro::FontIcon{},
|
icon_button::pro::FontIcon{},
|
||||||
link_icon_context,
|
link_icon_context,
|
||||||
},
|
},
|
||||||
ibpro::Clickable{ [sensor_ptr = &sensor, link_icon_context] {
|
ibpro::Clickable{ [sensor_ptr = &sensor, link_icon_context] {
|
||||||
auto& sensor = *sensor_ptr;
|
auto& sensor = *sensor_ptr;
|
||||||
if (!sensor.controller) {
|
if (!sensor.controller) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (sensor.controller->is_connected()) {
|
if (sensor.controller->is_connected()) {
|
||||||
sensor.controller->stop();
|
sensor.controller->stop();
|
||||||
link_icon_context->set(QString::fromLatin1(material::icon::kAddLink));
|
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: "
|
std::cerr << "Failed to start sensor stream: "
|
||||||
<< sensor.controller->last_error().toStdString()
|
<< sensor.controller->last_error().toStdString()
|
||||||
<< "\n";
|
<< "\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();
|
lnpro::Item<FilledButton>{
|
||||||
}
|
fbpro::ThemeManager{ manager },
|
||||||
|
fbpro::FixedSize{ 40, 40 },
|
||||||
sensor.port_items->set(std::move(ports_list));
|
fbpro::Radius{ 8.0 },
|
||||||
RefreshProfilesForView();
|
// 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::Font{ material::kRegularExtraSmallFont },
|
||||||
fbpro::Text{ "drive_file_move" },
|
fbpro::Text{ "drive_file_move" },
|
||||||
fbpro::Clickable{ [&sensor] {
|
fbpro::Clickable{ [&sensor] {
|
||||||
|
|||||||
Reference in New Issue
Block a user