#include "ProjectionModel.h" #include "Channel.h" #include "gui/QChannelWidget.h" #include "gui/QProjectorWindow.h" #include "gui/QChannelManagerWidget.h" using namespace projection; QChannelManagerWidget::QChannelManagerWidget(QWidget* pParent, Qt::WFlags flags) : QWidget(pParent, flags) { ui.setupUi(this); connect(ui.channelTable->horizontalHeader(), SIGNAL(sectionClicked(int)), this, SLOT(channelTableHeaderClicked(int))); } QChannelManagerWidget::~QChannelManagerWidget() { } void QChannelManagerWidget::setModel(ProjectionModel* pModel) { m_pModel = pModel; updateGUI(); } void QChannelManagerWidget::selectChannel(int index) { if (index < ui.channelTable->rowCount()) { ui.channelTable->selectRow(index); } } int QChannelManagerWidget::getSelectedChannel() const { return ui.channelTable->currentRow(); } void QChannelManagerWidget::updateChannelNamesGUI() { for (unsigned int i=0; igetNumChannels(); ++i) ui.channelTable->item(i, 0)->setText(m_pModel->getChannel(i)->getName()); } void QChannelManagerWidget::addChannelToTable(int row, Channel* pChannel) { ui.channelTable->setItem(row, 0, new QTableWidgetItem(pChannel->getName())); QCheckBox* pCheckBox; pCheckBox = new QCheckBox(ui.channelTable); pCheckBox->setTristate(true); if (pChannel->getProjector()->getShow()) pCheckBox->setChecked(true); if (pChannel->getProjector()->getShowArea()) pCheckBox->setCheckState(Qt::PartiallyChecked); connect(pCheckBox, SIGNAL(stateChanged(int)), this, SLOT(channelStateChanged())); if (pChannel->getProjector()->getShow()) pCheckBox->setChecked(true); ui.channelTable->setCellWidget(row, 1, pCheckBox); pCheckBox = new QCheckBox(ui.channelTable); pCheckBox->setTristate(true); if (pChannel->getView()->getShow()) pCheckBox->setChecked(true); if (pChannel->getView()->getShowArea()) pCheckBox->setCheckState(Qt::PartiallyChecked); connect(pCheckBox, SIGNAL(stateChanged(int)), this, SLOT(channelStateChanged())); if (pChannel->getView()->getShow()) pCheckBox->setChecked(true); ui.channelTable->setCellWidget(row, 2, pCheckBox); pCheckBox = new QCheckBox(ui.channelTable); if (pChannel->getShowProjectedScene()) pCheckBox->setChecked(true); connect(pCheckBox, SIGNAL(stateChanged(int)), this, SLOT(channelStateChanged())); ui.channelTable->setCellWidget(row, 3, pCheckBox); } void QChannelManagerWidget::updateGUI() { if (m_pModel) { unsigned int currentRow = ui.channelTable->currentRow(); ui.channelTable->clear(); ui.channelTable->setColumnCount(4); QStringList labels; labels << " Name " << "P" << "V" << "S"; // Name's Streach flag is ignored in Qt 4.1 ui.channelTable->setHorizontalHeaderLabels(labels); ui.channelTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch); ui.channelTable->setShowGrid(false); for (int j=1; j<4; ++j) { ui.channelTable->horizontalHeader()->setResizeMode(j, QHeaderView::Custom); } ui.channelTable->resizeColumnsToContents(); ui.channelTable->setRowCount(m_pModel->getNumChannels()); for (unsigned int i=0; igetNumChannels(); ++i) addChannelToTable(i, m_pModel->getChannel(i)); ui.channelTable->resizeRowsToContents(); ui.channelTable->setCurrentCell(currentRow, 0); } } void QChannelManagerWidget::on_addButton_clicked() { Channel* pChannel = m_pModel->addChannel(); ui.channelTable->insertRow(ui.channelTable->rowCount()); addChannelToTable(ui.channelTable->rowCount()-1, pChannel); ui.channelTable->resizeRowsToContents(); ui.channelTable->setCurrentCell(ui.channelTable->rowCount()-1, 0); } void QChannelManagerWidget::on_removeButton_clicked() { unsigned int currentRow = ui.channelTable->currentRow(); ui.channelTable->removeRow(currentRow); m_pModel->removeChannel(currentRow); } void QChannelManagerWidget::on_channelTable_currentCellChanged(int currentRow, int , int , int ) { m_pModel->selectChannel(m_pModel->getChannel(currentRow)); } void QChannelManagerWidget::on_channelTable_itemChanged(QTableWidgetItem* pItem) { if (ui.channelTable->column(pItem) == 0) { Channel* pChannel = m_pModel->getChannel(ui.channelTable->row(pItem)); if (pChannel->getName() != pItem->text()) pChannel->setName(pItem->text()); } } void QChannelManagerWidget::channelTableHeaderClicked(int index) { if (ui.channelTable->rowCount() == 0 || index == 0 || index > 3) return; int currentRow = ui.channelTable->currentRow(); if (currentRow < 0) currentRow = 0; Qt::CheckState checkState=Qt::Unchecked; if (index == 1 || index == 2) { switch (((QCheckBox*)ui.channelTable->cellWidget(currentRow, index))->checkState()) { case Qt::Unchecked: checkState = Qt::PartiallyChecked; break; case Qt::PartiallyChecked: checkState = Qt::Checked; break; case Qt::Checked: checkState = Qt::Unchecked; break; } } else if (index == 3) { switch (((QCheckBox*)ui.channelTable->cellWidget(currentRow, 3))->checkState()) { case Qt::Unchecked: checkState = Qt::Checked; break; case Qt::Checked: checkState = Qt::Unchecked; break; case Qt::PartiallyChecked: checkState = Qt::Unchecked; break; } } m_pModel->setBlockUpdate(true); for (int i=0; irowCount(); ++i) ((QCheckBox*)ui.channelTable->cellWidget(i, index))->setCheckState(checkState); m_pModel->setBlockUpdate(false); m_pModel->updateViews(); } void QChannelManagerWidget::channelStateChanged() { int currentRow = -1; for (int i=0; irowCount(); ++i) for (int j=1; j<4; ++j) if (ui.channelTable->cellWidget(i, j) == sender()) { currentRow = i; break; } if (currentRow < 0) return; Channel* pChannel = m_pModel->getChannel(currentRow); pChannel->getProjector()->setShow(((QCheckBox*)ui.channelTable->cellWidget(currentRow, 1))->checkState()==Qt::Checked); pChannel->getProjector()->setShowArea(((QCheckBox*)ui.channelTable->cellWidget(currentRow, 1))->checkState()!=Qt::Unchecked); pChannel->getView()->setShow(((QCheckBox*)ui.channelTable->cellWidget(currentRow, 2))->checkState()==Qt::Checked); pChannel->getView()->setShowArea(((QCheckBox*)ui.channelTable->cellWidget(currentRow, 2))->checkState()!=Qt::Unchecked); pChannel->setShowProjectedScene(((QCheckBox*)ui.channelTable->cellWidget(currentRow, 3))->checkState()!=Qt::Unchecked); }