00001
00002
00003
00004
00005
00006
00007 #include "DlgEditScale.h"
00008 #include "DlgValidatorAbstract.h"
00009 #include "DlgValidatorFactory.h"
00010 #include "DocumentAxesPointsRequired.h"
00011 #include "DocumentModelCoords.h"
00012 #include "DocumentModelGeneral.h"
00013 #include "EngaugeAssert.h"
00014 #include "FormatCoordsUnits.h"
00015 #include "FormatDateTime.h"
00016 #include "FormatDegreesMinutesSecondsNonPolarTheta.h"
00017 #include "FormatDegreesMinutesSecondsPolarTheta.h"
00018 #include "Logger.h"
00019 #include "MainWindow.h"
00020 #include "MainWindowModel.h"
00021 #include <QGridLayout>
00022 #include <QGroupBox>
00023 #include <QHBoxLayout>
00024 #include <QLabel>
00025 #include <QRect>
00026 #include "QtToString.h"
00027 #include <QVBoxLayout>
00028 #include "Transformation.h"
00029
00030 const Qt::Alignment ALIGNMENT = Qt::AlignCenter;
00031
00032 const int MIN_WIDTH_TO_FIT_STRANGE_UNITS = 200;
00033
00034 DlgEditScale::DlgEditScale (MainWindow &mainWindow,
00035 const DocumentModelCoords &modelCoords,
00036 const DocumentModelGeneral &modelGeneral,
00037 const MainWindowModel &modelMainWindow,
00038 const double *scaleLength) :
00039 QDialog (&mainWindow),
00040 m_modelCoords (modelCoords),
00041 m_modelGeneral (modelGeneral),
00042 m_modelMainWindow (modelMainWindow)
00043 {
00044 LOG4CPP_INFO_S ((*mainCat)) << "DlgEditScale::DlgEditScale";
00045
00046 QVBoxLayout *layout = new QVBoxLayout;
00047 setLayout (layout);
00048
00049 setCursor (QCursor (Qt::ArrowCursor));
00050 setModal(true);
00051 setWindowTitle (tr ("Edit Axis Point"));
00052
00053 createScaleLength (layout);
00054 createHint (layout);
00055 createOkCancel (layout);
00056
00057 initializeScaleLength (scaleLength);
00058
00059 updateControls ();
00060 }
00061
00062 DlgEditScale::~DlgEditScale()
00063 {
00064 LOG4CPP_INFO_S ((*mainCat)) << "DlgEditScale::~DlgEditScale";
00065 }
00066
00067 void DlgEditScale::createHint (QVBoxLayout *layoutOuter)
00068 {
00069
00070
00071
00072 QWidget *widget = new QWidget;
00073 layoutOuter->addWidget (widget, 0, Qt::AlignCenter);
00074
00075 QHBoxLayout *layout = new QHBoxLayout;
00076 widget->setLayout (layout);
00077
00078 QString locale = QLocaleToString (m_modelMainWindow.locale ());
00079 QString hint = QString ("%1: %2")
00080 .arg (tr ("Number format"))
00081 .arg (locale);
00082 QLabel *label = new QLabel (hint);
00083 layout->addWidget (label);
00084 }
00085
00086 void DlgEditScale::createOkCancel (QVBoxLayout *layoutOuter)
00087 {
00088 QWidget *panel = new QWidget (this);
00089 layoutOuter->addWidget (panel, 0, Qt::AlignCenter);
00090
00091 QHBoxLayout *layout = new QHBoxLayout (panel);
00092 panel->setLayout (layout);
00093
00094 m_btnOk = new QPushButton (tr ("Ok"), this);
00095 layout->addWidget(m_btnOk);
00096 connect (m_btnOk, SIGNAL (released ()), this, SLOT (accept ()));
00097
00098 m_btnCancel = new QPushButton (tr ("Cancel"), this);
00099 layout->addWidget(m_btnCancel);
00100 connect (m_btnCancel, SIGNAL (released ()), this, SLOT (reject ()));
00101 }
00102
00103 void DlgEditScale::createScaleLength (QVBoxLayout *layoutOuter)
00104 {
00105
00106 DlgValidatorFactory dlgValidatorFactory;
00107 m_validatorScaleLength = dlgValidatorFactory.createAboveZero (m_modelMainWindow.locale());
00108
00109
00110 QGroupBox *panel = new QGroupBox (tr ("Scale Length"), this);
00111 layoutOuter->addWidget (panel);
00112
00113 QHBoxLayout *layout = new QHBoxLayout (panel);
00114 panel->setLayout (layout);
00115
00116
00117 m_editScaleLength = new QLineEdit;
00118 m_editScaleLength->setMinimumWidth(MIN_WIDTH_TO_FIT_STRANGE_UNITS);
00119 m_editScaleLength->setAlignment (ALIGNMENT);
00120 m_editScaleLength->setValidator (m_validatorScaleLength);
00121
00122 m_editScaleLength->setWhatsThis (tr ("Enter the scale bar length"));
00123 layout->addWidget(m_editScaleLength, 0);
00124 connect (m_editScaleLength, SIGNAL (textChanged (const QString &)), this, SLOT (slotTextChanged (const QString &)));
00125 }
00126
00127 void DlgEditScale::initializeScaleLength (const double *scaleLength)
00128 {
00129 if (scaleLength != 0) {
00130 m_editScaleLength->setText (QString::number (*scaleLength));
00131 }
00132 }
00133
00134 double DlgEditScale::scaleLength () const
00135 {
00136 double xTheta, yRadius;
00137 const QString DUMMY_Y ("0");
00138
00139 FormatCoordsUnits format;
00140
00141
00142 format.formattedToUnformatted (m_editScaleLength->text(),
00143 DUMMY_Y,
00144 m_modelCoords,
00145 m_modelMainWindow,
00146 xTheta,
00147 yRadius);
00148
00149 return xTheta;
00150 }
00151
00152 void DlgEditScale::slotTextChanged (const QString &)
00153 {
00154 updateControls ();
00155 }
00156
00157 void DlgEditScale::updateControls ()
00158 {
00159 QString textScaleLength = m_editScaleLength->text();
00160
00161 int posScaleLength;
00162
00163
00164 m_btnOk->setEnabled (!textScaleLength.isEmpty () &&
00165 (m_validatorScaleLength->validate(textScaleLength, posScaleLength) == QValidator::Acceptable));
00166 }