|
@@ -8,6 +8,7 @@
|
|
#include "customcombobox.h"
|
|
#include "customcombobox.h"
|
|
#include "onesettingitem.h"
|
|
#include "onesettingitem.h"
|
|
#include "oneshadow.h"
|
|
#include "oneshadow.h"
|
|
|
|
+#include "ListItem.h"
|
|
|
|
|
|
SettingNum::SettingNum(QDialog *parent) :
|
|
SettingNum::SettingNum(QDialog *parent) :
|
|
QDialog(parent),
|
|
QDialog(parent),
|
|
@@ -43,6 +44,15 @@ SettingNum::SettingNum(QDialog *parent) :
|
|
m_shadow = new OneShadow(ui->widget->size(), 16);
|
|
m_shadow = new OneShadow(ui->widget->size(), 16);
|
|
ui->verticalLayout->setMargin(16);
|
|
ui->verticalLayout->setMargin(16);
|
|
|
|
|
|
|
|
+ /* 设置QListWidget拖拽 */
|
|
|
|
+ ui->listWidget->setDragDropMode(QAbstractItemView::InternalMove);
|
|
|
|
+ ui->listWidget->setDragEnabled(true);
|
|
|
|
+ ui->listWidget->setDropIndicatorShown(true);
|
|
|
|
+ ui->listWidget->setAcceptDrops(true);
|
|
|
|
+ ui->listWidget->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
+ /* 注册事件过滤器,拦截拖拽事件 */
|
|
|
|
+ // ui->listWidget->installEventFilter(this);
|
|
|
|
+
|
|
/* 初始化变量 */
|
|
/* 初始化变量 */
|
|
for(auto item : m_listItem)
|
|
for(auto item : m_listItem)
|
|
{
|
|
{
|
|
@@ -68,6 +78,8 @@ SettingNum::SettingNum(QDialog *parent) :
|
|
connect(ui->comboBox_rowNum, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &SettingNum::do_selectRowAndColumn);
|
|
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);
|
|
connect(ui->comboBox_columnNum, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &SettingNum::do_selectRowAndColumn);
|
|
|
|
|
|
|
|
+ connect(this, &SettingNum::signal_exec, this, &SettingNum::do_layoutItem);
|
|
|
|
+ connect(ui->listWidget, &ListItem::signal_dropComplete, this, &SettingNum::do_setItemNum);
|
|
}
|
|
}
|
|
|
|
|
|
SettingNum::~SettingNum()
|
|
SettingNum::~SettingNum()
|
|
@@ -95,16 +107,27 @@ void SettingNum::setRowAndColumn(int row, int column)
|
|
ui->comboBox_rowNum->setCurrentIndex(row - 1);
|
|
ui->comboBox_rowNum->setCurrentIndex(row - 1);
|
|
ui->comboBox_columnNum->setCurrentIndex(column - 1);
|
|
ui->comboBox_columnNum->setCurrentIndex(column - 1);
|
|
/* 根据 行 x 列 总数计算需要显示的个数 */
|
|
/* 根据 行 x 列 总数计算需要显示的个数 */
|
|
|
|
+ m_row = row;
|
|
|
|
+ m_column = column;
|
|
int num = row * column;
|
|
int num = row * column;
|
|
- for(int i = 0; i < 8; i++)
|
|
|
|
|
|
+ ui->listWidget->clear();
|
|
|
|
+ m_listItem.clear();
|
|
|
|
+
|
|
|
|
+ for(int i = 0; i < num; i++)
|
|
{
|
|
{
|
|
- OneSettingItem *item = new OneSettingItem(ui->widget_list);
|
|
|
|
|
|
+ OneSettingItem *item = new OneSettingItem(ui->listWidget);
|
|
item->setNum(i + 1);
|
|
item->setNum(i + 1);
|
|
connect(item, &OneSettingItem::signal_select_channel, this, &SettingNum::do_selectChannel);
|
|
connect(item, &OneSettingItem::signal_select_channel, this, &SettingNum::do_selectChannel);
|
|
m_listItem.append(item);
|
|
m_listItem.append(item);
|
|
|
|
+ /* 创建QListWidget的项和项高度 */
|
|
|
|
+ QListWidgetItem *listWidgetItem = new QListWidgetItem(ui->listWidget);
|
|
|
|
+ listWidgetItem->setSizeHint(QSize(0, 48));
|
|
|
|
+ ui->listWidget->setItemWidget(listWidgetItem, item);
|
|
}
|
|
}
|
|
|
|
+
|
|
/* 移动item的位置 */
|
|
/* 移动item的位置 */
|
|
- layoutItem(num);
|
|
|
|
|
|
+ // layoutItem(num);
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
/* 设置每个项的信息 */
|
|
/* 设置每个项的信息 */
|
|
@@ -130,16 +153,16 @@ void SettingNum::setChannelList(const QList<OneChannelInfo> &listChannelInfo)
|
|
{
|
|
{
|
|
item->setChannelList(listChannelInfo);
|
|
item->setChannelList(listChannelInfo);
|
|
}
|
|
}
|
|
|
|
+ m_listChannelInfo = listChannelInfo;
|
|
}
|
|
}
|
|
|
|
|
|
-/* 绘制阴影 */
|
|
|
|
-void SettingNum::paintEvent(QPaintEvent *event)
|
|
|
|
|
|
+/* 刷新布局 */
|
|
|
|
+void SettingNum::refreshLayout()
|
|
{
|
|
{
|
|
- // QPainter painter(this);
|
|
|
|
- // painter.setRenderHint(QPainter::Antialiasing);
|
|
|
|
- // painter.drawImage(QPoint(0,0),m_shadow->image());
|
|
|
|
|
|
+ layoutItem(m_row * m_column);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
/* 事件过滤器 */
|
|
/* 事件过滤器 */
|
|
bool SettingNum::eventFilter(QObject *watched, QEvent *event)
|
|
bool SettingNum::eventFilter(QObject *watched, QEvent *event)
|
|
{
|
|
{
|
|
@@ -150,9 +173,46 @@ bool SettingNum::eventFilter(QObject *watched, QEvent *event)
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ // if(watched == ui->listWidget)
|
|
|
|
+ // {
|
|
|
|
+ // SPDLOG_LOGGER_DEBUG(m_logger, "ui->listWidget事件");
|
|
|
|
+ // if(event->type() == QEvent::DragEnter)
|
|
|
|
+ // {
|
|
|
|
+ // QDragEnterEvent *dragEnterEvent = static_cast<QDragEnterEvent*>(event);
|
|
|
|
+ // dragEnterEvent->acceptProposedAction();
|
|
|
|
+ // emit signal_dragComplete();
|
|
|
|
+ // SPDLOG_LOGGER_DEBUG(m_logger, "拖拽进入");
|
|
|
|
+ // return true;
|
|
|
|
+ // }
|
|
|
|
+ // else if(event->type() == QEvent::Drop)
|
|
|
|
+ // {
|
|
|
|
+ // QDropEvent *dropEvent = static_cast<QDropEvent*>(event);
|
|
|
|
+ // dropEvent->acceptProposedAction();
|
|
|
|
+ // SPDLOG_LOGGER_DEBUG(m_logger, "拖拽完成");
|
|
|
|
+ // return true;
|
|
|
|
+ // }
|
|
|
|
+ // else if (event->type() == QEvent::DragMove)
|
|
|
|
+ // {
|
|
|
|
+ // QDragMoveEvent *dragMoveEvent = static_cast<QDragMoveEvent*>(event);
|
|
|
|
+ // dragMoveEvent->accept();
|
|
|
|
+ // SPDLOG_LOGGER_DEBUG(m_logger, "拖拽移动");
|
|
|
|
+ // return true;
|
|
|
|
+
|
|
|
|
+ // }else {
|
|
|
|
+ // qDebug() << "其他事件:" << event->type();
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
return QWidget::eventFilter(watched, event);
|
|
return QWidget::eventFilter(watched, event);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/* 显示事件 */
|
|
|
|
+void SettingNum::showEvent(QShowEvent *event)
|
|
|
|
+{
|
|
|
|
+ QDialog::showEvent(event);
|
|
|
|
+ /* 在这个页面显示出来后再设置一次项隐藏才可以 */
|
|
|
|
+ emit signal_exec();
|
|
|
|
+}
|
|
|
|
+
|
|
/* 关闭按钮槽函数 */
|
|
/* 关闭按钮槽函数 */
|
|
void SettingNum::do_pBtn_close()
|
|
void SettingNum::do_pBtn_close()
|
|
{
|
|
{
|
|
@@ -163,8 +223,8 @@ void SettingNum::do_pBtn_close()
|
|
void SettingNum::do_pBtn_ok()
|
|
void SettingNum::do_pBtn_ok()
|
|
{
|
|
{
|
|
isOk = true;
|
|
isOk = true;
|
|
- row = ui->comboBox_rowNum->currentText().toInt();
|
|
|
|
- column = ui->comboBox_columnNum->currentText().toInt();
|
|
|
|
|
|
+ m_row = ui->comboBox_rowNum->currentText().toInt();
|
|
|
|
+ m_column = ui->comboBox_columnNum->currentText().toInt();
|
|
|
|
|
|
/* 更新全局信息 */
|
|
/* 更新全局信息 */
|
|
for(auto &item : m_listItem)
|
|
for(auto &item : m_listItem)
|
|
@@ -185,10 +245,11 @@ void SettingNum::do_pBtn_cancel()
|
|
/* 选择行和列槽函数 */
|
|
/* 选择行和列槽函数 */
|
|
void SettingNum::do_selectRowAndColumn(int index)
|
|
void SettingNum::do_selectRowAndColumn(int index)
|
|
{
|
|
{
|
|
- row = ui->comboBox_rowNum->currentText().toInt();
|
|
|
|
- column = ui->comboBox_columnNum->currentText().toInt();
|
|
|
|
- int num = row * column;
|
|
|
|
- layoutItem(num);
|
|
|
|
|
|
+ m_row = ui->comboBox_rowNum->currentText().toInt();
|
|
|
|
+ m_column = ui->comboBox_columnNum->currentText().toInt();
|
|
|
|
+ int num = m_row * m_column;
|
|
|
|
+ // layoutItem(num);
|
|
|
|
+ addOrDelItem(num);
|
|
}
|
|
}
|
|
|
|
|
|
/* 通道选择槽函数,选择了一个通道,取消其他项可能已经选择的相同通道 */
|
|
/* 通道选择槽函数,选择了一个通道,取消其他项可能已经选择的相同通道 */
|
|
@@ -204,6 +265,19 @@ void SettingNum::do_selectChannel(const OscChnNum channel, const QString &channe
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/* 刷新listWidget */
|
|
|
|
+void SettingNum::do_layoutItem()
|
|
|
|
+{
|
|
|
|
+ layoutItem(m_row * m_column);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/* 重新设置序号并刷新显示 */
|
|
|
|
+void SettingNum::do_setItemNum()
|
|
|
|
+{
|
|
|
|
+ // SPDLOG_LOGGER_DEBUG(m_logger, "重新设置序号");
|
|
|
|
+ resetItemNum();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
|
|
/**
|
|
/**
|
|
* @brief 布局item
|
|
* @brief 布局item
|
|
@@ -214,8 +288,8 @@ void SettingNum::layoutItem(int num)
|
|
{
|
|
{
|
|
for(auto item : m_listItem)
|
|
for(auto item : m_listItem)
|
|
{
|
|
{
|
|
- auto dy = (item->getNum() - 1) * 48;
|
|
|
|
- item->move(0, dy);
|
|
|
|
|
|
+ // auto dy = (item->getNum() - 1) * 48;
|
|
|
|
+ // item->move(0, dy);
|
|
if(item->getNum() > num)
|
|
if(item->getNum() > num)
|
|
{
|
|
{
|
|
item->hide();
|
|
item->hide();
|
|
@@ -224,7 +298,46 @@ void SettingNum::layoutItem(int num)
|
|
item->show();
|
|
item->show();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/* 重新设置Item序号 */
|
|
|
|
+void SettingNum::resetItemNum()
|
|
|
|
+{
|
|
|
|
+ for(int i = 0; i < ui->listWidget->count(); i++)
|
|
|
|
+ {
|
|
|
|
+ auto item = qobject_cast<OneSettingItem*>(ui->listWidget->itemWidget(ui->listWidget->item(i)));
|
|
|
|
+ item->setNum(i + 1);
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/* 添加或删除项 */
|
|
|
|
+void SettingNum::addOrDelItem(int num)
|
|
|
|
+{
|
|
|
|
+ if(num > m_listItem.size())
|
|
|
|
+ {
|
|
|
|
+ for(int i = m_listItem.size(); i < num; i++)
|
|
|
|
+ {
|
|
|
|
+ OneSettingItem *item = new OneSettingItem(ui->listWidget);
|
|
|
|
+ item->setNum(i + 1);
|
|
|
|
+ /* 设置可选通道列表 */
|
|
|
|
+ item->setChannelList(m_listChannelInfo);
|
|
|
|
+ /* 设置默认选项 */
|
|
|
|
+ item->setItemInfo(GEyeMapInfo.getInitEyeMapInfo(i + 1));
|
|
|
|
+ connect(item, &OneSettingItem::signal_select_channel, this, &SettingNum::do_selectChannel);
|
|
|
|
+ m_listItem.append(item);
|
|
|
|
+ /* 创建QListWidget的项和项高度 */
|
|
|
|
+ QListWidgetItem *listWidgetItem = new QListWidgetItem(ui->listWidget);
|
|
|
|
+ listWidgetItem->setSizeHint(QSize(0, 48));
|
|
|
|
+ ui->listWidget->setItemWidget(listWidgetItem, item);
|
|
|
|
+ }
|
|
|
|
+ } else
|
|
|
|
+ {
|
|
|
|
+ for(int i = m_listItem.size() - 1; i >= num; i--)
|
|
|
|
+ {
|
|
|
|
+ delete m_listItem.at(i);
|
|
|
|
+ m_listItem.removeAt(i);
|
|
|
|
+ ui->listWidget->takeItem(i);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
|