[4] | 1 | #include "gui/Defines.h" |
---|
| 2 | #include "gui/QTransformMatrixWidget.h" |
---|
| 3 | |
---|
| 4 | using namespace projection; |
---|
| 5 | using namespace gmtl; |
---|
| 6 | |
---|
| 7 | QTransformMatrixWidget::QTransformMatrixWidget(QWidget* pParent, Qt::WFlags flags) |
---|
| 8 | : QWidget(pParent, flags) |
---|
| 9 | { |
---|
| 10 | ui.setupUi(this); |
---|
| 11 | m_bStopSlot = false; |
---|
| 12 | } |
---|
| 13 | |
---|
| 14 | QTransformMatrixWidget::~QTransformMatrixWidget() |
---|
| 15 | { |
---|
| 16 | } |
---|
| 17 | |
---|
| 18 | void QTransformMatrixWidget::setMatrix(const TransformMatrix& matrix) |
---|
| 19 | { |
---|
| 20 | if (m_bStopSlot) return; |
---|
| 21 | |
---|
| 22 | Vec3f pos = matrix.getPosition(); |
---|
| 23 | Vec3f rot = matrix.getRotation(); |
---|
| 24 | Vec3f scale = matrix.getScaling(); |
---|
| 25 | ui.posXEdit->setText(formatValue(pos[0])); |
---|
| 26 | ui.posYEdit->setText(formatValue(pos[1])); |
---|
| 27 | ui.posZEdit->setText(formatValue(pos[2])); |
---|
| 28 | ui.rotHEdit->setText(formatValue(rot[0])); |
---|
| 29 | ui.rotPEdit->setText(formatValue(rot[1])); |
---|
| 30 | ui.rotREdit->setText(formatValue(rot[2])); |
---|
| 31 | ui.scaleXEdit->setText(formatValue(scale[0])); |
---|
| 32 | ui.scaleYEdit->setText(formatValue(scale[1])); |
---|
| 33 | ui.scaleZEdit->setText(formatValue(scale[2])); |
---|
| 34 | |
---|
| 35 | // checkValueChanged(); |
---|
| 36 | m_matrix = matrix; |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | TransformMatrix QTransformMatrixWidget::getMatrix() const |
---|
| 40 | { |
---|
| 41 | return m_matrix; |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | void QTransformMatrixWidget::clear() |
---|
| 45 | { |
---|
| 46 | ui.posXEdit->setText(""); |
---|
| 47 | ui.posYEdit->setText(""); |
---|
| 48 | ui.posZEdit->setText(""); |
---|
| 49 | ui.rotHEdit->setText(""); |
---|
| 50 | ui.rotPEdit->setText(""); |
---|
| 51 | ui.rotREdit->setText(""); |
---|
| 52 | ui.scaleXEdit->setText(""); |
---|
| 53 | ui.scaleYEdit->setText(""); |
---|
| 54 | ui.scaleZEdit->setText(""); |
---|
| 55 | m_matrix = TransformMatrix(); |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | void QTransformMatrixWidget::setUseScale(bool bUseScale) |
---|
| 59 | { |
---|
| 60 | if (bUseScale) |
---|
| 61 | { |
---|
| 62 | ui.scaleLabel->show(); |
---|
| 63 | ui.scaleXEdit->show(); |
---|
| 64 | ui.scaleYEdit->show(); |
---|
| 65 | ui.scaleZEdit->show(); |
---|
| 66 | } |
---|
| 67 | else |
---|
| 68 | { |
---|
| 69 | ui.scaleLabel->hide(); |
---|
| 70 | ui.scaleXEdit->hide(); |
---|
| 71 | ui.scaleYEdit->hide(); |
---|
| 72 | ui.scaleZEdit->hide(); |
---|
| 73 | } |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | void QTransformMatrixWidget::checkValueChanged() |
---|
| 77 | { |
---|
| 78 | Vec3f pos(ui.posXEdit->text().toFloat(), ui.posYEdit->text().toFloat(), ui.posZEdit->text().toFloat()); |
---|
| 79 | Vec3f rot(ui.rotHEdit->text().toFloat(), ui.rotPEdit->text().toFloat(), ui.rotREdit->text().toFloat()); |
---|
| 80 | Vec3f scale(ui.scaleXEdit->text().toFloat(), ui.scaleYEdit->text().toFloat(), ui.scaleZEdit->text().toFloat()); |
---|
| 81 | TransformMatrix matrix; |
---|
| 82 | matrix.setPosition(pos); |
---|
| 83 | matrix.setRotation(rot); |
---|
| 84 | matrix.setScaling(scale); |
---|
| 85 | |
---|
| 86 | if (m_matrix != matrix) |
---|
| 87 | { |
---|
| 88 | m_matrix = matrix; |
---|
| 89 | m_bStopSlot = true; |
---|
| 90 | emit matrixChanged(m_matrix); |
---|
| 91 | m_bStopSlot = false; |
---|
| 92 | } |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | void QTransformMatrixWidget::on_posXEdit_editingFinished() |
---|
| 96 | { |
---|
| 97 | checkValueChanged(); |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | void QTransformMatrixWidget::on_posYEdit_editingFinished() |
---|
| 101 | { |
---|
| 102 | checkValueChanged(); |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | void QTransformMatrixWidget::on_posZEdit_editingFinished() |
---|
| 106 | { |
---|
| 107 | checkValueChanged(); |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | void QTransformMatrixWidget::on_rotHEdit_editingFinished() |
---|
| 111 | { |
---|
| 112 | checkValueChanged(); |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | void QTransformMatrixWidget::on_rotPEdit_editingFinished() |
---|
| 116 | { |
---|
| 117 | checkValueChanged(); |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | void QTransformMatrixWidget::on_rotREdit_editingFinished() |
---|
| 121 | { |
---|
| 122 | checkValueChanged(); |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | void QTransformMatrixWidget::on_scaleXEdit_editingFinished() |
---|
| 126 | { |
---|
| 127 | checkValueChanged(); |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | void QTransformMatrixWidget::on_scaleYEdit_editingFinished() |
---|
| 131 | { |
---|
| 132 | checkValueChanged(); |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | void QTransformMatrixWidget::on_scaleZEdit_editingFinished() |
---|
| 136 | { |
---|
| 137 | checkValueChanged(); |
---|
| 138 | } |
---|