00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "PSQt/WdgPointPos.h"
00011 #include "PSQt/Logger.h"
00012
00013 #include <iostream>
00014 #include <sstream>
00015
00016
00017 namespace PSQt {
00018
00019
00020
00021 WdgPointPos::WdgPointPos( QWidget *parent
00022 , const std::string& label1
00023 , const std::string& label2
00024 , const float& val1
00025 , const float& val2
00026 , const bool& show_boarder
00027 , const unsigned& fld_width
00028 , const unsigned& precision
00029 )
00030
00031 : Frame(parent)
00032 , m_show_boarder(show_boarder)
00033 , m_fld_width(fld_width)
00034 , m_precision(precision)
00035 {
00036 Frame::setBoarderVisible(show_boarder);
00037
00038 m_lab1 = new QLabel(label1.c_str());
00039 m_lab2 = new QLabel(label2.c_str());
00040
00041 m_edi1 = new QLineEdit("");
00042 m_edi2 = new QLineEdit("");
00043 m_edi1 -> setFixedWidth(m_fld_width);
00044 m_edi2 -> setFixedWidth(m_fld_width);
00045 m_edi1 -> setValidator(new QDoubleValidator(-100000, 100000, m_precision, this));
00046 m_edi2 -> setValidator(new QDoubleValidator(-100000, 100000, m_precision, this));
00047
00048
00049
00050 setPointPos(QPointF(val1,val2));
00051
00052 connect(m_edi1, SIGNAL(editingFinished()), this, SLOT(onEdi()));
00053 connect(m_edi2, SIGNAL(editingFinished()), this, SLOT(onEdi()));
00054 connect(this, SIGNAL(posIsChanged(const QPointF&)), this, SLOT(testPosIsChanged(const QPointF&)) );
00055
00056 QHBoxLayout *hbox = new QHBoxLayout;
00057 hbox -> addWidget(m_lab1);
00058 hbox -> addWidget(m_edi1);
00059 hbox -> addWidget(m_lab2);
00060 hbox -> addWidget(m_edi2);
00061 this -> setLayout(hbox);
00062
00063 this -> setWindowTitle(tr("WdgPointPos"));
00064 this -> setFixedHeight( (m_show_boarder)? 50 : 36);
00065 if (! m_show_boarder) this -> setContentsMargins(-9,-9,-9,-9);
00066
00067
00068
00069 this -> showTips();
00070 }
00071
00072
00073
00074 void
00075 WdgPointPos::showTips()
00076 {
00077 m_edi1 -> setToolTip("Type value to change");
00078 m_edi2 -> setToolTip("Type value to change");
00079 }
00080
00081
00082
00083 void
00084 WdgPointPos::resizeEvent(QResizeEvent *event)
00085 {
00086
00087 }
00088
00089
00090
00091 void
00092 WdgPointPos::closeEvent(QCloseEvent *event)
00093 {
00094 QWidget::closeEvent(event);
00095 stringstream ss; ss << "closeEvent(...): type = " << event -> type();
00096 MsgInLog(_name_(), INFO, ss.str());
00097 }
00098
00099
00100
00101
00102
00103
00104 void
00105 WdgPointPos::setPointPos(const QPointF& pos)
00106 {
00107
00108 stringstream ss1, ss2;
00109 ss1 << fixed << std::setprecision(m_precision) << pos.x();
00110 ss2 << fixed << std::setprecision(m_precision) << pos.y();
00111
00112 m_edi1->setText(ss1.str().c_str());
00113 m_edi2->setText(ss2.str().c_str());
00114
00115
00116
00117
00118 }
00119
00120
00121
00122 void
00123 WdgPointPos::onEdi()
00124 {
00125 std::string str1 = (m_edi1 -> displayText()).toStdString();
00126 std::string str2 = (m_edi2 -> displayText()).toStdString();
00127
00128 float val1, val2;
00129 stringstream ss; ss << str1 << ' ' << str2; ss >> val1 >> val2;
00130 QPointF pos(val1,val2);
00131
00132 emit posIsChanged(pos);
00133 }
00134
00135
00136
00137 void
00138 WdgPointPos::testPosIsChanged(const QPointF& pos)
00139 {
00140 stringstream ss; ss << "Center position is changed to x: " << pos.x() << " y: " << pos.y();
00141 MsgInLog(_name_(), INFO, ss.str());
00142
00143 }
00144
00145
00146
00147
00148
00149 }
00150
00151