void Ajout::on_b_valider_clicked() { MainWindow* parent = qobject_cast<MainWindow*>(this->parent()); if (parent == 0) { return; } if((ui->q_nbPieces->value() == 0) || (ui->q_superficieTerrain->value() == 0) || (ui->q_adresse->text() == "") || (ui->q_ville->text() == "") || (ui->q_codePostal->text() == "") || (ui->q_description->toPlainText() == "") || (ui->q_prix->value() == 0)) { QMessageBox::information(this, "Validation impossible", "Certains champs n'ont pas été remplis correctement"); if(ui->q_nbPieces->value() == 0) { QPalette palette = ui->l_nbPieces->palette(); QBrush brush(QColor(255, 0, 0, 255)); brush.setStyle(Qt::SolidPattern); palette.setBrush(QPalette::Active, QPalette::WindowText, brush); ui->l_nbPieces->setPalette(palette); } else { QPalette palette = ui->l_nbPieces->palette(); QBrush brush(QColor(0, 0, 0, 255)); brush.setStyle(Qt::SolidPattern); palette.setBrush(QPalette::Active, QPalette::WindowText, brush); ui->l_nbPieces->setPalette(palette); } if(ui->q_superficieTerrain->value() == 0) { QPalette palette = ui->l_superficieTerrain->palette(); QBrush brush(QColor(255, 0, 0, 255)); brush.setStyle(Qt::SolidPattern); palette.setBrush(QPalette::Active, QPalette::WindowText, brush); ui->l_superficieTerrain->setPalette(palette); } else { QPalette palette = ui->l_superficieTerrain->palette(); QBrush brush(QColor(0, 0, 0, 255)); brush.setStyle(Qt::SolidPattern); palette.setBrush(QPalette::Active, QPalette::WindowText, brush); ui->l_superficieTerrain->setPalette(palette); } if(ui->q_adresse->text() == "") { QPalette palette = ui->l_adresse->palette(); QBrush brush(QColor(255, 0, 0, 255)); brush.setStyle(Qt::SolidPattern); palette.setBrush(QPalette::Active, QPalette::WindowText, brush); ui->l_adresse->setPalette(palette); } else { QPalette palette = ui->l_adresse->palette(); QBrush brush(QColor(0, 0, 0, 255)); brush.setStyle(Qt::SolidPattern); palette.setBrush(QPalette::Active, QPalette::WindowText, brush); ui->l_adresse->setPalette(palette); } if(ui->q_ville->text() == "") { QPalette palette = ui->l_ville->palette(); QBrush brush(QColor(255, 0, 0, 255)); brush.setStyle(Qt::SolidPattern); palette.setBrush(QPalette::Active, QPalette::WindowText, brush); ui->l_ville->setPalette(palette); } else { QPalette palette = ui->l_ville->palette(); QBrush brush(QColor(0, 0, 0, 255)); brush.setStyle(Qt::SolidPattern); palette.setBrush(QPalette::Active, QPalette::WindowText, brush); ui->l_ville->setPalette(palette); } if(ui->q_codePostal->text() == "") { QPalette palette = ui->q_codePostal->palette(); QBrush brush(QColor(255, 0, 0, 255)); brush.setStyle(Qt::SolidPattern); palette.setBrush(QPalette::Active, QPalette::WindowText, brush); ui->q_codePostal->setPalette(palette); } else { QPalette palette = ui->q_codePostal->palette(); QBrush brush(QColor(0, 0, 0, 255)); brush.setStyle(Qt::SolidPattern); palette.setBrush(QPalette::Active, QPalette::WindowText, brush); ui->q_codePostal->setPalette(palette); } if(ui->q_description->toPlainText() == "") { QPalette palette = ui->l_description->palette(); QBrush brush(QColor(255, 0, 0, 255)); brush.setStyle(Qt::SolidPattern); palette.setBrush(QPalette::Active, QPalette::WindowText, brush); ui->l_description->setPalette(palette); } else { QPalette palette = ui->l_description->palette(); QBrush brush(QColor(0, 0, 0, 255)); brush.setStyle(Qt::SolidPattern); palette.setBrush(QPalette::Active, QPalette::WindowText, brush); ui->l_description->setPalette(palette); } if(ui->q_prix->value() == 0) { QPalette palette = ui->l_prix->palette(); QBrush brush(QColor(255, 0, 0, 255)); brush.setStyle(Qt::SolidPattern); palette.setBrush(QPalette::Active, QPalette::WindowText, brush); ui->l_prix->setPalette(palette); } else { QPalette palette = ui->l_prix->palette(); QBrush brush(QColor(0, 0, 0, 255)); brush.setStyle(Qt::SolidPattern); palette.setBrush(QPalette::Active, QPalette::WindowText, brush); ui->l_prix->setPalette(palette); } } else { QList<QString> ps; for(int i=0;i<ui->listWidget->count();i++) { QList<QString> file = ui->listWidget->item(i)->text().split('/'); QString filePath ="../../../../BestResidence/Photos/"+file.value(file.length()-1); QFile::copy(ui->listWidget->item(i)->text(),filePath); ps.append(filePath); } Client* prop; for(int i=0;i<parent->clients.length();i++) { if(parent->clients.value(i)->getId() == ui->q_client->currentData().toString()) { prop = parent->clients.value(i); } } QList<QString> file = ui->l_photoPrincipal->text().split('/'); QString filePath ="../../../../BestResidence/Photos/"+file.value(file.length()-1); QFile::copy(ui->l_photoPrincipal->text(),filePath); if(modif == 0) { QString date = QString::fromStdString(currentDate()); Annonce* a = new Annonce(ui->q_typeAnnonce->currentText(), ui->q_typeBien->currentText(), ui->q_nbPieces->value(), ui->q_superficieTerrain->value(), ui->q_adresse->text(), ui->q_ville->text(), ui->q_codePostal->text(), ui->q_description->toPlainText(), ui->q_prix->value(), QDate::fromString(date, "dd-MM-yyyy"), filePath, ps, 0, prop, NULL); parent->annonces.append(a); prop->setNbContrats(prop->getNbContrats()+1); } else { ann_a_modif->setTypeAnnonce(ui->q_typeAnnonce->currentText()); ann_a_modif->setTypeBien(ui->q_typeBien->currentText()); ann_a_modif->setNbPieces(ui->q_nbPieces->value()); ann_a_modif->setSuperficie(ui->q_superficieTerrain->value()); ann_a_modif->setAdresse(ui->q_adresse->text()); ann_a_modif->setVille(ui->q_ville->text()); ann_a_modif->setCodePostal(ui->q_codePostal->text()); ann_a_modif->setDescription(ui->q_description->toPlainText()); ann_a_modif->setPrix(ui->q_prix->value()); ann_a_modif->setPhotoPrincipale(filePath); ann_a_modif->setPhotosSupp(ps); ann_a_modif->setProp(prop); } parent->setAnnule(false); this->close(); } }
void MainWindow::updateScene() { // Style for points. QPen pen(Qt::black); QBrush brush(Qt::blue); QString details; // Remove all the previous walkItems, that is, the previous triangles // drawn as part of the walk. while (! walkItems.isEmpty() ) scene->removeItem(walkItems.takeFirst()); if (inputPoints >= 0) { // Find the face we are hovering over. Face_handle f = dt->locate(c(points[0])); // Check the face is finite, and then draw it. if (!dt->is_infinite(f)) { QGraphicsItem *tr = Walk<Delaunay>::drawTriangle(f,QPen(),QColor("#D2D2D2")); scene->addItem(tr); walkItems.append(tr); } } // If we have enough data to plot a walk, then do so. if (inputPoints > 0) { Face_handle f = dt->locate(c(points[0])); Face_handle g = dt->locate(c(points[1])); if ( !dt->is_infinite(f) && !dt->is_infinite(g) ) { if (drawStraightWalk) { StraightWalk<Delaunay> w(c(points[1]), dt, f); QGraphicsItem* walkGraphics = w.getGraphics(QPen(),QColor("#EBEBD2")); walkItems.append(walkGraphics); scene->addItem(walkGraphics); details += "<b>Straight Walk</b><br>"; details += "Orientations: "; details += QString::number(w.getNumOrientationsPerformed()); details += "<br>Triangles Visited: "; details += QString::number(w.getNumTrianglesVisited()); details += "<br><br>"; } if (drawVisibilityWalk) { VisibilityWalk<Delaunay> w(c(points[1]), dt, f); QGraphicsItem* walkGraphics = w.getGraphics(QPen(), QColor("#D2D2EB")); walkItems.append(walkGraphics); scene->addItem(walkGraphics); details += "<b>Visibility Walk</b><br>"; details += "Orientations: "; details += QString::number(w.getNumOrientationsPerformed()); details += "<br>Triangles Visited: "; details += QString::number(w.getNumTrianglesVisited()); details += "<br><br>"; } if (drawPivotWalk) { PivotWalk<Delaunay> w(c(points[1]), dt, f); QGraphicsItem* walkGraphics = w.getGraphics(QPen(), QColor("#EBD2D2")); walkItems.append(walkGraphics); scene->addItem(walkGraphics); details += "<b>Pivot Walk</b><br>"; details += "Orientations: "; details += QString::number(w.getNumOrientationsPerformed()); details += "<br>Triangles Visited: "; details += QString::number(w.getNumTrianglesVisited()); details += "<br><br>"; } } } if (inputPoints == 2) { QPoint p = points[1]; walkItems.append(scene->addEllipse(QRect(p, QSize(10,10)),pen,brush)); } status->setText(details); }
void ResizeViewItem::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/){ QBrush brush(color); painter->setBrush(brush); painter->drawRect(QRectF(-box / 2, box / 2)); }
void acCustomGraphicsScene::drawBackground(QPainter *painter, const QRectF &rect) { // color Black QColor ColorBlack(0, 0, 0); // color White QColor ColorWhite(255, 255, 255); // Draw a line grid if (m_gridenabled > 0) { painter->setPen(Qt::white); // Start point for Horizonal steps qreal startH = 0; //Start point for Virtical steps qreal startV = 0; switch (m_gridenabled) { case eCustomGraphicsScene_Grids::Block: { QImage image(":/CompressonatorGUI/Images/GridSolid.png"); QBrush brush(image); painter->fillRect(rect, brush); break; } case eCustomGraphicsScene_Grids::Lines: { // First fill the BackGround as black painter->fillRect(rect, ColorBlack); // draw horizontal grid lines painter->setPen(QPen(ColorWhite)); for (qreal y = startH; y < rect.bottom();) { y += m_gridStep; painter->drawLine(rect.left(), y, rect.right(), y); } // draw virtical grid lines for (qreal x = startV; x < rect.right();) { x += m_gridStep; painter->drawLine(x, rect.top(), x, rect.bottom()); } break; } case eCustomGraphicsScene_Grids::Dots: { // First fill the BackGround as black painter->fillRect(rect, ColorBlack); // draw points painter->setPen(QPen(ColorWhite)); for (qreal y = startH; y < rect.bottom();) { y += m_gridStep; // draw virtical grid lines for (qreal x = startV; x < rect.right();) { x += m_gridStep; painter->drawPoint(x, y); } } break; } default: { painter->fillRect(rect, ColorBlack); break; } } } else painter->fillRect(rect, ColorBlack); }
//绘制一个像素点:这里为了观察方便,绘制10*10的矩形作为像素点 void drawPixelTable(int x, int y,CDC* pDC) { CBrush brush(RGB(22, 22, 22)); CRect rect(x-+1, y+1, x+ PrixlWidth, y+ PrixlWidth); pDC->FillRect(rect, &brush); }
void toBarChart::paintChart(QPainter *p, QRect &rect) { QFontMetrics fm = p->fontMetrics(); if (!Zooming) { if (MinAuto) { bool first = true; std::list<std::list<double> >::reverse_iterator i = Values.rbegin(); if (i != Values.rend()) { for (std::list<double>::iterator j = (*i).begin();j != (*i).end();j++) { if (first) { first = false; zMinValue = *j; } else if (zMinValue > *j) zMinValue = *j; } } } if (MaxAuto) { bool first = true; std::list<double> total; std::list<bool>::iterator e = Enabled.begin(); { for (std::list<std::list<double> >::iterator i = Values.begin();i != Values.end();i++) { std::list<double>::iterator k = total.begin(); if (e == Enabled.end() || *e) { for (std::list<double>::iterator j = (*i).begin();j != (*i).end();j++) { if (k == total.end()) { total.insert(total.end(), *j); k = total.end(); } else { *k += *j; k++; } } } if (e != Enabled.end()) e++; } } for (std::list<double>::iterator i = total.begin();i != total.end();i++) { if (first) { first = false; zMaxValue = *i; } else if (zMaxValue < *i) zMaxValue = *i; } } if (!MinAuto) zMinValue = MinValue; else { zMinValue = round(zMinValue, false); MinValue = zMinValue; } if (!MaxAuto) zMaxValue = MaxValue; else { zMaxValue = round(zMaxValue, true); MaxValue = zMaxValue; } } paintTitle(p, rect); paintLegend(p, rect); paintAxis(p, rect); std::list<QPolygon> Points; int cp = 0; int samples = countSamples(); int zeroy = int(rect.height() - 2 - ( -zMinValue / (zMaxValue - zMinValue) * (rect.height() - 4))); if (samples > 1) { const QMatrix &mtx = p->worldMatrix(); p->setClipRect(int(mtx.dx() + 2), int(mtx.dy() + 2), rect.width() - 3, rect.height() - 3); if (Zooming) p->drawText(2, 2, rect.width() - 4, rect.height() - 4, Qt::AlignLeft | Qt::AlignTop, tr("Zoom")); std::list<bool>::reverse_iterator e = Enabled.rbegin(); for (std::list<std::list<double> >::reverse_iterator i = Values.rbegin();i != Values.rend();i++) { if (e == Enabled.rend() || *e) { std::list<double> &val = *i; int count = 0; int skip = SkipSamples; QPolygon a(samples + 10); int x = rect.width() - 2; for (std::list<double>::reverse_iterator j = val.rbegin();j != val.rend() && x >= 2; j++) { if (skip > 0) skip--; else { int val = int(rect.height() - 2 - ((*j - zMinValue) / (zMaxValue - zMinValue) * (rect.height() - 4))); x = rect.width() - 2 - count * (rect.width() - 4) / (samples - 1); a.setPoint(count, x, val); count++; if (count >= samples) break; } } a.resize(count*2); Points.insert(Points.end(), a); } cp++; if (e != Enabled.rend()) e++; } } std::map<int, int> Bottom; std::list<bool>::reverse_iterator e = Enabled.rbegin(); for (std::list<QPolygon>::iterator i = Points.begin();i != Points.end();) { while (e != Enabled.rend() && !*e) { cp--; e++; } if (e != Enabled.rend()) e++; cp--; QPolygon a = *i; int lx = 0; int lb = 0; for (int j = 0;j < a.size() / 2;j++) { int x, y; a.point(j, &x, &y); if (Bottom.find(x) == Bottom.end()) Bottom[x] = 0; if (lx != x) lb = Bottom[x]; a.setPoint(a.size() - 1 - j, x, zeroy - lb); y -= lb; a.setPoint(j, x, y); Bottom[x] = zeroy - y; lx = x; } p->save(); QBrush brush(toChartBrush(cp)); p->setBrush(brush.color()); p->drawPolygon(a); if (brush.style() != Qt::SolidPattern) { p->setBrush(QBrush(Qt::white, brush.style())); p->drawPolygon(a); } p->restore(); i++; } }
QImage createImage(int width, int height) { QImage image(width, height, QImage::Format_RGB16); QPainter painter; QPen pen; pen.setStyle(Qt::NoPen); QBrush brush(Qt::blue); painter.begin(&image); painter.fillRect(image.rect(), brush); brush.setColor(Qt::white); painter.setPen(pen); painter.setBrush(brush); static const QPointF points1[3] = { QPointF(4, 4), QPointF(7, 4), QPointF(5.5, 1) }; static const QPointF points2[3] = { QPointF(1, 4), QPointF(7, 4), QPointF(10, 10) }; static const QPointF points3[3] = { QPointF(4, 4), QPointF(10, 4), QPointF(1, 10) }; painter.setWindow(0, 0, 10, 10); int x = 0; int y = 0; int starWidth = image.width()/3; int starHeight = image.height()/3; QRect rect(x, y, starWidth, starHeight); for (int i = 0; i < 9; ++i) { painter.setViewport(rect); painter.drawPolygon(points1, 3); painter.drawPolygon(points2, 3); painter.drawPolygon(points3, 3); if (i % 3 == 2) { y = y + starHeight; rect.moveTop(y); x = 0; rect.moveLeft(x); } else { x = x + starWidth; rect.moveLeft(x); } } painter.end(); return image; }
void renderCode128(OROPage * page, const QRectF & r, const QString & _str, int align) { QVector<int> str; int i = 0; // create the list.. if the list is empty then just set a start code and move on if (_str.isEmpty()) str.push_back(104); else { int rank_a = 0; int rank_b = 0; int rank_c = 0; QChar c; for (i = 0; i < _str.length(); ++i) { c = _str.at(i); rank_a += (code128Index(c, SETA) != -1 ? 1 : 0); rank_b += (code128Index(c, SETB) != -1 ? 1 : 0); rank_c += (c >= '0' && c <= '9' ? 1 : 0); } if (rank_c == _str.length() && ((rank_c % 2) == 0 || rank_c > 4)) { // every value in the is a digit so we are going to go with mode C // and we have an even number or we have more than 4 values i = 0; if ((rank_c % 2) == 1) { str.push_back(104); // START B c = _str.at(0); str.push_back(code128Index(c, SETB)); str.push_back(99); // MODE C i = 1; } else str.push_back(105); // START C for (i = i; i < _str.length(); i += 2) { char a, b; c = _str.at(i); a = c.toLatin1(); a -= 48; c = _str.at(i + 1); b = c.toLatin1(); b -= 48; str.push_back(int((a * 10) + b)); } } else { // start in the mode that had the higher number of hits and then // just shift into the opposite mode as needed int set = (rank_a > rank_b ? SETA : SETB); str.push_back((rank_a > rank_b ? 103 : 104)); int v = -1; for (i = 0; i < _str.length(); ++i) { c = _str.at(i); v = code128Index(c, set); if (v == -1) { v = code128Index(c, (set == SETA ? SETB : SETA)); if (v != -1) { str.push_back(98); // SHIFT str.push_back(v); } } else str.push_back(v); } } } // calculate and append the checksum value to the list int checksum = str.at(0); for (i = 1; i < str.size(); ++i) checksum += (str.at(i) * i); checksum = checksum % 103; str.push_back(checksum); // lets determine some core attributes about this barcode qreal bar_width = 1; // the width of the base unit bar 1/100 inch // this is are mandatory minimum quiet zone qreal quiet_zone = bar_width * 10; if (quiet_zone < 0.1) quiet_zone = 0.1; // what kind of area do we have to work with qreal draw_width = r.width(); qreal draw_height = r.height(); // how long is the value we need to encode? int val_length = str.size() - 2; // we include start and checksum in are list so // subtract them out for our calculations // L = (11C + 35)X // L length of barcode (excluding quite zone) in units same as X and I // C the number of characters in the value excluding the start/stop and checksum characters // X the width of a bar (pixels in our case) qreal L; qreal C = val_length; qreal X = bar_width; L = (((11.0 * C) + 35.0) * X); // now we have the actual width the barcode will be so can determine the actual // size of the quiet zone (we assume we center the barcode in the given area // what should we do if the area is too small???? // At the moment the way the code is written is we will always start at the minimum // required quiet zone if we don't have enough space.... I guess we'll just have over-run // to the right // // calculate the starting position based on the alignment option // for left align we don't need to do anything as the values are already setup for it if (align == 1) { // center qreal nqz = (draw_width - L) / 2.0; if (nqz > quiet_zone) quiet_zone = nqz; } else if (align > 1) // right quiet_zone = draw_width - (L + quiet_zone); // else if(align < 1) {} // left : do nothing qreal pos = r.left() + quiet_zone; qreal top = r.top(); QPen pen(Qt::NoPen); QBrush brush(QColor("black")); bool space = false; int idx = 0, b = 0; qreal w = 0.0; for (i = 0; i < str.size(); ++i) { // loop through each value and render the barcode idx = str.at(i); if (idx < 0 || idx > 105) { qDebug("Encountered a non-compliant element while rendering a 3of9 barcode -- skipping"); continue; } space = false; for (b = 0; b < 6; ++b, space = !space) { w = _128codes[idx].values[b] * bar_width; if (!space) { ORORect * rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos, top, w, draw_height)); page->addPrimitive(rect); } pos += w; } } // we have to do the stop character separately like this because it has // 7 elements in it's bar sequence rather than 6 like the others int STOP_CHARACTER[] = { 2, 3, 3, 1, 1, 1, 2 }; space = false; for (b = 0; b < 7; ++b, space = !space) { w = STOP_CHARACTER[b] * bar_width; if (!space) { ORORect * rect = new ORORect(); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos, top, w, draw_height)); page->addPrimitive(rect); } pos += w; } }
void frmListSubtitles::setSubtitlesList(const QList<QNapiSubtitleInfo> & list) { QNapi n; n.addEngines(n.enumerateEngines()); ui.twSubtitles->clear(); ui.twSubtitles->setColumnCount(4); ui.twSubtitles->setRowCount(list.size()); ui.twSubtitles->horizontalHeader()->hide(); ui.twSubtitles->verticalHeader()->hide(); ui.twSubtitles->verticalHeader()->setDefaultSectionSize(20); ui.twSubtitles->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed); int i = 0, good = 0, bad = 0; foreach(QNapiSubtitleInfo s, list) { QTableWidgetItem *item; bool highlight = (s.resolution != SUBTITLE_UNKNOWN); QBrush brush((s.resolution == SUBTITLE_GOOD) ? QColor(qRgb(200, 255, 200)) : QColor(qRgb(255, 200, 200))); if(highlight && (s.resolution == SUBTITLE_GOOD)) ++good; else if(highlight && (s.resolution == SUBTITLE_GOOD)) ++bad; QString lang_path = QString(":/languages/") + s.lang + ".gif"; if(QFile::exists(lang_path)) { item = new QTableWidgetItem(QIcon(lang_path), ""); } else { item = new QTableWidgetItem(s.lang); } if(highlight) item->setBackground(brush); item->setToolTip(s.comment); ui.twSubtitles->setItem(i, 1, item); item = new QTableWidgetItem(s.name); if(highlight) item->setBackground(brush); item->setToolTip(s.comment); ui.twSubtitles->setItem(i, 2, item); item = new QTableWidgetItem(s.format); if(highlight) item->setBackground(brush); item->setToolTip(s.comment); ui.twSubtitles->setItem(i, 3, item); QNapiAbstractEngine *e = n.engineByName(s.engine); if(e) { item = new QTableWidgetItem(e->engineIcon(), ""); if(highlight) item->setBackground(brush); item->setToolTip(s.comment); ui.twSubtitles->setItem(i, 0, item); } ++i; }
void paintEvent(Wt::WPaintDevice *paintDevice) { Wt::WPainter painter(paintDevice); // Draw a grid of rectangles; each one in a different color. for (int row = 0; row < 6; row++) for (int col = 0; col < 6; col++) { // Generate a unique RGB color for each square. Only the red and // green values are modified; the blue channel has a fixed value. Wt::WBrush brush(Wt::WColor(255 - 42*row, 255 - 42*col, 0)); painter.fillRect(row*25, col*25, 25, 25, brush); } painter.translate(0, 160); // Draw a grid of circles similar to the above example but now using the // strokePath method. Wt::WPen pen; pen.setWidth(3); for (int row = 0; row < 6; row++) { for (int col = 0; col < 6; col++) { // Generate a unique RGB color for each circle. Only the green and // blue values are modified; the red channel has a fixed value. Wt::WPainterPath path; path.addEllipse(3 + col*25, 3 + row*25, 20, 20); pen.setColor(Wt::WColor(0, 255 - 42*row, 255 - 42*col)); painter.strokePath(path, pen); } } painter.translate(0, 160); // Transparency example with rectangles // Create a background composed of 4 stacked rectangles. painter.fillRect(0, 0, 150, 37.5, Wt::WBrush(Wt::yellow)); painter.fillRect(0, 37.5, 150, 37.5, Wt::WBrush(Wt::green)); painter.fillRect(0, 75, 150, 37.5, Wt::WBrush(Wt::blue)); painter.fillRect(0, 112.5, 150, 37.5, Wt::WBrush(Wt::red)); // On top of these draw semi transparent rectangles with increasing opacity for (int i = 0; i < 10; i++) { Wt::WBrush brush = Wt::WBrush(Wt::WColor(255, 255, 255, 255/10*i)); for (int j = 0; j < 4; j++) { Wt::WPainterPath path; path.addRect(5 + i*14, 5 + j*37.5, 14, 27.5); painter.fillPath(path, brush); } } painter.translate(0, 160); // Transparency example with circles // Create a square composed of four different colored squares. painter.fillRect(0, 0, 75, 75, Wt::WBrush(Wt::yellow)); painter.fillRect(75, 0, 75, 75, Wt::WBrush(Wt::green)); painter.fillRect(0, 75, 75, 75, Wt::WBrush(Wt::blue)); painter.fillRect(75, 75, 75, 75, Wt::WBrush(Wt::red)); // On top of these draw a set of semi-transparant white circles with // increasing diameter. The final result is a radial gradient. for (int i = 1; i < 8; i++) { Wt::WPainterPath path; path.addEllipse(75 - i*10, 75 - i*10, i*20, i*20); Wt::WBrush brush = Wt::WBrush(Wt::WColor(255, 255, 255, 50)); painter.fillPath(path, brush); } painter.translate(0, 170); // Gradient Brush example // Rectangle with a linear gradient from left top to right bottom painter.setPen(Wt::WPen(Wt::NoPen)); Wt::WGradient linGrad; linGrad.setLinearGradient(0, 0, 100, 150); linGrad.addColorStop(0, Wt::WColor(255, 0, 0, 255)); linGrad.addColorStop(0.5, Wt::WColor(0, 0, 255, 255)); linGrad.addColorStop(1, Wt::WColor(0, 255, 0, 255)); Wt::WBrush linearGradientBrush(linGrad); painter.setBrush(linearGradientBrush); painter.drawRect(0, 0, 100, 150); // Circle with a radial gradient Wt::WGradient radGrad; radGrad.setRadialGradient(170, 100, 50, 130, 130); radGrad.addColorStop(0.2, Wt::WColor(255, 0, 0, 255)); radGrad.addColorStop(0.9, Wt::WColor(0, 0, 255, 255)); radGrad.addColorStop(1, Wt::WColor(0, 0, 255, 0)); Wt::WBrush radialGradientBrush(radGrad); painter.setBrush(radialGradientBrush); painter.drawEllipse(120, 50, 100, 100); painter.translate(0, 170); // LineWidth example // You can use WPainter::drawLine() or WPainter::strokePath() to draw a // line. Using strokePath() you can draw thicker lines. // The line is centered on the path. In other words, the area that's drawn // extends to half the line width on either side of the path. Because // canvas coordinates do not directly reference pixels, you have to take // special care to obtain crisp horizontal and vertical lines. // All lines with an odd integer width thickness in the example below do // not appear crisp, because of the path's positioning. for (int i = 0; i < 11; i++) { Wt::WPainterPath path; path.moveTo(i*14, 0); path.lineTo(i*14, 150); pen = Wt::WPen(); pen.setWidth(i+1); painter.strokePath(path, pen); } painter.translate(160, 0); // LineWidth example with crisp lines // To obtain a crisp line for an odd integer width thickness line you have // to be very precise in your path creation, e.g. a 1.0 width line will // extend half a unit to either side of the path. for (int i = 0; i < 11; i++) { Wt::WPainterPath path; if (i % 2 == 0) { path.moveTo(i*14-0.5, 0); path.lineTo(i*14-0.5, 150); } else { path.moveTo(i*14, 0); path.lineTo(i*14, 150); } pen = Wt::WPen(); pen.setCapStyle(Wt::FlatCap); // Now, all lines will have equal length. pen.setWidth(i+1); painter.strokePath(path, pen); } painter.translate(-160, 170); // PenCapStyle example // The PenCapStyle can be FlatCap, SquareCap or RoundCap. // Start with drawing guides: Wt::WPainterPath guidePath; guidePath.moveTo(0, 10); guidePath.lineTo(150,10); guidePath.moveTo(0,140); guidePath.lineTo(150,140); pen = Wt::WPen(Wt::blue); painter.strokePath(guidePath, pen); // Draw lines with different cap styles // Create three parallel paths: std::vector<Wt::WPainterPath> paths; for (int i = 0; i < 3; i++) { Wt::WPainterPath path; path.moveTo(25+i*50, 10); path.lineTo(25+i*50, 140); paths.push_back(path); } pen = Wt::WPen(); pen.setWidth(20); pen.setCapStyle(Wt::FlatCap); painter.strokePath(paths[0], pen); pen = Wt::WPen(); pen.setWidth(20); pen.setCapStyle(Wt::SquareCap); painter.strokePath(paths[1], pen); pen = Wt::WPen(); pen.setWidth(20); pen.setCapStyle(Wt::RoundCap); painter.strokePath(paths[2], pen); painter.translate(0, 170); // PenJoinStyle example // The PenJoinStyle can be MiterJoin, BevelJoin or RoundJoin. // Create three parallel paths: paths.clear(); for (int i = 0; i < 3; i++) { Wt::WPainterPath path; path.moveTo(15, 5+i*40); path.lineTo(45, 45+i*40); path.lineTo(75, 5+i*40); path.lineTo(105,45+i*40); path.lineTo(135, 5+i*40); paths.push_back(path); } // Draw the first path with miter joins. // The connected segments are joined by extending their outside edges to // connect at a single point. pen = Wt::WPen(); pen.setWidth(20); pen.setJoinStyle(Wt::MiterJoin); painter.strokePath(paths[0], pen); // Draw the second path with bevel joins. // An additional triangular area is filled between the common endpoint of // connected segments and the separate outside rectangular corners of each // segment. pen = Wt::WPen(); pen.setWidth(20); pen.setJoinStyle(Wt::BevelJoin); painter.strokePath(paths[1], pen); // Draw the third path with round joins. // The corners of the shape are rounded off by filling an aditonal sector // of disc centered at the common endpoint of connected segments. The // radius of the rounded corners is equal to the line width. pen = Wt::WPen(); pen.setWidth(20); pen.setJoinStyle(Wt::RoundJoin); painter.strokePath(paths[2], pen); }
void GCDCGraphs::DrawSeasonLimitInfo(wxGraphicsContext &dc, int i, int month, int day, bool summer) { const double stripe_width = 2; double x1 = GetX(i); double x2 = GetX(i + 1); double x = (x1 + x2) / 2; int w, h; GetClientSize(&w, &h); wxColour color = summer ? *wxBLUE : *wxRED; dc.SetFont(GetFont(), color); dc.SetPen(wxPen(color, 1, wxSOLID)); wxBrush brush(color); dc.SetBrush(brush); dc.DrawRectangle(x + 1, m_screen_margins.topmargin, stripe_width, w - m_screen_margins.topmargin - m_screen_margins.bottommargin); wxString str; if (summer) str = wxString(_("summer season")); else str = wxString(_("winter season")); str += wxString::Format(_T(" %d "), day); switch (month) { case 1: str += _("january"); break; case 2: str += _("february"); break; case 3: str += _("march"); break; case 4: str += _("april"); break; case 5: str += _("may"); break; case 6: str += _("june"); break; case 7: str += _("july"); break; case 8: str += _("august"); break; case 9: str += _("septermber"); break; case 10: str += _("october"); break; case 11: str += _("november"); break; case 12: str += _("december"); break; default: assert(false); } double tw, th, td, tsel; dc.GetTextExtent(_T("W"), &tw, &th, &td, &tsel); int ty = m_screen_margins.topmargin + 1; for (size_t i = 0; i < str.Len(); ++i) { double lw, lh, ld, lsel; wxString letter = str.Mid(i, 1); dc.GetTextExtent(letter, &lw, &lh, &ld, &lsel); dc.DrawText(letter, x + stripe_width + 2 + (tw - lw) / 2, ty); ty += th + 2; } }
void LayeredWindowBase::Render() { wchar_t pszbuf[] = L"1.Text Designer中文字也可顯示\n2.Text Designer中文字也可顯示\n3.Text Designer中文字也可顯示\n4.Text Designer中文字也可顯示\n5.Text Designer中文字也可顯示\n6.Text Designer中文字也可顯示 Text Designer中文字也可顯示\n7.Text Designer中文字也可顯示\n8.Text Designer中文字也可顯示\n9.Text Designer中文字也可顯示\n10.Text Designer中文字也可顯示"; int nStrLen = wcslen(pszbuf); if (m_techType & LayeredWindow_TechType_D2D) { //m_pWin.pD2D->BeginDraw(); m_pWin.pD2D->m_pRenderTarget->Clear(D2D1::ColorF(D2D1::ColorF::White,0.5)); //m_pWin.pD2D->m_pRenderTarget->DrawText(pszbuf,nStrLen, // // IFR(m_spDWriteFactory->CreateTextFormat( // msc_fontName, // NULL, // DWRITE_FONT_WEIGHT_NORMAL, // DWRITE_FONT_STYLE_NORMAL, // DWRITE_FONT_STRETCH_NORMAL, // msc_fontSize, // L"", //locale // &m_spTextFormat // )); //// Center the text both horizontally and vertically. //m_spTextFormat->SetTextAlignment( // DWRITE_TEXT_ALIGNMENT_CENTER // ); //m_spTextFormat->SetParagraphAlignment( // DWRITE_PARAGRAPH_ALIGNMENT_CENTER // ); //m_pWin.pD2D->m_pRenderTarget->DrawText( // pszbuf,nStrLen, // m_spTextFormat, // D2D1::RectF( // 0,0,rtSize.width, rtSize.height // ), // m_spBlackBrush // );) //m_pWin.pD2D->EndDraw(); } else if (m_techType & LayeredWindow_TechType_GDI) { //m_pWin.pGDI->BeginDraw(); //Gdiplus::Graphics graphics( m_pBitmap->GetDC() ); //#MOD m_pWin.pGDI->m_pGraphics->Clear( Gdiplus::Color( 128, 255, 255, 255 ) ); Gdiplus::FontFamily fontFamily(L"微軟正黑體"); Gdiplus::Font oMS( &fontFamily, 32, Gdiplus::FontStyle::FontStyleRegular, Gdiplus::Unit::UnitPixel ); Gdiplus::StringFormat strformat; Gdiplus::GraphicsPath *Path; Gdiplus::GraphicsPath path; // Region *aRegion; Gdiplus::RectF rectf; rectf.X = 10; rectf.Y = 10; rectf.Width = 500; rectf.Height = 500; path.AddString(pszbuf, nStrLen, &fontFamily, Gdiplus::FontStyleRegular, 32,rectf,&strformat ); Gdiplus::SolidBrush brush(Gdiplus::Color(255,100,255)); m_pWin.pGDI->m_pGraphics->FillPath(&brush, &path); //SelectObject(m_bitmap.m_hdc, m_bitmap.m_bitmap); //m_pWin.pGDI->EndDraw(); } }
void CBlockUnit::DrawBlock(Graphics *pGraph) { Pen pen(Color(0, 0, 0)); Font fontBold(L"Tahoma", 10, FontStyleBold); Font fontNormal(L"Tahoma", 10, FontStyleRegular); SolidBrush brush(Color(0, 0, 0)); // Check & update block size UINT nMinWidth = GetMinWidth(); UINT nMinHeight = GetMinHeight(); if ((INT)m_rRect.Width < (INT)nMinWidth) { m_rRect.Width = ROUND(nMinWidth); } if ((INT)m_rRect.Height < (INT)nMinHeight) { m_rRect.Height = ROUND(nMinHeight); } // select color according to type switch (m_nType) { case T_FUNCTION: { brush.SetColor(Color(220, 220, 255)); } break; case T_SUBSYSTEM: { brush.SetColor(Color(255, 220, 220)); } break; case T_TEXTBOX: { brush.SetColor(Color(255, 255, 230)); } break; case T_INPUT: { brush.SetColor(Color(255, 255, 220)); } break; case T_OUTPUT: { brush.SetColor(Color(255, 255, 220)); } break; default: { ASSERT(TRUE); } } // Mark selected if (m_bSelected) { pen.SetWidth(2); } // Outline error connections if (m_bError) { pen.SetColor(Color(255, 100, 100)); } else { pen.SetColor(Color(0, 0, 0)); } // Draw rectangle body pGraph->FillRectangle(&brush, m_rRect); pGraph->DrawRectangle(&pen, m_rRect); if ((m_nType != T_INPUT) && (m_nType != T_OUTPUT)) { pen.SetWidth(1); brush.SetColor(Color(0, 0, 0)); RectF rect, rectSize; StringFormat format; // Write title string if (m_nType == T_TEXTBOX) { rect = RectF(m_rRect.X, m_rRect.Y, m_rRect.Width, m_rRect.Height); wstring ws(m_sName.begin(), m_sName.end()); pGraph->DrawString(ws.c_str(), -1, &fontNormal, rect, &format, &brush); // Measure title text width rect.Width = 0; pGraph->MeasureString(ws.c_str(), -1, &fontNormal, rect, &format, &rectSize); m_lName = (INT)rectSize.Width; } else { // Draw title line pGraph->DrawLine(&pen, m_rRect.X, m_rRect.Y+20, m_rRect.GetRight(), m_rRect.Y+20); format.SetAlignment(StringAlignmentCenter); format.SetLineAlignment(StringAlignmentCenter); rect = RectF(m_rRect.X, m_rRect.Y, m_rRect.Width, 20); wstring ws(m_sName.begin(), m_sName.end()); pGraph->DrawString(ws.c_str(), -1, &fontBold, rect, &format, &brush); // Measure title text width rect.Width = 0; pGraph->MeasureString(ws.c_str(), -1, &fontBold, rect, &format, &rectSize); m_lName = (INT)rectSize.Width; } } // Draw input variables Point ptInput(m_rRect.X, m_rRect.GetTop() + 10); if ((m_nType != T_INPUT) && (m_nType != T_OUTPUT)) { ptInput.Y += 20; } for (int i=0; i<m_vInput.size(); i++) { // Skip if input port if (m_nType == T_INPUT) { break; } // Draw port m_vInput[i]->DrawIOPort(pGraph, ptInput.X, ptInput.Y); ptInput.Y += 20; // Only draw one if I/O ports if (m_nType == T_OUTPUT) { break; } } // Draw output variables Point ptOutput(m_rRect.GetRight(), m_rRect.Y + 10); if ((m_nType != T_INPUT) && (m_nType != T_OUTPUT)) { ptOutput.Y += 20; } for (int i=0; i<m_vOutput.size(); i++) { // Skip if output port if (m_nType == T_OUTPUT) { break; } // Draw port m_vOutput[i]->DrawIOPort(pGraph, ptOutput.X, ptOutput.Y); ptOutput.Y += 20; // Only draw one if I/O ports if (m_nType == T_INPUT) { break; } } }
void Popover::generateMask(Direction direction, int offset) { mMask = new QBitmap(size()); mMask->clear(); QPainter maskPainter(mMask); QBrush brush(Qt::color1); maskPainter.setBrush(brush); // Clip to valid locations. offset = std::max(offset, 26); if(direction == Direction::Top || direction == Direction::Bottom) { offset = std::min(offset, mMask->width()-26); } else { offset = std::min(offset, mMask->height()-26); } switch(direction) { case Top: //Add the rounded rect. maskPainter.drawRoundedRect(0,20,mMask->width(),mMask->height()-20,5,5); //Add the triangle. maskPainter.drawPolygon(QPolygon({ QPoint(offset, 0), QPoint(offset-20, 20), QPoint(offset+20, 20)})); layout()->setContentsMargins(12, 32, 12, 12); break; case Right: //Add the rounded rect. maskPainter.drawRoundedRect(0,0,mMask->width()-20,mMask->height(),5,5); //Add the triangle. maskPainter.drawPolygon(QPolygon({ QPoint(mMask->width(), offset), QPoint(mMask->width()-20, offset-20), QPoint(mMask->width()-20, offset+20)})); layout()->setContentsMargins(12, 12, 32, 12); break; case Bottom: //Add the rounded rect. maskPainter.drawRoundedRect(0,0,mMask->width(),mMask->height()-20,5,5); //Add the triangle. maskPainter.drawPolygon(QPolygon({ QPoint(offset, mMask->height()), QPoint(offset-20, mMask->height()-20), QPoint(offset+20, mMask->height()-20)})); layout()->setContentsMargins(12, 12, 12, 32); break; case Left: //Add the rounded rect. maskPainter.drawRoundedRect(20,0,mMask->width()-20,mMask->height(),5,5); //Add the triangle. maskPainter.drawPolygon(QPolygon({ QPoint(0, offset), QPoint(20, offset-20), QPoint(20, offset+20)})); layout()->setContentsMargins(32, 12, 12, 12); break; } setMask(*mMask); }
bool PSV_ChartItem::addEllipseItem(PSV_CurveInfo &curveInfo) { if(curveInfo.m_isHidden) { return true; } setCurrentAxisType(curveInfo.m_axisType); QMap<double, double> curveData = curveInfo.m_curveDataMap; QMapIterator<double, double> iter(curveData); QPolygonF polygon; int m_radius = curveInfo.m_pointSize; double pointY0 = getAxisY(*m_min_y_curP,m_radius);; QPointF fisrtPoint(0,pointY0); QString curveName = curveInfo.m_curveName; QPen pen(curveInfo.m_pointColor); QBrush brush(curveInfo.m_pointColor); int count =1; double previous_time = 1.0 * qrand(); QGraphicsEllipseItem* preItem = NULL; int index = 1; while(iter.hasNext()) { iter.next(); double x = getAxisX(iter.key(),m_radius); double y = getAxisY(iter.value(),m_radius); QPointF point(x, y); if(index == 1) { fisrtPoint = QPointF(x + m_radius,pointY0 + m_radius); polygon.append(fisrtPoint); } polygon.append(QPointF(x+m_radius,y+m_radius)); if(index == curveData.count()) { polygon.append(QPointF(x + m_radius,pointY0 + m_radius)); polygon.append(fisrtPoint); } index++; QGraphicsEllipseItem *ellipse_item = new QGraphicsEllipseItem(this); ellipse_item->setZValue(m_curveZValue); ellipse_item->setRect(0,0,2*m_radius,2*m_radius); ellipse_item->setPos(point); ellipse_item->setFlag(QGraphicsItem::ItemIsSelectable); ellipse_item->setPen(pen); ellipse_item->setBrush(brush); ellipse_item->setData(E_CURVE_NAME,curveName); //设置属于哪条曲线 ellipse_item->setData(E_AXIS_X,iter.key()); //设置对应的X坐标轴值 ellipse_item->setData(E_PREVIOUS_TIME,previous_time); ellipse_item->setData(E_NEXT_TIME,previous_time); ellipse_item->setData(E_POINT_TYPE,EV_FIRST); ellipse_item->setData(E_ITEM_TYPE,PSV::ellipseItem); ellipse_item->setToolTip(getToolTipText(iter.key(),iter.value())); ellipse_item->installSceneEventFilter(this); if(ellipse_item != NULL) { preItem->setData(E_NEXT_TIME,iter.key()); if(count == curveData.count() - 1) { ellipse_item->setData(E_POINT_TYPE,EV_LAST); } else if(count != 1) { ellipse_item->setData(E_POINT_TYPE,EV_MID); } } preItem = ellipse_item; previous_time = iter.key(); } curveInfo.m_polygon = polygon; m_curveZValue++; return true; }
void PSV_ChartItem::updateForDouble() { QMapIterator<QString,PSV_CurveInfo> iter(m_curveDataMap); qreal posY = m_staStartPoint.y(); qreal posX = m_staStartPoint.x(); while(iter.hasNext()) { iter.next(); PSV_CurveInfo curveInfo = iter.value(); updateAxisRange(curveInfo.m_axisType); addCurveItem(curveInfo); addEllipseItem(curveInfo); if(!isStaHidden()) { QGraphicsTextItem *textItem = new QGraphicsTextItem(this); textItem->setData(E_ITEM_TYPE,PSV::staLabelItem); textItem->setData(E_CURVE_NAME,curveInfo.m_curveName); textItem->setFlags(QGraphicsItem::ItemIsSelectable); textItem->installSceneEventFilter(this); textItem->setDefaultTextColor(getDefaultColor()); textItem->setFont(staFont()); textItem->setHtml(curveInfo.m_staHtmText); double textHeight = textItem->boundingRect().height(); int staMaxHeight = (int)textHeight* 6 / 10; textItem->setPos(posX + textItem->boundingRect().height(),posY); QPixmap pixmap(staMaxHeight,staMaxHeight); pixmap.fill(); QPen pen(curveInfo.m_lineColor); pen.setWidth(3); QPainter painter(&pixmap); painter.setPen(pen); if(!curveInfo.m_isHidden) { QBrush brush(curveInfo.m_lineColor); painter.setBrush(brush); } painter.drawRect(0, 0, pixmap.height(), pixmap.height()); QGraphicsPixmapItem* pixmapItem = new QGraphicsPixmapItem(pixmap,this); pixmapItem->setPixmap(pixmap); pixmapItem->setPos(posX,posY + textHeight * 2 / 10); pixmapItem->setData(E_ITEM_TYPE,PSV::staLabelItem); pixmapItem->setData(E_CURVE_NAME,curveInfo.m_curveName); pixmapItem->setFlags(QGraphicsItem::ItemIsSelectable); pixmapItem->installSceneEventFilter(this); if(posX + 2 * m_staMaxWidth > m_chartRect.right()) { posX = m_staStartPoint.x(); posY += textItem->boundingRect().height() + getData(PSV::margin,3).toInt(); } else { posX += m_staMaxWidth; } } } //TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT // QGraphicsRectItem *item = new QGraphicsRectItem(m_rect,this);//TTTTTTTTTTTTTTT // item->setPen(QPen(QColor(Qt::red)));//TTTTTTTTTTTTTTT //TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT }
int main() { init(); brush(); quit(); return 0; }
void stitch::Vec3::equidistantVectors_FibonacciSpiralSphere(const size_t minimumNumVectors, std::vector<stitch::Vec3> &vectors, std::vector<size_t> &binIndices) { //std::cout << "stitch::Vec3::equidistantVectors_FibonacciSpiralSphere(...)..."; //std::cout.flush(); vectors.clear(); binIndices.clear(); //Generate the vectors based on the golden section spiral a.k.a. the Fibonacci Spiral sphere. const float phi=(sqrtf(5.0f)+1.0f)/2.0f-1.0f; const float ga=phi * ((float)M_PI); for (size_t vectorNum=0; vectorNum<minimumNumVectors; ++vectorNum) { const float lon=ga * vectorNum; const float lat=asinf(stitch::MathUtil::clamp(-1.0f + (2.0f * vectorNum)/minimumNumVectors, -1.0f, 1.0f)); #ifdef USE_CXX11 vectors.emplace_back(cosf(lon)*cosf(lat), sinf(lon)*cosf(lat), sinf(lat)); #else vectors.push_back(Vec3(cosf(lon)*cosf(lat), sinf(lon)*cosf(lat), sinf(lat))); #endif } //Build a brush that contains the sphere and use the updateVerticesAndLines method to create a new set of vertices and indices. // It is assumed that a tesselation of the Fiboncci Spiral sphere would be strickly convex. // Ducplicate brush vertices are not added. { stitch::Brush brush(new stitch::DiffuseMaterial(stitch::Colour_t(0.9f, 0.9f, 0.9f))); const size_t numVertices=vectors.size(); //=== Create a permutation of vertices v0, v1, v2 === for (size_t vertexNum0=0; vertexNum0<numVertices; ++vertexNum0) { for (size_t vertexNum1=vertexNum0+1; vertexNum1<numVertices; ++vertexNum1) { for (size_t vertexNum2=vertexNum1+1; vertexNum2<numVertices; ++vertexNum2) { stitch::Vec3 v0=vectors[vertexNum0]; stitch::Vec3 v1=vectors[vertexNum1]; stitch::Vec3 v2=vectors[vertexNum2]; stitch::Plane plane(v0, v1, v2); bool verticesOnPositiveSide=false; bool verticesOnNegativeSide=false; //Test if this permutation of vertices defines a brush face. for (size_t vertexNum=0; vertexNum<numVertices; ++vertexNum) { if ((vertexNum!=vertexNum0) && (vertexNum!=vertexNum1) && (vertexNum!=vertexNum2)) { stitch::Vec3 v=vectors[vertexNum]; if (v * plane.normal_<plane.d_) { verticesOnNegativeSide=true; } else { verticesOnPositiveSide=true; } if (verticesOnPositiveSide && verticesOnNegativeSide) { break; //from for loop. Permutation of vertices v0, v1, v2 is not on a brush plane. } } } if (verticesOnPositiveSide && (!verticesOnNegativeSide)) {//All vertices on postive side i.e. this is a brush face. //Flip brush face normal to have all other vertices on negative/in side of face. plane.normal_=plane.normal_ * -1.0f; plane.d_=plane.d_ * -1.0f; brush.addFace(stitch::BrushFace(plane, false)); } if ((!verticesOnPositiveSide) && verticesOnNegativeSide) {//All vertices on negative side i.e. this is a brush face. brush.addFace(stitch::BrushFace(plane, false)); } } } //if ((vertexNum0%10)==0) //{ //std::cout << 100.0f * (vertexNum0 / ((float)numVertices)) << "%..."; //std::cout.flush(); //} } //=== === //=== Calculate the face vertices from the brush face planes === brush.updateLinesVerticesAndBoundingVolume(true); //=== === //=== Create fresh vectors and indices from the brush === // The vectors should be the same as those generated by the Fibonacci spiral, // but possibly in a different order. vectors.clear(); const size_t numFaces=brush.getNumFaces(); for (size_t faceNum=0; faceNum<numFaces; ++faceNum) { const stitch::BrushFace &face=brush.getFaceByConstRef(faceNum); size_t numFaceVertices=face.vertexCoordVector_.size(); if (numFaceVertices>=4) { //The first face vertex is the centre vertex so start at the second vertex. stitch::Vec3 v0=face.vertexCoordVector_[1]; //If there are more than 3 perimeter vertices then v0 will be used as the common vertex to // generate (numFaceVertices-2) triangle bins. for (size_t faceVertexNum=3; faceVertexNum<numFaceVertices; ++faceVertexNum) { stitch::Vec3 v1=face.vertexCoordVector_[faceVertexNum-1l]; stitch::Vec3 v2=face.vertexCoordVector_[faceVertexNum]; ssize_t i0=-1; ssize_t i1=-1; ssize_t i2=-1; //Check if any of the face vertices are already in the vectors list. size_t numVectors=vectors.size(); for (size_t vectorNum=0; vectorNum<numVectors; ++vectorNum) { stitch::Vec3 v=vectors[vectorNum]; if ((i0<0l)&&(Vec3::calcDistToPointSq(v, v0)<0.00001f)) i0=vectorNum; if ((i1<0l)&&(Vec3::calcDistToPointSq(v, v1)<0.00001f)) i1=vectorNum; if ((i2<0l)&&(Vec3::calcDistToPointSq(v, v2)<0.00001f)) i2=vectorNum; } if (i0<0l) {//This is a new vector. vectors.push_back(v0); i0=vectors.size()-1; } if (i1<0l) {//This is a new vector. vectors.push_back(v1); i1=vectors.size()-1; } if (i2<0l) {//This is a new vector. vectors.push_back(v2); i2=vectors.size()-1; } binIndices.push_back(i0); binIndices.push_back(i1); binIndices.push_back(i2); } } } //=== ===// } //=== ===// //std::cout << "vectors.size()="<<vectors.size()<<" done.\n"; //std::cout.flush(); }
void ProcessDateTime::UpdateTexture() { Status stat; RectF layoutBox; SIZE textSize; RectF boundingBox(0.0f, 0.0f, 32.0f, 32.0f); UpdateCurrentText(); if (bUpdateTexture) { bUpdateTexture = false; if (hFont) { DeleteObject(hFont); hFont = NULL; } hFont = GetFont(); if (!hFont) return; } StringFormat format(Gdiplus::StringFormat::GenericTypographic()); SetStringFormat(format); HDC hdc = CreateCompatibleDC(NULL); Font font(hdc, hFont); Graphics graphics(hdc); graphics.SetTextRenderingHint(TextRenderingHintAntiAlias); if (strCurrentText.IsValid()) { stat = graphics.MeasureString(strCurrentText, -1, &font, PointF(0.0f, 0.0f), &format, &boundingBox); if (stat != Ok) Log::writeError(LOG_RTSPSERV, 1, "TextSource::UpdateTexture: Gdiplus::Graphics::MeasureString failed: %u", (int)stat); if (bUseOutline) { //Note: since there's no path widening in DrawOutlineText the padding is half than what it was supposed to be. boundingBox.Width += outlineSize; boundingBox.Height += outlineSize; } } DeleteDC(hdc); hdc = NULL; if (boundingBox.Height < size) { textSize.cy = size; boundingBox.Height = float(size); } else textSize.cy = LONG(boundingBox.Height + EPSILON); textSize.cx = LONG(boundingBox.Width + EPSILON); //textSize.cx &= 0xFFFFFFFE; //textSize.cy &= 0xFFFFFFFE; textSize.cx += textSize.cx % 2; textSize.cy += textSize.cy % 2; ClampVal(textSize.cx, 32, 8192); ClampVal(textSize.cy, 32, 8192); //---------------------------------------------------------------------- // write image { HDC hTempDC = CreateCompatibleDC(NULL); BITMAPINFO bi; zero(&bi, sizeof(bi)); void* lpBits; BITMAPINFOHEADER &bih = bi.bmiHeader; bih.biSize = sizeof(bih); bih.biBitCount = 32; bih.biWidth = textSize.cx; bih.biHeight = textSize.cy; bih.biPlanes = 1; HBITMAP hBitmap = CreateDIBSection(hTempDC, &bi, DIB_RGB_COLORS, &lpBits, NULL, 0); Bitmap bmp(textSize.cx, textSize.cy, 4 * textSize.cx, PixelFormat32bppARGB, (BYTE*)lpBits); Graphics graphics(&bmp); SolidBrush brush(Gdiplus::Color(GetAlphaVal(opacity) | (color & 0x00FFFFFF))); DWORD bkColor; bkColor = ((strCurrentText.IsValid()) ? GetAlphaVal(0) : GetAlphaVal(0)); if (textSize.cx > boundingBox.Width || textSize.cy > boundingBox.Height) { stat = graphics.Clear(Gdiplus::Color(0x00000000)); if (stat != Gdiplus::Ok) Log::writeError(LOG_RTSPSERV, 1, "TextSource::UpdateTexture: Graphics::Clear failed: %u", (int)stat); SolidBrush *bkBrush = new SolidBrush(Gdiplus::Color(bkColor)); graphics.FillRectangle(bkBrush, boundingBox); delete bkBrush; } else { stat = graphics.Clear(Gdiplus::Color(bkColor)); if (stat != Ok) Log::writeError(LOG_RTSPSERV, 1, "TextSource::UpdateTexture: Graphics::Clear failed: %u", (int)stat); } graphics.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias); graphics.SetCompositingMode(Gdiplus::CompositingModeSourceOver); graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias); if (strCurrentText.IsValid()) { if (bUseOutline) { boundingBox.Offset(outlineSize / 2, outlineSize / 2); FontFamily fontFamily; GraphicsPath path; font.GetFamily(&fontFamily); path.AddString(strCurrentText, -1, &fontFamily, font.GetStyle(), font.GetSize(), boundingBox, &format); DrawOutlineText(&graphics, font, path, format, &brush); } else { stat = graphics.DrawString(strCurrentText, -1, &font, boundingBox, &format, &brush); if (stat != Gdiplus::Ok) Log::writeError(LOG_RTSPSERV, 1, "TextSource::UpdateTexture: Graphics::DrawString failed: %u", (int)stat); } } //---------------------------------------------------------------------- // upload texture if (textureSize.cx != textSize.cx || textureSize.cy != textSize.cy) { if (texture) { delete texture; texture = NULL; } mcpy(&textureSize, &textSize, sizeof(textureSize)); texture = CreateTexture(textSize.cx, textSize.cy, GS_BGRA, lpBits, FALSE, FALSE); } else if (texture) SetImage(texture,lpBits, GS_IMAGEFORMAT_BGRA, 4 * textSize.cx); if (!texture) { Log::writeError(LOG_RTSPSERV,1,"TextSource::UpdateTexture: could not create texture"); DeleteObject(hFont); } DeleteDC(hTempDC); DeleteObject(hBitmap); } }
VisibleAreaMode::VisibleAreaMode(QGraphicsScene& scene, Toolbar& toolbar) : AbstractMode(scene), toolbar_(toolbar), initialized_(false), rectTop(new QGraphicsRectItem), rectBottom(new QGraphicsRectItem), rectLeft(new QGraphicsRectItem), rectRight(new QGraphicsRectItem), lineTop(new QGraphicsLineItem), lineBottom(new QGraphicsLineItem), lineLeft(new QGraphicsLineItem), lineRight(new QGraphicsLineItem) { QPen pen(Qt::NoPen); QBrush brush(Qt::black); rectTop->setOpacity(.65); rectBottom->setOpacity(.65); rectLeft->setOpacity(.65); rectRight->setOpacity(.65); rectTop->setPen(pen); rectBottom->setPen(pen); rectLeft->setPen(pen); rectRight->setPen(pen); rectTop->setBrush(brush); rectBottom->setBrush(brush); rectLeft->setBrush(brush); rectRight->setBrush(brush); rectTop->setZValue(1); rectBottom->setZValue(1); rectLeft->setZValue(1); rectRight->setZValue(1); // First rectangle fullscreen rectTop->setRect(0, 0, scene.width(), scene.height()); scene.addItem(rectTop); scene.addItem(rectBottom); scene.addItem(rectLeft); scene.addItem(rectRight); QPen linePen; linePen.setWidthF(.2); linePen.setColor(QColor(230, 230, 230)); lineTop->setPen(linePen); lineBottom->setPen(linePen); lineLeft->setPen(linePen); lineRight->setPen(linePen); lineTop->setZValue(1); lineBottom->setZValue(1); lineLeft->setZValue(1); lineRight->setZValue(1); scene.addItem(lineTop); scene.addItem(lineBottom); scene.addItem(lineLeft); scene.addItem(lineRight); }
bool QgsComposerItem::_writeXML( QDomElement& itemElem, QDomDocument& doc ) const { if ( itemElem.isNull() ) { return false; } QDomElement composerItemElem = doc.createElement( "ComposerItem" ); //frame if ( mFrame ) { composerItemElem.setAttribute( "frame", "true" ); } else { composerItemElem.setAttribute( "frame", "false" ); } //scene rect composerItemElem.setAttribute( "x", QString::number( transform().dx() ) ); composerItemElem.setAttribute( "y", QString::number( transform().dy() ) ); composerItemElem.setAttribute( "width", QString::number( rect().width() ) ); composerItemElem.setAttribute( "height", QString::number( rect().height() ) ); composerItemElem.setAttribute( "zValue", QString::number( zValue() ) ); composerItemElem.setAttribute( "outlineWidth", QString::number( pen().widthF() ) ); composerItemElem.setAttribute( "rotation", QString::number( mRotation ) ); composerItemElem.setAttribute( "id", mId ); //position lock for mouse moves/resizes if ( mItemPositionLocked ) { composerItemElem.setAttribute( "positionLock", "true" ); } else { composerItemElem.setAttribute( "positionLock", "false" ); } composerItemElem.setAttribute( "lastValidViewScaleFactor", QString::number( mLastValidViewScaleFactor ) ); //frame color QDomElement frameColorElem = doc.createElement( "FrameColor" ); QColor frameColor = pen().color(); frameColorElem.setAttribute( "red", QString::number( frameColor.red() ) ); frameColorElem.setAttribute( "green", QString::number( frameColor.green() ) ); frameColorElem.setAttribute( "blue", QString::number( frameColor.blue() ) ); frameColorElem.setAttribute( "alpha", QString::number( frameColor.alpha() ) ); composerItemElem.appendChild( frameColorElem ); //background color QDomElement bgColorElem = doc.createElement( "BackgroundColor" ); QColor bgColor = brush().color(); bgColorElem.setAttribute( "red", QString::number( bgColor.red() ) ); bgColorElem.setAttribute( "green", QString::number( bgColor.green() ) ); bgColorElem.setAttribute( "blue", QString::number( bgColor.blue() ) ); bgColorElem.setAttribute( "alpha", QString::number( bgColor.alpha() ) ); composerItemElem.appendChild( bgColorElem ); itemElem.appendChild( composerItemElem ); return true; }
HRESULT CGifSmileyCtrl::OnDrawSmiley(ATL_DRAWINFO& di, bool bCustom=false) { USES_CONVERSION; if (di.dwDrawAspect != DVASPECT_CONTENT) { return E_FAIL; } if ( bCustom && !IsVisible(di)) { return S_OK; } if (!m_pGifImage) { return E_FAIL; } RECT& rc = *(RECT*)di.prcBounds; HRGN hOldRgn, hNewRgn; if (!IsRectEmpty(&m_rectPos)) { //strange workaround for drawing zoom out smileys (look MS calculate it one pix larger than exactly) if (rc.bottom-rc.top-1 == m_rectPos.bottom-m_rectPos.top && rc.right-rc.left== m_rectPos.right-m_rectPos.left) rc.top+=1; } if ( bCustom )SelectSmileyClipRgn(di.hdcDraw, rc, hOldRgn, hNewRgn, TRUE); InflateRect(&rc,-1,0); //border offset to fix blinked cursor painting if ( (m_dwFlags&REO_INVERTEDSELECT) == 0 || !bCustom || m_bTransparent) DoDrawSmiley(di.hdcDraw, rc, rc.right-rc.left,rc.bottom-rc.top, m_nFrameSize.Width, m_nFrameSize.Height); else { Bitmap bmp(rc.right-rc.left,rc.bottom-rc.top, PixelFormat32bppARGB); Graphics g(&bmp); COLORREF col=(COLORREF)(m_clrBackColor); SolidBrush brush(Color(GetRValue(col),GetGValue(col),GetBValue(col))); g.FillRectangle( &brush, 0 ,0, rc.right-rc.left, rc.bottom-rc.top); HDC hdc=g.GetHDC(); RECT mrc={0}; mrc.right=rc.right-rc.left; mrc.bottom=rc.bottom-rc.top; DoDrawSmiley(hdc, mrc, mrc.right-mrc.left,mrc.bottom-mrc.top, m_nFrameSize.Width, m_nFrameSize.Height); InvertRect(hdc, &mrc); BitBlt(di.hdcDraw, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, hdc, 0, 0, SRCCOPY ); g.ReleaseHDC(hdc); } if ((m_dwFlags&REO_SELECTED) == REO_SELECTED && bCustom) { //Draw frame around HBRUSH oldBrush=(HBRUSH)SelectObject(di.hdcDraw, GetStockObject(NULL_BRUSH)); HPEN oldPen=(HPEN)SelectObject(di.hdcDraw, GetStockObject(BLACK_PEN)); ::Rectangle(di.hdcDraw, rc.left, rc.top, rc.right, rc.bottom ); SelectObject(di.hdcDraw, oldBrush); SelectObject(di.hdcDraw, oldPen); } AdvanceFrame(); if (!bCustom) m_bPaintValid=false; ResetClip(di.hdcDraw, hOldRgn, hNewRgn); return S_OK; }
void GraphicsTextButtonItem::hoverEnterEvent(QGraphicsSceneHoverEvent * event) { _normalBrush = brush(); setBrush(_rolloverBrush); QGraphicsSimpleTextItem::hoverEnterEvent(event); }
// EFW - Various changes to make it draw cells better when using alternate // color schemes. Also removed printing references as that's now done // by PrintCell() and fixed the sort marker so that it doesn't draw out // of bounds. BOOL CGridCellBase::Draw(CDC* pDC, int nRow, int nCol, CRect rect, BOOL bEraseBkgnd /*=TRUE*/) { CGridCtrl* pGrid = GetGrid(); ASSERT(pGrid); if (!pGrid || !pDC) return FALSE; if( rect.Width() <= 0 || rect.Height() <= 0) // prevents imagelist item from drawing even return FALSE; // though cell is hidden //TRACE3("Drawing %scell %d, %d\n", IsFixed()? _T("Fixed ") : _T(""), nRow, nCol); int nSavedDC = pDC->SaveDC(); pDC->SetBkMode(TRANSPARENT); // Get the default cell implementation for this kind of cell. We use it if this cell // has anything marked as "default" CGridDefaultCell *pDefaultCell = (CGridDefaultCell*) GetDefaultCell(); if (!pDefaultCell) return FALSE; // Set up text and background colours COLORREF TextClr, TextBkClr; TextClr = (GetTextClr() == CLR_DEFAULT)? pDefaultCell->GetTextClr() : GetTextClr(); if (GetBackClr() == CLR_DEFAULT) TextBkClr = pDefaultCell->GetBackClr(); else { bEraseBkgnd = TRUE; TextBkClr = GetBackClr(); } // Draw cell background and highlighting (if necessary) if ( IsFocused() || IsDropHighlighted() ) { // Always draw even in list mode so that we can tell where the // cursor is at. Use the highlight colors though. if(GetState() & GVIS_SELECTED) { TextBkClr = ::GetSysColor(COLOR_HIGHLIGHT); TextClr = ::GetSysColor(COLOR_HIGHLIGHTTEXT); bEraseBkgnd = TRUE; } rect.right++; rect.bottom++; // FillRect doesn't draw RHS or bottom if (bEraseBkgnd) { TRY { CBrush brush(TextBkClr); pDC->FillRect(rect, &brush); } CATCH(CResourceException, e) { //e->ReportError(); } END_CATCH } // Don't adjust frame rect if no grid lines so that the // whole cell is enclosed. if(pGrid->GetGridLines() != GVL_NONE) { rect.right--; rect.bottom--; } if (pGrid->GetFrameFocusCell()) { // Use same color as text to outline the cell so that it shows // up if the background is black. TRY { CBrush brush(TextClr); pDC->FrameRect(rect, &brush); } CATCH(CResourceException, e) { //e->ReportError(); } END_CATCH } pDC->SetTextColor(TextClr); // Adjust rect after frame draw if no grid lines if(pGrid->GetGridLines() == GVL_NONE) { rect.right--; rect.bottom--; } rect.DeflateRect(1,1); }
void render3of9(OROPage * page, const QRectF & r, const QString & _str, ORBarcodeData * bc) { QString str = _str; // lets determine some core attributes about this barcode qreal narrow_bar = bc->narrowBarWidth; qreal interchange_gap = narrow_bar; // the space between each 'set' of bars int bar_width_mult = 2; // the wide bar width multiple of the narrow bar // this is our mandatory minimum quiet zone qreal quiet_zone = narrow_bar * 10; if(quiet_zone < 0.1) quiet_zone = 0.1; // what kind of area do we have to work with qreal draw_width = r.width(); qreal draw_height = r.height(); // how long is the value we need to encode? int val_length = str.length(); // L = (C + 2)(3N + 6)X + (C + 1)I // L length of barcode (excluding quite zone) in units same as X and I // C the number of characters in the value excluding the start/stop // N the bar width multiple for wide bars // X the width of a bar (pixels in our case) // I the interchange gap in the same units as X (value is same as X for our case) qreal L; qreal C = val_length; qreal N = bar_width_mult; qreal X = narrow_bar; qreal I = interchange_gap; L = ((C + 2.0) * (3.0*N + 6.0) * X) + ((C + 1.0) * I); // now we have the actual width the barcode will be so can determine the actual // size of the quiet zone (we assume we center the barcode in the given area // what should we do if the area is too small???? // At the moment the way the code is written is we will always start at the minimum // required quiet zone if we don't have enough space.... I guess we'll just have over-run // to the right // // calculate the starting position based on the alignment option // for left align we don't need to do anything as the values are already setup for it if(bc->align == 1) // center { qreal nqz = (draw_width - L) / 2.0; if(nqz > quiet_zone) quiet_zone = nqz; } else if(bc->align > 1) // right quiet_zone = draw_width - (L + quiet_zone); //else if(align < 1) {} // left : do nothing qreal pos = r.left() + quiet_zone; qreal top = r.top(); // ok we need to prepend and append the str with a * str = QString().sprintf("*%s*",str.toLatin1().data()); QPen pen(Qt::NoPen); QBrush brush(QColor("black")); for(int i = 0; i < str.length(); i++) { // loop through each char and render the barcode QChar c = str.at(i); int idx = codeIndex(c); if(idx == -1) { qDebug("Encountered a non-compliant character while rendering a 3of9 barcode -- skipping"); continue; } bool space = false; for(int b = 0; b < 9; b++, space = !space) { qreal w = (_3of9codes[idx].values[b] == 1 ?narrow_bar*bar_width_mult:narrow_bar); if(!space) { ORORect * rect = new ORORect(bc); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos,top, w,draw_height)); rect->setRotationAxis(r.topLeft()); page->addPrimitive(rect); } pos += w; } pos += interchange_gap; } return; }
void createCurveIcons() { QDir dir(QDir::current()); if (dir.dirName() == QLatin1String("debug") || dir.dirName() == QLatin1String("release")) { dir.cdUp(); } dir.cdUp(); dir.cdUp(); dir.cdUp(); QSize iconSize(128, 128); QPixmap pix(iconSize); QPainter painter(&pix); QLinearGradient gradient(0,0, 0, iconSize.height()); gradient.setColorAt(0.0, QColor(240, 240, 240)); gradient.setColorAt(1.0, QColor(224, 224, 224)); QBrush brush(gradient); const QMetaObject &mo = QEasingCurve::staticMetaObject; QMetaEnum metaEnum = mo.enumerator(mo.indexOfEnumerator("Type")); QFont oldFont = painter.font(); // Skip QEasingCurve::Custom QString output(QString::fromAscii("%1/images").arg(dir.absolutePath())); printf("Generating images to %s\n", qPrintable(output)); for (int i = 0; i < QEasingCurve::NCurveTypes - 1; ++i) { painter.setFont(oldFont); QString name(QLatin1String(metaEnum.key(i))); painter.fillRect(QRect(QPoint(0, 0), iconSize), brush); QEasingCurve curve((QEasingCurve::Type)i); painter.setPen(QColor(0, 0, 255, 64)); qreal xAxis = iconSize.height()/1.5; qreal yAxis = iconSize.width()/3; painter.drawLine(0, xAxis, iconSize.width(), xAxis); // hor painter.drawLine(yAxis, 0, yAxis, iconSize.height()); // ver qreal curveScale = iconSize.height()/2; painter.drawLine(yAxis - 2, xAxis - curveScale, yAxis + 2, xAxis - curveScale); // hor painter.drawLine(yAxis + curveScale, xAxis + 2, yAxis + curveScale, xAxis - 2); // ver painter.drawText(yAxis + curveScale - 8, xAxis - curveScale - 4, QLatin1String("(1,1)")); painter.drawText(yAxis + 42, xAxis + 10, QLatin1String("progress")); painter.drawText(15, xAxis - curveScale - 10, QLatin1String("value")); painter.setPen(QPen(Qt::red, 1, Qt::DotLine)); painter.drawLine(yAxis, xAxis - curveScale, yAxis + curveScale, xAxis - curveScale); // hor painter.drawLine(yAxis + curveScale, xAxis, yAxis + curveScale, xAxis - curveScale); // ver QPoint start(yAxis, xAxis - curveScale * curve.valueForProgress(0)); painter.setPen(Qt::black); QFont font = oldFont; font.setPixelSize(oldFont.pixelSize() + 15); painter.setFont(font); painter.drawText(0, iconSize.height() - 20, iconSize.width(), 20, Qt::AlignHCenter, name); QPainterPath curvePath; curvePath.moveTo(start); for (qreal t = 0; t <= 1.0; t+=1.0/curveScale) { QPoint to; to.setX(yAxis + curveScale * t); to.setY(xAxis - curveScale * curve.valueForProgress(t)); curvePath.lineTo(to); } painter.setRenderHint(QPainter::Antialiasing, true); painter.strokePath(curvePath, QColor(32, 32, 32)); painter.setRenderHint(QPainter::Antialiasing, false); QString fileName(QString::fromAscii("qeasingcurve-%1.png").arg(name.toLower())); printf("%s\n", qPrintable(fileName)); pix.save(QString::fromAscii("%1/%2").arg(output).arg(fileName), "PNG"); } }
void CSkinButton2::DrawFrame(Gdiplus::Graphics& gdi,CRect& rect) { if( m_enmuDrawType == NO_FRAME ) { Gdiplus::Pen pen1( m_colFrame1 ); gdi.DrawLine( &pen1, rect.left+1, rect.top, rect.right-2, rect.top ); gdi.DrawLine( &pen1, rect.left+1, rect.bottom-1, rect.right-2, rect.bottom-1 ); gdi.DrawLine( &pen1, rect.left, rect.top+1, rect.left, rect.bottom-2 ); gdi.DrawLine( &pen1, rect.right-1, rect.top+1, rect.right-1, rect.bottom-2 ); Gdiplus::Color colpix; pen1.GetColor( &colpix ); colpix.SetValue( Gdiplus::Color::MakeARGB(colpix.GetA()/2,colpix.GetR(),colpix.GetG(),colpix.GetB() ) ); Gdiplus::Pen penPix1( colpix ); gdi.DrawLine( &penPix1, rect.left, rect.top, rect.left+1, rect.top ); gdi.DrawLine( &penPix1, rect.right-1, rect.top, rect.right-1, rect.top+1 ); gdi.DrawLine( &penPix1, rect.right-1, rect.bottom-1, rect.right-2, rect.bottom-1 ); gdi.DrawLine( &penPix1, rect.left, rect.bottom-1, rect.left+1, rect.bottom-1 ); CRect rect2 = rect; ::InflateRect( &rect2, -1,-1 ); if( !m_bMouseDown ) { Gdiplus::Pen pen2(m_colFrame2); if( m_bMouseDown ) pen2.SetColor(m_colFrame1); else pen2.SetColor(m_colFrame2); gdi.DrawLine( &pen2, rect2.left+1, rect2.top, rect2.right-2, rect2.top ); gdi.DrawLine( &pen2, rect2.left+1, rect2.bottom-1, rect2.right-2, rect2.bottom-1 ); gdi.DrawLine( &pen2, rect2.left, rect2.top+1, rect2.left, rect2.bottom-2 ); gdi.DrawLine( &pen2, rect2.right-1, rect2.top+1, rect2.right-1, rect2.bottom-2 ); Gdiplus::Color colpix2; pen2.GetColor( &colpix2 ); colpix2.SetValue( Gdiplus::Color::MakeARGB(colpix2.GetA()/2,colpix2.GetR(),colpix2.GetG(),colpix2.GetB() ) ); Gdiplus::Pen penPix2( colpix2 ); gdi.DrawLine( &penPix2, rect2.left, rect2.top, rect2.left+1, rect2.top ); gdi.DrawLine( &penPix2, rect2.right-1, rect2.top, rect2.right-1, rect2.top+1 ); gdi.DrawLine( &penPix2, rect2.right-1, rect2.bottom-1, rect2.right-2, rect2.bottom-1 ); gdi.DrawLine( &penPix2, rect2.left, rect2.bottom-1, rect2.left+1, rect2.bottom-1 ); } if( m_bMouseDown ) { Gdiplus::RectF rc( rect2.left, rect2.top, rect2.Width(), rect2.Height()/3 ); Gdiplus::Color colBrush1,colBrush2; colBrush1.SetValue( Gdiplus::Color::MakeARGB(15,1,1,1) ); colBrush2.SetValue( Gdiplus::Color::MakeARGB(0,1,1,1) ); LinearGradientBrush brush( rc, colBrush1, colBrush2,LinearGradientModeVertical ); gdi.FillRectangle( &brush, rc ); } else { Gdiplus::RectF rc( rect2.left, rect2.top, rect2.Width(), rect2.Height()/2 ); rc.Inflate(-1,-1); LinearGradientBrush brush( rc, m_colBrush1, m_colBrush2,LinearGradientModeVertical ); gdi.FillRectangle( &brush, rc ); } return; } else if( m_enmuDrawType == NO_FRAME_SELECT ) { Gdiplus::Pen pen1( m_colFrame1 ); gdi.DrawLine( &pen1, rect.left+1, rect.top, rect.right-2, rect.top ); gdi.DrawLine( &pen1, rect.left+1, rect.bottom-1, rect.right-2, rect.bottom-1 ); gdi.DrawLine( &pen1, rect.left, rect.top+1, rect.left, rect.bottom-2 ); gdi.DrawLine( &pen1, rect.right-1, rect.top+1, rect.right-1, rect.bottom-2 ); Gdiplus::Color colpix; pen1.GetColor( &colpix ); colpix.SetValue( Gdiplus::Color::MakeARGB(colpix.GetA()/2,colpix.GetR(),colpix.GetG(),colpix.GetB() ) ); Gdiplus::Pen penPix1( colpix ); gdi.DrawLine( &penPix1, rect.left, rect.top, rect.left+1, rect.top ); gdi.DrawLine( &penPix1, rect.right-1, rect.top, rect.right-1, rect.top+1 ); gdi.DrawLine( &penPix1, rect.right-1, rect.bottom-1, rect.right-2, rect.bottom-1 ); gdi.DrawLine( &penPix1, rect.left, rect.bottom-1, rect.left+1, rect.bottom-1 ); CRect rect2 = rect; ::InflateRect( &rect2, -1,-1 ); if( !m_bMouseDown ) { Gdiplus::Pen pen2(m_colFrame2); if( m_bMouseDown ) pen2.SetColor(m_colFrame1); else pen2.SetColor(m_colFrame2); gdi.DrawLine( &pen2, rect2.left+1, rect2.top, rect2.right-2, rect2.top ); gdi.DrawLine( &pen2, rect2.left+1, rect2.bottom-1, rect2.right-2, rect2.bottom-1 ); gdi.DrawLine( &pen2, rect2.left, rect2.top+1, rect2.left, rect2.bottom-2 ); gdi.DrawLine( &pen2, rect2.right-1, rect2.top+1, rect2.right-1, rect2.bottom-2 ); Gdiplus::Color colpix2; pen2.GetColor( &colpix2 ); colpix2.SetValue( Gdiplus::Color::MakeARGB(colpix2.GetA()/2,colpix2.GetR(),colpix2.GetG(),colpix2.GetB() ) ); Gdiplus::Pen penPix2( colpix2 ); gdi.DrawLine( &penPix2, rect2.left, rect2.top, rect2.left+1, rect2.top ); gdi.DrawLine( &penPix2, rect2.right-1, rect2.top, rect2.right-1, rect2.top+1 ); gdi.DrawLine( &penPix2, rect2.right-1, rect2.bottom-1, rect2.right-2, rect2.bottom-1 ); gdi.DrawLine( &penPix2, rect2.left, rect2.bottom-1, rect2.left+1, rect2.bottom-1 ); } /* if( m_bMouseDown ) { Gdiplus::RectF rc( rect2.left, rect2.top, rect2.Width(), rect2.Height()/3 ); Gdiplus::Color colBrush1,colBrush2; colBrush1.SetValue( Gdiplus::Color::MakeARGB(15,1,1,1) ); colBrush2.SetValue( Gdiplus::Color::MakeARGB(0,1,1,1) ); LinearGradientBrush brush( rc, colBrush1, colBrush2,LinearGradientModeVertical ); gdi.FillRectangle( &brush, rc ); } else { Gdiplus::RectF rc( rect2.left, rect2.top, rect2.Width(), rect2.Height()/2 ); rc.Inflate(-1,-1); LinearGradientBrush brush( rc, m_colBrush1, m_colBrush2,LinearGradientModeVertical ); gdi.FillRectangle( &brush, rc ); }*/ CRect rect3 = rect2; ::InflateRect( &rect3, -1,-1 ); Gdiplus::RectF rc( rect3.left, rect3.top, rect3.Width(), rect3.Height() ); LinearGradientBrush brush( rc, m_colBK, m_colBK,LinearGradientModeVertical ); gdi.FillRectangle( &brush, rc ); Gdiplus::Color colBlack1 = Gdiplus::Color::MakeARGB(30,50,50,50); Gdiplus::Color colBlack2 = Gdiplus::Color::MakeARGB(15,50,50,50); Gdiplus::RectF rc1( rect3.left, rect3.top+rect3.Height()/2, rect3.Width(), rect3.Height()/2 ); LinearGradientBrush brush2( rc1, colBlack1, colBlack2,LinearGradientModeVertical ); gdi.FillRectangle( &brush2, rc1 ); return; } if( m_enmuDrawType == TOP_ARC ) { Gdiplus::Pen pen1( m_colFrame1 ); gdi.DrawLine( &pen1, rect.left+5, rect.top, rect.right-7, rect.top ); gdi.DrawLine( &pen1, rect.left, rect.bottom-1, rect.right, rect.bottom-1 ); gdi.DrawLine( &pen1, rect.left, rect.top+5, rect.left, rect.bottom-2 ); gdi.DrawLine( &pen1, rect.right-1, rect.top+5, rect.right-1, rect.bottom-2 ); CRect rect2 = rect; ::InflateRect( &rect2, -1,-1 ); if( !m_bMouseDown ) { Gdiplus::Pen pen2(m_colFrame2); gdi.DrawLine( &pen2, rect2.left+4, rect2.top, rect2.right-5, rect2.top ); gdi.DrawLine( &pen2, rect2.left, rect2.bottom-1, rect2.right-1, rect2.bottom-1 ); gdi.DrawLine( &pen2, rect2.left, rect2.top+4, rect2.left, rect2.bottom-2 ); gdi.DrawLine( &pen2, rect2.right-1, rect2.top+4, rect2.right-1, rect2.bottom-2 ); Gdiplus::RectF rectLeftTop2; rectLeftTop2.X = rect2.left; rectLeftTop2.Y = rect2.top; rectLeftTop2.Width = 6; rectLeftTop2.Height = 6; gdi.DrawArc( &pen2, rectLeftTop2,180,90 ); Gdiplus::RectF rectRightTop2; rectRightTop2.X = rect2.right-7; rectRightTop2.Y = rect2.top; rectRightTop2.Width = 6; rectRightTop2.Height = 6; gdi.DrawArc( &pen2, rectRightTop2,270,90 ); } Gdiplus::RectF rectLeftTop; rectLeftTop.X = rect.left; rectLeftTop.Y = rect.top; rectLeftTop.Width = 9; rectLeftTop.Height = 9; gdi.DrawArc( &pen1, rectLeftTop,180,90 ); Gdiplus::RectF rectRightTop; rectRightTop.X = rect.right-10; rectRightTop.Y = rect.top; rectRightTop.Width = 9; rectRightTop.Height = 9; gdi.DrawArc( &pen1, rectRightTop,270,90 ); /*Gdiplus::SolidBrush sb( m_colBrush ); Gdiplus::Brush *pbrush = sb.Clone();*/ if( m_bMouseDown ) { Gdiplus::RectF rc( rect2.left, rect2.top, rect2.Width(), rect2.Height()/3 ); Gdiplus::Color colBrush1,colBrush2; colBrush1.SetValue( Gdiplus::Color::MakeARGB(15,1,1,1) ); colBrush2.SetValue( Gdiplus::Color::MakeARGB(0,1,1,1) ); LinearGradientBrush brush( rc, colBrush1, colBrush2,LinearGradientModeVertical ); gdi.FillRectangle( &brush, rc ); } else { Gdiplus::RectF rc( rect2.left, rect2.top, rect2.Width(), rect2.Height()/2 ); rc.Inflate(-1,-1); LinearGradientBrush brush( rc, m_colBrush1, m_colBrush2,LinearGradientModeVertical ); gdi.FillRectangle( &brush, rc ); } } else if( m_enmuDrawType == BOTTON_ARC ) { } else if( m_enmuDrawType == RIGHT_ARC ) { } else if( m_enmuDrawType == LEFT_ARC ) { } else if( m_enmuDrawType & (TOP_ARC|BOTTON_ARC) || m_enmuDrawType & (RIGHT_ARC|LEFT_ARC) ) { // 四角都有弧线 } //gdi.DrawString( }
void CSymbolTypeComboBox::DrawItem(LPDRAWITEMSTRUCT pDIStruct) { CRect rItemRect = pDIStruct->rcItem; COLORREF clrNormal = ::GetSysColor(COLOR_WINDOW); COLORREF clrSelected = ::GetSysColor(COLOR_HIGHLIGHT); COLORREF drawColor = symColor; CDC dcContext; if (!dcContext.Attach(pDIStruct->hDC)) { return; } int iState = pDIStruct->itemState; if (iState & ODS_SELECTED) { drawColor = 0x00FFFFFF & ~(drawColor); dcContext.SetBkColor(clrSelected); dcContext.FillSolidRect(&rItemRect, clrSelected); } else { dcContext.SetBkColor(clrNormal); dcContext.FillSolidRect(&rItemRect, clrNormal); } if (iState & ODS_FOCUS) { dcContext.DrawFocusRect(&rItemRect); } int iItem = pDIStruct->itemID; if (iItem != -1) { dcContext.SetBkMode(TRANSPARENT); if (iState & ODS_DISABLED) { drawColor = ::GetSysColor(COLOR_INACTIVECAPTIONTEXT); } PlotSymbol currSym = PlotSymbol(iItem); bool filledSym = PlotSymbolOps::SymbolIsFilled(currSym); rItemRect.DeflateRect(4, 0); int lThick = IMin(rItemRect.bottom - rItemRect.top - 2, symLThick); if (filledSym) lThick = 1; CPen drawPen(PS_SOLID, lThick, drawColor); CPen* pOldPen = dcContext.SelectObject(&drawPen); CBrush brush(drawColor); CBrush* pOldBrush = dcContext.SelectObject(&brush); int drawSymSize = IMin((rItemRect.bottom - rItemRect.top), symSize); int rectMidY = (rItemRect.top + rItemRect.bottom) / 2; int rectMidX = (rItemRect.left + rItemRect.right) / 2; switch (currSym) { case ps_X : { drawSymSize /= 2; dcContext.MoveTo(rectMidX - drawSymSize, rectMidY - drawSymSize); dcContext.LineTo(rectMidX + drawSymSize, rectMidY + drawSymSize); dcContext.MoveTo(rectMidX + drawSymSize, rectMidY - drawSymSize); dcContext.LineTo(rectMidX - drawSymSize, rectMidY + drawSymSize); break; } case ps_Plus : { drawSymSize /= 2; dcContext.MoveTo(rectMidX - drawSymSize, rectMidY); dcContext.LineTo(rectMidX + drawSymSize, rectMidY); dcContext.MoveTo(rectMidX, rectMidY - drawSymSize); dcContext.LineTo(rectMidX, rectMidY + drawSymSize); break; } case ps_Square : case ps_FSquare :{ drawSymSize /= 2; CPoint pts[4]; pts[0].x = rectMidX - drawSymSize; pts[0].y = rectMidY - drawSymSize; pts[1].x = rectMidX + drawSymSize; pts[1].y = rectMidY - drawSymSize; pts[2].x = rectMidX + drawSymSize; pts[2].y = rectMidY + drawSymSize; pts[3].x = rectMidX - drawSymSize; pts[3].y = rectMidY + drawSymSize; DrawSymbol(dcContext, pts, 4, filledSym); break; } case ps_Circle : case ps_FCircle: { static const Point2D cicoords[] = {Point2D(0.00000 ,0.50000), Point2D(0.25000 ,0.43301), Point2D(0.43301 ,0.25000), Point2D(0.50000 ,0.00000), Point2D(0.43301 ,-0.25000), Point2D(0.25000 ,-0.43301), Point2D(0.00000 ,-0.50000), Point2D(-0.25000,-0.43301), Point2D(-0.43301,-0.25000), Point2D(-0.50000,0.00000), Point2D(-0.43301,0.25000), Point2D(-0.25000,0.43301)}; CPoint pts[12]; for (int i = 0; i < 12; i++) { int offX = int(double(drawSymSize) * cicoords[i].pX); int offY = int(double(drawSymSize) * cicoords[i].pY); pts[i].x = rectMidX + offX; pts[i].y = rectMidY + offY; } DrawSymbol(dcContext, pts, 12, filledSym); break; } case ps_Triangle : case ps_FTriangle : { int offX = int(double(drawSymSize) * 0.4330); int offY = int(double(drawSymSize) * 0.25); CPoint pts[3]; pts[0].x = rectMidX - offX; pts[0].y = rectMidY + offY; pts[1].x = rectMidX + offX; pts[1].y = rectMidY + offY; pts[2].x = rectMidX; pts[2].y = rectMidY - drawSymSize / 2; DrawSymbol(dcContext, pts, 3, filledSym); break; } case ps_Diamond : case ps_FDiamond : { drawSymSize /= 2; CPoint pts[4]; pts[0].x = rectMidX; pts[0].y = rectMidY - drawSymSize; pts[1].x = rectMidX + drawSymSize; pts[1].y = rectMidY; pts[2].x = rectMidX; pts[2].y = rectMidY + drawSymSize; pts[3].x = rectMidX - drawSymSize; pts[3].y = rectMidY; DrawSymbol(dcContext, pts, 4, filledSym); break; } } } dcContext.Detach(); }
void renderCodeDatamatrix(OROPage *page, const QRectF &qrect, const QString &qstr, ORBarcodeData * bc) { //5 pixel par carré //qreal pix = 5; //lecture du type de datamatrix QRegExp regex("[a-zA-Z]{10}_([0-9]{1,2})_([LCR]{1})"); regex.indexIn(bc->format); int type = regex.cap(1).toInt(); QString align = regex.cap(2); size_t width, height, bytesPerPixel; //pointer declaration unsigned char *pxl = NULL; DmtxEncode *enc = NULL; DmtxImage *img = NULL; ORORect *rect = NULL; int valeur = 0; /* 1) ENCODE a new Data Matrix barcode image (in memory only) */ enc = dmtxEncodeCreate(); //see DmtxSymbolSize in dmtx.h for more details enc->sizeIdxRequest = type; enc->marginSize = 0; //number of pixel for one square enc->moduleSize = 1; try { //assert(enc != NULL); dmtxEncodeDataMatrix(enc, qstr.size(), (unsigned char*)qstr.toStdString().c_str()); /* 2) COPY the new image data before releasing encoding memory */ width = dmtxImageGetProp(enc->image, DmtxPropWidth); height = dmtxImageGetProp(enc->image, DmtxPropHeight); bytesPerPixel = dmtxImageGetProp(enc->image, DmtxPropBytesPerPixel); if(width > 1000000000) { throw std::runtime_error("Code is to big for the Datamatrix"); } pxl = (unsigned char *)malloc(width * height * bytesPerPixel); //assert(pxl != NULL); memcpy(pxl, enc->image->pxl, width * height * bytesPerPixel); dmtxEncodeDestroy(&enc); /* 3) DECODE the Data Matrix barcode from the copied image */ img = dmtxImageCreate(pxl, width, height, DmtxPack24bppRGB); QPen pen(Qt::NoPen); QBrush brush(QColor("black")); qreal Xo = 0; qreal Yo = 0; //length of square qreal pas = 0; datamatrixGeometry(align,qrect,img,&Xo,&Yo,&pas); //draw the datamatrix for(int y = 0; y < img->height; y++) { for(int x = 0; x < img->width; x++) { dmtxImageGetPixelValue(img,x,y,0,&valeur); rect = new ORORect(bc); rect->setPen(pen); if(valeur == 0) { brush.setColor(Qt::black); rect->setBrush(brush); rect->setRect(QRectF( Xo + x*pas, Yo - y*pas, pas, pas)); rect->setRotationAxis(qrect.topLeft()); page->addPrimitive(rect); } } delete rect; } //memory cleanning free(pxl); dmtxEncodeDestroy(&enc); dmtxImageDestroy(&img); } catch(...) { //there is a problem with the datamatrix //RR is printed printRR(page,bc,qrect); //memory cleaning if(rect != NULL) { delete rect; } if(enc != NULL) { dmtxEncodeDestroy(&enc); } if(img != NULL) { dmtxImageDestroy(&img); } if(pxl!=NULL) { free(pxl); } } }
QGraphicsScene* Ploter::drawParallelPlot(Machine **machines, int MachineCount, int JobCount) { int currentMashineJobWidth = 0; int LabelsCount = JobCount; plot.clear(); plot.setSceneRect(0,0,356,86); QPen pen(colorTab[0]); QBrush brush(colorTab[0]); QString jobLabelContent; QGraphicsSimpleTextItem **TimeLabels = new QGraphicsSimpleTextItem*[LabelsCount]; plot.clear(); for(int i=0; i < LabelsCount; ++i) { TimeLabels[i] = new QGraphicsSimpleTextItem(); } int labelIdxj=0; int offsetForJob; int maxTime = 0; for(int j=0; j < MachineCount; ++j) { offsetForJob = 0; for(int i=1; i <= machines[j]->getNumberOfJobs(); ++i) { { int jobId = machines[j]->getJobId(i); pen.setColor(colorTab[jobId]); brush.setColor(colorTab[jobId]); jobLabelContent.setNum(jobId); jobLabelContent.insert(0,"Z"); if(jobId != 0) { TimeLabels[labelIdxj]->setText(jobLabelContent); TimeLabels[labelIdxj]->setPos(labelOffset.x() + offsetForJob * scale, lineStartingY[j] + labelOffset.y()); } currentMashineJobWidth = machines[j]->getJobDuration(i); plot.addRect(lineStartingX + offsetForJob * scale, lineStartingY[j], currentMashineJobWidth * scale, jobHeight , pen, brush); if(jobId != 0 && currentMashineJobWidth != 0) plot.addItem(TimeLabels[labelIdxj++]); offsetForJob += currentMashineJobWidth; } } if(maxTime < machines[j]->getEndingTimeForLastJob()) maxTime = machines[j]->getEndingTimeForLastJob(); } PrepareAxis(maxTime, MachineCount); return &plot; }