|
@@ -9,7 +9,7 @@
|
|
|
#include <QMouseEvent>
|
|
|
#include <QCheckBox>
|
|
|
#include <QVBoxLayout>
|
|
|
-#include <qcheckbox.h>
|
|
|
+#include <tipwidget.h>
|
|
|
|
|
|
#include "warning/warning.h"
|
|
|
#include "LHQLogAPI.h"
|
|
@@ -41,16 +41,19 @@ CopyToOther::CopyToOther(QWidget *parent) :
|
|
|
m_layout->setContentsMargins(0, 0, 0, 0);
|
|
|
m_layout->setSpacing(0);
|
|
|
ui->scrollAreaWidgetContents->setLayout(m_layout);
|
|
|
- /* 添加一个竖直弹簧 */
|
|
|
- auto pSpacerItem = new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding);
|
|
|
- m_layout->addItem(pSpacerItem);
|
|
|
+ /* 使用空白的Widget替代弹簧 */
|
|
|
+ // auto pSpacerItem = new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding);
|
|
|
+ QWidget* spacerWidget = new QWidget(this);
|
|
|
+ spacerWidget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding);
|
|
|
+ spacerWidget->setObjectName("widget_spacer");
|
|
|
+ m_layout->addWidget(spacerWidget);
|
|
|
|
|
|
|
|
|
connect(ui->pBtn_close,SIGNAL(clicked()),this,SLOT(close()));
|
|
|
connect(ui->pBtn_cancel,SIGNAL(clicked()),this,SLOT(close()));
|
|
|
connect(ui->pBtn_ok,SIGNAL(clicked()),this,SLOT(do_ok()));
|
|
|
|
|
|
- connect(ui->checkBox_list, &QCheckBox::stateChanged, this, &CopyToOther::do_checkBox_stateChanged);
|
|
|
+ connect(ui->checkBox_list, &QCheckBox::stateChanged, this, &CopyToOther::do_checkBox_list_stateChanged);
|
|
|
|
|
|
/* 注册事件过滤器 */
|
|
|
ui->pBtn_close->installEventFilter(this);
|
|
@@ -95,6 +98,13 @@ void CopyToOther::do_ok()
|
|
|
m_listChannel.append(info);
|
|
|
}
|
|
|
}
|
|
|
+ /* 判断有没有勾选 */
|
|
|
+ if(m_listChannel.isEmpty())
|
|
|
+ {
|
|
|
+ // LH_WRITE_ERROR("没有选择频率");
|
|
|
+ TipWidget::display(TipWidget::OPERATOR_WARN, "请选择一个频率", this);
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
m_isOk = true;
|
|
@@ -102,7 +112,43 @@ void CopyToOther::do_ok()
|
|
|
this->close();
|
|
|
}
|
|
|
|
|
|
-/* 点击了一个checkBox,取消其他同频率的checkBox */
|
|
|
+/* 点击了全选按钮 */
|
|
|
+void CopyToOther::do_checkBox_list_stateChanged(int state)
|
|
|
+{
|
|
|
+ auto checkBox = qobject_cast<QCheckBox*>(sender());
|
|
|
+ if(checkBox == nullptr)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // LH_WRITE_LOG_DEBUG(QString("全选状态:%1").arg(state));
|
|
|
+ Qt::CheckState checkState = Qt::Unchecked;
|
|
|
+ /* 判断是全选还是取消全选 */
|
|
|
+ if(state == Qt::Checked)
|
|
|
+ {
|
|
|
+ checkState = Qt::Checked;
|
|
|
+
|
|
|
+ }
|
|
|
+ else if(state == Qt::Unchecked)
|
|
|
+ {
|
|
|
+ checkState = Qt::Unchecked;
|
|
|
+ }
|
|
|
+ else if(state == Qt::PartiallyChecked)
|
|
|
+ {
|
|
|
+ /* 部分选中,设置为全选 */
|
|
|
+ ui->checkBox_list->blockSignals(true);
|
|
|
+ ui->checkBox_list->setCheckState(Qt::Checked);
|
|
|
+ ui->checkBox_list->blockSignals(false);
|
|
|
+ checkState = Qt::Checked;
|
|
|
+ }
|
|
|
+ for(auto it : m_listCheckBox)
|
|
|
+ {
|
|
|
+ it->blockSignals(true);
|
|
|
+ it->setCheckState(checkState);
|
|
|
+ it->blockSignals(false);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/* 点击了一个checkBox */
|
|
|
void CopyToOther::do_checkBox_stateChanged(int state)
|
|
|
{
|
|
|
auto checkBox = qobject_cast<QCheckBox*>(sender());
|
|
@@ -110,25 +156,34 @@ void CopyToOther::do_checkBox_stateChanged(int state)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
- /* 先判断是不是全选 */
|
|
|
- if(checkBox == ui->checkBox_list)
|
|
|
+ // LH_WRITE_LOG_DEBUG(QString("单个checkBox状态:%1").arg(state));
|
|
|
+ /* 不是点击了全选,改变全选的状态 */
|
|
|
+ bool isAllChecked = true;
|
|
|
+ bool isAllUnchecked = true;
|
|
|
+ for(auto it : m_listCheckBox)
|
|
|
{
|
|
|
- /* 判断是全选还是取消全选 */
|
|
|
- if(state == Qt::Checked)
|
|
|
+ if(it->checkState() == Qt::Checked)
|
|
|
{
|
|
|
- for(auto it : m_listCheckBox)
|
|
|
- {
|
|
|
- it->setChecked(true);
|
|
|
- }
|
|
|
- }else {
|
|
|
- for(auto it : m_listCheckBox)
|
|
|
- {
|
|
|
- it->setChecked(false);
|
|
|
- }
|
|
|
+ isAllUnchecked = false;
|
|
|
+ }
|
|
|
+ else if(it->checkState() == Qt::Unchecked)
|
|
|
+ {
|
|
|
+ isAllChecked = false;
|
|
|
}
|
|
|
- return;
|
|
|
}
|
|
|
-
|
|
|
+ Qt::CheckState checkState = Qt::Unchecked;
|
|
|
+ if(isAllChecked)
|
|
|
+ {
|
|
|
+ checkState = Qt::Checked;
|
|
|
+ }else if(isAllUnchecked)
|
|
|
+ {
|
|
|
+ checkState = Qt::Unchecked;
|
|
|
+ }else {
|
|
|
+ checkState = Qt::PartiallyChecked;
|
|
|
+ }
|
|
|
+ ui->checkBox_list->blockSignals(true);
|
|
|
+ ui->checkBox_list->setCheckState(checkState);
|
|
|
+ ui->checkBox_list->blockSignals(false);
|
|
|
}
|
|
|
|
|
|
/* 显示事件 */
|
|
@@ -149,8 +204,8 @@ void CopyToOther::setQSSPath(const QString& qssPath)
|
|
|
QFile file(qssFile);
|
|
|
if(file.open(QFile::ReadOnly))
|
|
|
{
|
|
|
- QString styleSheet = file.readAll();
|
|
|
- this->setStyleSheet(styleSheet);
|
|
|
+ m_qss = file.readAll();
|
|
|
+ this->setStyleSheet(m_qss);
|
|
|
file.close();
|
|
|
}else
|
|
|
{
|
|
@@ -168,22 +223,10 @@ void CopyToOther::createRow(const ChannelInfo& info)
|
|
|
checkBox->setText(info.ChannelName);
|
|
|
checkBox->setProperty(m_propertyChnID.c_str(), info.ChannelID);
|
|
|
checkBox->setMinimumHeight(34);
|
|
|
- checkBox->setStyleSheet(R"(
|
|
|
- QCheckBox
|
|
|
- {
|
|
|
- background: #464649;
|
|
|
-
|
|
|
- font-weight: 400;
|
|
|
- font-size: 14px;
|
|
|
- color: #B1B3B4;
|
|
|
- text-align: left;
|
|
|
- font-style: normal;
|
|
|
- text-transform: none;
|
|
|
-
|
|
|
- padding-left: 16px;
|
|
|
- })"
|
|
|
- );
|
|
|
+ /* 设置只有两种状态 */
|
|
|
+ checkBox->setTristate(false);
|
|
|
connect(checkBox, &QCheckBox::stateChanged, this, &CopyToOther::do_checkBox_stateChanged);
|
|
|
+ checkBox->setStyleSheet(m_qss);
|
|
|
/* 插入到最后一个弹簧之前 */
|
|
|
m_layout->insertWidget(m_layout->count() - 1, checkBox);
|
|
|
/* 添加到列表中 */
|