source: projectionDesigner/trunk/projdesigner/src/gui/QSceneWidget.cpp @ 120

Last change on this file since 120 was 4, checked in by Torben Dannhauer, 15 years ago
File size: 3.1 KB
Line 
1#include "Scene.h"
2#include "ProjectionModel.h"
3#include "gui/Defines.h"
4#include "gui/QSceneWidget.h"
5
6using namespace projection;
7
8QSceneWidget::QSceneWidget(QWidget* pParent, Qt::WFlags flags)
9    : QWidget(pParent, flags)
10{
11    ui.setupUi(this);
12
13    m_pScene = NULL;
14}
15
16QSceneWidget::~QSceneWidget()
17{
18}
19
20void QSceneWidget::setScene(Scene* pScene)
21{
22        // Note : only scene knows the scene "names". The combo and the stackedWidget have to adapt themselves to the Scene
23        Q_ASSERT(pScene);
24        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.
25    m_pScene = pScene;
26    ui.typeComboBox->clear();
27    for (unsigned int i=0; i<m_pScene->getNumContents(); ++i)
28        {
29        QString name = m_pScene->getContentName(i);
30        ui.typeComboBox->addItem(name);
31
32                SceneContent *sc = m_pScene->getContent(name);
33                SceneInterface *si = sc->plugin();
34                SceneWidget *widget = si->newSceneWidget(sc->scene_name());
35                ui.stackedWidget->addWidget(widget);
36                widget->disconnect();
37                m_pScene->disconnect();
38                connect(widget, SIGNAL(dataChanged(const SceneContent&)), m_pScene, SLOT(updateSceneContent(const SceneContent&)));
39        }
40
41    updateGUI();
42}
43
44void QSceneWidget::updateGUI()
45{
46    if (m_pScene)
47    {
48        ui.transformWidget->setMatrix(m_pScene->getMatrix());
49
50        ui.showInDesignViewCheckBox->setChecked(m_pScene->getShowInDesignView());
51        ui.sceneSizeEdit->setText(formatValue(m_pScene->getSize()));
52        ui.gridCheckBox->setChecked(m_pScene->getShowGrid());
53        ui.gridSizeEdit->setText(formatValue(m_pScene->getShowGrid()));
54
55        ui.typeComboBox->setCurrentIndex(ui.typeComboBox->findText(m_pScene->getCurrentContentName()));
56        ui.stackedWidget->setCurrentIndex(ui.typeComboBox->currentIndex());
57
58                SceneWidget* pSceneWidget = static_cast<SceneWidget*>(ui.stackedWidget->currentWidget());
59                Q_ASSERT(NULL!=pSceneWidget);
60                pSceneWidget->updateGUI(m_pScene->getCurrentContent());
61    }
62}
63
64void QSceneWidget::on_transformWidget_matrixChanged(const TransformMatrix& matrix)
65{
66    if (m_pScene && m_pScene->getMatrix() != matrix)
67    {
68        m_pScene->setMatrix(matrix);
69        updateGUI();
70    }
71}
72
73void QSceneWidget::on_typeComboBox_activated(int)
74{
75    if (m_pScene)
76    {
77        m_pScene->setCurrentContent(ui.typeComboBox->currentText());
78        updateGUI();
79    }
80}
81
82void QSceneWidget::on_showInDesignViewCheckBox_toggled(bool checked)
83{
84    if (m_pScene)
85        m_pScene->setShowInDesignView(checked);
86}
87
88void QSceneWidget::on_sceneSizeEdit_editingFinished()
89{
90    if (m_pScene)
91        m_pScene->setSize(formatValue(ui.sceneSizeEdit->text()));
92}
93
94void QSceneWidget::on_gridCheckBox_toggled(bool checked)
95{
96    if (m_pScene)
97        m_pScene->setShowGrid(checked);
98}
99
100void QSceneWidget::on_gridSizeEdit_editingFinished()
101{
102    if (m_pScene && m_pScene->getGridSize() != ui.gridSizeEdit->text().toDouble())
103        m_pScene->setGridSize(ui.gridSizeEdit->text().toDouble());
104}
105
106void QSceneWidget::on_centerViewButton_clicked()
107{
108    m_pScene->centerView();
109}
110
111void QSceneWidget::on_viewAllButton_clicked()
112{
113    m_pScene->viewAll();
114}
Note: See TracBrowser for help on using the repository browser.