cv::Mat draw(int id, int cellSize, bool withMargin, cv::Scalar color) const { // Creating the image of the bit matrix static const int DATA_SIZE = 6; cv::Size dataDim(DATA_SIZE,DATA_SIZE); unsigned char dataMatrix[DATA_SIZE*DATA_SIZE]; mDecode.getCodec().getTagEncodedId(id, dataMatrix); cv::Mat dataImage(dataDim, CV_8U, dataMatrix); // Adding the black border arounf the bit matrix cv::Size borderSize(2,2); cv::Mat tagImage(dataImage.size()+borderSize*2, CV_8U, cv::Scalar(0)); dataImage.copyTo(tagImage(cv::Rect(borderSize, dataImage.size()))); // Adding the optionnal white margin cv::Size marginSize(0,0); if (withMargin) marginSize += borderSize; cv::Mat outlinedImage(tagImage.size()+marginSize*2, CV_8U, cv::Scalar(1)); tagImage.copyTo(outlinedImage(cv::Rect(marginSize, tagImage.size()))); // Resizing to specified cellSize cv::Mat sizedImage(outlinedImage.size()*cellSize, CV_8U); cv::resize(outlinedImage, sizedImage, sizedImage.size(), 0, 0, cv::INTER_NEAREST); // Coloring cv::Mat redImage = (1-sizedImage)*color[0]+sizedImage*255; cv::Mat greenImage = (1-sizedImage)*color[1]+sizedImage*255; cv::Mat blueImage = (1-sizedImage)*color[2]+sizedImage*255; cv::Mat colorImage(sizedImage.size(), CV_8UC3); cv::merge(std::vector<cv::Mat>{blueImage, greenImage, redImage}, colorImage); return colorImage; }
int RegSexyDisplay::maxContentHeight() const { int max = 0; QFontMetrics metrics = fontMetrics(); for(size_t i = 0; i < m_reg.GetReg().field.size(); i++) { QString s = QString::fromStdString(m_reg.GetReg().field[i].name); // add extra spaces arounds s = " " + s + " "; max = qMax(max, metrics.boundingRect(s).width()); } return 2 * marginSize() + max; }
void MWidgetController::resizeEvent(QGraphicsSceneResizeEvent *event) { Q_D(MWidgetController); // check if we have, or if we can create a view if (view()) { QRect margins = d->view->margins(); QSizeF marginSize(margins.x() + margins.width(), margins.top() + margins.height()); // Round the incoming resize event values. event->setOldSize(event->oldSize().toSize() - marginSize); event->setNewSize(event->newSize().toSize() - marginSize); // forward the event to the view d->view->resizeEvent(event); } }
void RegSexyDisplay::paintEvent(QPaintEvent *event) { // FIXME could be optimised with QStaticText Q_UNUSED(event); int txt_h = fontMetrics().height(); int sep_sz = separatorSize(); int w = width(); int h = height() - 1; int col_w = (w - 33 * sep_sz) / 32; int hdr_h = headerHeight(); int gap_h = gapHeight(); int tot_w = 33 * sep_sz + 32 * col_w; int margin = marginSize(); int txt_sep = textSep(); int tot_hdr_sz = 2 * sep_sz + hdr_h; // computer xshift int x_shift = (w - tot_w) / 2; #define ith_col_x(i) (x_shift + (i) * (sep_sz + col_w)) QPainter painter(this); QBrush back_brush = palette().base(); QBrush line_brush = palette().dark(); // fill interesting zone with base painter.fillRect(x_shift, 0, tot_w, h, back_brush); // draw top and bottom lines painter.setPen(QPen(palette().dark(), sep_sz)); painter.fillRect(x_shift, 0, tot_w, sep_sz, line_brush); painter.fillRect(x_shift, h - sep_sz, tot_w, sep_sz, line_brush); // draw intemediate lines for(int i = 0; i <= 32; i++) painter.fillRect(ith_col_x(i), 0, sep_sz, 2 * sep_sz + hdr_h, line_brush); // draw bottom header lines painter.fillRect(ith_col_x(0), sep_sz + hdr_h, tot_w, sep_sz, line_brush); painter.fillRect(ith_col_x(0), tot_hdr_sz + gap_h, tot_w, sep_sz, line_brush); // redraw some lines but wider for(int i = 4; i < 32; i += 4) painter.fillRect(ith_col_x(i) - sep_sz, 0, 3 * sep_sz, tot_hdr_sz, line_brush); // draw numbers in the header painter.setPen(palette().brush(QPalette::ButtonText).color()); for(int i = 0; i < 32; i++) { QRect r(ith_col_x(i), sep_sz + margin, col_w, txt_h); painter.drawText(r, Qt::AlignCenter, QString("%1").arg((31 - i) / 10)); r.translate(0, txt_h + txt_sep); painter.drawText(r, Qt::AlignCenter, QString("%1").arg((31 - i) % 10)); } // display content for(size_t i = 0; i < m_reg.GetReg().field.size(); i++) { const soc_reg_field_t& field = m_reg.GetReg().field[i]; QRect r(QPoint(ith_col_x(31 - field.last_bit) + sep_sz, tot_hdr_sz), QPoint(ith_col_x(32 - field.first_bit), h - sep_sz)); painter.fillRect(r.x() - sep_sz, r.y(), sep_sz, r.height(), line_brush); painter.fillRect(r.right(), r.y(), sep_sz, r.height(), line_brush); r.setY(r.y() + gap_h + sep_sz); // draw rotated text painter.save(); painter.translate(r.bottomLeft()); painter.rotate(-90); //painter.fillRect(QRect(0, 0, r.height(), r.width()), QBrush(Qt::red)); QRect r2(0, 0, r.height(), r.width()); painter.drawText(r2, Qt::AlignCenter, QString::fromStdString(field.name)); painter.restore(); } #undef ith_col_x }
int RegSexyDisplay::gapHeight() const { return marginSize() / 2; }
int RegSexyDisplay::columnWidth() const { return 2 * marginSize() + fontMetrics().height(); }
int RegSexyDisplay::headerHeight() const { return 2 * marginSize() + textSep() + 2 * fontMetrics().height(); }
int RegSexyDisplay::textSep() const { return marginSize() / 2; }
int TextItem::fakeMarginSize(){ return marginSize()+5; }