diff --git a/LedOK/base/loqtreewidget.cpp b/LedOK/base/loqtreewidget.cpp index 3132eb1..3cc4ae8 100644 --- a/LedOK/base/loqtreewidget.cpp +++ b/LedOK/base/loqtreewidget.cpp @@ -9,16 +9,15 @@ public: } QWidget *fdIsSelAll; protected: - void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const override; + void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const override { + QHeaderView::paintSection(painter, rect, logicalIndex); + if(logicalIndex == 0) fdIsSelAll->setGeometry(rect); + } }; -void CheckableHeader::paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const{ - QHeaderView::paintSection(painter, rect, logicalIndex); - if(logicalIndex == 0) fdIsSelAll->setGeometry(rect); -} LoQTreeWidget::LoQTreeWidget(QWidget *parent) : QTreeWidget(parent), m_checkState(CheckNone) { - fdIsSelAll = new QCheckBox(); + fdIsSelAll = new QCheckBox; fdIsSelAll->setStyleSheet("QCheckBox{margin-left: 5px;}"); m_header = new CheckableHeader(Qt::Horizontal, fdIsSelAll); setHeader(m_header); diff --git a/LedOK/devicepanel.cpp b/LedOK/devicepanel.cpp index 84641a6..236fb1e 100644 --- a/LedOK/devicepanel.cpp +++ b/LedOK/devicepanel.cpp @@ -142,6 +142,39 @@ QPushButton:hover {background-color: #08b;} vBox->addLayout(mHBox); + m_headerItem = new QTreeWidgetItem(); + for(int i=1; isetTextAlignment(i, Qt::AlignCenter); + mDeviceTable->setHeaderItem(m_headerItem); + mDeviceTable->header()->setSectionResizeMode(DeviceTable_Check, QHeaderView::Fixed); + mDeviceTable->setColumnWidth(DeviceTable_Check, 36); + mDeviceTable->header()->setSectionResizeMode(DeviceTable_Online, QHeaderView::Fixed); + mDeviceTable->setColumnWidth(DeviceTable_Online, 48); + mDeviceTable->header()->setSectionResizeMode(DeviceTable_ID, QHeaderView::Stretch); + mDeviceTable->header()->setSectionResizeMode(DeviceTable_IP, QHeaderView::Stretch); + mDeviceTable->header()->setSectionResizeMode(DeviceTable_ScreenSize, QHeaderView::Fixed); + mDeviceTable->setColumnWidth(DeviceTable_ScreenSize, 108); + mDeviceTable->header()->setSectionResizeMode(DeviceTable_Remark, QHeaderView::Stretch); + mDeviceTable->header()->setSectionResizeMode(DeviceTable_Brightness, QHeaderView::Fixed); + mDeviceTable->setColumnWidth(DeviceTable_Brightness, 108); + mDeviceTable->header()->setSectionResizeMode(DeviceTable_Power, QHeaderView::Fixed); + mDeviceTable->setColumnWidth(DeviceTable_Power, 84); + mDeviceTable->header()->setSectionResizeMode(DeviceTable_Password, QHeaderView::Fixed); + mDeviceTable->setColumnWidth(DeviceTable_Password, 72); + mDeviceTable->header()->setSectionResizeMode(DeviceTable_Info, QHeaderView::Fixed); + mDeviceTable->setColumnWidth(DeviceTable_Info, 72); + mDeviceTable->header()->setSectionResizeMode(DeviceTable_Screenshot, QHeaderView::Fixed); + mDeviceTable->setColumnWidth(DeviceTable_Screenshot, 72); + + connect(mDeviceTable, &LoQTreeWidget::sigCheckStateChanged, this, [=] { + gSelCards.clear(); + int cnt = mDeviceTable->topLevelItemCount(); + for(int i=0; itopLevelItem(i)->checkState(0) == Qt::Checked) gSelCards.append(static_cast(mDeviceTable->topLevelItem(i))->mCard); + emit sigSelectedDeviceList(); + }); + mDeviceTable->hideColumn(0); + mDeviceTable->fdIsSelAll->hide(); + mDeviceTable->sortItems(DeviceTable_ID, Qt::AscendingOrder); + connect(&mUdpTimer, &QTimer::timeout, this, &DevicePanel::sendGetInfo); connect(&mUdpSocket, &QUdpSocket::readyRead, this, [this] { while(mUdpSocket.hasPendingDatagrams()) { @@ -237,38 +270,6 @@ QPushButton:hover {background-color: #08b;} } }); - m_headerItem = new QTreeWidgetItem(); - for(int i=1; isetTextAlignment(i, Qt::AlignCenter); - mDeviceTable->setHeaderItem(m_headerItem); - mDeviceTable->header()->setSectionResizeMode(DeviceTable_Check, QHeaderView::Fixed); - mDeviceTable->setColumnWidth(DeviceTable_Check, 36); - mDeviceTable->header()->setSectionResizeMode(DeviceTable_Online, QHeaderView::Fixed); - mDeviceTable->setColumnWidth(DeviceTable_Online, 48); - mDeviceTable->header()->setSectionResizeMode(DeviceTable_ID, QHeaderView::Stretch); - mDeviceTable->header()->setSectionResizeMode(DeviceTable_IP, QHeaderView::Stretch); - mDeviceTable->header()->setSectionResizeMode(DeviceTable_ScreenSize, QHeaderView::Fixed); - mDeviceTable->setColumnWidth(DeviceTable_ScreenSize, 108); - mDeviceTable->header()->setSectionResizeMode(DeviceTable_Remark, QHeaderView::Stretch); - mDeviceTable->header()->setSectionResizeMode(DeviceTable_Brightness, QHeaderView::Fixed); - mDeviceTable->setColumnWidth(DeviceTable_Brightness, 108); - mDeviceTable->header()->setSectionResizeMode(DeviceTable_Power, QHeaderView::Fixed); - mDeviceTable->setColumnWidth(DeviceTable_Power, 84); - mDeviceTable->header()->setSectionResizeMode(DeviceTable_Password, QHeaderView::Fixed); - mDeviceTable->setColumnWidth(DeviceTable_Password, 72); - mDeviceTable->header()->setSectionResizeMode(DeviceTable_Info, QHeaderView::Fixed); - mDeviceTable->setColumnWidth(DeviceTable_Info, 72); - mDeviceTable->header()->setSectionResizeMode(DeviceTable_Screenshot, QHeaderView::Fixed); - mDeviceTable->setColumnWidth(DeviceTable_Screenshot, 72); - - connect(mDeviceTable, &LoQTreeWidget::sigCheckStateChanged, this, [=] { - gSelCards.clear(); - int cnt = mDeviceTable->topLevelItemCount(); - for(int i=0; itopLevelItem(i)->checkState(0) == Qt::Checked) gSelCards.append(static_cast(mDeviceTable->topLevelItem(i))->mCard); - emit sigSelectedDeviceList(); - }); - mDeviceTable->hideColumn(0); - mDeviceTable->fdIsSelAll->hide(); - specifyIPDlg = new QDialog(this); specifyIPDlg->setWindowTitle(tr("Specify IP")); diff --git a/LedOK/program/sendprogramdialog.cpp b/LedOK/program/sendprogramdialog.cpp index 1671e01..c98fe83 100644 --- a/LedOK/program/sendprogramdialog.cpp +++ b/LedOK/program/sendprogramdialog.cpp @@ -46,7 +46,7 @@ SendProgramDialog::SendProgramDialog(QString progName, QWidget *parent) : QDialo hBox->addWidget(txtSearch); table = new Table{ - {"id", "ID", 140}, + {"id", "ID", 130}, {"online", tr("Online"), 40}, {"ip", "IP", 100}, {"size", tr("Screen Size"), 80}, @@ -66,7 +66,7 @@ SendProgramDialog::SendProgramDialog(QString progName, QWidget *parent) : QDialo connect(fdCheckAll, &QCheckBox::stateChanged, this, [=](int state) { if(state==Qt::PartiallyChecked) return; int cnt = table->rowCount(); - for(int i=0; iitemValid(i, colId)->setCheckState((Qt::CheckState) state); + for(int rr=0; rrisRowHidden(rr)) table->itemValid(rr, colId)->setCheckState((Qt::CheckState) state); }); connect(table, &Table::updGeos, this, [=] { fdCheckAll->move(table->verticalHeader()->size().width() + 8, 2); @@ -78,7 +78,7 @@ SendProgramDialog::SendProgramDialog(QString progName, QWidget *parent) : QDialo item->setCheckState(state); int cnt = table->rowCount(); fdCheckAll->blockSignals(true); - for(int i=0; iitemValid(i, colId)->checkState()!=state) { + for(int rr=0; rrisRowHidden(rr) && table->itemValid(rr, colId)->checkState()!=state) { fdCheckAll->setCheckState(Qt::PartiallyChecked); goto end; } @@ -86,7 +86,11 @@ SendProgramDialog::SendProgramDialog(QString progName, QWidget *parent) : QDialo end:fdCheckAll->blockSignals(false); }; connect(table, &Table::cellClicked, table, cellClicked); - connect(table, &Table::cellEntered, table, cellClicked); + connect(table, &Table::cellEntered, table, [=](int row, int column) { + if(column!=colId) return; + if((QApplication::mouseButtons() & Qt::LeftButton) == 0) return; + cellClicked(row, column); + }); auto btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); btnBox->button(QDialogButtonBox::Ok)->setText(tr("Publish")); @@ -95,18 +99,18 @@ SendProgramDialog::SendProgramDialog(QString progName, QWidget *parent) : QDialo if(mWaitCnt > 0) return; int cnt = table->rowCount(); int sentCnt{0}; - for(int i=0; iitemValid(i, colId); + for(int rr=0; rrisRowHidden(rr)) { + auto fdId = table->itemValid(rr, colId); if(fdId->checkState()!=Qt::Checked) continue; if(fdId->data(isSending).toBool()) continue; - auto btnUnlock = (QPushButton*) table->cellWidget(i, "encrypt"); - auto fdRemarks = table->itemValid(i, "remarks"); + auto btnUnlock = (QPushButton*) table->cellWidget(rr, "encrypt"); + auto fdRemarks = table->itemValid(rr, "remarks"); if(btnUnlock && btnUnlock->property("isLocked").toBool()) { fdRemarks->setText(tr("This screen is encrypted")); fdRemarks->setForeground(Qt::red); continue; } - auto fdProgress = (QProgressBar*) table->cellWidget(i, "progress"); + auto fdProgress = (QProgressBar*) table->cellWidget(rr, "progress"); fdProgress->setValue(0); if(sentCnt>=5) { fdRemarks->setText(" "+tr("Waiting")+" ..."); @@ -116,7 +120,7 @@ SendProgramDialog::SendProgramDialog(QString progName, QWidget *parent) : QDialo } fdId->setData(isSending, true); fdRemarks->setText(""); - auto sendProg = new SendProgThread(programsDir()+"/"+mProgName+"_tmp", table->text(i, "ip"), 3333); + auto sendProg = new SendProgThread(programsDir()+"/"+mProgName+"_tmp", table->text(rr, "ip"), 3333); connect(sendProg, &SendProgThread::emErr, fdProgress, [=](QString strTip) { fdId->setData(isSending, false); if(strTip=="OK") { @@ -155,7 +159,7 @@ void SendProgramDialog::addRow(LedCard card) { auto item = table->setText(cnt, "id", card.id); item->setCheckState(Qt::Unchecked); - item->setFlags(Qt::ItemIsEnabled); + item->setFlags(item->flags() & ~Qt::ItemIsUserCheckable); auto fdOnline = new QLabel; fdOnline->setAlignment(Qt::AlignCenter); @@ -229,20 +233,20 @@ void SendProgramDialog::closeEvent(QCloseEvent *) { void SendProgramDialog::sendNext() { if(mWaitCnt <= 0) return; int cnt = table->rowCount(); - for(int i=0; iitemValid(i, "id"); + for(int rr=0; rrisRowHidden(rr)) { + auto fdId = table->itemValid(rr, "id"); if(fdId->checkState()!=Qt::Checked) continue; if(fdId->data(isSending).toBool()) continue; - auto btnUnlock = (QPushButton*) table->cellWidget(i, "encrypt"); + auto btnUnlock = (QPushButton*) table->cellWidget(rr, "encrypt"); if(btnUnlock && btnUnlock->property("isLocked").toBool()) continue; - auto fdRemarks = table->itemValid(i, "remarks"); + auto fdRemarks = table->itemValid(rr, "remarks"); if(! fdRemarks->text().startsWith(" ")) continue; fdRemarks->setText(""); - auto fdProgress = (QProgressBar*) table->cellWidget(i, "progress"); + auto fdProgress = (QProgressBar*) table->cellWidget(rr, "progress"); fdProgress->setValue(0); fdId->setData(isSending, true); mWaitCnt--; - auto sendProg = new SendProgThread(programsDir()+"/"+mProgName+"_tmp", table->text(i, "ip"), 3333); + auto sendProg = new SendProgThread(programsDir()+"/"+mProgName+"_tmp", table->text(rr, "ip"), 3333); connect(sendProg, &SendProgThread::emErr, fdProgress, [=](QString strTip) { fdId->setData(isSending, false); if(strTip=="OK") { @@ -264,6 +268,6 @@ void SendProgramDialog::sendNext() { void SendProgramDialog::refresh() { int cnt = gDevicePanel->mDeviceTable->topLevelItemCount(); - for(int i=0; i(gDevicePanel->mDeviceTable->topLevelItem(i))->mCard); + for(int rr=0; rrmDeviceTable->topLevelItem(rr))->mCard); label->setText(tr("All")+": "+QString::number(cnt)); }