#include "copytoother.h" #include "ui_copytoother.h" #include #include #include #include #include #include #include #include #include #include "warning/warning.h" #include "LHQLogAPI.h" #include "OneShadowEffect.h" #include "TransmitterSwitchInfo.h" #include "UIStyleManager.h" #include "template.h" CopyToOther::CopyToOther(QWidget *parent) : QDialog(parent), ui(new Ui::CopyToOther) { ui->setupUi(this); /* 设置隐藏边框 */ this->setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint); /* 设置底层样式表 */ this->setAttribute(Qt::WA_TranslucentBackground); /* 创建阴影 */ QSize size = this->size(); size.setWidth(size.width() - 40); size.setHeight(size.height() - 40); auto pShadow = new OneShadowEffect(this); this->setGraphicsEffect(pShadow); /* 给滚动区域添加一个布局 */ m_layout = new QVBoxLayout(ui->scrollAreaWidgetContents); 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); 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); /* 注册事件过滤器 */ ui->pBtn_close->installEventFilter(this); } CopyToOther::~CopyToOther() { delete ui; } /** * @brief 设置频率列表,并去掉当前的频率 * * @param currChn * @param list */ void CopyToOther::setFrequencyList(ChannelInfo& currChn, QMap& list) { for(auto it : list) { if(it.ChannelID == currChn.ChannelID) { continue; /* 跳过当前频率 */ } createRow(it); } } void CopyToOther::do_ok() { /* 获取已选中的模版列表 */ for(auto it : m_listCheckBox) { if(it->isChecked()) { auto chnID = it->property(m_propertyChnID.c_str()).toInt(); ChannelInfo info; info.ChannelID = chnID; info.ChannelName = it->text(); m_listChannel.append(info); } } m_isOk = true; emit signal_templateName(m_templateName); this->close(); } /* 点击了一个checkBox,取消其他同频率的checkBox */ void CopyToOther::do_checkBox_stateChanged(int state) { auto checkBox = qobject_cast(sender()); if(checkBox == nullptr) { return; } /* 先判断是不是全选 */ if(checkBox == ui->checkBox_list) { /* 判断是全选还是取消全选 */ if(state == Qt::Checked) { for(auto it : m_listCheckBox) { it->setChecked(true); } }else { for(auto it : m_listCheckBox) { it->setChecked(false); } } return; } } /* 显示事件 */ void CopyToOther::showEvent(QShowEvent *event) { } /* 设置QSS */ void CopyToOther::setQSSPath(const QString& qssPath) { if(qssPath.isEmpty()) { return; } QString qssFile = qssPath + "/copytoother.qss"; QFile file(qssFile); if(file.open(QFile::ReadOnly)) { QString styleSheet = file.readAll(); this->setStyleSheet(styleSheet); file.close(); }else { LH_WRITE_ERROR(QString("Open %1 failed").arg(qssFile)); } } /* 添加一行 */ void CopyToOther::createRow(const ChannelInfo& info) { QCheckBox* checkBox = new QCheckBox(this); 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; })" ); connect(checkBox, &QCheckBox::stateChanged, this, &CopyToOther::do_checkBox_stateChanged); /* 插入到最后一个弹簧之前 */ m_layout->insertWidget(m_layout->count() - 1, checkBox); /* 添加到列表中 */ m_listCheckBox.append(checkBox); } /* 事件过滤器 */ bool CopyToOther::eventFilter(QObject *watched, QEvent *event) { if(watched == ui->pBtn_close) { if(event->type() == QEvent::Enter) { ui->pBtn_close->setProperty("Hover", true); ui->pBtn_close->style()->unpolish(ui->pBtn_close); ui->pBtn_close->style()->polish(ui->pBtn_close); return true; }else if(event->type() == QEvent::Leave) { ui->pBtn_close->setProperty("Hover", false); ui->pBtn_close->style()->unpolish(ui->pBtn_close); ui->pBtn_close->style()->polish(ui->pBtn_close); return true; } } return QWidget::eventFilter(watched,event); } /* 鼠标点击事件 */ void CopyToOther::mousePressEvent(QMouseEvent *event) { m_lastPos = event->globalPos(); event->accept(); } /* 鼠标移动事件 */ void CopyToOther::mouseMoveEvent(QMouseEvent *event) { // QRect rect = this->geometry(); // rect.setBottom(rect.top()+50); auto point = ui->widget_Top->mapToGlobal(QPoint(0, 0)); QRect rect(point, ui->widget_Top->size()); if(!rect.contains(m_lastPos)) { event->accept(); return; } int dx = event->globalX() - m_lastPos.x(); int dy = event->globalY() - m_lastPos.y(); move(x()+dx, y()+dy); m_lastPos = event->globalPos(); event->accept(); } /* 鼠标释放事件 */ void CopyToOther::mouseReleaseEvent(QMouseEvent *event) { event->accept(); }