[4] | 1 | #include "ProjectionModel.h" |
---|
| 2 | #include "Channel.h" |
---|
| 3 | #include "Warp.h" |
---|
| 4 | #include "gui/QChannelWidget.h" |
---|
| 5 | #include "gui/QDesignViewWindow.h" |
---|
| 6 | |
---|
| 7 | using namespace projection; |
---|
| 8 | |
---|
| 9 | QChannelWidget::QChannelWidget(QWidget* pParent, Qt::WFlags flags) |
---|
| 10 | : QWidget(pParent, flags), m_pChannel(NULL) |
---|
| 11 | { |
---|
| 12 | ui.setupUi(this); |
---|
| 13 | |
---|
| 14 | ui.pluginComboBox->clear(); |
---|
| 15 | |
---|
| 16 | foreach (ProjectorInterface *projector_interface, ProjectionModel::projector_interfaces) |
---|
| 17 | { |
---|
| 18 | foreach (QString projector_name, projector_interface->projectors()) |
---|
| 19 | { |
---|
| 20 | ProjectorWidget* projector_widget = projector_interface->newProjectorWidget(projector_name); |
---|
| 21 | Q_ASSERT (NULL!=projector_widget); |
---|
| 22 | ui.stackedWidget->addWidget(projector_widget); |
---|
| 23 | ui.pluginComboBox->addItem(projector_widget->data().getFullName()); |
---|
| 24 | } |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | // If we only have the default plugin, the combo is not displayed. |
---|
| 28 | if (ui.pluginComboBox->count()==1) |
---|
| 29 | { |
---|
| 30 | ui.pluginComboBox->hide(); |
---|
| 31 | ui.pluginLabel->hide(); |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | connect(ui.pluginComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(on_pluginComboBox_currentIndexChanged(int))); |
---|
| 36 | |
---|
| 37 | ui.toolBox->setAutoFillBackground(false); |
---|
| 38 | |
---|
| 39 | setEnabled(false); |
---|
| 40 | |
---|
| 41 | ui.projectionTransformWidget->disconnect(); |
---|
| 42 | connect(ui.projectionTransformWidget, SIGNAL(matrixChanged(const TransformMatrix&)), |
---|
| 43 | this, SLOT(on_projectionTransformWidget_matrixChanged(const TransformMatrix&))); |
---|
| 44 | |
---|
| 45 | ui.projectionTransformWidget->setUseScale(false); |
---|
| 46 | ui.viewTransformWidget->setUseScale(false); |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | QChannelWidget::~QChannelWidget() |
---|
| 50 | { |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | void QChannelWidget::setChannel(Channel* pChannel) |
---|
| 54 | { |
---|
| 55 | if (m_pChannel==pChannel) return; |
---|
| 56 | |
---|
| 57 | m_pChannel = pChannel; |
---|
| 58 | |
---|
| 59 | if (pChannel) |
---|
| 60 | { |
---|
| 61 | Q_ASSERT(NULL!=pChannel->getProjector()); |
---|
| 62 | QString fullname=pChannel->getProjector()->getFullName(); |
---|
| 63 | int next_index=ui.pluginComboBox->findText(fullname); |
---|
| 64 | ui.pluginComboBox->setCurrentIndex(next_index); |
---|
| 65 | |
---|
| 66 | // In some case, the on_pluginComboBox_currentIndexChanged is not called at first time (because the index does not change indeed). |
---|
| 67 | // So, we force the connection |
---|
| 68 | ProjectorWidget* projector_widget=qobject_cast<ProjectorWidget*>(ui.stackedWidget->currentWidget()); |
---|
| 69 | projector_widget->disconnect(); |
---|
| 70 | m_pChannel->disconnect(); |
---|
| 71 | |
---|
| 72 | connect(projector_widget, SIGNAL(dataChanged(const ProjectorData&)), m_pChannel, SLOT(updatePluginData(const ProjectorData&))); |
---|
| 73 | |
---|
| 74 | } |
---|
| 75 | else ui.pluginComboBox->setCurrentIndex(0); |
---|
| 76 | updateGUI(); |
---|
| 77 | |
---|
| 78 | setEnabled(NULL!=pChannel); |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | Channel* QChannelWidget::getChannel() const |
---|
| 82 | { |
---|
| 83 | return m_pChannel; |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | void QChannelWidget::updateGUI() |
---|
| 87 | { |
---|
| 88 | if (m_pChannel) |
---|
| 89 | { |
---|
| 90 | ui.nameEdit->setText(m_pChannel->getName()); |
---|
| 91 | ui.overlayNameCheckBox->setChecked(m_pChannel->getOverlayName()); |
---|
| 92 | ui.remoteHostNameEdit->setText(m_pChannel->getRemoteHostName()); |
---|
| 93 | ui.remoteFullScreenCheckBox->setChecked(m_pChannel->getRemoteFullScreen()); |
---|
| 94 | ui.remoteScreenComboBox->setCurrentIndex(ui.remoteScreenComboBox->findText(QString::number(m_pChannel->getRemoteScreen()))); |
---|
| 95 | ui.overlayImageEdit->setText(m_pChannel->getOverlayImageFileName()); |
---|
| 96 | |
---|
| 97 | // On s'occupe de la partie Projection |
---|
| 98 | // Inutile si elle n'est pas selectionnee, d'ailleurs. |
---|
| 99 | |
---|
| 100 | // On met a jour les donnees. |
---|
| 101 | const ProjectorData* projector_data=m_pChannel->getProjector(); |
---|
| 102 | ProjectorWidget* projector_widget=qobject_cast<ProjectorWidget*>(ui.stackedWidget->currentWidget()); |
---|
| 103 | projector_widget->updateGUI(projector_data); |
---|
| 104 | |
---|
| 105 | ui.projectionTransformWidget->setMatrix(m_pChannel->getProjectorTransformMatrix()); |
---|
| 106 | |
---|
| 107 | ui.warpCheckBox->setChecked(m_pChannel->getDistWarpEnabled()); |
---|
| 108 | ui.warpResSpinBox->setValue(m_pChannel->getDistWarp()->getNumCtrlPoints()); |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | |
---|
| 112 | |
---|
| 113 | // On s'occupe de la partie View |
---|
| 114 | // Inutile si elle n'est pas selectionnee, d'ailleurs. |
---|
| 115 | |
---|
| 116 | |
---|
| 117 | ui.viewProjectionWidget->disconnect(); |
---|
| 118 | ui.viewTransformWidget->disconnect(); |
---|
| 119 | |
---|
| 120 | connect(ui.viewProjectionWidget, SIGNAL(matrixChanged(const ProjectionMatrix&)), |
---|
| 121 | this, SLOT(on_viewProjectionWidget_matrixChanged(const ProjectionMatrix&))); |
---|
| 122 | connect(ui.viewTransformWidget, SIGNAL(matrixChanged(const TransformMatrix&)), |
---|
| 123 | this, SLOT(on_viewTransformWidget_matrixChanged(const TransformMatrix&))); |
---|
| 124 | ui.viewProjectionWidget->setMatrix(m_pChannel->getView()->getProjectionMatrix()); |
---|
| 125 | ui.viewTransformWidget->setMatrix(m_pChannel->getView()->getTransformMatrix()); |
---|
| 126 | |
---|
| 127 | } |
---|
| 128 | else |
---|
| 129 | { |
---|
| 130 | ui.nameEdit->setText(""); |
---|
| 131 | ui.overlayNameCheckBox->setChecked(false); |
---|
| 132 | ui.remoteHostNameEdit->setText(""); |
---|
| 133 | ui.remoteFullScreenCheckBox->setChecked(false); |
---|
| 134 | ui.remoteScreenComboBox->setCurrentIndex(0); |
---|
| 135 | ui.overlayImageEdit->setText(""); |
---|
| 136 | |
---|
| 137 | ui.projectionTransformWidget->clear(); |
---|
| 138 | ui.viewProjectionWidget->clear(); |
---|
| 139 | ui.viewTransformWidget->clear(); |
---|
| 140 | |
---|
| 141 | Q_ASSERT(NULL!=ui.stackedWidget); |
---|
| 142 | if (NULL!=ui.stackedWidget->currentWidget()) |
---|
| 143 | { |
---|
| 144 | ProjectorWidget* projector_widget=qobject_cast<ProjectorWidget*>(ui.stackedWidget->currentWidget()); |
---|
| 145 | Q_ASSERT(NULL!=projector_widget); |
---|
| 146 | projector_widget->clear(); |
---|
| 147 | |
---|
| 148 | } |
---|
| 149 | } |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | void QChannelWidget::on_nameEdit_editingFinished() |
---|
| 153 | { |
---|
| 154 | if (m_pChannel) |
---|
| 155 | { |
---|
| 156 | if (m_pChannel->getName() != ui.nameEdit->text()) |
---|
| 157 | { |
---|
| 158 | m_pChannel->setName(ui.nameEdit->text()); |
---|
| 159 | ui.nameEdit->setText(m_pChannel->getName()); |
---|
| 160 | } |
---|
| 161 | } |
---|
| 162 | } |
---|
| 163 | |
---|
| 164 | void QChannelWidget::on_overlayNameCheckBox_toggled(bool checked) |
---|
| 165 | { |
---|
| 166 | if (m_pChannel) |
---|
| 167 | { |
---|
| 168 | m_pChannel->setOverlayName(checked); |
---|
| 169 | } |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | void QChannelWidget::on_remoteHostNameEdit_editingFinished() |
---|
| 173 | { |
---|
| 174 | if (m_pChannel) |
---|
| 175 | { |
---|
| 176 | if (m_pChannel->getRemoteHostName() != ui.remoteHostNameEdit->text()) |
---|
| 177 | m_pChannel->setRemoteHostName(ui.remoteHostNameEdit->text()); |
---|
| 178 | } |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | void QChannelWidget::on_remoteFullScreenCheckBox_toggled(bool checked) |
---|
| 182 | { |
---|
| 183 | if (m_pChannel) |
---|
| 184 | { |
---|
| 185 | m_pChannel->setRemoteFullScreen(checked); |
---|
| 186 | } |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | void QChannelWidget::on_remoteScreenComboBox_activated(int) |
---|
| 190 | { |
---|
| 191 | if (m_pChannel) |
---|
| 192 | { |
---|
| 193 | m_pChannel->setRemoteScreen(ui.remoteScreenComboBox->currentText().toInt()); |
---|
| 194 | } |
---|
| 195 | } |
---|
| 196 | |
---|
| 197 | void QChannelWidget::on_overlayImageEdit_editingFinished() |
---|
| 198 | { |
---|
| 199 | if (m_pChannel) |
---|
| 200 | { |
---|
| 201 | if (m_pChannel->getOverlayImageFileName() != ui.overlayImageEdit->text()) |
---|
| 202 | m_pChannel->setOverlayImageFileName(ui.overlayImageEdit->text()); |
---|
| 203 | } |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | void QChannelWidget::on_overlayImageBrowseButton_clicked() |
---|
| 207 | { |
---|
| 208 | if (m_pChannel) |
---|
| 209 | { |
---|
| 210 | QString fileName = QFileDialog::getOpenFileName(this, "Choose a file to open", ui.overlayImageEdit->text(), "Image files (*.*)"); |
---|
| 211 | if (!fileName.isEmpty()) { |
---|
| 212 | ui.overlayImageEdit->setText(fileName); |
---|
| 213 | on_overlayImageEdit_editingFinished(); |
---|
| 214 | } |
---|
| 215 | } |
---|
| 216 | } |
---|
| 217 | |
---|
| 218 | void QChannelWidget::on_warpCheckBox_toggled(bool checked) |
---|
| 219 | { |
---|
| 220 | if (m_pChannel) |
---|
| 221 | { |
---|
| 222 | m_pChannel->setDistWarpEnabled(checked); |
---|
| 223 | } |
---|
| 224 | } |
---|
| 225 | |
---|
| 226 | void QChannelWidget::on_warpResSpinBox_valueChanged(int value) |
---|
| 227 | { |
---|
| 228 | if (m_pChannel) |
---|
| 229 | { |
---|
| 230 | m_pChannel->getDistWarp()->setNumCtrlPoints(value); |
---|
| 231 | m_pChannel->updateData(); |
---|
| 232 | } |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | void QChannelWidget::on_warpResetButton_clicked() |
---|
| 236 | { |
---|
| 237 | if (m_pChannel) |
---|
| 238 | { |
---|
| 239 | m_pChannel->getDistWarp()->reset(); |
---|
| 240 | m_pChannel->updateData(); |
---|
| 241 | } |
---|
| 242 | } |
---|
| 243 | |
---|
| 244 | void QChannelWidget::on_calibrateButton_clicked() |
---|
| 245 | { |
---|
| 246 | } |
---|
| 247 | |
---|
| 248 | void QChannelWidget::on_fitButton_clicked() |
---|
| 249 | { |
---|
| 250 | if (m_pChannel) |
---|
| 251 | { |
---|
| 252 | m_pChannel->fitView(); |
---|
| 253 | } |
---|
| 254 | } |
---|
| 255 | |
---|
| 256 | void QChannelWidget::on_windowButton_clicked() |
---|
| 257 | { |
---|
| 258 | if (m_pChannel) |
---|
| 259 | { |
---|
| 260 | m_pChannel->showProjectorWindow(); |
---|
| 261 | } |
---|
| 262 | } |
---|
| 263 | |
---|
| 264 | void QChannelWidget::on_projectionTransformWidget_matrixChanged(const TransformMatrix& matrix) |
---|
| 265 | { |
---|
| 266 | m_pChannel->setProjectorTransformMatrix(matrix); |
---|
| 267 | } |
---|
| 268 | |
---|
| 269 | void QChannelWidget::on_viewProjectionWidget_matrixChanged(const ProjectionMatrix& matrix) |
---|
| 270 | { |
---|
| 271 | m_pChannel->setViewProjectionMatrix(matrix); |
---|
| 272 | } |
---|
| 273 | |
---|
| 274 | void QChannelWidget::on_viewTransformWidget_matrixChanged(const TransformMatrix& matrix) |
---|
| 275 | { |
---|
| 276 | m_pChannel->setViewTransformMatrix(matrix); |
---|
| 277 | } |
---|
| 278 | |
---|
| 279 | void QChannelWidget::on_pluginComboBox_currentIndexChanged(int current_index) |
---|
| 280 | { |
---|
| 281 | ui.stackedWidget->currentWidget()->disconnect(); |
---|
| 282 | ui.stackedWidget->setCurrentIndex(current_index); |
---|
| 283 | ui.stackedWidget->currentWidget()->disconnect(); |
---|
| 284 | if (m_pChannel) |
---|
| 285 | { |
---|
| 286 | m_pChannel->setProjector (ui.pluginComboBox->currentText()); |
---|
| 287 | ProjectorWidget* projector_widget=qobject_cast<ProjectorWidget*>(ui.stackedWidget->currentWidget()); |
---|
| 288 | m_pChannel->disconnect(); |
---|
| 289 | connect(projector_widget, SIGNAL(dataChanged(const ProjectorData&)), m_pChannel, SLOT(updatePluginData(const ProjectorData&))); |
---|
| 290 | m_pChannel->updateData(); |
---|
| 291 | |
---|
| 292 | } |
---|
| 293 | updateGUI(); |
---|
| 294 | } |
---|