00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "NeovisionII/ChipValidator/ChipValidatorQt.qt.H"
00039
00040 #include <QtGui/QVBoxLayout>
00041 #include <QtGui/QHBoxLayout>
00042 #include <QtGui/QSlider>
00043 #include <QtGui/QGridLayout>
00044 #include <QtGui/QPushButton>
00045 #include <QtGui/QApplication>
00046
00047 #include "Image/DrawOps.H"
00048 #include "QtUtil/ImageConvert4.H"
00049 #include "Util/log.H"
00050 #include "Util/sformat.H"
00051
00052
00053 ChipValidatorQt::ChipValidatorQt(QApplication *qapp, std::vector<ChipData>& chipvec,
00054 const Dims& griddims, QWidget* parent) :
00055 QWidget(parent), itsChipVec(chipvec), itsGridDims(griddims), itsChipLabels(), itsPage(0)
00056 {
00057 QVBoxLayout *main = new QVBoxLayout(this);
00058 main->setSpacing(4);
00059 main->setMargin(2);
00060
00061 QHBoxLayout *hgrid = new QHBoxLayout;
00062 hgrid->addStretch(1);
00063
00064 QGridLayout *grid = new QGridLayout;
00065 grid->setSpacing(3); uint idx = 0;
00066 for (int j = 0; j < itsGridDims.h(); ++j)
00067 for (int i = 0; i < itsGridDims.w(); ++i) {
00068 ChipQLabel *cl = new ChipQLabel(idx, this);
00069 grid->addWidget(cl, j, i);
00070 itsChipLabels.push_back(cl);
00071 setChipImage(idx);
00072 ++idx;
00073 }
00074 hgrid->addLayout(grid);
00075
00076 hgrid->addStretch(1);
00077
00078 main->addLayout(hgrid);
00079
00080 QHBoxLayout *hcontrol = new QHBoxLayout;
00081
00082 QSlider *slider = new QSlider(Qt::Horizontal , this);
00083 slider->setRange(0, itsChipVec.size() / itsGridDims.sz() + ( (itsChipVec.size() % itsGridDims.sz() ) ? 0 : -1));
00084 slider->setValue(0);
00085 slider->setPageStep(1);
00086 slider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
00087 hcontrol->addWidget(slider);
00088 connect(slider, SIGNAL(valueChanged(int)), this, SLOT(pageChanged(int)));
00089
00090 QPushButton *button = new QPushButton("Save + Exit", this);
00091 hcontrol->addWidget(button);
00092 connect(button, SIGNAL(pressed()), qapp, SLOT(quit()));
00093
00094 main->addLayout(hcontrol);
00095
00096 itsStatusLabel = new QLabel("Status: Idle.", this);
00097 itsStatusLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
00098 main->addWidget(itsStatusLabel);
00099
00100 this->setLayout(main);
00101 }
00102
00103
00104 ChipValidatorQt::~ChipValidatorQt()
00105 { }
00106
00107
00108 void ChipValidatorQt::setChipImage(const uint idx)
00109 {
00110 if (itsChipVec.size() == 0) LFATAL("No chips loaded, I need at least one chip to work");
00111 if (idx >= uint(itsGridDims.sz())) LFATAL("Trying to set chip image for out-of-grid chip");
00112
00113
00114 const uint fullidx = itsPage * itsGridDims.sz() + idx;
00115
00116 if (fullidx < itsChipVec.size()) {
00117 Image< PixRGB<byte> > im = itsChipVec[fullidx].image;
00118
00119
00120 if (itsChipVec[fullidx].positive == false) {
00121 drawLine(im, Point2D<int>(0, 0), Point2D<int>(im.getWidth()-1, im.getHeight()-1), PixRGB<byte>(255, 0, 0), 2);
00122 drawLine(im, Point2D<int>(im.getWidth()-1, 0), Point2D<int>(0, im.getHeight()-1), PixRGB<byte>(255, 0, 0), 2);
00123 }
00124
00125
00126 QPixmap pixmap = convertToQPixmap4(im);
00127 itsChipLabels[idx]->setPixmap(pixmap);
00128 } else {
00129
00130 Image<PixRGB<byte> > im(itsChipVec[0].image.getDims(), NO_INIT); im.clear(PixRGB<byte>(192));
00131 QPixmap pixmap = convertToQPixmap4(im);
00132 itsChipLabels[idx]->setPixmap(pixmap);
00133 }
00134 }
00135
00136
00137 void ChipValidatorQt::chipClicked(const uint idx)
00138 {
00139 if (idx >= uint(itsGridDims.sz())) LFATAL("Clicked an out-of-grid chip");
00140
00141 const uint fullidx = itsPage * itsGridDims.sz() + idx;
00142 if (fullidx < itsChipVec.size()) {
00143 itsChipVec[fullidx].positive = ! itsChipVec[fullidx].positive;
00144 itsStatusLabel->setText(sformat("Chip %u/%"ZU" marked as %s.", fullidx, itsChipVec.size()-1,
00145 itsChipVec[fullidx].positive ? "positive" : "negative").c_str());
00146 setChipImage(idx);
00147 }
00148 }
00149
00150
00151 void ChipValidatorQt::pageChanged(const int idx)
00152 {
00153 itsPage = idx;
00154
00155 const uint startidx = itsPage*itsGridDims.sz();
00156 const uint stopidx = std::min(startidx + itsGridDims.sz() - 1, uint(itsChipVec.size() - 1));
00157 itsStatusLabel->setText(sformat("Showing chips %u - %u", startidx, stopidx).c_str());
00158
00159 for (uint i = 0; i < uint(itsGridDims.sz()); ++i) setChipImage(i);
00160 }
00161
00162
00163
00164
00165
00166
00167