|
@@ -0,0 +1,299 @@
|
|
|
+#include "settingnum.h"
|
|
|
+#include "ui_settingnum.h"
|
|
|
+
|
|
|
+#include <QDebug>
|
|
|
+#include <QFile>
|
|
|
+#include <QPainter>
|
|
|
+#include <QVBoxLayout>
|
|
|
+#include <QHeaderView>
|
|
|
+
|
|
|
+#include "customcombobox.h"
|
|
|
+#include "onesettingitem.h"
|
|
|
+#include "oneshadow.h"
|
|
|
+
|
|
|
+SettingNum::SettingNum(QDialog *parent) :
|
|
|
+ QDialog(parent),
|
|
|
+ ui(new Ui::SettingNum)
|
|
|
+{
|
|
|
+ ui->setupUi(this);
|
|
|
+
|
|
|
+ m_logger = spdlog::get("EyeMap");
|
|
|
+ if(m_logger == nullptr)
|
|
|
+ {
|
|
|
+ qDebug() << "获取 EyeMap logger 失败";
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ /* 注册事件过滤,主要是消除滚轮对comboBox的影响 */
|
|
|
+ ui->comboBox_rowNum->installEventFilter(this);
|
|
|
+ ui->comboBox_columnNum->installEventFilter(this);
|
|
|
+
|
|
|
+ /* 设置无边框和背景透明 */
|
|
|
+ this->setWindowFlags(Qt::FramelessWindowHint);
|
|
|
+ this->setAttribute(Qt::WA_TranslucentBackground);
|
|
|
+ /* 加载QSS */
|
|
|
+ QFile fileQss(":/qss/SettingNum/SettingNum.qss");
|
|
|
+ if(fileQss.open(QFile::ReadOnly))
|
|
|
+ {
|
|
|
+ QString qss = fileQss.readAll();
|
|
|
+ this->setStyleSheet(qss);
|
|
|
+ fileQss.close();
|
|
|
+ } else
|
|
|
+ {
|
|
|
+ SPDLOG_LOGGER_ERROR(m_logger, "加载QSS文件失败");
|
|
|
+ }
|
|
|
+ /* 设置阴影 */
|
|
|
+ m_shadow = new OneShadow(ui->widget->size(), 16);
|
|
|
+ ui->verticalLayout->setMargin(16);
|
|
|
+
|
|
|
+ /* 初始化变量 */
|
|
|
+ for(auto item : m_listItem)
|
|
|
+ {
|
|
|
+ item = nullptr;
|
|
|
+ }
|
|
|
+
|
|
|
+ // ui->pBtn_close->move(ui->widget_top->width() - 40, 13);
|
|
|
+
|
|
|
+ /* 设置下拉框可选个数 */
|
|
|
+ QStringList listRow;
|
|
|
+ listRow << "1" << "2" << "3" << "4";
|
|
|
+ ui->comboBox_rowNum->addItems(listRow);
|
|
|
+ ui->comboBox_columnNum->addItem("1");
|
|
|
+ ui->comboBox_columnNum->addItem("2");
|
|
|
+ ui->comboBox_rowNum->setCurrentIndex(1);
|
|
|
+ ui->comboBox_columnNum->setCurrentIndex(1);
|
|
|
+
|
|
|
+ /* 初始化表格列表 */
|
|
|
+ initTableList();
|
|
|
+
|
|
|
+
|
|
|
+ connect(ui->pBtn_close, &QPushButton::clicked, this, &SettingNum::do_pBtn_close);
|
|
|
+ connect(ui->pBtn_ok, &QPushButton::clicked, this, &SettingNum::do_pBtn_ok);
|
|
|
+ connect(ui->pBtn_cancel, &QPushButton::clicked, this, &SettingNum::do_pBtn_cancel);
|
|
|
+
|
|
|
+ connect(ui->comboBox_rowNum, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &SettingNum::do_selectRowAndColumn);
|
|
|
+ connect(ui->comboBox_columnNum, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &SettingNum::do_selectRowAndColumn);
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+SettingNum::~SettingNum()
|
|
|
+{
|
|
|
+ for(auto item : m_listItem)
|
|
|
+ {
|
|
|
+ if(item == nullptr)
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ delete item;
|
|
|
+ item = nullptr;
|
|
|
+ }
|
|
|
+ if(m_shadow != nullptr)
|
|
|
+ {
|
|
|
+ delete m_shadow;
|
|
|
+ m_shadow = nullptr;
|
|
|
+ }
|
|
|
+ delete ui;
|
|
|
+}
|
|
|
+
|
|
|
+/* 设置行数和列数 */
|
|
|
+void SettingNum::setRowAndColumn(int row, int column)
|
|
|
+{
|
|
|
+ ui->comboBox_rowNum->setCurrentIndex(row - 1);
|
|
|
+ ui->comboBox_columnNum->setCurrentIndex(column - 1);
|
|
|
+ /* 根据 行 x 列 总数计算需要显示的个数 */
|
|
|
+ int num = row * column;
|
|
|
+ // for(int i = 0; i < 8; i++)
|
|
|
+ // {
|
|
|
+ // OneSettingItem *item = new OneSettingItem(ui->widget_list);
|
|
|
+ // item->setNum(i + 1);
|
|
|
+ // connect(item, &OneSettingItem::signal_select_channel, this, &SettingNum::do_selectChannel);
|
|
|
+ // m_listItem.append(item);
|
|
|
+ // }
|
|
|
+ /* 移动item的位置 */
|
|
|
+ // layoutItem(num);
|
|
|
+}
|
|
|
+
|
|
|
+/* 设置每个项的信息 */
|
|
|
+void SettingNum::setEveryEyeMapInfo(const QList<OneEyeMapInfo> &listInfo)
|
|
|
+{
|
|
|
+ // for(auto &item : m_listItem)
|
|
|
+ // {
|
|
|
+ // for(auto &info : listInfo)
|
|
|
+ // {
|
|
|
+ // if(item->getNum() == info.num)
|
|
|
+ // {
|
|
|
+ // item->setItemInfo(info);
|
|
|
+ // break;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+}
|
|
|
+
|
|
|
+/* 设置可用的通道信息 */
|
|
|
+void SettingNum::setChannelList(const QList<OneChannelInfo> &listChannelInfo)
|
|
|
+{
|
|
|
+ // for(auto &item : m_listItem)
|
|
|
+ // {
|
|
|
+ // item->setChannelList(listChannelInfo);
|
|
|
+ // }
|
|
|
+}
|
|
|
+
|
|
|
+/* 绘制阴影 */
|
|
|
+// void SettingNum::paintEvent(QPaintEvent *event)
|
|
|
+// {
|
|
|
+// // QPainter painter(this);
|
|
|
+// // painter.setRenderHint(QPainter::Antialiasing);
|
|
|
+// // painter.drawImage(QPoint(0,0),m_shadow->image());
|
|
|
+// }
|
|
|
+
|
|
|
+/* 事件过滤器 */
|
|
|
+bool SettingNum::eventFilter(QObject *watched, QEvent *event)
|
|
|
+{
|
|
|
+ if(watched == ui->comboBox_rowNum || watched == ui->comboBox_columnNum)
|
|
|
+ {
|
|
|
+ if(event->type() == QEvent::Wheel)
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return QWidget::eventFilter(watched, event);
|
|
|
+}
|
|
|
+
|
|
|
+/* 关闭按钮槽函数 */
|
|
|
+void SettingNum::do_pBtn_close()
|
|
|
+{
|
|
|
+ this->close();
|
|
|
+}
|
|
|
+
|
|
|
+/* 点击了OK按钮 */
|
|
|
+void SettingNum::do_pBtn_ok()
|
|
|
+{
|
|
|
+ isOk = true;
|
|
|
+ row = ui->comboBox_rowNum->currentText().toInt();
|
|
|
+ column = ui->comboBox_columnNum->currentText().toInt();
|
|
|
+
|
|
|
+ /* 更新全局信息 */
|
|
|
+ for(auto &item : m_listItem)
|
|
|
+ {
|
|
|
+ GEyeMapInfo.updateSettingNum(item->getEyeMapInfo());
|
|
|
+ }
|
|
|
+
|
|
|
+ this->close();
|
|
|
+}
|
|
|
+
|
|
|
+/* 点击了取消按钮 */
|
|
|
+void SettingNum::do_pBtn_cancel()
|
|
|
+{
|
|
|
+ isOk = false;
|
|
|
+ this->close();
|
|
|
+}
|
|
|
+
|
|
|
+/* 选择行和列槽函数 */
|
|
|
+void SettingNum::do_selectRowAndColumn(int index)
|
|
|
+{
|
|
|
+ row = ui->comboBox_rowNum->currentText().toInt();
|
|
|
+ column = ui->comboBox_columnNum->currentText().toInt();
|
|
|
+ int num = row * column;
|
|
|
+ layoutItem(num);
|
|
|
+}
|
|
|
+
|
|
|
+/* 通道选择槽函数,选择了一个通道,取消其他项可能已经选择的相同通道 */
|
|
|
+void SettingNum::do_selectChannel(const OscChnNum channel, const QString &channelName)
|
|
|
+{
|
|
|
+ auto sender = qobject_cast<OneSettingItem*>(QObject::sender());
|
|
|
+ for(auto item : m_listItem)
|
|
|
+ {
|
|
|
+ if((item->getCurrentChannel().channel == channel) && (item != sender))
|
|
|
+ {
|
|
|
+ item->setCurrentChannel(GEyeMapInfo.getChannelName(OscChnNum::Osc_None));
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief 布局item
|
|
|
+ *
|
|
|
+ * @param num 需要显示的几个item
|
|
|
+ */
|
|
|
+void SettingNum::layoutItem(int num)
|
|
|
+{
|
|
|
+ for(auto item : m_listItem)
|
|
|
+ {
|
|
|
+ auto dy = (item->getNum() - 1) * 48;
|
|
|
+ item->move(0, dy);
|
|
|
+ if(item->getNum() > num)
|
|
|
+ {
|
|
|
+ item->hide();
|
|
|
+ } else
|
|
|
+ {
|
|
|
+ item->show();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+/* 初始化表格列表 */
|
|
|
+void SettingNum::initTableList()
|
|
|
+{
|
|
|
+ /* 设置一个布局 */
|
|
|
+ QVBoxLayout *layout = new QVBoxLayout(ui->widget_list);
|
|
|
+ layout->setMargin(0);
|
|
|
+ layout->setSpacing(0);
|
|
|
+ ui->widget_list->setLayout(layout);
|
|
|
+
|
|
|
+ /* 设置模型和视图 */
|
|
|
+ m_tableView = new QTableView(ui->widget_list);
|
|
|
+ m_model = new QStandardItemModel(this);
|
|
|
+ m_tableView->setModel(m_model);
|
|
|
+ layout->addWidget(m_tableView);
|
|
|
+
|
|
|
+ /****** 设置表格属性 ******/
|
|
|
+ /* 设置列数和标题 */
|
|
|
+ m_model->setColumnCount(4);
|
|
|
+ m_model->setHeaderData(0, Qt::Horizontal, "序号");
|
|
|
+ m_model->setHeaderData(1, Qt::Horizontal, "通道");
|
|
|
+ m_model->setHeaderData(2, Qt::Horizontal, "通道展示名称");
|
|
|
+ m_model->setHeaderData(3, Qt::Horizontal, "底色");
|
|
|
+
|
|
|
+ /* 设置标题栏属性 */
|
|
|
+ m_tableView->horizontalHeader()->setFixedHeight(48);
|
|
|
+ /* 禁止点击标题选择一列 */
|
|
|
+ m_tableView->horizontalHeader()->setSectionsClickable(false);
|
|
|
+ /* 设置标题栏文字间距等都在样式表中设置 */
|
|
|
+ m_tableView->horizontalHeader()->setDefaultAlignment(Qt::AlignVCenter | Qt::AlignLeft);
|
|
|
+
|
|
|
+ /* 设置列宽,各减少1个像素点给分割线 */
|
|
|
+ m_tableView->setColumnWidth(0, 67);
|
|
|
+ m_tableView->setColumnWidth(1, 296);
|
|
|
+ m_tableView->setColumnWidth(2, 296);
|
|
|
+ m_tableView->setColumnWidth(3, 64);
|
|
|
+
|
|
|
+ /* 设置行高 */
|
|
|
+ m_tableView->verticalHeader()->setDefaultSectionSize(48);
|
|
|
+ /* 去掉列序号 */
|
|
|
+ m_tableView->verticalHeader()->hide();
|
|
|
+ /* 设置第一列内容文字左间距为12px */
|
|
|
+ // m_tableView->setStyleSheet("QTableView::item{padding-left: 12px;}");
|
|
|
+
|
|
|
+ /* 添加8列,展示效果用的 */
|
|
|
+ for(int i = 0; i < 8; i++)
|
|
|
+ {
|
|
|
+ m_model->setRowCount(i + 1);
|
|
|
+ m_model->setData(m_model->index(i, 0), i + 1);
|
|
|
+ m_model->setData(m_model->index(i, 1), "通道" + QString::number(i + 1));
|
|
|
+ m_model->setData(m_model->index(i, 2), "通道" + QString::number(i + 1));
|
|
|
+ m_model->setData(m_model->index(i, 3), QColor(255, 255, 255));
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 设置QCombobox */
|
|
|
+ m_tableView->setIndexWidget(m_model->index(0, 1), new CustomComboBox(m_tableView));
|
|
|
+ m_tableView->setIndexWidget(m_model->index(1, 1), new CustomComboBox(m_tableView));
|
|
|
+ m_tableView->setIndexWidget(m_model->index(2, 1), new CustomComboBox(m_tableView));
|
|
|
+ m_tableView->setIndexWidget(m_model->index(3, 1), new CustomComboBox(m_tableView));
|
|
|
+ // m_tableView->setItemDelegateForColumn(1, new CustomComboBoxDelegate(m_tableView));
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|