00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "PSQt/WdgColorTable.h"
00011 #include "PSQt/Logger.h"
00012
00013 #include <QString>
00014 #include <string>
00015
00016 #include <iostream>
00017 #include <cstring>
00018 #include <sstream>
00019
00020
00021
00022 namespace PSQt {
00023
00024
00025
00026 WdgColorTable::WdgColorTable( QWidget *parent, const float& h1, const float& h2, const unsigned& colors )
00027 : QWidget(parent)
00028 , m_h1(h1)
00029 , m_h2(h2)
00030 , m_colors(colors)
00031 {
00032
00033 m_figsize = 256;
00034 m_cbar_width = 40;
00035
00036 this -> setFrame();
00037
00038 m_edi_h1 = new QLineEdit( val_to_string<float>(m_h1).c_str(), this );
00039 m_edi_h2 = new QLineEdit( val_to_string<float>(m_h2).c_str(), this );
00040 m_but_apply = new QPushButton("Apply");
00041 m_lab_cring = new PSQt::LabColorRing(this, m_figsize, m_h1, m_h2);
00042
00043 QChar chars1[] = {0x03B1, '1', ':'};
00044 QChar chars2[] = {0x03B1, '2', ':'};
00045 m_lab_h1 = new QLabel(QString(chars1));
00046 m_lab_h2 = new QLabel(QString(chars2));
00047 m_lab_cbar = new QLabel("L2", this);
00048
00049 connect( m_edi_h1, SIGNAL( editingFinished() ), this, SLOT(onEdiH1()) );
00050 connect( m_edi_h2, SIGNAL( editingFinished() ), this, SLOT(onEdiH2()) );
00051 connect( m_but_apply, SIGNAL( clicked() ), this, SLOT(onButApply()) );
00052
00053 connect( m_lab_cring, SIGNAL( hueAngleIsMoving(const unsigned&) ),
00054 this, SLOT(onSetH(const unsigned&)) );
00055
00056 connect( m_lab_cring, SIGNAL( hueAngleIsMoved() ),
00057 this, SLOT(onHueAngleIsChanged()) );
00058
00059 connect( this, SIGNAL( hueAngleIsEdited(const unsigned&) ),
00060 m_lab_cring, SLOT(onSetShifter(const unsigned&)) );
00061
00062 connect( this, SIGNAL( hueAnglesUpdated(const float&, const float&) ),
00063 this, SLOT(testSignalHueAnglesUpdated(const float&, const float&)) );
00064
00065 QHBoxLayout *hbox1 = new QHBoxLayout();
00066 hbox1 -> addWidget(m_lab_h1);
00067 hbox1 -> addWidget(m_edi_h1);
00068 hbox1 -> addStretch(1);
00069 hbox1 -> addWidget(m_lab_h2);
00070 hbox1 -> addWidget(m_edi_h2);
00071 hbox1 -> addStretch(1);
00072 hbox1 -> addWidget(m_but_apply);
00073
00074 QVBoxLayout *vbox = new QVBoxLayout();
00075 vbox -> addWidget(m_lab_cring);
00076 vbox -> addLayout(hbox1);
00077 vbox -> addWidget(m_lab_cbar);
00078 vbox -> addStretch(1);
00079
00080
00081
00082
00083
00084 this -> setLayout(vbox);
00085 this -> setWindowTitle(tr("Color Table"));
00086 this -> move(100,50);
00087
00088 showTips();
00089 setStyle();
00090
00091 m_pixmap_cbar=0;
00092 setColorBar(m_h1, m_h2, m_cbar_width, m_figsize);
00093
00094
00095
00096
00097
00098 }
00099
00100
00101
00102 void
00103 WdgColorTable::showTips()
00104 {
00105 m_edi_h1 -> setToolTip("Hue angle 1");
00106 m_edi_h2 -> setToolTip("Hue angle 2");
00107 }
00108
00109
00110
00111 void
00112 WdgColorTable::setFrame()
00113 {
00114 m_frame = new QFrame(this);
00115 m_frame -> setFrameStyle ( QFrame::Box | QFrame::Sunken);
00116
00117
00118 m_frame -> setLineWidth(0);
00119 m_frame -> setMidLineWidth(1);
00120
00121
00122 }
00123
00124
00125
00126 void
00127 WdgColorTable::setStyle()
00128 {
00129 m_edi_h1 -> setFixedSize(50,30);
00130 m_edi_h2 -> setFixedSize(50,30);
00131 m_lab_cbar -> setMargin(0);
00132 m_lab_cbar -> setFixedSize(m_figsize, m_cbar_width);
00133 m_but_apply-> setFixedSize(60,30);
00134 this -> setFixedWidth(m_figsize+22);
00135
00136
00137
00138
00139 }
00140
00141
00142
00143 void
00144 WdgColorTable::resizeEvent(QResizeEvent *event)
00145 {
00146
00147 m_frame->setGeometry(0, 0, event->size().width(), event->size().height());
00148
00149
00150
00151
00152 m_lab_cbar ->setPixmap(m_pixmap_cbar ->scaled(m_lab_cbar->size(), Qt::KeepAspectRatio, Qt::FastTransformation));
00153
00154 }
00155
00156
00157
00158 void
00159 WdgColorTable::closeEvent(QCloseEvent *event)
00160 {
00161 QWidget::closeEvent(event);
00162 std::stringstream ss; ss << "closeEvent(...): type = " << event -> type();
00163 MsgInLog(_name_(), DEBUG, ss.str());
00164 }
00165
00166
00167 void
00168 WdgColorTable::moveEvent(QMoveEvent *event)
00169 {
00170
00171
00172
00173
00174 }
00175
00176
00177
00178 void
00179 WdgColorTable::mousePressEvent(QMouseEvent *event)
00180 {
00181
00182
00183
00184
00185 }
00186
00187
00188 void
00189 WdgColorTable::mouseMoveEvent(QMouseEvent *e)
00190 {
00191
00192
00193
00194 }
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207 void
00208 WdgColorTable::onEdiH1()
00209 {
00210 std::string str = (m_edi_h1 -> displayText()).toStdString();
00211
00212
00213 m_h1 = (float)string_to_int(str);
00214 emit hueAngleIsEdited(1);
00215 setColorBar(m_h1, m_h2, m_cbar_width, m_figsize);
00216 this->onHueAngleIsChanged();
00217 }
00218
00219
00220
00221 void
00222 WdgColorTable::onEdiH2()
00223 {
00224 std::string str = (m_edi_h2 -> displayText()).toStdString();
00225
00226
00227 m_h2 = (float)string_to_int(str);
00228 emit hueAngleIsEdited(2);
00229 setColorBar(m_h1, m_h2, m_cbar_width, m_figsize);
00230 this->onHueAngleIsChanged();
00231 }
00232
00233
00234
00235 void
00236 WdgColorTable::onSetH(const unsigned& selected)
00237 {
00238
00239
00240
00241 if(selected == 1) m_edi_h1 -> setText(QString(val_to_string<int>(int(m_h1)).c_str()));
00242 if(selected == 2) m_edi_h2 -> setText(QString(val_to_string<int>(int(m_h2)).c_str()));
00243
00244 setColorBar(m_h1, m_h2, m_cbar_width, m_figsize);
00245 }
00246
00247
00248 void
00249 WdgColorTable::onButApply()
00250 {
00251 std::stringstream ss; ss << "Emit signal with Hue angles h1:" << m_h1 << " h2:" << m_h2;
00252 MsgInLog(_name_(), INFO, ss.str());
00253 emit hueAnglesUpdated(m_h1, m_h2);
00254 }
00255
00256
00257
00258 void
00259 WdgColorTable::onHueAngleIsChanged()
00260 {
00261
00262
00263
00264 }
00265
00266
00267
00268 void
00269 WdgColorTable::onButExit()
00270 {
00271
00272 this->close();
00273 }
00274
00275
00276
00277 void
00278 WdgColorTable::setColorBar( const float& hue1,
00279 const float& hue2,
00280 const unsigned& rows,
00281 const unsigned& cols
00282 )
00283 {
00284
00285 uint32_t* ctable = ColorTable(cols, hue1, hue2);
00286 uint32_t dimg[rows][cols];
00287
00288 for(unsigned r=0; r<rows; ++r) {
00289 std::memcpy(&dimg[r][0], &ctable[0], cols*sizeof(uint32_t));
00290 }
00291
00292 QImage image((const uchar*) &dimg[0], cols, rows, QImage::Format_ARGB32);
00293 setPixmapForLabel(image, m_pixmap_cbar, m_lab_cbar);
00294
00295 }
00296
00297
00298
00299 ndarray<uint32_t,1>
00300 WdgColorTable::getColorTableAsNDArray(const unsigned& colors)
00301 {
00302 uint32_t* ctable = ColorTable(colors, m_h1, m_h2);
00303 unsigned shape[] = {colors}; ndarray<uint32_t,1> nda(shape);
00304
00305 std::memcpy(nda.data(), ctable, colors*sizeof(uint32_t));
00306
00307 return nda;
00308 }
00309
00310
00311 void
00312 WdgColorTable::testSignalHueAnglesUpdated(const float& h1, const float& h2)
00313 {
00314 std::stringstream ss; ss << ":testSignalHueAnglesUpdated h1:" << m_h1 << " h2:" << m_h2;
00315 MsgInLog(_name_(), DEBUG, ss.str());
00316 }
00317
00318
00319
00320 }
00321
00322