TerrainParamDialog.cc 3.96 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#include "TerrainParamDialog.h"

#include <QFormLayout>
#include <QGroupBox>
#include <QPushButton>

TerrainParamDialog::TerrainParamDialog(QWidget* parent)
 : QDialog(parent)
{
    QVBoxLayout* layout = new QVBoxLayout;
    setLayout(layout);

    setWindowTitle(tr("Terrain Parameters"));
    setModal(true);

    buildLayout(layout);
}

void
TerrainParamDialog::getTerrainParams(GlobalViewParamsPtr &globalViewParams)
{
22 23
    QVector3D& positionOffset = globalViewParams->terrainPositionOffset();
    QVector3D& attitudeOffset = globalViewParams->terrainAttitudeOffset();
24 25

    TerrainParamDialog dialog;
26 27 28 29 30 31
    dialog.mXOffsetSpinBox->setValue(positionOffset.x());
    dialog.mYOffsetSpinBox->setValue(positionOffset.y());
    dialog.mZOffsetSpinBox->setValue(positionOffset.z());
    dialog.mRollOffsetSpinBox->setValue(osg::RadiansToDegrees(attitudeOffset.x()));
    dialog.mPitchOffsetSpinBox->setValue(osg::RadiansToDegrees(attitudeOffset.y()));
    dialog.mYawOffsetSpinBox->setValue(osg::RadiansToDegrees(attitudeOffset.z()));
32 33 34

    if (dialog.exec() == QDialog::Accepted)
    {
35 36 37 38 39 40
        positionOffset.setX(dialog.mXOffsetSpinBox->value());
        positionOffset.setY(dialog.mYOffsetSpinBox->value());
        positionOffset.setZ(dialog.mZOffsetSpinBox->value());
        attitudeOffset.setX(osg::DegreesToRadians(dialog.mRollOffsetSpinBox->value()));
        attitudeOffset.setY(osg::DegreesToRadians(dialog.mPitchOffsetSpinBox->value()));
        attitudeOffset.setZ(osg::DegreesToRadians(dialog.mYawOffsetSpinBox->value()));
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
    }
}

void
TerrainParamDialog::closeWithSaving(void)
{
    done(QDialog::Accepted);
}

void
TerrainParamDialog::closeWithoutSaving(void)
{
    done(QDialog::Rejected);
}

void
TerrainParamDialog::buildLayout(QVBoxLayout* layout)
{
    QGroupBox* offsetGroupBox = new QGroupBox(tr("Offset"), this);

    mXOffsetSpinBox = new QDoubleSpinBox(this);
    mXOffsetSpinBox->setDecimals(1);
    mXOffsetSpinBox->setRange(-100.0, 100.0);
    mXOffsetSpinBox->setValue(0.0);

    mYOffsetSpinBox = new QDoubleSpinBox(this);
    mYOffsetSpinBox->setDecimals(1);
    mYOffsetSpinBox->setRange(-100.0, 100.0);
    mYOffsetSpinBox->setValue(0.0);

    mZOffsetSpinBox = new QDoubleSpinBox(this);
    mZOffsetSpinBox->setDecimals(1);
    mZOffsetSpinBox->setRange(-100.0, 100.0);
    mZOffsetSpinBox->setValue(0.0);

76 77 78 79 80 81 82 83 84 85
    mRollOffsetSpinBox = new QDoubleSpinBox(this);
    mRollOffsetSpinBox->setDecimals(0);
    mRollOffsetSpinBox->setRange(-180.0, 180.0);
    mRollOffsetSpinBox->setValue(0.0);

    mPitchOffsetSpinBox = new QDoubleSpinBox(this);
    mPitchOffsetSpinBox->setDecimals(0);
    mPitchOffsetSpinBox->setRange(-180.0, 180.0);
    mPitchOffsetSpinBox->setValue(0.0);

86 87 88 89 90 91 92 93 94
    mYawOffsetSpinBox = new QDoubleSpinBox(this);
    mYawOffsetSpinBox->setDecimals(0);
    mYawOffsetSpinBox->setRange(-180.0, 180.0);
    mYawOffsetSpinBox->setValue(0.0);

    QFormLayout* formLayout = new QFormLayout;
    formLayout->addRow(tr("x (m)"), mXOffsetSpinBox);
    formLayout->addRow(tr("y (m)"), mYOffsetSpinBox);
    formLayout->addRow(tr("z (m)"), mZOffsetSpinBox);
95 96
    formLayout->addRow(tr("Roll (deg)"), mRollOffsetSpinBox);
    formLayout->addRow(tr("Pitch (deg)"), mPitchOffsetSpinBox);
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
    formLayout->addRow(tr("Yaw (deg)"), mYawOffsetSpinBox);

    offsetGroupBox->setLayout(formLayout);

    layout->addWidget(offsetGroupBox);
    layout->addItem(new QSpacerItem(10, 0, QSizePolicy::Expanding, QSizePolicy::Expanding));

    QPushButton* cancelButton = new QPushButton(this);
    cancelButton->setText("Cancel");

    QPushButton* saveButton = new QPushButton(this);
    saveButton->setText("Save");

    QHBoxLayout* buttonLayout = new QHBoxLayout;
    buttonLayout->addWidget(cancelButton);
    buttonLayout->addItem(new QSpacerItem(10, 0, QSizePolicy::Expanding, QSizePolicy::Expanding));
    buttonLayout->addWidget(saveButton);

    layout->addLayout(buttonLayout);

    connect(cancelButton, SIGNAL(clicked()), this, SLOT(closeWithoutSaving()));
    connect(saveButton, SIGNAL(clicked()), this, SLOT(closeWithSaving()));
}