void Chip::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(widget); QColor fillColor = (option->state & QStyle::State_Selected) ? color.dark(150) : color; if (option->state & QStyle::State_MouseOver) fillColor = fillColor.light(125); if (option->levelOfDetail < 0.2) { if (option->levelOfDetail < 0.125) { painter->fillRect(QRectF(0, 0, 110, 70), fillColor); return; } painter->setPen(QPen(Qt::black, 0)); painter->setBrush(fillColor); painter->drawRect(13, 13, 97, 57); return; } QPen oldPen = painter->pen(); QPen pen = oldPen; int width = 0; if (option->state & QStyle::State_Selected) width += 2; pen.setWidth(width); painter->setBrush(QBrush(fillColor.dark(option->state & QStyle::State_Sunken ? 120 : 100))); painter->drawRect(QRect(14, 14, 79, 39)); if (option->levelOfDetail >= 1) { painter->setPen(QPen(Qt::gray, 1)); painter->drawLine(15, 54, 94, 54); painter->drawLine(94, 53, 94, 15); painter->setPen(QPen(Qt::black, 0)); } // Draw text if (option->levelOfDetail >= 2) { QFont font("Times", 10); font.setStyleStrategy(QFont::ForceOutline); painter->setFont(font); painter->save(); painter->scale(0.1, 0.1); painter->drawText(170, 180, QString("Model: VSC-2000 (Very Small Chip) at %1x%2").arg(x).arg(y)); painter->drawText(170, 200, QString("Serial number: DLWR-WEER-123L-ZZ33-SDSJ")); painter->drawText(170, 220, QString("Manufacturer: Chip Manufacturer")); painter->restore(); } // Draw lines QVarLengthArray<QLineF, 36> lines; if (option->levelOfDetail >= 0.5) { for (int i = 0; i <= 10; i += (option->levelOfDetail > 0.5 ? 1 : 2)) { lines.append(QLineF(18 + 7 * i, 13, 18 + 7 * i, 5)); lines.append(QLineF(18 + 7 * i, 54, 18 + 7 * i, 62)); } for (int i = 0; i <= 6; i += (option->levelOfDetail > 0.5 ? 1 : 2)) { lines.append(QLineF(5, 18 + i * 5, 13, 18 + i * 5)); lines.append(QLineF(94, 18 + i * 5, 102, 18 + i * 5)); } } if (option->levelOfDetail >= 0.4) { const QLineF lineData[] = { QLineF(25, 35, 35, 35), QLineF(35, 30, 35, 40), QLineF(35, 30, 45, 35), QLineF(35, 40, 45, 35), QLineF(45, 30, 45, 40), QLineF(45, 35, 55, 35) }; lines.append(lineData, 6); } painter->drawLines(lines.data(), lines.size()); // Draw red ink if (stuff.size() > 1) { painter->setPen(QPen(Qt::red, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); painter->setBrush(Qt::NoBrush); QPainterPath path; path.moveTo(stuff.first()); for (int i = 1; i < stuff.size(); ++i) path.lineTo(stuff.at(i)); painter->drawPath(path); } }
void renderFullTree(QPaintDevice *paintdev, SketchXMLHandler* XMLHandlr, QColor LineColor, std::uint16_t BaseFontSize, std::string SelectedGUID, double Width, double Height, double PermaScale, double ScaleFactor, double PanX, double PanY, QTransform *paintTransform = nullptr) { QPainter paint(paintdev); paint.resetTransform(); paint.translate(double(Width/2) + (PanX * ScaleFactor), double(Height/2) + (PanY * ScaleFactor)); paint.scale(PermaScale * Width * ScaleFactor, PermaScale * Width * ScaleFactor); if (paintTransform != nullptr) *paintTransform = paint.worldTransform(); paint.setRenderHint(QPainter::Antialiasing, true); paint.setRenderHint(QPainter::TextAntialiasing, true); paint.setRenderHint(QPainter::SmoothPixmapTransform, true); QPen linepen (LineColor); linepen.setWidth(5); paint.setPen(linepen); std::for_each(XMLHandlr->nodelinkmap.begin(), XMLHandlr->nodelinkmap.end(), [&](std::pair<std::string, std::vector<std::string>> block) { FlowNode fnparent = XMLHandlr->OrphanNodes[block.first]; std::for_each(block.second.begin(), block.second.end(), [&](std::string child) { FlowNode fnchild = XMLHandlr->OrphanNodes[child]; if ((fnchild.Type == NodeType::NONE) || (fnparent.Type == NodeType::NONE)) return; paint.drawLine(fnparent.CenterPosX, fnparent.CenterPosY, fnchild.CenterPosX, fnchild.CenterPosY); }); }); std::for_each(XMLHandlr->OrphanNodes.begin(), XMLHandlr->OrphanNodes.end(), [&](std::pair<std::string, FlowNode> nodepair) { if (nodepair.second.Type == NodeType::NONE) return; QFont basefont = QFont("sans-serif", BaseFontSize*nodepair.second.FontSizeMult); QFont titlefont = QFont("sans-serif", BaseFontSize*nodepair.second.FontSizeMult*1.5); NodeSize ns = getNodeSize(basefont, titlefont, nodepair.second); int rectoriginx = nodepair.second.CenterPosX - (ns.Width/2); int rectoriginy = nodepair.second.CenterPosY - (ns.Height/2); QColor PrimColor = QColor(nodepair.second.ColorRGBA[0], nodepair.second.ColorRGBA[1], nodepair.second.ColorRGBA[2], nodepair.second.ColorRGBA[3]); paint.fillRect(rectoriginx, rectoriginy, ns.Width, ns.Height, PrimColor); QColor SecColor; if (PrimColor.toHsl().lightness() > 256) SecColor = PrimColor.lighter(200); else SecColor = PrimColor.darker(300); QPen textpen (SecColor); textpen.setWidth(3); paint.setPen(textpen); paint.drawRect(rectoriginx, rectoriginy, ns.Width, ns.Height); paint.setFont(titlefont); paint.drawText(rectoriginx + BlockPadding, rectoriginy + BlockPadding, ns.Width - (BlockPadding*2), ns.TitleBoundBox.height(), Qt::AlignCenter, QString(nodepair.second.Title.c_str())); paint.setFont(basefont); paint.drawText(nodepair.second.CenterPosX - (ns.DescBoundBox.width()/2), rectoriginy + BlockPadding + ns.TitleBoundBox.height() + BlockPadding, ns.DescBoundBox.width(), ns.DescBoundBox.height(), Qt::AlignCenter | Qt::TextWordWrap, QString(nodepair.second.Desc.c_str())); if (nodepair.second.GUID == SelectedGUID) { //Edge blocks paint.fillRect(rectoriginx + ns.Width - GripWidth/2, rectoriginy - GripWidth/2, GripWidth, GripWidth, Qt::black); paint.fillRect(rectoriginx + ns.Width + 2 - GripWidth/2, rectoriginy + 2 - GripWidth/2, GripWidth-4, GripWidth-4, Qt::white); } }); paint.end(); }
//----------------------------------------------------------------------------------------- // New version, site/cell size is fixed, the blob grows //----------------------------------------------------------------------------------------- void Field::displayField(int hr, int *res) { // QGraphicsScene* scene = new QGraphicsScene(QRect(0, 0, CANVAS_WIDTH, CANVAS_WIDTH)); QBrush brush; int i, k, ix, iy, iz, w, rgbcol[3], ichemo, ixyz; double xp, yp, x, y, d, C, cmin, cmax, rmax, valmin; double a, b, Wc, dx, Wx, radius; int Nc, NX, NY, NZ; double beta = 1.0; NEW_FIELD_DATA fdata; ichemo = Global::GUI_to_DLL_index[field_constituent]; LOG_QMSG("displayField: field: " + QString::number(field_constituent) + " --> " + QString::number(ichemo)); use_log = false; // temporary *res = 0; if (hr >= 0) hour = hr; if (slice_changed) { // LOG_MSG("call new_get_fielddata"); new_get_fielddata(&axis, &fraction, &fdata, &ixyz, res); if (*res != 0) { LOG_MSG("Error: new_get_fielddata: FAILED"); sprintf(msg, "axis: %d fraction: %6.3f ixyz: %d res: %d",axis,fraction,ixyz,*res); LOG_MSG(msg); // exit(1); return; } // sprintf(msg,"fdata: %d %d %d %d ncells: %d",fdata.NX,fdata.NY,fdata.NZ,fdata.NCONST,fdata.ncells); // LOG_MSG(msg); slice_changed = false; } cmin = 1.0e10; cmax = 0; rmax = 1; NX = fdata.NX; NY = fdata.NY; NZ = fdata.NZ; dx = fdata.DX; Wx = (NX-1)*dx; Wc = CANVAS_WIDTH; a = Wc/(beta*Wx); b = Wc/2 - a*Wx/2; // sprintf(msg,"NX: %d dx: %f Wx: %f Wc: %f a: %f b: %f",NX,dx,Wx,Wc,a,b); // LOG_MSG(msg); brush.setStyle(Qt::SolidPattern); brush.setColor(QColor(0,0,0)); scene->addRect(0,0,CANVAS_WIDTH,CANVAS_WIDTH,Qt::NoPen, brush); view->setScene(scene); view->setGeometry(QRect(0, 0, CANVAS_WIDTH+4, CANVAS_WIDTH+4)); cmax = line_maxConc_list[field_constituent]->text().toDouble(); // sprintf(msg,"displayField: field constituent: %d ichemo: %d cmax: %f",field_constituent,ichemo,cmax); // LOG_MSG(msg); rgbcol[0] = 0; rgbcol[1] = 0; rgbcol[2] = 0; w = a*dx + 0.5; valmin = 1.0e10; scene->clear(); if (axis == X_AXIS) { // Y-Z plane ix = ixyz; for (iy=0; iy<NY; iy++) { x = iy*dx; for (iz=0; iz<NZ; iz++) { y = (NZ-1-iz)*dx; k = (ichemo-1)*NZ*NY*NX + iz*NY*NX + iy*NX + ix; // index(ix,iy,iz,ichemo); C = fdata.Cave[k]; valmin = MIN(C,valmin); rgbcol[1] = 255*min(C,cmax)/cmax; rgbcol[2] = 255*min(C,cmax)/cmax; xp = int(a*x + b); yp = int(a*y + b); // chooseFieldColor(data[i].conc[ichemo],cmin,cmax,use_log,rgbcol); // sprintf(msg,"c: %f %f %f rgbcol: %d %d %d",data[i].conc[constituent],cmin,cmax,rgbcol[0],rgbcol[1],rgbcol[2]); // LOG_MSG(msg); brush.setColor(QColor(rgbcol[0],rgbcol[1],rgbcol[2])); scene->addRect(xp,yp,w,w,Qt::NoPen, brush); } } } else if (axis == Y_AXIS) { // X-Z plane iy = ixyz; for (ix=0; ix<NX; ix++) { x = ix*dx; for (iz=0; iz<NZ; iz++) { y = (NZ-1-iz)*dx; k = (ichemo-1)*NZ*NY*NX + iz*NY*NX + iy*NX + ix; // index(ix,iy,iz,ichemo); C = fdata.Cave[k]; valmin = MIN(C,valmin); rgbcol[1] = 255*min(C,cmax)/cmax; rgbcol[2] = 255*min(C,cmax)/cmax; xp = int(a*x + b); yp = int(a*y + b); brush.setColor(QColor(rgbcol[0],rgbcol[1],rgbcol[2])); scene->addRect(xp,yp,w,w,Qt::NoPen, brush); } } } else if (axis == Z_AXIS) { // X-Y plane iz = ixyz; for (ix=0; ix<NX; ix++) { x = ix*dx; for (iy=0; iy<NY; iy++) { y = iy*dx; k = (ichemo-1)*NZ*NY*NX + iz*NY*NX + iy*NX + ix; // index(ix,iy,iz,ichemo); C = fdata.Cave[k]; // sprintf(msg,"%d %d %d %d %d %d %d %d %8.3f",NX,NY,NZ,ichemo,ix,iy,iz,k,C); // LOG_MSG(msg); valmin = MIN(C,valmin); rgbcol[1] = 255*min(C,cmax)/cmax; rgbcol[2] = 255*min(C,cmax)/cmax; // if (ix == NX/2) { // sprintf(msg,"iy,C,cmax: %4d %8.3f %8.3f rgb: %3d %3d %3d",iy,C,cmax, // rgbcol[0],rgbcol[1],rgbcol[2]); // LOG_MSG(msg); // } xp = int(a*x + b); yp = int(a*y + b); brush.setColor(QColor(rgbcol[0],rgbcol[1],rgbcol[2])); scene->addRect(xp,yp,w,w,Qt::NoPen, brush); } } } // sprintf(msg,"axis: %d valmin: %f",axis,valmin); // LOG_MSG(msg); if (!show_cells) return; // ichemo = Global::GUI_to_DLL_index[cell_constituent]; // LOG_QMSG("displayField: cell: " + QString::number(cell_constituent) + " --> " + QString::number(ichemo)); // LOG_QMSG("displayField: nc: " + QString::number(fdata.ncells)); for (i=0; i<fdata.ncells; i++) { x = fdata.cell_data[i].centre[0]; y = fdata.cell_data[i].centre[1]; radius = fdata.cell_data[i].radius; xp = a*x + b; yp = a*y + b; d = 2*a*radius; // sprintf(msg,"Cell: %d x,y: %f %f radius: %f xp,yp: %f %f",i,x,y,radius,xp,yp); // LOG_MSG(msg); int status = fdata.cell_data[i].status; if (Global::only2colours2D && Global::celltypecolours2D) { if (status == 0 || status == 10 || status == 1 || status == 3) { int celltype = fdata.cell_data[i].celltype; QColor color = Global::celltype_colour[celltype]; rgbcol[0] = color.red(); rgbcol[1] = color.green(); rgbcol[2] = color.blue(); } else if (status == 2 || status == 4) { // tagged to die of starvation rgbcol[0] = 0; rgbcol[1] = 0; rgbcol[2] = 255; } else if (status > 10) { // tagged to die of treatment rgbcol[0] = 255; rgbcol[1] = 150; rgbcol[2] = 0; } } else { if (status == 0 || status == 10) { // growing (This is unnecessarily complicated, since cell_data[].celltype is available) if (!Global::celltypecolours2D) { // use original colour (light green) rgbcol[0] = 0; rgbcol[1] = 255; rgbcol[2] = 0; } else if (status == 0) { // use colours from 3D screen QColor color = Global::celltype_colour[1]; rgbcol[0] = color.red(); rgbcol[1] = color.green(); rgbcol[2] = color.blue(); } else { QColor color = Global::celltype_colour[2]; rgbcol[0] = color.red(); rgbcol[1] = color.green(); rgbcol[2] = color.blue(); } } else if (status == 1) { // radiobiological hypoxia rgbcol[0] = 50; rgbcol[1] = 100; rgbcol[2] = 32; } else if (status == 2 || status == 4) { // tagged to die of starvation rgbcol[0] = 0; rgbcol[1] = 0; rgbcol[2] = 255; } else if (status == 3) { // mitosis rgbcol[0] = 255; rgbcol[1] = 0; rgbcol[2] = 255; } else if (status > 10) { // tagged to die of treatment rgbcol[0] = 255; rgbcol[1] = 150; rgbcol[2] = 0; } } brush.setColor(QColor(rgbcol[0],rgbcol[1],rgbcol[2])); scene->addEllipse(xp,yp,d,d,Qt::NoPen, brush); } double w_scalebar = a*0.01 + b; // 100um = 0.01cm double scalebar0 = a*2*dx + b; QPen pen; QFont font; pen.setBrush(Qt::black); pen.setWidth(3); scene->addLine(scalebar0, scalebar0, scalebar0+w_scalebar, scalebar0, pen); QGraphicsTextItem *scalebar_text = scene->addText("100 um",font); scalebar_text->setPos(scalebar0,1.4*scalebar0); view->show(); // return; if (save_images && hour >= record2D_start_hour && hour <= record2D_end_hour) { scene->clearSelection(); // Selections would also render to the file scene->setSceneRect(scene->itemsBoundingRect()); // Re-shrink the scene to it's bounding contents QImage image(scene->sceneRect().size().toSize(), QImage::Format_ARGB32); // Create the image with the exact size of the shrunk scene image.fill(Qt::transparent); // Start all pixels transparent QPainter painter(&image); scene->render(&painter); ifield++; QString numstr = QString("%1").arg(hour, 4, 10, QChar('0')); QString filename = record2D_base_name + numstr + ".png"; // char *filename = qstr.toAscii(); // char filename[] = "image/field0000.png"; // char numstr[5]; // sprintf(numstr,"%04d",hour); // for (int i=0; i<4; i++) // filename[11+i] = numstr[i]; image.save(filename); } }
void tract_report::on_refresh_report_clicked() { if(cur_tracking_window->tractWidget->tract_models.size() > 1 && cur_tracking_window->tractWidget->tract_models[0]->get_tract_color(0) == cur_tracking_window->tractWidget->tract_models[1]->get_tract_color(0)) cur_tracking_window->tractWidget->assign_colors(); ui->report_widget->clearGraphs(); double max_y = 0.0,min_x = 0.0,max_x = 0; if(ui->profile_dir->currentIndex() <= 2) min_x = cur_tracking_window->slice.geometry[ui->profile_dir->currentIndex()]; for(unsigned int index = 0;index < cur_tracking_window->tractWidget->tract_models.size();++index) { if(cur_tracking_window->tractWidget->item(index,0)->checkState() != Qt::Checked) continue; std::vector<float> values,data_profile; cur_tracking_window->tractWidget->tract_models[index]->get_report( ui->profile_dir->currentIndex(), ui->report_bandwidth->value(), ui->report_index->currentText().toLocal8Bit().begin(), values,data_profile); if(data_profile.empty()) continue; for(unsigned int i = 0;i < data_profile.size();++i) if(data_profile[i] > 0.0) { max_y = std::max<float>(max_y,data_profile[i]); max_x = std::max<float>(max_x,values[i]); min_x = std::min<float>(min_x,values[i]); } QVector<double> x(data_profile.size()),y(data_profile.size()); std::copy(values.begin(),values.end(),x.begin()); std::copy(data_profile.begin(),data_profile.end(),y.begin()); ui->report_widget->addGraph(); QPen pen; image::rgb_color color = cur_tracking_window->tractWidget->tract_models[index]->get_tract_color(0); pen.setColor(QColor(color.r,color.g,color.b,200)); pen.setWidth(ui->linewidth->value()); ui->report_widget->graph()->setLineStyle(QCPGraph::lsLine); ui->report_widget->graph()->setPen(pen); ui->report_widget->graph()->setData(x, y); ui->report_widget->graph()->setName(cur_tracking_window->tractWidget->item(index,0)->text()); // give the axes some labels: //customPlot->xAxis->setLabel("x"); //customPlot->yAxis->setLabel("y"); // set axes ranges, so we see all data: } ui->report_widget->xAxis->setRange(min_x,max_x); ui->report_widget->yAxis->setRange(ui->report_index->currentIndex() ? 0 : cur_tracking_window->ui->fa_threshold->value(), max_y); if(ui->report_legend->checkState() == Qt::Checked) { ui->report_widget->legend->setVisible(true); QFont legendFont = font(); // start out with MainWindow's font.. legendFont.setPointSize(9); // and make a bit smaller for legend ui->report_widget->legend->setFont(legendFont); ui->report_widget->legend->setPositionStyle(QCPLegend::psRight); ui->report_widget->legend->setBrush(QBrush(QColor(255,255,255,230))); } else ui->report_widget->legend->setVisible(false); ui->report_widget->replot(); cur_tracking_window->copy_target = 2; }
int Nightcharts::draw(QPainter *painter) { painter->setRenderHint(QPainter::Antialiasing); painter->setPen(Qt::NoPen); if (this->ctype==Nightcharts::Pie) { pW = 0; double pdegree = 0; //Options QLinearGradient gradient(cX+0.5*cW,cY,cX+0.5*cW,cY+cH*2.5); gradient.setColorAt(1,Qt::black); //Draw //pdegree = (360/100)*pieces[i].pPerc; if (shadows) { double sumangle = 0; for (int i=0;i<pieces.size();i++) { sumangle += 3.6*pieces[i].pPerc; } painter->setBrush(Qt::darkGray); painter->drawPie(cX,cY+pW+5,cW,cH,palpha*16,sumangle*16); } QPen pen; pen.setWidth(2); for (int i=0;i<pieces.size();i++) { gradient.setColorAt(0,pieces[i].rgbColor); painter->setBrush(gradient); pen.setColor(pieces[i].rgbColor); painter->setPen(pen); pdegree = 3.6*pieces[i].pPerc; painter->drawPie(cX,cY,cW,cH,palpha*16,pdegree*16); palpha += pdegree; } } else if (this->ctype==Nightcharts::Dpie) { pW = 50; double pdegree = 0; QPointF p; QLinearGradient gradient(cX-0.5*cW,cY+cH/2,cX+1.5*cW,cY+cH/2); gradient.setColorAt(0,Qt::black); gradient.setColorAt(1,Qt::white); QLinearGradient gradient_side(cX,cY+cH,cX+cW,cY+cH); gradient_side.setColorAt(0,Qt::black); double sumangle = 0; for (int i=0;i<pieces.size();i++) { sumangle += 3.6*pieces[i].pPerc; } if (shadows) { painter->setBrush(Qt::darkGray); painter->drawPie(cX,cY+pW+5,cW,cH,palpha*16,sumangle*16); } int q = GetQuater(palpha+sumangle); if (q ==2 || q==3) { QPointF p = GetPoint(palpha+sumangle); QPointF points[4] = { QPointF(p.x(),p.y()), QPointF(p.x(),p.y()+pW), QPointF(cX+cW/2,cY+cH/2+pW), QPointF(cX+cW/2,cY+cH/2) }; gradient_side.setColorAt(1,pieces[pieces.size()-1].rgbColor); painter->setBrush(gradient_side); painter->drawPolygon(points,4); } p = GetPoint(palpha); q = GetQuater(palpha); if (q ==1 || q==4) { QPointF points[4] = { QPointF(p.x(),p.y()), QPointF(p.x(),p.y()+pW), QPointF(cX+cW/2,cY+cH/2+pW), QPointF(cX+cW/2,cY+cH/2) }; gradient_side.setColorAt(1,pieces[0].rgbColor); painter->setBrush(gradient_side); painter->drawPolygon(points,4); } for (int i=0;i<pieces.size();i++) { gradient.setColorAt(0.5,pieces[i].rgbColor); painter->setBrush(gradient); pdegree = 3.6*pieces[i].pPerc; painter->drawPie(cX,cY,cW,cH,palpha*16,pdegree*16); double a_ = Angle360(palpha); int q_ = GetQuater(palpha); palpha += pdegree; double a = Angle360(palpha); int q = GetQuater(palpha); QPainterPath path; p = GetPoint(palpha); if((q == 3 || q == 4) && (q_ == 3 || q_ == 4)) { // 1) if (a>a_) { QPointF p_old = GetPoint(palpha-pdegree); path.moveTo(p_old.x()-1,p_old.y()); path.arcTo(cX,cY,cW,cH,palpha-pdegree,pdegree); path.lineTo(p.x(),p.y()+pW); path.arcTo(cX,cY+pW,cW,cH,palpha,-pdegree); } // 2) else { path.moveTo(cX,cY+cH/2); path.arcTo(cX,cY,cW,cH,180,Angle360(palpha)-180); path.lineTo(p.x(),p.y()+pW); path.arcTo(cX,cY+pW,cW,cH,Angle360(palpha),-Angle360(palpha)+180); path.lineTo(cX,cY+cH/2); path.moveTo(p.x(),p.y()); path.arcTo(cX,cY,cW,cH,palpha-pdegree,360-Angle360(palpha-pdegree)); path.lineTo(cX+cW,cY+cH/2+pW); path.arcTo(cX,cY+pW,cW,cH,0,-360+Angle360(palpha-pdegree)); } } // 3) else if((q == 3 || q == 4) && (q_ == 1 || q_ == 2) && a>a_ ) { path.moveTo(cX,cY+cH/2); path.arcTo(cX,cY,cW,cH,180,Angle360(palpha)-180); path.lineTo(p.x(),p.y()+pW); path.arcTo(cX,cY+pW,cW,cH,Angle360(palpha),-Angle360(palpha)+180); path.lineTo(cX,cY+cH/2); } // 4) else if((q == 1 || q == 2) && (q_ == 3 || q_ == 4) && a<a_) { p = GetPoint(palpha-pdegree); path.moveTo(p.x(),p.y()); path.arcTo(cX,cY,cW,cH,palpha-pdegree,360-Angle360(palpha-pdegree)); path.lineTo(cX+cW,cY+cH/2+pW); path.arcTo(cX,cY+pW,cW,cH,0,-360+Angle360(palpha-pdegree)); } // 5) else if((q ==1 || q==2) && (q_==1 || q_==2) && a<a_) { path.moveTo(cX,cY+cH/2); path.arcTo(cX,cY,cW,cH,180,180); path.lineTo(cX+cW,cY+cH/2+pW); path.arcTo(cX,cY+pW,cW,cH,0,-180); path.lineTo(cX,cY+cH/2); } if (!path.isEmpty()) { gradient_side.setColorAt(1,pieces[i].rgbColor); painter->setBrush(gradient_side); painter->drawPath(path); } } } else if (this->ctype==Nightcharts::Histogramm) { double pDist = 15; double pW = (cW-(pieces.size())*pDist)/pieces.size(); QLinearGradient gradient(cX+cW/2,cY,cX+cW/2,cY+cH); gradient.setColorAt(0,Qt::black); QPen pen; pen.setWidth(3); for (int i=0;i<pieces.size();i++) { if (shadows) { painter->setPen(Qt::NoPen); painter->setBrush(Qt::darkGray); painter->drawRect(cX+pDist+i*(pW + pDist)-pDist/2,cY+cH-1,pW,-cH/100*pieces[i].pPerc+pDist/2-5); } gradient.setColorAt(1,pieces[i].rgbColor); painter->setBrush(gradient); pen.setColor(pieces[i].rgbColor); painter->setPen(pen); painter->drawRect(cX+pDist+i*(pW + pDist),cY+cH,pW,-cH/100*pieces[i].pPerc-5); QString label = QString::number(pieces[i].pPerc)+"%"; painter->setPen(Qt::SolidLine); painter->drawText(cX+pDist+i*(pW + pDist)+pW/2-painter->fontMetrics().width(label)/2,cY+cH-cH/100*pieces[i].pPerc-painter->fontMetrics().height()/2,label); } painter->setPen(Qt::SolidLine); for (int i=1;i<10;i++) { painter->drawLine(cX-3,cY+cH/10*i,cX+3,cY+cH/10*i); //деления по оси Y //painter->drawText(cX-20,cY+cH/10*i,QString::number((10-i)*10)+"%"); } painter->drawLine(cX,cY+cH,cX,cY); //ось Y painter->drawLine(cX,cY,cX+4,cY+10); //стрелки painter->drawLine(cX,cY,cX-4,cY+10); painter->drawLine(cX,cY+cH,cX+cW,cY+cH); //ось Х } return 0; }
void PainterThread::drawAttrib(QPainter *p, Attributes *attrib) { if (attrib->getType() == TObsAgent) return; //---- Desenha o atributo p->begin(attrib->getImage()); p->setPen(Qt::NoPen); //defaultPen); //@RAIAN: Desenhando a vizinhanca if (attrib->getType() == TObsNeighborhood) { QColor color(Qt::white); QVector<QMap<QString, QList<double> > > *neighborhoods = attrib->getNeighValues(); QVector<ObsLegend> *vecLegend = attrib->getLegend(); QPen pen = p->pen(); pen.setStyle(Qt::SolidLine); pen.setWidth(attrib->getWidth()); // int random = qrand() % 256; double xCell = -1.0, yCell = -1.0; for (int pos = 0; pos < neighborhoods->size(); pos++) { QMap<QString, QList<double> > neigh = neighborhoods->at(pos); xCell = attrib->getXsValue()->at(pos); yCell = attrib->getYsValue()->at(pos); if ((xCell >= 0) && (yCell >=0)) { QMap<QString, QList<double> >::Iterator itNeigh = neigh.begin(); while (itNeigh != neigh.end()) { QString neighID = itNeigh.key(); QList<double> neighbor = itNeigh.value(); double xNeigh = neighbor.at(0); double yNeigh = neighbor.at(1); double weight = neighbor.at(2); if (vecLegend->isEmpty()) { weight = weight - attrib->getMinValue(); double c = weight * attrib->getVal2Color(); if (c >= 0 && c <= 255) { color.setRgb(c, c, c); } else { color.setRgb(255, 255, 255); } pen.setColor(color); } else { for (int j = 0; j < vecLegend->size(); j++) { ObsLegend leg = vecLegend->at(j); if (attrib->getGroupMode() == 3) { if (weight == leg.getTo().toDouble()) { pen.setColor(leg.getColor()); break; } } else { if ((leg.getFrom().toDouble() <= weight) && (weight < leg.getTo().toDouble())) { pen.setColor(leg.getColor()); break; } } } } p->setPen(pen); if ((xNeigh >= 0) && (yNeigh >= 0)) { drawNeighborhood(p, xCell, yCell, xNeigh, yNeigh); } itNeigh++; } } } } //@RAIAN: FIM else { if (attrib->getDataType() == TObsNumber) { QColor color(Qt::white); QVector<double> *values = attrib->getNumericValues(); QVector<ObsLegend> *vecLegend = attrib->getLegend(); double x = -1.0, y = -1.0, v = 0.0; int vSize = values->size(); int xSize = attrib->getXsValue()->size(); int ySize = attrib->getYsValue()->size(); for (int pos = 0; (pos < vSize && pos < xSize && pos < ySize); pos++) { v = values->at(pos); // Corrige o bug gerando quando um agente morre if (attrib->getXsValue()->isEmpty() || attrib->getXsValue()->size() == pos) break; x = attrib->getXsValue()->at(pos); y = attrib->getYsValue()->at(pos); if (vecLegend->isEmpty()) { v = v - attrib->getMinValue(); double c = v * attrib->getVal2Color(); if ((c >= 0) && (c <= 255)) { color.setRgb(c, c, c); } else { color.setRgb(255, 255, 255); } p->setBrush(color); } else { for (int j = 0; j < vecLegend->size(); j++) { p->setBrush(Qt::white); const ObsLegend &leg = vecLegend->at(j); if (attrib->getGroupMode() == TObsUniqueValue) // valor ?nico 3 { if (v == leg.getToNumber()) { p->setBrush(leg.getColor()); break; } } else { if ((leg.getFromNumber() <= v) && (v < leg.getToNumber())) { p->setBrush(leg.getColor()); break; } } } } if ((x >= 0) && (y >= 0)) draw(p, attrib->getType(), x, y); } } else if (attrib->getDataType() == TObsText) { QVector<QString> *values = attrib->getTextValues(); QVector<ObsLegend> *vecLegend = attrib->getLegend(); int random = qrand() % 256; double x = -1.0, y = -1.0; int vSize = values->size(); int xSize = attrib->getXsValue()->size(); int ySize = attrib->getYsValue()->size(); for (int pos = 0; (pos < vSize && pos < xSize && pos < ySize); pos++) { const QString & v = values->at(pos); // Corrige o bug gerando quando um agente morre if (attrib->getXsValue()->isEmpty() || attrib->getXsValue()->size() == pos) break; x = attrib->getXsValue()->at(pos); y = attrib->getYsValue()->at(pos); if (vecLegend->isEmpty()) { p->setBrush(QColor(random, random, random)); } else { p->setBrush(Qt::white); for (int j = 0; j < vecLegend->size(); j++) { const ObsLegend &leg = vecLegend->at(j); if (v == leg.getFrom()) { p->setBrush(leg.getColor()); break; } } } if ((x >= 0) && (y >= 0)) draw(p, attrib->getType(), x, y); } } } p->end(); }
void CellItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(widget); Q_UNUSED(option); QRectF frame(QPointF(0, 0), geometry().size()); qreal rounded_pix = (frame.width() + frame.height()) / 30; qreal background_opacity = 1; switch (state) { case STATE_DEFAULT: painter->setBrush(QBrush(background_color_default, Qt::SolidPattern)); break; case STATE_NOT_ALLOWED: painter->setBrush(QBrush(background_color_not_allowed, Qt::SolidPattern)); background_opacity = 0.5; break; case STATE_SELECTED: painter->setBrush(QBrush(background_color_selected, Qt::SolidPattern)); break; default: break; } QPen pen; pen.setWidth(1); if (is_wait_char) pen.setColor(border_color_wait_char ); else { if (is_focused) pen.setColor( border_color_focused ); else pen.setColor( border_color_unfocused ); } painter->setPen( pen ); painter->setOpacity(background_opacity); painter->save(); painter->rotate(angle); painter->drawRoundedRect(frame, rounded_pix, rounded_pix); painter->restore(); painter->setOpacity(1); if (!is_empty) { QFont font; font.setPixelSize(frame.height() / 2); font.setBold(true); if (is_font_marked) { font.setItalic(true); painter->setPen(font_color_marked); } else painter->setPen(font_color_unmarked); painter->setFont(font); painter->drawText(frame, c, QTextOption(Qt::AlignCenter)); } }
void scene::prepareItem(QPoint startpoint) { selecting=true; start=startpoint; tool=currenttool; if(rect!=NULL) { removeItem(rect); rect=NULL; } if(ellipse!=NULL) { removeItem(ellipse); ellipse=NULL; } if(line!=NULL) { removeItem(line); line=NULL; } handles.clear(); QPen pen; pen.setWidth(0); pen.setColor(Qt::red); QBrush brush; switch (tool) { case 0: { rect=addRect(start.x(),start.y(),0,0,pen,brush); for(int i=0;i<4;i++) { QGraphicsRectItem* handle=new QGraphicsRectItem(start.x()-handlew/2,start.y()-handleh/2,handlew,handleh,rect); handle->setPen(pen); handles<<handle; } ellipse=addEllipse(rect->rect(),pen,brush); break; } case 1: { line=addLine(start.x(),start.y(),start.x(),start.y(),pen); for(int i=0;i<3;i++) { QGraphicsRectItem* handle=new QGraphicsRectItem(start.x()-handlew/2,start.y()-handleh/2,handlew,handleh,line); handle->setPen(pen); handles<<handle; } break; } case 2: { rect=addRect(start.x(),start.y(),0,0,pen,brush); for(int i=0;i<4;i++) { QGraphicsRectItem* handle=new QGraphicsRectItem(start.x()-handlew/2,start.y()-handleh/2,handlew,handleh,rect); handle->setPen(pen); handles<<handle; } break; } case 3: { rect=addRect(start.x()-handlew/2,start.y()-handleh/2,handlew,handleh,pen,brush); QGraphicsRectItem* handle=new QGraphicsRectItem(start.x()-handlew/2,start.y()-handleh/2,handlew,handleh,rect); handle->setPen(pen); QGraphicsLineItem* line=new QGraphicsLineItem(start.x()-10,start.y(),start.x()+10,start.y(),rect); line->setPen(pen); line=new QGraphicsLineItem(start.x(),start.y()-10,start.x(),start.y()+10,rect); line->setPen(pen); handles<<handle; } break; default: break; } }
void ConnectionPainter:: paint(QPainter* painter, ConnectionGeometry const& geom, ConnectionState const& state) { double const lineWidth = geom.lineWidth(); double const pointDiameter = geom.pointDiameter(); #ifdef DEBUG_DRAWING { QPointF const& source = geom.source(); QPointF const& sink = geom.sink(); auto points = geom.pointsC1C2(); painter->setPen(Qt::red); painter->setBrush(Qt::red); painter->drawLine(QLineF(source, points.first)); painter->drawLine(QLineF(points.first, points.second)); painter->drawLine(QLineF(points.second, sink)); painter->drawEllipse(points.first, 4, 4); painter->drawEllipse(points.second, 4, 4); painter->setBrush(Qt::NoBrush); painter->drawPath(cubicPath()); } #endif auto cubic = cubicPath(geom); bool const hovered = geom.hovered(); if (hovered) { QPen p; p.setWidth(2 * lineWidth); p.setColor(QColor(Qt::cyan).lighter()); painter->setPen(p); painter->setBrush(Qt::NoBrush); // cubic spline painter->drawPath(cubic); } // draw normal line { QPen p; p.setWidth(lineWidth); p.setColor(QColor(Qt::cyan).darker(150)); if (state.requiresPort()) { p.setWidth(2.0); p.setColor(QColor(Qt::gray)); p.setStyle(Qt::DashLine); } painter->setPen(p); painter->setBrush(Qt::NoBrush); // cubic spline painter->drawPath(cubic); } QPointF const& source = geom.source(); QPointF const& sink = geom.sink(); painter->setPen(Qt::white); painter->setBrush(Qt::white); double const pointRadius = pointDiameter / 2.0; painter->drawEllipse(source, pointRadius, pointRadius); painter->drawEllipse(sink, pointRadius, pointRadius); }
// Paint event handler. void LfoScreen::paintEvent(QPaintEvent*) { QPainter p(this); QPen pen; pen.setWidth(1); p.setFont(QFont("Helvetica", 8)); p.setPen(pen); int l1, l2; int nsteps = 0.0; int beat = 4; int npoints = 0; int ypos, xpos, xscale, yscale; w = QWidget::width(); h = QWidget::height(); int notestreak_thick = 2; int ofs; int x, x1; int beatRes = 1; int beatDiv = 0; int grooveTmp = 0; l2 = 0; //Grid if (p_data.isEmpty()) return; npoints = p_data.count() - 1; nsteps = p_data.at(npoints).tick / TPQN; beatRes = npoints / nsteps; beatDiv = (npoints > 64) ? 64 / nsteps : beatRes; xscale = (w - 2 * LFOSCR_HMARG); yscale = h - 2 * LFOSCR_VMARG; //Beryll Filled Frame if (isMuted) p.fillRect(0, 0, w, h, QColor(70, 70, 70)); else p.fillRect(0, 0, w, h, QColor(50, 10, 10)); p.setViewport(0, 0, w, h); p.setWindow(0, 0, w, h); p.setPen(QColor(160, 20, 20)); //Beat separators for (l1 = 0; l1 < nsteps + 1; l1++) { if (l1 < 10) { ofs = w / nsteps * .5 - 4 + LFOSCR_HMARG; } else { ofs = w / nsteps * .5 - 6 + LFOSCR_HMARG; } if ((bool)(l1%beat)) { p.setPen(QColor(180, 100, 60)); } else { p.setPen(QColor(180, 100, 100)); } x = l1 * xscale / nsteps; p.drawLine(LFOSCR_HMARG + x, LFOSCR_VMARG, LFOSCR_HMARG + x, h-LFOSCR_VMARG); if (l1 < nsteps) { p.setPen(QColor(180, 150, 100)); //Beat numbers p.drawText(ofs + x, LFOSCR_VMARG, QString::number(l1+1)); // Beat divisor separators p.setPen(QColor(120, 60, 20)); x1 = x; for (l2 = 1; l2 < beatDiv; l2++) { x1 = x + l2 * xscale / nsteps / beatDiv; if (x1 < xscale) p.drawLine(LFOSCR_HMARG + x1, LFOSCR_VMARG, LFOSCR_HMARG + x1, h - LFOSCR_VMARG); } } xMax = LFOSCR_HMARG + x; } //Draw function pen.setWidth(notestreak_thick); p.setPen(pen); grooveTmp = (beatRes < 32) ? grooveTick : 0; l1 = 0; while (l1 < npoints) { x = (l1 + .01 * (double)grooveTmp * (l1 % 2)) * xscale / npoints; ypos = yscale - yscale * p_data.at(l1).value / 128 + LFOSCR_VMARG; xpos = LFOSCR_HMARG + x + pen.width() / 2; if (p_data.at(l1).muted) { pen.setColor(QColor(100, 40, 5)); } else { pen.setColor(QColor(180, 130, 50)); } p.setPen(pen); p.drawLine(xpos, ypos, xpos + (xscale / nsteps / beatRes) - (pen.width()/(2+npoints/(TPQN*8))), ypos); l1++; l1+=npoints/(TPQN*4); } //Horizontal separators and numbers p.setPen(QColor(180, 120, 40)); for (l1 = 0; l1 < 3; l1++) { ypos = yscale * l1 / 2 + LFOSCR_VMARG; p.drawLine(LFOSCR_HMARG, ypos, xMax, ypos); p.drawText(1, yscale * (l1) + LFOSCR_VMARG + 4, QString::number(128 * (1 - l1))); } }
void Plotter::drawGrid(QPainter *painter) { //qDebug() << "Inside DrawGrid"; QRect rect(Margin,Margin,width()-2*Margin,height()-2*Margin); if(!rect.isValid()) return; QPen pen; QColor objColor(55,55,55,255); pen.setBrush(Qt::darkGray); pen.setStyle(Qt::DotLine); pen.setColor(objColor); pen.setCapStyle(Qt::RoundCap); pen.setJoinStyle(Qt::RoundJoin); painter->setPen(pen); //QPoint *pixPoint = new QPoint(); PlotSettings settings = zoomStack[curZoom]; if(m_bGrid) { for(int i=0;i<settings.numXTicks;i++) { int x = rect.left() + (i * (rect.width()) / settings.numXTicks); double label = settings.minX + (i*settings.spanX()/settings.numXTicks); //printf("X Axis:%f\n",label); for(float l_nPoint=1;l_nPoint<rect.height();l_nPoint+=2.0) painter->drawPoint(QPointF(x,rect.top()+l_nPoint)); //painter->drawLine(x,rect.bottom(),x,rect.bottom()+5); painter->drawText(x-50,rect.bottom()+5,100,20, Qt::AlignHCenter|Qt::AlignTop,QString::number(label,5,2)); } for(int j=0;j<settings.numYTicks;j++) { int y = rect.bottom() - (j * (rect.height()) / settings.numYTicks); double label = settings.minY + (j*settings.spanY()/settings.numYTicks); //printf("Y Axis:%f\n",label); for(float l_nPoint=0;l_nPoint<rect.width();l_nPoint+=2.0) painter->drawPoint(QPointF(rect.left()+l_nPoint,y)); //painter->drawLine(rect.left(),y,rect.right(),y); painter->drawText(rect.left()-Margin,y-10,Margin-5, 20,Qt::AlignRight|Qt::AlignVCenter,QString::number(label,5,2)); } pen.setStyle(Qt::SolidLine); painter->setPen(pen); //int Value =0; for(int i=0;i<rect.height();i+=((rect.height()/settings.numYTicks)/5)) { if(i!=0 && i%5!=0){ //painter->drawLine(Margin+rect.width()/2-3,Margin+i,Margin+rect.width()/2+3,Margin+i); } } for(int j=0;j<rect.width();j+=(rect.width()/settings.numXTicks)/5 ) { if(j!=0 && j%5!=0){ //painter->drawLine(Margin+j,Margin+rect.height()/2-3,Margin+j,Margin+rect.height()/2+3); } } } if(m_bGrid == false){ pen.setStyle(Qt::SolidLine); pen.setBrush(Qt::darkGray); pen.setColor(objColor); pen.setWidth(1); painter->setPen(pen); /*vertical line*/ painter->drawLine(Margin+rect.width()/2-1,Margin,Margin+rect.width()/2-1,Margin+rect.height()); /*horizontal line*/ painter->drawLine(Margin,Margin+rect.height()/2-1,Margin+rect.width(),Margin+rect.height()/2-1); for(int i=0;i<rect.height();i+=((rect.height()/settings.numYTicks)/2)) { if(i!=0 && i%2!=0) { /*vertical grid*/ painter->drawLine((Margin+rect.width()/2-3)-1,Margin+i,(Margin+rect.width()/2+3)-1,Margin+i); } } for(int j=0;j<rect.width();j=j+(rect.width()/settings.numXTicks)+5 ) { if(j!=0) { /*horizontal grid*/ painter->drawLine(Margin+j-5,Margin+rect.height()/2-3,Margin+j-5,Margin+rect.height()/2+3); } } } if(m_bVILabels == true) { pen.setWidth(2); pen.setBrush(Qt::gray); painter->setPen(pen); //qDebug() << "XLabel" << m_strXLabel << "YLabel" << m_strYLabel; painter->drawText(Margin+rect.width()/2+8,3,65,45,Qt::AlignLeft|Qt::AlignTop,m_strY1Label); painter->drawText(4,Margin+rect.height()/2+2,35,45,Qt::AlignLeft|Qt::AlignTop,m_strX1Label); painter->drawText(Margin+rect.width()-35,Margin+rect.height()/2,35,45,Qt::AlignHCenter|Qt::AlignTop,m_strX2Label); painter->drawText(Margin+rect.width()/2+8,Margin+rect.height()-20,65,45,Qt::AlignLeft|Qt::AlignTop,m_strY2Label); } //painter->drawRect(rect.adjusted(+0,+0,-1,-1)); // qDebug() << "outSide DrawGrid"; //painter->drawRect(rect.adjusted(+0,+0,-1,-1)); }
void qtvplugin_geomarker::on_pushButton_QTV_update_clicked() { if (m_pVi==0 || !m_pScene) return; QString name = ui->lineEdit_QTV_currentID->text(); ini_save(); //Get pen and brush settings Qt::PenStyle pst [] ={ Qt::NoPen , Qt::SolidLine , Qt::DashLine , Qt::DotLine , Qt::DashDotLine , Qt::DashDotDotLine , Qt::CustomDashLine }; Qt::BrushStyle bst [] = { Qt::NoBrush, Qt::SolidPattern, Qt::Dense1Pattern, Qt::Dense2Pattern, Qt::Dense3Pattern, Qt::Dense4Pattern, Qt::Dense5Pattern, Qt::Dense6Pattern, Qt::Dense7Pattern, Qt::HorPattern, Qt::VerPattern, Qt::CrossPattern, Qt::BDiagPattern, Qt::FDiagPattern, Qt::DiagCrossPattern }; int ptdd = ui->comboBox_QTV_linePad->currentIndex(); if (ptdd < 0 || ptdd >=7) ptdd = 1; QColor penColor = string2color( ui->lineEdit_QTV_PenColor->text()); int penWidth = ui->spinBox_QTV_penWidth->value(); QPen pen;//(QBrush(color),width,pst[ptdd]); pen.setColor(penColor); pen.setWidth(penWidth); pen.setStyle(pst[ptdd]); int btdd = ui->comboBox_QTV_fillPad->currentIndex(); if (btdd < 0 || btdd >=15) btdd = 1; QColor brushColor = string2color( ui->lineEdit_QTV_FillColor->text()); QBrush brush; brush.setColor(brushColor); brush.setStyle(bst[btdd]); QTVP_GEOMARKER::geoItemBase * newitem = 0; if (ui->radioButton_QTV_tool_point->isChecked()) { double lat = ui->lineEdit_QTV_point_lat->text().toDouble(); double lon = ui->lineEdit_QTV_point_lon->text().toDouble(); int tp = ui->radioButton_QTV_PointRect->isChecked()?0:1; int width = ui->spinBox_QTV_point_width->value(); int height = ui->spinBox_QTV_point_height->value(); if (tp==0) newitem = update_point<QTVP_GEOMARKER::geoGraphicsRectItem>(name,lat,lon,width,height,pen,brush); else newitem = update_point<QTVP_GEOMARKER::geoGraphicsEllipseItem>(name,lat,lon,width,height,pen,brush); } else if (ui->radioButton_QTV_tool_line->isChecked()) { double lat1 = ui->lineEdit_QTV_lineLat1->text().toDouble(); double lat2 = ui->lineEdit_QTV_lineLat2->text().toDouble(); double lon1 = ui->lineEdit_QTV_lineLon1->text().toDouble(); double lon2 = ui->lineEdit_QTV_lineLon2->text().toDouble(); newitem = update_line(name,lat1,lon1,lat2,lon2,pen); } else if (ui->radioButton_QTV_tool_polygon->isChecked()) { QPolygonF latlons; QString strPlainTexts = ui->plainTextEdit_QTV_corners->toPlainText(); strPlainTexts.remove(' '); strPlainTexts.remove('\n'); strPlainTexts.remove('\r'); strPlainTexts.remove('\015'); strPlainTexts.remove('\012'); QStringList lst = strPlainTexts.split(QRegExp("[,;]"),QString::SkipEmptyParts); int c = 0; QPointF ll; foreach (QString s,lst) { if (c%2==0) ll.setY(s.toDouble()); else ll.setX(s.toDouble()); if ((++c) % 2==0) latlons.push_back(ll); } if (latlons.size()) newitem = update_polygon(name,latlons,pen,brush,ui->checkBox_QTV_multiline->isChecked()?true:false); }
/*! \brief Draw the scale \param painter The painter \param palette Palette, text color is used for the labels, foreground color for ticks and backbone */ void QwtAbstractScaleDraw::draw( QPainter *painter, const QPalette& palette ) const { painter->save(); QPen pen = painter->pen(); pen.setWidth( d_data->penWidth ); pen.setCosmetic( false ); painter->setPen( pen ); if ( hasComponent( QwtAbstractScaleDraw::Labels ) ) { painter->save(); painter->setPen( palette.color( QPalette::Text ) ); // ignore pen style const QList<double> &majorTicks = d_data->scaleDiv.ticks( QwtScaleDiv::MajorTick ); for ( int i = 0; i < majorTicks.count(); i++ ) { const double v = majorTicks[i]; if ( d_data->scaleDiv.contains( v ) ) drawLabel( painter, v ); } painter->restore(); } if ( hasComponent( QwtAbstractScaleDraw::Ticks ) ) { painter->save(); QPen pen = painter->pen(); pen.setColor( palette.color( QPalette::WindowText ) ); pen.setCapStyle( Qt::FlatCap ); painter->setPen( pen ); for ( int tickType = QwtScaleDiv::MinorTick; tickType < QwtScaleDiv::NTickTypes; tickType++ ) { const QList<double> &ticks = d_data->scaleDiv.ticks( tickType ); for ( int i = 0; i < ticks.count(); i++ ) { const double v = ticks[i]; if ( d_data->scaleDiv.contains( v ) ) drawTick( painter, v, d_data->tickLength[tickType] ); } } painter->restore(); } if ( hasComponent( QwtAbstractScaleDraw::Backbone ) ) { painter->save(); QPen pen = painter->pen(); pen.setColor( palette.color( QPalette::WindowText ) ); pen.setCapStyle( Qt::FlatCap ); painter->setPen( pen ); drawBackbone( painter ); painter->restore(); } painter->restore(); }
void WidgetHighlighter::paintEvent(QPaintEvent* event) { Q_UNUSED(event); //Painting the WidgetHighlighter over its parent widget with a //semi-transparent color is the best I could get. However, it has some //flaws. For example, a QMenu does not highlight its menu button. And some //widgets may be hardly highlighted if their background color is almost the //same as the highlight color (although it should not happen very often). // //Changing the parent widget palette does not work because some widgets //(like tool buttons) don't paint a background, only paint the text and get //its parent widget background. Forcing the painting of the background with //some color role does not help, as it may look ugly in some styles that use //a gradient for the background. Changing the palette has one benefit, //though, as it also changes the palette from the children widgets, which //means that a QMenu would highlight its menu button. // //Ideally, the highlighter should lighten its parent widget but when it is //too bright (for example, the white background of a text edit). In that //case, the parent widget should be darkened. To do this, however, the //WidgetHighlighter must know how its parent widget is painted. // //Calling QPixmap::grabWidget from the WidgetHighlighter::paintEvent is not //good, as it triggers a recursive paint event in its parent (provided the //WidgetHighlighter paintEvent is guarded against a recursive call, else the //application would directly hang). Calling it from the updateProgress and //storing the QPixmap in memory would theoretically work, but it showed some //strange artifacts. // //Setting a custom QGraphicsEffect does not seem like a good idea, as Qt can //be compiled without them, and because, as far as I know, only one effect //can be used on a widget at a time (as making a Composite design pattern //with something like QComposedGraphicsEffect class is pretty easy and there //is no such class, I presume that it is not a good idea to use several //effects on the same widget, at least for now). // //Anyway, I do not know how to check whether a picture is light or dark //quickly enough to be done in a realtime animation, so... a //semi-transparent colored child widget is good enough until someone makes //something better ;) // //However, filling the whole widget and animating it is too CPU intensive //when tinting a parent widget with lots of child widgets (for example, the //main widget in showfoto). So, instead of tinting the whole parent only //a frame is painted and animated. In this case, the frame gets its full //opacity at the peak of the animation, instead of half the opacity as used //when tinting the whole widget. //The inactive palette does not usually have a lot of contrast between //normal color and highlight color (for example, a QStatusBar in Oxygen //style). The highlight color from the active palette is used in every case //to ensure that the widget is clearly highlighted, even if the window is //not the active one. QColor color = mTargetWidget->palette().color(QPalette::Active, QPalette::Highlight); QPainter painter(this); painter.setOpacity(mProgress); QPen pen; pen.setWidth(mFrameWidth); pen.setColor(color); painter.setPen(pen); //Third and fourth arguments are width and height, not end coordinates painter.drawRect(pen.width() / 2, pen.width() / 2, width() - pen.width(), height() - pen.width()); painter.end(); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); // create MapControl mc = new MapControl(QSize(638,370)); mc->setObjectName("MapControl"); mc->showScale(true); ui->verticalLayout->addWidget(mc); mapadapter = new GoogleMapAdapter(); //MapAdapter* mapadapter_overlay = new YahooMapAdapter("us.maps3.yimg.com", "/aerial.maps.yimg.com/png?v=2.2&t=h&s=256&x=%2&y=%3&z=%1"); // create a layer with the mapadapter and type MapLayer l = new MapLayer("Custom Layer", mapadapter); // overlay = new MapLayer("Overlay", mapadapter_overlay); // overlay->setVisible(false); mc->addLayer(l); // mc->addLayer(overlay); notes = new GeometryLayer("Sun", mapadapter); mc->addLayer(notes); QPen* pen = new QPen(QColor(0,0,255,100)); pen->setWidth(5); sunRise = new Vector(8.85,51.46, 1000, 45, "SunRiseArrow", Vector::Middle, pen); sunSet = new Vector(8.85,51.46, 1000, 45, "SunSetArrow", Vector::Middle, pen); pen = new QPen(QColor(255,0,0,100)); pen->setWidth(5); sunHeading = new Vector(8.85,51.46, 1000, 45, "SunArrow", Vector::Middle, pen); QList<Point*> points; points << sunHeading; points << sunRise; points << sunSet; LineString* sunArrows = new LineString(points, "", pen); notes->addGeometry(sunArrows); mc->setUseBoundingBox(false); mc->setView(QPointF(8.85,51.46)); mc->setZoom(10); ui->dateTimeEdit->setDateTime(QDateTime::currentDateTime()); ui->latEdit->setText("51,46"); ui->lngEdit->setText("8,85"); addZoomButtons(); setSunRiseAndSetVectors(QDateTime::currentDateTime()); setSunCurrentHeading(QDateTime::currentDateTime()); }
void GlanceShower::Start () { if (!TabWidget_) { qWarning () << Q_FUNC_INFO << "no tab widget set"; return; } int count = TabWidget_->count (); if (count < 2) return; QSequentialAnimationGroup *animGroup = new QSequentialAnimationGroup; int sqr = std::sqrt ((double)count); int rows = sqr; int cols = sqr; if (rows * cols < count) ++cols; if (rows * cols < count) ++rows; QRect screenGeom = QApplication::desktop ()-> screenGeometry (Core::Instance ().GetReallyMainWindow ()); int width = screenGeom.width (); int height = screenGeom.height (); int singleW = width / cols; int singleH = height / rows; int wW = singleW * 4 / 5; int wH = singleH * 4 / 5; qreal scaleFactor = 0; QSize sSize; int animLength = 500 / (sqr); QProgressDialog pg; pg.setMinimumDuration (1000); pg.setRange (0, count); for (int row = 0; row < rows; ++row) for (int column = 0; column < cols && column + row * cols < count; ++column) { int idx = column + row * cols; pg.setValue (idx); QWidget *w = TabWidget_->widget (idx); if (!sSize.isValid ()) sSize = w->size () / 2; if (sSize != w->size ()) w->resize (sSize * 2); if (!scaleFactor) scaleFactor = std::min (static_cast<qreal> (wW) / sSize.width (), static_cast<qreal> (wH) / sSize.height ()); QPixmap pixmap (sSize * 2); w->render (&pixmap); pixmap = pixmap.scaled (sSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); { QPainter p (&pixmap); QPen pen (Qt::black); pen.setWidth (2 / scaleFactor + 1); p.setPen (pen); p.drawRect (QRect (QPoint (0, 0), sSize)); } GlanceItem *item = new GlanceItem (pixmap); item->SetIndex (idx); connect (item, SIGNAL (clicked (int)), this, SLOT (handleClicked (int))); Scene_->addItem (item); item->setTransformOriginPoint (sSize.width () / 2, sSize.height () / 2); item->setScale (scaleFactor); item->SetIdealScale (scaleFactor); item->setOpacity (0); item->moveBy (column * singleW, row * singleH); QParallelAnimationGroup *pair = new QParallelAnimationGroup; QPropertyAnimation *posAnim = new QPropertyAnimation (item, "Pos"); posAnim->setDuration (animLength); posAnim->setStartValue (QPointF (0, 0)); posAnim->setEndValue (QPointF (column * singleW, row * singleH)); posAnim->setEasingCurve (QEasingCurve::OutSine); pair->addAnimation (posAnim); QPropertyAnimation *opacityAnim = new QPropertyAnimation (item, "Opacity"); opacityAnim->setDuration (animLength); opacityAnim->setStartValue (0.); opacityAnim->setEndValue (1.); pair->addAnimation (opacityAnim); animGroup->addAnimation (pair); } setScene (Scene_); setGeometry (screenGeom); animGroup->start (); show (); }
void DiagramCanvas::paint_all( QRect& r ) { int i; QPainter p( &buffer ); QPen pen; QBrush brush; QPointArray a; QColor color; QRegion mask, crossing_disk; set<double>::iterator dbl_it; for ( i=0; i<crossingList.size(); ++i ) { Crossing *c = crossingList[i]; c->under->underpasses.insert( c->under->underpasses.end(), c->position_on_understrand ); } for ( i=0; i<edgeList.size(); ++i ) { Edge *e = edgeList[i]; pen.setWidth( e->thickness ); pen.setColor( CANVAS ); p.setPen( pen ); QPoint v, v1, v2, p1, p2 ; p1 = e->vertex[begin]->position; p2 = e->vertex[end]->position; p.drawLine( p1, p2 ); /* if (e->edge_type==singular) { v = p1 - p2; v1.setX( v.x() - v.y() ); v1.setY( v.x() + v.y() ); v2.setX( v.x() + v.y() ); v2.setY( -v.x() + v.y() ); v1 = 5 * v1 / sqrt( double (v1.x() * v1.x() + v1.y() * v1.y()) ); v2 = 5 * v2 / sqrt( double (v2.x() * v2.x() + v2.y() * v2.y()) ); v = v / 2; pen.setWidth( ARROW ); p.setPen( pen ); p.drawLine( p2+v, p2+v1+v ); p.drawLine( p2+v, p2+v2+v ); } */ } for ( i=0; i<edgeList.size(); ++i ) { Edge *e = edgeList[i]; color = (e->edge_type == drilled) ? DRILLED : colorList[e->arc_id % 18 ]; pen.setWidth( e->thickness ); pen.setColor( color ); p.setPen( pen ); brush.setColor( color ); brush.setStyle( SolidPattern ); p.setBrush( brush ); if ( e->underpasses.size() > 0 ) { p.setClipping( TRUE ); mask = QRegion( 0, 0, width(), height(), QRegion::Rectangle ); for ( dbl_it=e->underpasses.begin(); dbl_it!=e->underpasses.end(); ++dbl_it ) { QPoint center = time_to_point( e, *dbl_it ); crossing_disk = QRegion( center.x()-7, center.y()-7, 14, 14 , QRegion::Ellipse ); mask -= crossing_disk; } p.setClipRegion( mask ); QPoint v, v1, v2, p1, p2 ; p1 = e->vertex[begin]->position; p2 = e->vertex[end]->position; p.drawLine( p1, p2 ); /* if (e->edge_type==singular) { v = p1 - p2; v1.setX( v.x() - v.y() ); v1.setY( v.x() + v.y() ); v2.setX( v.x() + v.y() ); v2.setY( -v.x() + v.y() ); v1 = 5 * v1 / sqrt( double (v1.x() * v1.x() + v1.y() * v1.y()) ); v2 = 5 * v2 / sqrt( double (v2.x() * v2.x() + v2.y() * v2.y()) ); v = v / 2; pen.setWidth( ARROW ); p.setPen( pen ); p.drawLine( p2+v, p2+v1+v ); p.drawLine( p2+v, p2+v2+v ); } */ p.setClipping( FALSE ); } else { QPoint v, v1, v2, p1, p2 ; p1 = e->vertex[begin]->position; p2 = e->vertex[end]->position; p.drawLine( p1, p2 ); /* if (e->edge_type==singular) { v = p1 - p2; v1.setX( v.x() - v.y() ); v1.setY( v.x() + v.y() ); v2.setX( v.x() + v.y() ); v2.setY( -v.x() + v.y() ); v1 = 5 * v1 / sqrt( double (v1.x() * v1.x() + v1.y() * v1.y()) ); v2 = 5 * v2 / sqrt( double (v2.x() * v2.x() + v2.y() * v2.y()) ); v = v / 2; pen.setWidth( ARROW ); p.setPen( pen ); p.drawLine( p2+v, p2+v1+v ); p.drawLine( p2+v, p2+v2+v ); } */ } e->underpasses.clear(); } p.end(); bitBlt( this, r.x(), r.y(), &buffer, r.x(), r.y(), r.width(), r.height() ); }
/** * \brief Paint sequence to screen. */ void KeyComponent::paint(QPainter * painter, const QRect & rect) { // Only if parented if (this->alignmentView()) { // Set font to be a little smaller than usual QFont font = painter->font(); font.setPointSizeF(8); painter->setFont(font); QPair< int, AlignmentView::ComponentPosition > logicalKeyPosition = this->alignmentView()->componentPosition(this); int actualKeyPosition = this->alignmentView()->logicalToActualComponent(logicalKeyPosition.first, logicalKeyPosition.second); bool top = actualKeyPosition != 0; bool bottom = actualKeyPosition != (this->alignmentView()->componentCount() - 1); // Draw control painter->setPen(Qt::NoPen); painter->setBrush(QColor(245, 245, 255)); painter->drawRect(rect); // Set style painter->setPen(this->alignmentView()->palette().color(QPalette::Dark)); QPen pen = painter->pen(); pen.setWidth(1); painter->setPen(pen); // Find cell sizes double unitSize = this->alignmentView()->unitSizeF(); int firstUnit = this->alignmentIndexAt(rect.topLeft()); int lastUnit = this->alignmentIndexAt(rect.topRight()); int height = this->height(); // Calculate legend frequency int interval = 1; if (unitSize < 100) { double unitsIn100 = 100 / unitSize; double log = log10(unitsIn100); interval = pow(10, ceil(log)); // if (log > 1.3) { interval = 20; } // else if (log > 0.8) { interval = 10; } // else { interval = 5; } } for (int actual = firstUnit; actual <= lastUnit; ++actual) { int index = actual + 1; QRectF unitRect = this->rectAt(actual); int unitMiddle = unitRect.center().x(); int ext = 0; if (index % interval == 0) { ext = 3; } // Ticks if (bottom) { painter->drawLine(unitMiddle, this->height() - 1, unitMiddle, this->height() - 3 - ext); } if (top) { painter->drawLine(unitMiddle, 0, unitMiddle, 2 + ext); } // Legend if (index % interval == 0) { QRect textRect(unitRect.left() - 30, unitRect.top() + 1, unitRect.width() + 60, unitRect.bottom()); painter->drawText(textRect, Qt::AlignVCenter | Qt::AlignHCenter, QString("%1").arg(index)); } } pen = painter->pen(); pen.setWidth(1); painter->setPen(pen); if (bottom) { painter->drawLine(rect.left(), this->height() - 1, rect.right(), this->height() - 1); } if (top) { painter->drawLine(rect.left(), 0, rect.right(), 0); } } }
void RangeWidget::paint_view(QPainter *painter, const QRectF &rect) { QPen pen; pen.setColor(QColor("#F28585")); pen.setWidth(10); painter->setPen(pen); painter->setRenderHint(QPainter::Antialiasing); painter->setRenderHint(QPainter::HighQualityAntialiasing); QRectF handle(this->boundingRect().center().x() - 5, this->boundingRect().center().y() - 5, 10, 10); QRectF borderRect(boundingRect().x() + 24, boundingRect().y() + 24, boundingRect().width() - 48, boundingRect().height() - 48); painter->save(); QPen pen_border; pen_border.setColor(QColor("#F0F0F0")); pen_border.setWidth(4); painter->setPen(pen_border); // painter->drawEllipse(borderRect); painter->drawLine( QPointF(0.0, this->boundingRect().height() / 2), QPointF(this->boundingRect().width(), this->boundingRect().height() / 2)); painter->restore(); /* QPainterPath clockInisde; clockInisde.addEllipse(QRectF(borderRect.x() + 2, borderRect.y() + 2, borderRect.width() - 4 , borderRect.height() - 4)); //painter->fillPath(clockInisde, QColor("#F28585")); painter->fillPath(clockInisde, QColor(Qt::white)); QFont font = painter->font(); font.setBold(true); font.setPixelSize(32); painter->save(); painter->setFont(font); // painter->drawText(borderRect, Qt::AlignCenter, d->convertAngleToTimeString(d->mAngle)); painter->restore(); painter->save(); QTransform xform; QPointF transPos = this->boundingRect().center(); xform.translate(transPos.x(), transPos.y()); xform.rotate(d->mAngle); xform.translate(-transPos.x(), -transPos.y()); painter->setTransform(xform); QLineF line(handle.center(), QPointF(boundingRect().width() - 48, (boundingRect().height() / 2) - 48)); // QRectF ctrRect(line.x2(), line.y2(), 10, 10); QRectF ctrFrameRect(line.x2(), line.y2(), 32, 32); QPainterPath path; path.addEllipse(ctrFrameRect); painter->fillPath(path, QColor(Qt::white)); painter->fillPath(path, QColor("#F28585")); QPen whitePen; whitePen.setColor(Qt::white); painter->setPen(whitePen); painter->drawText(ctrFrameRect, Qt::AlignCenter, QString("%1").arg((int)d->mProgressValue)); painter->restore(); */ }
QImage* MyTextEffect::drawImage() { QFont myFont; QPen myPen; myPen.setJoinStyle( Qt::RoundJoin ); QBrush myBrush( QColor(0,0,0,0) ); QColor backgroundColor(0,0,0,0); int outline = 0; int align = 1; int arrowType = 0, arrowSize = 0, arrowPos = 0; QStringList sl = currentText.split("\n"); while ( !sl.isEmpty() ) { if ( sl.last().trimmed().isEmpty() ) sl.takeLast(); else break; } if ( sl.count() ) { QStringList desc = sl[0].split("|"); if ( desc.count() >= 9 ) { myFont.fromString( desc[0] ); myFont.setPointSize( desc[1].toInt() ); myFont.setBold( desc[2].toInt() ); myFont.setItalic( desc[3].toInt() ); QStringList fc = desc[4].split( "." ); if ( fc.count() == 2 ) { QColor col; col.setNamedColor( fc[ 0 ] ); col.setAlpha( fc[ 1 ].toInt() ); myPen.setColor( col ); myBrush.setColor( col ); } QStringList bc = desc[5].split( "." ); if ( bc.count() == 2 ) { backgroundColor.setNamedColor( bc[ 0 ] ); backgroundColor.setAlpha( bc[ 1 ].toInt() ); } align = desc[6].toInt(); int osize = desc[7].toInt(); if ( osize > 0 ) { QStringList oc = desc[8].split( "." ); if ( oc.count() == 2 ) { outline = osize; myPen.setWidth( osize ); myFont.setStyleStrategy( QFont::ForceOutline ); QColor col; col.setNamedColor( oc[ 0 ] ); col.setAlpha( oc[ 1 ].toInt() ); myPen.setColor( col ); } } } if ( desc.count() >= 12 ) { arrowType = desc[9].toInt(); arrowSize = desc[10].toInt(); arrowPos = desc[11].toInt(); } sl.takeFirst(); } QImage *image = new QImage( 10, 10, QImage::Format_ARGB32_Premultiplied ); QPainter painter; painter.begin( image ); painter.setPen( myPen ); painter.setBrush( myBrush ); painter.setFont( myFont ); QList<QRectF> br; QFontMetrics metrics( myFont ); int h = sl.count() * metrics.lineSpacing(); int w = 0; for ( int i = 0; i < sl.count(); ++i ) { QRectF minrect( 0, 0, 1, 1 ); QRectF r = painter.boundingRect( minrect, Qt::AlignHCenter | Qt::AlignVCenter, sl[i] ); if ( r.width() > w ) w = r.width(); br.append( r ); } QRectF minrect( 0, 0, 1, 1 ); int margin = qMax( painter.boundingRect( minrect, Qt::AlignHCenter | Qt::AlignVCenter, "M" ).width() / 3.0, 3.0 ); painter.end(); double x = ((double)outline + margin * 2) / 2.0; double y = x; w += 2 * x; h += 2 * y; if ( w > iwidth ) { x -= (w - iwidth) / 2.0; w = iwidth; } if ( h > iheight ) { y -= (h - iheight) / 2.0; h = iheight; } QPointF polygon[7]; arrowSize = h * arrowSize / 100.0; int n = 0; int leftOffset = 0, topOffset = 0; int wMargin = 0, hMargin = 0; if (arrowType) { switch (arrowType) { case 1: { leftOffset = arrowSize; wMargin = arrowSize; polygon[n].setX(1 + arrowSize); polygon[n++].setY(1); polygon[n].setY(qMax(1.0, qMin(h - 1.0, h * arrowPos / 100.0 - arrowSize / 2.0) ) ); polygon[n++].setX(1 + arrowSize); polygon[n].setY(qMax(1.0, qMin(h - 1.0, h * arrowPos / 100.0) ) ); polygon[n++].setX(1); polygon[n].setY(qMax(1.0, qMin(h - 1.0, h * arrowPos / 100.0 + arrowSize / 2.0) ) ); polygon[n++].setX(1 + arrowSize); polygon[n].setX(1 + arrowSize); polygon[n++].setY(h - 1); polygon[n].setX(w - 1 + arrowSize); polygon[n++].setY(h - 1); polygon[n].setX(w - 1 + arrowSize); polygon[n++].setY(1); break; } case 2: { wMargin = arrowSize; polygon[n].setX(1); polygon[n++].setY(1); polygon[n].setX(1); polygon[n++].setY(h - 1); polygon[n].setX(w - 1); polygon[n++].setY(h - 1); polygon[n].setY(qMax(1.0, qMin(h - 1.0, h * arrowPos / 100.0 + arrowSize / 2.0) ) ); polygon[n++].setX(w - 1); polygon[n].setY(qMax(1.0, qMin(h - 1.0, h * arrowPos / 100.0) ) ); polygon[n++].setX(w - 1 + arrowSize); polygon[n].setY(qMax(1.0, qMin(h - 1.0, h * arrowPos / 100.0 - arrowSize / 2.0) ) ); polygon[n++].setX(w - 1); polygon[n].setX(w - 1); polygon[n++].setY(1); break; } case 3: { topOffset = arrowSize; hMargin = arrowSize; polygon[n].setX(1); polygon[n++].setY(1 + arrowSize); polygon[n].setX(1); polygon[n++].setY(h - 1 + arrowSize); polygon[n].setX(w - 1); polygon[n++].setY(h - 1 + arrowSize); polygon[n].setX(w - 1); polygon[n++].setY(1 + arrowSize); polygon[n].setX(qMax(1.0, qMin(w - 1.0, w * arrowPos / 100.0 + arrowSize / 2.0) ) ); polygon[n++].setY(1 + arrowSize); polygon[n].setX(qMax(1.0, qMin(w - 1.0, w * arrowPos / 100.0) ) ); polygon[n++].setY(1); polygon[n].setX(qMax(1.0, qMin(w - 1.0, w * arrowPos / 100.0 - arrowSize / 2.0) ) ); polygon[n++].setY(1 + arrowSize); break; } case 4: { hMargin = arrowSize; polygon[n].setX(1); polygon[n++].setY(1); polygon[n].setX(1); polygon[n++].setY(h - 1); polygon[n].setX(qMax(1.0, qMin(w - 1.0, w * arrowPos / 100.0 - arrowSize / 2.0) ) ); polygon[n++].setY(h - 1); polygon[n].setX(qMax(1.0, qMin(w - 1.0, w * arrowPos / 100.0) ) ); polygon[n++].setY(h - 1 + arrowSize); polygon[n].setX(qMax(1.0, qMin(w - 1.0, w * arrowPos / 100.0 + arrowSize / 2.0) ) ); polygon[n++].setY(h - 1); polygon[n].setX(w - 1); polygon[n++].setY(h - 1); polygon[n].setX(w - 1); polygon[n++].setY(1); break; } } } delete image; image = new QImage( w + wMargin, h + hMargin, QImage::Format_ARGB32_Premultiplied ); image->fill( QColor(0,0,0,0) ); painter.begin( image ); painter.setRenderHints( QPainter::Antialiasing | QPainter::TextAntialiasing ); if ( backgroundColor.alpha() > 0 ) { painter.setPen( QColor(0,0,0,0) ); painter.setBrush( backgroundColor ); if (arrowType) { painter.drawPolygon( polygon, 7 ); } else { painter.drawRect( 1, 1, w - 2, h - 2 ); } } painter.setPen( myPen ); painter.setBrush( myBrush ); painter.setFont( myFont ); for ( int i = 0; i < sl.count(); ++i ) { QPointF point( 0, y + topOffset + metrics.ascent() ); switch ( align ) { case 2: { point.setX( leftOffset + (double)w / 2.0 - br[i].width() / 2.0 ); break; } case 3: { point.setX( leftOffset + w - x - br[i].width() ); break; } default: { point.setX( leftOffset + x ); break; } } if ( outline ) { QPainterPath myPath; myPath.addText( point, myFont, sl[i] ); painter.drawPath( myPath ); } else painter.drawText( point, sl[i] ); y += metrics.lineSpacing(); } painter.end(); return image; }
const Glyph& TextRenderer::getGlyph(char c) { Glyph& glyph = _glyphs[c]; if (glyph.isValid()) { return glyph; } // we use 'J' as a representative size for the solid block character QChar ch = (c == SOLID_BLOCK_CHAR) ? QChar('J') : QChar(c); QRect bounds = _metrics.boundingRect(ch); if (bounds.isEmpty()) { glyph = Glyph(0, QPoint(), QRect(), _metrics.width(ch)); return glyph; } // grow the bounds to account for effect, if any if (_effectType == SHADOW_EFFECT) { bounds.adjust(-_effectThickness, 0, 0, _effectThickness); } else if (_effectType == OUTLINE_EFFECT) { bounds.adjust(-_effectThickness, -_effectThickness, _effectThickness, _effectThickness); } // grow the bounds to account for antialiasing bounds.adjust(-1, -1, 1, 1); if (_x + bounds.width() > IMAGE_SIZE) { // we can't fit it on the current row; move to next _y += _rowHeight; _x = _rowHeight = 0; } if (_y + bounds.height() > IMAGE_SIZE) { // can't fit it on current texture; make a new one glGenTextures(1, &_currentTextureID); _x = _y = _rowHeight = 0; glBindTexture(GL_TEXTURE_2D, _currentTextureID); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, IMAGE_SIZE, IMAGE_SIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); _allTextureIDs.append(_currentTextureID); } else { glBindTexture(GL_TEXTURE_2D, _currentTextureID); } // render the glyph into an image and copy it into the texture QImage image(bounds.width(), bounds.height(), QImage::Format_ARGB32); if (c == SOLID_BLOCK_CHAR) { image.fill(QColor(255, 255, 255)); } else { image.fill(0); QPainter painter(&image); painter.setFont(_font); if (_effectType == SHADOW_EFFECT) { for (int i = 0; i < _effectThickness; i++) { painter.drawText(-bounds.x() - 1 - i, -bounds.y() + 1 + i, ch); } } else if (_effectType == OUTLINE_EFFECT) { QPainterPath path; QFont font = _font; font.setStyleStrategy(QFont::ForceOutline); path.addText(-bounds.x() - 0.5, -bounds.y() + 0.5, font, ch); QPen pen; pen.setWidth(_effectThickness); pen.setJoinStyle(Qt::RoundJoin); pen.setCapStyle(Qt::RoundCap); painter.setPen(pen); painter.setRenderHint(QPainter::Antialiasing); painter.drawPath(path); } painter.setPen(QColor(255, 255, 255)); painter.drawText(-bounds.x(), -bounds.y(), ch); } glTexSubImage2D(GL_TEXTURE_2D, 0, _x, _y, bounds.width(), bounds.height(), GL_RGBA, GL_UNSIGNED_BYTE, image.constBits()); glyph = Glyph(_currentTextureID, QPoint(_x, _y), bounds, _metrics.width(ch)); _x += bounds.width(); _rowHeight = qMax(_rowHeight, bounds.height()); glBindTexture(GL_TEXTURE_2D, 0); return glyph; }
void SliderThumb::paintEvent(QPaintEvent *event) { QPainter painter(this); // Halo QBrush brush; brush.setStyle(Qt::SolidPattern); brush.setColor(_haloColor); painter.setBrush(brush); painter.setPen(Qt::NoPen); painter.setRenderHint(QPainter::Antialiasing); QPointF disp = Qt::Horizontal == slider->orientation() ? QPointF(SLIDER_MARGIN + slider->thumbOffset(), slider->height()/2) : QPointF(slider->width()/2, SLIDER_MARGIN + slider->thumbOffset()); QRectF halo((slider->pos() - QPointF(_haloSize, _haloSize)/2) + disp, QSizeF(_haloSize, _haloSize)); painter.drawEllipse(halo); // Knob brush.setColor(slider->value() > slider->minimum() ? (slider->isEnabled() ? _fillColor : Style::instance().themeColor("disabled")) : _minFillColor); painter.setBrush(brush); if (_borderWidth > 0) { QPen pen; pen.setColor(Style::instance().themeColor("accent3")); pen.setWidthF(_borderWidth); painter.setPen(pen); } else { painter.setPen(Qt::NoPen); } QRectF geometry = Qt::Horizontal == slider->orientation() ? QRectF(slider->thumbOffset(), slider->height()/2 - SLIDER_MARGIN, SLIDER_MARGIN*2, SLIDER_MARGIN*2).translated(slider->pos()) : QRectF(slider->width()/2 - SLIDER_MARGIN, slider->thumbOffset(), SLIDER_MARGIN*2, SLIDER_MARGIN*2).translated(slider->pos()); QRectF thumb(0, 0, _diameter, _diameter); thumb.moveCenter(geometry.center()); painter.drawEllipse(thumb); #ifdef DEBUG_LAYOUT QPen pen; pen.setColor(Qt::red); pen.setWidth(2); painter.setPen(pen); painter.setBrush(Qt::NoBrush); painter.drawRect(geometry); painter.drawRect(rect().adjusted(0, 0, -2, -2)); #endif QWidget::paintEvent(event); }