123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- #include "copytoother.h"
- #include "ui_copytoother.h"
- #include <QDebug>
- #include <QPoint>
- #include <QTableWidgetItem>
- #include <QFile>
- #include <QPainter>
- #include <QMouseEvent>
- #include <QCheckBox>
- #include <QVBoxLayout>
- #include <qcheckbox.h>
- #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<int, ChannelInfo>& 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();
- OneTemplateInfo info;
- info.channelInfo.ChannelID = chnID;
- info.channelInfo.ChannelName = it->text();
- info.templateName = it->text() + QString::number(chnID);
- }
- }
- m_isOk = true;
- emit signal_templateName(m_templateName);
- this->close();
- }
- /* 点击了一个checkBox,取消其他同频率的checkBox */
- void CopyToOther::do_checkBox_stateChanged(int state)
- {
- auto checkBox = qobject_cast<QCheckBox*>(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);
- 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();
- }
|