source: projectionDesigner/trunk/projdesigner/src/gui/QChannelManagerWidget.cpp @ 305

Last change on this file since 305 was 4, checked in by Torben Dannhauer, 15 years ago
File size: 6.6 KB
Line 
1#include "ProjectionModel.h"
2#include "Channel.h"
3#include "gui/QChannelWidget.h"
4#include "gui/QProjectorWindow.h"
5
6#include "gui/QChannelManagerWidget.h"
7
8using namespace projection;
9
10QChannelManagerWidget::QChannelManagerWidget(QWidget* pParent, Qt::WFlags flags)
11    : QWidget(pParent, flags)
12{
13    ui.setupUi(this);
14    connect(ui.channelTable->horizontalHeader(), SIGNAL(sectionClicked(int)), this, SLOT(channelTableHeaderClicked(int)));
15}
16
17QChannelManagerWidget::~QChannelManagerWidget()
18{
19}
20
21void QChannelManagerWidget::setModel(ProjectionModel* pModel)
22{
23    m_pModel = pModel;
24
25    updateGUI();
26}
27
28void QChannelManagerWidget::selectChannel(int index)
29{
30    if (index < ui.channelTable->rowCount()) {
31        ui.channelTable->selectRow(index);
32    }
33}
34
35int QChannelManagerWidget::getSelectedChannel() const
36{
37    return ui.channelTable->currentRow();
38}
39
40void QChannelManagerWidget::updateChannelNamesGUI()
41{
42    for (unsigned int i=0; i<m_pModel->getNumChannels(); ++i)
43        ui.channelTable->item(i, 0)->setText(m_pModel->getChannel(i)->getName());
44}
45
46void QChannelManagerWidget::addChannelToTable(int row, Channel* pChannel)
47{
48    ui.channelTable->setItem(row, 0, new QTableWidgetItem(pChannel->getName()));
49    QCheckBox* pCheckBox;
50    pCheckBox = new QCheckBox(ui.channelTable); pCheckBox->setTristate(true);
51    if (pChannel->getProjector()->getShow()) pCheckBox->setChecked(true);
52    if (pChannel->getProjector()->getShowArea()) pCheckBox->setCheckState(Qt::PartiallyChecked);
53    connect(pCheckBox, SIGNAL(stateChanged(int)), this, SLOT(channelStateChanged()));
54    if (pChannel->getProjector()->getShow()) pCheckBox->setChecked(true);
55    ui.channelTable->setCellWidget(row, 1, pCheckBox);
56    pCheckBox = new QCheckBox(ui.channelTable); pCheckBox->setTristate(true);
57    if (pChannel->getView()->getShow()) pCheckBox->setChecked(true);
58    if (pChannel->getView()->getShowArea()) pCheckBox->setCheckState(Qt::PartiallyChecked);
59    connect(pCheckBox, SIGNAL(stateChanged(int)), this, SLOT(channelStateChanged()));
60    if (pChannel->getView()->getShow()) pCheckBox->setChecked(true);
61    ui.channelTable->setCellWidget(row, 2, pCheckBox);
62    pCheckBox = new QCheckBox(ui.channelTable);
63    if (pChannel->getShowProjectedScene()) pCheckBox->setChecked(true);
64    connect(pCheckBox, SIGNAL(stateChanged(int)), this, SLOT(channelStateChanged()));
65    ui.channelTable->setCellWidget(row, 3, pCheckBox);
66}
67
68void QChannelManagerWidget::updateGUI()
69{
70    if (m_pModel)
71    {
72        unsigned int currentRow = ui.channelTable->currentRow();
73        ui.channelTable->clear();
74        ui.channelTable->setColumnCount(4);
75        QStringList labels;
76        labels << "        Name        " << "P" << "V" << "S";  // Name's Streach flag is ignored in Qt 4.1
77        ui.channelTable->setHorizontalHeaderLabels(labels);
78        ui.channelTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
79        ui.channelTable->setShowGrid(false);
80        for (int j=1; j<4; ++j) {
81            ui.channelTable->horizontalHeader()->setResizeMode(j, QHeaderView::Custom);
82        }
83        ui.channelTable->resizeColumnsToContents();
84        ui.channelTable->setRowCount(m_pModel->getNumChannels());
85        for (unsigned int i=0; i<m_pModel->getNumChannels(); ++i)
86            addChannelToTable(i, m_pModel->getChannel(i));
87        ui.channelTable->resizeRowsToContents();
88        ui.channelTable->setCurrentCell(currentRow, 0);
89    }
90}
91
92void QChannelManagerWidget::on_addButton_clicked()
93{
94    Channel* pChannel = m_pModel->addChannel();
95    ui.channelTable->insertRow(ui.channelTable->rowCount());
96    addChannelToTable(ui.channelTable->rowCount()-1, pChannel);
97    ui.channelTable->resizeRowsToContents();
98    ui.channelTable->setCurrentCell(ui.channelTable->rowCount()-1, 0);
99}
100
101void QChannelManagerWidget::on_removeButton_clicked()
102{
103    unsigned int currentRow = ui.channelTable->currentRow();
104    ui.channelTable->removeRow(currentRow);
105    m_pModel->removeChannel(currentRow);
106}
107
108void QChannelManagerWidget::on_channelTable_currentCellChanged(int currentRow, int , int , int )
109{
110    m_pModel->selectChannel(m_pModel->getChannel(currentRow));
111}
112
113void QChannelManagerWidget::on_channelTable_itemChanged(QTableWidgetItem* pItem)
114{
115    if (ui.channelTable->column(pItem) == 0)
116    {
117        Channel* pChannel = m_pModel->getChannel(ui.channelTable->row(pItem));
118        if (pChannel->getName() != pItem->text())
119            pChannel->setName(pItem->text());
120    }
121}
122
123void QChannelManagerWidget::channelTableHeaderClicked(int index)
124{
125    if (ui.channelTable->rowCount() == 0 || index == 0 || index > 3)
126        return;
127    int currentRow = ui.channelTable->currentRow();
128    if (currentRow < 0)
129        currentRow = 0;
130    Qt::CheckState checkState=Qt::Unchecked;
131    if (index == 1 || index == 2)
132    {
133        switch (((QCheckBox*)ui.channelTable->cellWidget(currentRow, index))->checkState()) {
134            case Qt::Unchecked: checkState = Qt::PartiallyChecked; break;
135            case Qt::PartiallyChecked: checkState = Qt::Checked; break;
136            case Qt::Checked: checkState = Qt::Unchecked; break;
137        }
138    }
139    else if (index == 3)
140    {
141        switch (((QCheckBox*)ui.channelTable->cellWidget(currentRow, 3))->checkState()) {
142            case Qt::Unchecked: checkState = Qt::Checked; break;
143            case Qt::Checked: checkState = Qt::Unchecked; break;
144            case Qt::PartiallyChecked: checkState = Qt::Unchecked; break;
145        }
146    }
147    m_pModel->setBlockUpdate(true);
148    for (int i=0; i<ui.channelTable->rowCount(); ++i)
149        ((QCheckBox*)ui.channelTable->cellWidget(i, index))->setCheckState(checkState);
150    m_pModel->setBlockUpdate(false);
151    m_pModel->updateViews();
152}
153
154void QChannelManagerWidget::channelStateChanged()
155{
156    int currentRow = -1;
157    for (int i=0; i<ui.channelTable->rowCount(); ++i)
158        for (int j=1; j<4; ++j)
159            if (ui.channelTable->cellWidget(i, j) == sender()) {
160                currentRow = i;
161                break;
162            }
163    if (currentRow < 0) return;
164    Channel* pChannel = m_pModel->getChannel(currentRow);
165    pChannel->getProjector()->setShow(((QCheckBox*)ui.channelTable->cellWidget(currentRow, 1))->checkState()==Qt::Checked);
166    pChannel->getProjector()->setShowArea(((QCheckBox*)ui.channelTable->cellWidget(currentRow, 1))->checkState()!=Qt::Unchecked);
167    pChannel->getView()->setShow(((QCheckBox*)ui.channelTable->cellWidget(currentRow, 2))->checkState()==Qt::Checked);
168    pChannel->getView()->setShowArea(((QCheckBox*)ui.channelTable->cellWidget(currentRow, 2))->checkState()!=Qt::Unchecked);
169    pChannel->setShowProjectedScene(((QCheckBox*)ui.channelTable->cellWidget(currentRow, 3))->checkState()!=Qt::Unchecked);
170}
Note: See TracBrowser for help on using the repository browser.