#include "Scene.h" #include "ProjectionModel.h" #include "gui/Defines.h" #include "gui/QSceneWidget.h" using namespace projection; QSceneWidget::QSceneWidget(QWidget* pParent, Qt::WFlags flags) : QWidget(pParent, flags) { ui.setupUi(this); m_pScene = NULL; } QSceneWidget::~QSceneWidget() { } void QSceneWidget::setScene(Scene* pScene) { // Note : only scene knows the scene "names". The combo and the stackedWidget have to adapt themselves to the Scene Q_ASSERT(pScene); Q_ASSERT(!m_pScene); // <-- If this Q_ASSERT match, this is that 'setScene()' has been called twice. Then we'll need to delete all the widgets. m_pScene = pScene; ui.typeComboBox->clear(); for (unsigned int i=0; igetNumContents(); ++i) { QString name = m_pScene->getContentName(i); ui.typeComboBox->addItem(name); SceneContent *sc = m_pScene->getContent(name); SceneInterface *si = sc->plugin(); SceneWidget *widget = si->newSceneWidget(sc->scene_name()); ui.stackedWidget->addWidget(widget); widget->disconnect(); m_pScene->disconnect(); connect(widget, SIGNAL(dataChanged(const SceneContent&)), m_pScene, SLOT(updateSceneContent(const SceneContent&))); } updateGUI(); } void QSceneWidget::updateGUI() { if (m_pScene) { ui.transformWidget->setMatrix(m_pScene->getMatrix()); ui.showInDesignViewCheckBox->setChecked(m_pScene->getShowInDesignView()); ui.sceneSizeEdit->setText(formatValue(m_pScene->getSize())); ui.gridCheckBox->setChecked(m_pScene->getShowGrid()); ui.gridSizeEdit->setText(formatValue(m_pScene->getShowGrid())); ui.typeComboBox->setCurrentIndex(ui.typeComboBox->findText(m_pScene->getCurrentContentName())); ui.stackedWidget->setCurrentIndex(ui.typeComboBox->currentIndex()); SceneWidget* pSceneWidget = static_cast(ui.stackedWidget->currentWidget()); Q_ASSERT(NULL!=pSceneWidget); pSceneWidget->updateGUI(m_pScene->getCurrentContent()); } } void QSceneWidget::on_transformWidget_matrixChanged(const TransformMatrix& matrix) { if (m_pScene && m_pScene->getMatrix() != matrix) { m_pScene->setMatrix(matrix); updateGUI(); } } void QSceneWidget::on_typeComboBox_activated(int) { if (m_pScene) { m_pScene->setCurrentContent(ui.typeComboBox->currentText()); updateGUI(); } } void QSceneWidget::on_showInDesignViewCheckBox_toggled(bool checked) { if (m_pScene) m_pScene->setShowInDesignView(checked); } void QSceneWidget::on_sceneSizeEdit_editingFinished() { if (m_pScene) m_pScene->setSize(formatValue(ui.sceneSizeEdit->text())); } void QSceneWidget::on_gridCheckBox_toggled(bool checked) { if (m_pScene) m_pScene->setShowGrid(checked); } void QSceneWidget::on_gridSizeEdit_editingFinished() { if (m_pScene && m_pScene->getGridSize() != ui.gridSizeEdit->text().toDouble()) m_pScene->setGridSize(ui.gridSizeEdit->text().toDouble()); } void QSceneWidget::on_centerViewButton_clicked() { m_pScene->centerView(); } void QSceneWidget::on_viewAllButton_clicked() { m_pScene->viewAll(); }