#include "DefaultModelSceneWidget.h" /** * Default constructor. * */ DefaultModelSceneWidget::DefaultModelSceneWidget(SceneInterface *plugin, QWidget* pParent, Qt::WFlags flag): SceneWidget(plugin, pParent, flag), m_content(plugin) { setupUi (this); updateGUI(); } /** * Destructor. * */ DefaultModelSceneWidget::~DefaultModelSceneWidget() { } /** * Updates the widget. * * This method can be used it two ways: to force a refresh or to update the * data of the widget. * * @param content A const pointer on the contents to be used for the widget. * This contents will be duplicated in the widget. If content * is NULL, the current content are used and the refresh is * forced. If no content are given, NULL is used. * */ void DefaultModelSceneWidget::updateGUI(const SceneContent* _content) { if (_content) { const DefaultModelSceneContent *content = static_cast(_content); Q_ASSERT(NULL!=content); // <-- Assume that the conversion was successful m_content.copy_from(*content); } // From now, we will only use m_content modelFileNameEdit->setText(m_content.fileName()); modelCullingCheckBox->setChecked(m_content.backFaceCulling()); modelSmoothingCheckBox->setChecked(m_content.smoothing()); } /** * [private slot] Called when the "filename" field is edited. * */ void DefaultModelSceneWidget::on_modelFileNameEdit_editingFinished() { QString fileName = modelFileNameEdit->text(); if (fileName!=m_content.fileName()) { m_content.setFileName(fileName); emit dataChanged(m_content); } } /** * [private slot] Called when the "browse" button is pressed. * */ void DefaultModelSceneWidget::on_modelBrowseButton_clicked() { QString fileName = QFileDialog::getOpenFileName(this, "Choose a file to open", modelFileNameEdit->text(), "Model files (*.obj)"); if (!fileName.isEmpty()) { modelFileNameEdit->setText(fileName); on_modelFileNameEdit_editingFinished(); } } /** * [private slot] Called when the culling checkbox state changes. * * @param checked true if the checkbox is checked. * */ void DefaultModelSceneWidget::on_modelCullingCheckBox_toggled(bool checked) { if (checked!=m_content.backFaceCulling()) { m_content.setBackFaceCulling(checked); emit dataChanged(m_content); } } /** * [private slot] Called when the smooth checkbox state changes. * * @param checked true if the checkbox is checked. * */ void DefaultModelSceneWidget::on_modelSmoothingCheckBox_toggled(bool checked) { if (checked!=m_content.smoothing()) { m_content.setSmoothing(checked); emit dataChanged(m_content); } }