void draw_stop_line( int x1, int y1, int center_to_road, int road_width, int n_lines, int ratio, CDC* pDC ) { center_to_road = STOP_LINE; int x5 = get_x5(x1,STOP_LINE,ratio); int y5 = get_y5(y1,STOP_LINE,ratio); int x6 = get_x6(get_x2(x1,road_width,ratio),STOP_LINE,ratio); int y6 = get_y6(get_y2(y1,road_width,ratio),STOP_LINE,ratio); float fac = (float)n_lines*(float)LINE_WIDTH / road_width; int x7 = x5+(x6-x5)*fac; int y7 = y5+(y6-y5)*fac; CPen line_edge_pen(PS_SOLID,2,RGB(0,0,0)); auto old_pen = pDC->SelectObject(line_edge_pen); pDC->MoveTo(x5,y5); pDC->LineTo(x7,y7); pDC->MoveTo(x7,y7 ); pDC->SelectObject(old_pen); CPen center_pen(PS_SOLID,2,RGB(255,255,0)); pDC->SelectObject(center_pen); pDC->LineTo(get_x4(x7,MAIN_RECT_WIDTH,ratio),get_y4(y7,MAIN_RECT_WIDTH,ratio)); pDC->SelectObject(old_pen); int line_start_x = x_move_to(x5,LINE_WIDTH,ratio); int line_start_y = y_move_to(y5,LINE_WIDTH,ratio); CPen line_pen(PS_DASH,1,LINE_EDGE_COLOR.rgb()); old_pen = pDC->SelectObject(line_pen); int total_lines=road_width/LINE_WIDTH; while (--total_lines>0) { pDC->MoveTo(line_start_x,line_start_y); if (total_lines == n_lines) { line_start_x = x_move_to(line_start_x,LINE_WIDTH,ratio); line_start_y = y_move_to(line_start_y,LINE_WIDTH,ratio); continue; } pDC->LineTo(get_x4(line_start_x,MAIN_RECT_WIDTH,ratio),get_y4(line_start_y,MAIN_RECT_WIDTH,ratio)); line_start_x = x_move_to(line_start_x,LINE_WIDTH,ratio); line_start_y = y_move_to(line_start_y,LINE_WIDTH,ratio); } pDC->SelectObject(old_pen); }
void Pitch::draw_pitch() { scene.clear(); footballers.clear(); balls.clear(); scene.update(); viewport()->update(); QPen line_pen(Qt::black); for(int i = 0; i < 8; i++) { scene.addLine(0, i * ROW_SIZE, 7 * ROW_SIZE, i * ROW_SIZE, line_pen); scene.addLine(i * ROW_SIZE, 0, i * ROW_SIZE, 7 * ROW_SIZE, line_pen); } fitInView(scene.sceneRect()); for(int i = 0; i < 14; i++) { footballers.append(new Footballer(game->id_color(i), i % 7, ROW_SIZE)); scene.addItem(footballers.last()); footballers.last()->setPos(pos_to_coord(game->get_elem_pos(i))); QObject::connect(footballers.last(), SIGNAL(chosen(int,int)), this, SLOT(show_pos_moves(int,int))); QObject::connect(footballers.last(), SIGNAL(anim_start()), this, SLOT(on_anim_start())); QObject::connect(footballers.last(), SIGNAL(anim_end()), this, SLOT(on_anim_end())); } balls.append(new Ball(Game::WHITE, ROW_SIZE)); scene.addItem(balls.last()); int wh_ball_pos = game->get_elem_pos(game->get_ball_owner(Game::WHITE)); int bl_ball_pos = game->get_elem_pos(game->get_ball_owner(Game::BLACK)); balls.last()->setPos(ball_pos_to_coord(wh_ball_pos)); QObject::connect(balls.last(), SIGNAL(anim_start()), this, SLOT(on_anim_start())); QObject::connect(balls.last(), SIGNAL(anim_end()), this, SLOT(on_anim_end())); balls.append(new Ball(Game::BLACK, ROW_SIZE)); scene.addItem(balls.last()); balls.last()->setPos(ball_pos_to_coord(bl_ball_pos)); QObject::connect(balls.last(), SIGNAL(anim_start()), this, SLOT(on_anim_start())); QObject::connect(balls.last(), SIGNAL(anim_end()), this, SLOT(on_anim_end())); update_state(); }
void RelatedPacketDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) QStyleOptionViewItemV4 option_vi = option; #else QStyleOptionViewItem option_vi = option; #endif QStyledItemDelegate::initStyleOption(&option_vi, index); int em_w = option_vi.fontMetrics.height(); int en_w = (em_w + 1) / 2; int line_w = (option_vi.fontMetrics.lineWidth()); #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) option_vi.features |= QStyleOptionViewItemV4::HasDecoration; #else option_vi.features |= QStyleOptionViewItem::HasDecoration; #endif option_vi.decorationSize.setHeight(1); option_vi.decorationSize.setWidth(em_w); QStyledItemDelegate::paint(painter, option_vi, index); guint32 setup_frame = 0, last_frame = 0; if (conv_) { setup_frame = (int) conv_->setup_frame; last_frame = (int) conv_->last_frame; } const frame_data *fd; PacketListRecord *record = static_cast<PacketListRecord*>(index.internalPointer()); if (!record || (fd = record->frameData()) == NULL) { return; } painter->save(); if (QApplication::style()->objectName().contains("vista")) { // QWindowsVistaStyle::drawControl does this internally. Unfortunately there // doesn't appear to be a more general way to do this. option_vi.palette.setColor(QPalette::All, QPalette::HighlightedText, option_vi.palette.color(QPalette::Active, QPalette::Text)); } QPalette::ColorGroup cg = option_vi.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled; QColor fg; if (cg == QPalette::Normal && !(option_vi.state & QStyle::State_Active)) cg = QPalette::Inactive; if (option_vi.state & QStyle::State_Selected) { fg = option_vi.palette.color(cg, QPalette::HighlightedText); } else { fg = option_vi.palette.color(cg, QPalette::Text); } fg = ColorUtils::alphaBlend(fg, option_vi.palette.color(cg, QPalette::Base), 0.5); QPen line_pen(fg); line_pen.setWidth(line_w); line_pen.setJoinStyle(Qt::RoundJoin); painter->setPen(line_pen); painter->translate(option_vi.rect.x(), option_vi.rect.y()); painter->translate(en_w + 0.5, 0.5); painter->setRenderHint(QPainter::Antialiasing, true); int height = option_vi.rect.height(); // Uncomment to make the boundary visible. // painter->save(); // painter->setPen(Qt::darkRed); // painter->drawRect(QRectF(0.5, 0.5, en_w - 1, height - 1)); // painter->restore(); // The current decorations are based on what looked good and were easy // to code. // It might be useful to have a JACKPOT_MODE define that shows each // decoration in sequence in order to make it easier to create // screenshots for the User's Guide. // Vertical line. Lower and upper half for the start and end of the // conversation respectively, solid for conversation member, dashed // for other packets in the start-end range. if (setup_frame > 0 && last_frame > 0 && setup_frame != last_frame) { if (fd->num == setup_frame) { QPoint start_line[] = { QPoint(en_w - 1, height / 2), QPoint(0, height / 2), QPoint(0, height) }; painter->drawPolyline(start_line, 3); } else if (fd->num > setup_frame && fd->num < last_frame) { painter->save(); if (conv_ != record->conversation()) { QPen other_pen(line_pen); other_pen.setStyle(Qt::DashLine); painter->setPen(other_pen); } painter->drawLine(0, 0, 0, height); painter->restore(); } else if (fd->num == last_frame) { QPoint end_line[] = { QPoint(en_w - 1, height / 2), QPoint(0, height / 2), QPoint(0, 0) }; painter->drawPolyline(end_line, 3); } } // Related packet indicator. Rightward arrow for requests, leftward // arrow for responses, circle for others. // XXX These are comically oversized when we have multi-line rows. if (related_frames_.contains(fd->num)) { painter->setBrush(fg); switch (related_frames_[fd->num]) { // Request and response arrows are moved forward one pixel in order to // maximize white space between the heads and the conversation line. case FT_FRAMENUM_REQUEST: { int hh = height / 2; QPoint tail(2 - en_w, hh); QPoint head(en_w, hh); drawArrow(painter, tail, head, hh / 2); break; } case FT_FRAMENUM_RESPONSE: { int hh = height / 2; QPoint tail(en_w - 1, hh); QPoint head(1 - en_w, hh); drawArrow(painter, tail, head, hh / 2); break; } case FT_FRAMENUM_ACK: { QRect bbox (2 - en_w, height / 3, em_w - 2, height / 2); drawCheckMark(painter, bbox); break; } case FT_FRAMENUM_DUP_ACK: { QRect bbox (2 - en_w, (height / 3) - (line_w * 2), em_w - 2, height / 2); drawCheckMark(painter, bbox); bbox.moveTop(bbox.top() + (line_w * 3)); drawCheckMark(painter, bbox); break; } case FT_FRAMENUM_NONE: default: painter->drawEllipse(QPointF(0.0, option_vi.rect.height() / 2), 2, 2); } } painter->restore(); }
void MainWindow::paintEvent(QPaintEvent *) { QPainter painter(this); painter.save(); //fist, draw a rounded rect for header & graphic area; painter.drawRoundedRect(header_area,15,15); painter.drawRoundedRect(curve_area.x(),curve_area.y(),curve_area.width(),table_area.y()+table_area.height()-curve_area.y(),15,15); //painter.drawRoundedRect(curve_area,15,15); painter.setPen(Qt::SolidLine); QFont Nr_font("Arial",8); QPen nom_line_pen(Qt::black, 1.5, Qt::SolidLine); QPen act_line_pen(Qt::red, 1.5 ,Qt::SolidLine); QPen line_pen(Qt::blue, 1 , Qt::SolidLine); QPen tol_line_pen(Qt::green, 1 , Qt::SolidLine); //move the painter to the left mid position painter.translate(curve_area.x()+gap,curve_area.center().y()); //draw coordinate axis QPen axis_pen(Qt::blue,1,Qt::SolidLine); painter.setPen(axis_pen); painter.drawLine(0,curve_area.height()/2-10,curve_area.width()-gap*2,curve_area.height()/2-10); painter.drawLine(curve_area.width()/2-gap,curve_area.height()/2,curve_area.width()/2-gap,-curve_area.height()/2); //draw X axis sign & number painter.setFont(Nr_font); int be,en; be = std::ceil(min_x)+1; en = std::floor(max_x)-1; for(int i=be;i<=en;++i) { painter.drawLine((i-min_x)*scale_x,curve_area.height()/2-5,(i-min_x)*scale_x,curve_area.height()/2-15); painter.drawText((i-min_x)*scale_x+3,curve_area.height()/2,QString("%1").arg(i)); } //draw Y axis sign & number be = std::ceil(min_y*1000); en = std::floor(max_y*1000); be-=3; en+=4; //draw 10e-3 painter.drawText(curve_area.width()/2-gap-20,-curve_area.height()/2+10, 10,10, Qt::AlignRight|Qt::AlignVCenter,QString("10")); painter.setFont(QFont("Arial",6)); painter.drawText(curve_area.width()/2-gap-12,-curve_area.height()/2+7, 10,10, Qt::AlignRight|Qt::AlignVCenter,QString("-3")); for(int i=be;i<=en;i++) { if (i%2==0) { painter.drawLine(curve_area.width()/2-gap-5,(double(i)/1000-(min_y+max_y)/2)*scale_y, curve_area.width()/2-gap+5,(double(i)/1000-(min_y+max_y)/2)*scale_y); painter.drawText(curve_area.width()/2-gap-15,(double(i)/1000-(min_y+max_y)/2)*scale_y-5, 10,10, Qt::AlignRight|Qt::AlignVCenter,QString("%1").arg(i)); } else { painter.drawLine(curve_area.width()/2-gap-2,(double(i)/1000-(min_y+max_y)/2)*scale_y, curve_area.width()/2-gap+2,(double(i)/1000-(min_y+max_y)/2)*scale_y); } } //draw nominal und actual curves painter.setPen(nom_line_pen); painter.drawPath(*nom_path); painter.setPen(act_line_pen); painter.drawPath(*act_path); painter.setPen(tol_line_pen); painter.drawPath(*ut_path); painter.drawPath(*lt_path); //painter.drawPoints(nom_points,data->size()); //draw nominal points as single points painter.setPen(line_pen); for(int i=0;i<size;++i) { painter.drawEllipse(nom_points[i],1.2,1.2); } //draw nominal points number for(int i=0;i<28;i++) { painter.drawLine(nom_points[i],QPointF(nom_points[i].x(),-curve_area.height()/2+50)); painter.save(); painter.translate(nom_points[i].x()-2,-curve_area.height()/2+50); painter.rotate(-40); painter.setFont(Nr_font); painter.drawText(0,0,QString("%1").arg(i+1)); painter.restore(); } //draw profile value painter.restore(); painter.save(); painter.translate(table_area.center().x(),table_area.y()); for(int i=0;i<3;++i) { painter.drawRect(-90+i*60,5,60,20); } painter.drawArc(-70,10,20,20,0,180*16); painter.drawText(-30,5,60,20,Qt::AlignCenter,QString("%1").arg(profil)); painter.drawText(30,5,60,20,Qt::AlignCenter,QString("%1").arg(QString::number(act_profil,'f',4))); //draw data tables painter.restore(); painter.save(); painter.translate(table_area.x(),table_area.y()); //set draw paras for the table lines & fonts painter.setPen(axis_pen); QRectF one_cell(0,0,50,15); QRectF title_cell(0,0,80,15); QPointF start_pos(60,40); QFont word_font("Times New Roman",10); QFont num_font("Times New Roman",10); num_font.setLetterSpacing(QFont::AbsoluteSpacing,1.5); //draw first line table and data painter.drawRect(start_pos.x(),start_pos.y(),title_cell.width(),title_cell.height()); for(int i=1;i<5;++i) { painter.drawRect(start_pos.x(),start_pos.y()+title_cell.height()*i+5,title_cell.width(),title_cell.height()); } for(int j=1;j<15;++j) { painter.drawRect(start_pos.x()+title_cell.width()+gap+(j-1)*one_cell.width(),start_pos.y(),one_cell.width(),one_cell.height()); for(int i=1;i<5;++i) { painter.drawRect(start_pos.x()+title_cell.width()+gap+(j-1)*one_cell.width(),start_pos.y()+one_cell.height()*i+5,one_cell.width(),one_cell.height()); } } //draw text for titles painter.setFont(word_font); painter.drawText(start_pos.x(),start_pos.y(),title_cell.width(),title_cell.height(),Qt::AlignHCenter|Qt::AlignBottom, QString("number")); { int i; i=1; painter.drawText(start_pos.x(),start_pos.y()+title_cell.height()*i+5,title_cell.width(),title_cell.height(), Qt::AlignHCenter|Qt::AlignBottom,QString("X [mm]")); i=2; painter.drawText(start_pos.x(),start_pos.y()+title_cell.height()*i+5,title_cell.width(),title_cell.height(), Qt::AlignHCenter|Qt::AlignBottom,QString("Ys [um]")); i=3; painter.drawText(start_pos.x(),start_pos.y()+title_cell.height()*i+5,title_cell.width(),title_cell.height(), Qt::AlignHCenter|Qt::AlignBottom,QString("Yi [um]")); i=4; painter.drawText(start_pos.x(),start_pos.y()+title_cell.height()*i+5,title_cell.width(),title_cell.height(), Qt::AlignHCenter|Qt::AlignBottom,QString("dev.[um]")); } //draw the data painter.setFont(num_font); for (int i=0;i<14;++i) { painter.drawText(start_pos.x()+title_cell.width()+gap+(i)*one_cell.width(),start_pos.y(),one_cell.width(),one_cell.height(), Qt::AlignHCenter|Qt::AlignBottom,QString("%1").arg(i+1)); { int j=1; painter.drawText(start_pos.x()+title_cell.width()+gap+(i)*one_cell.width(),start_pos.y()+one_cell.height()*j+5, one_cell.width()-2,one_cell.height(), Qt::AlignVCenter|Qt::AlignRight, QString("%1").arg(QString::number(nom_data->at(i).x,'f',2))); j=2; painter.drawText(start_pos.x()+title_cell.width()+gap+(i)*one_cell.width(),start_pos.y()+one_cell.height()*j+5, one_cell.width()-2,one_cell.height(), Qt::AlignVCenter|Qt::AlignRight, QString("%1").arg(QString::number(nom_data->at(i).y*1000,'f',2))); j=3; painter.drawText(start_pos.x()+title_cell.width()+gap+(i)*one_cell.width(),start_pos.y()+one_cell.height()*j+5, one_cell.width()-2,one_cell.height(), Qt::AlignVCenter|Qt::AlignRight, QString("%1").arg(QString::number(act_data->at(i).y*1000,'f',2))); j=4; painter.drawText(start_pos.x()+title_cell.width()+gap+(i)*one_cell.width(),start_pos.y()+one_cell.height()*j+5, one_cell.width()-2,one_cell.height(), Qt::AlignVCenter|Qt::AlignRight, QString("%1").arg(QString::number((act_data->at(i).y-nom_data->at(i).y)*1000,'f',2))); } } painter.translate(0,90); painter.drawRect(start_pos.x(),start_pos.y(),title_cell.width(),title_cell.height()); for(int i=1;i<5;++i) { painter.drawRect(start_pos.x(),start_pos.y()+title_cell.height()*i+5,title_cell.width(),title_cell.height()); } for(int j=1;j<15;++j) { painter.drawRect(start_pos.x()+title_cell.width()+gap+(j-1)*one_cell.width(),start_pos.y(),one_cell.width(),one_cell.height()); for(int i=1;i<5;++i) { painter.drawRect(start_pos.x()+title_cell.width()+gap+(j-1)*one_cell.width(),start_pos.y()+one_cell.height()*i+5,one_cell.width(),one_cell.height()); } } //draw text for titles painter.setFont(word_font); painter.drawText(start_pos.x(),start_pos.y(),title_cell.width(),title_cell.height(),Qt::AlignHCenter|Qt::AlignBottom, QString("number")); { int i; i=1; painter.drawText(start_pos.x(),start_pos.y()+title_cell.height()*i+5,title_cell.width(),title_cell.height(), Qt::AlignHCenter|Qt::AlignBottom,QString("X [mm]")); i=2; painter.drawText(start_pos.x(),start_pos.y()+title_cell.height()*i+5,title_cell.width(),title_cell.height(), Qt::AlignHCenter|Qt::AlignBottom,QString("Ys [um]")); i=3; painter.drawText(start_pos.x(),start_pos.y()+title_cell.height()*i+5,title_cell.width(),title_cell.height(), Qt::AlignHCenter|Qt::AlignBottom,QString("Yi [um]")); i=4; painter.drawText(start_pos.x(),start_pos.y()+title_cell.height()*i+5,title_cell.width(),title_cell.height(), Qt::AlignHCenter|Qt::AlignBottom,QString("dev.[um]")); } //draw the data painter.setFont(num_font); for (int i=14;i<28;++i) { painter.drawText(start_pos.x()+title_cell.width()+gap+(i-14)*one_cell.width(),start_pos.y(),one_cell.width(),one_cell.height(), Qt::AlignHCenter|Qt::AlignBottom,QString("%1").arg(i+1)); { int j=1; painter.drawText(start_pos.x()+title_cell.width()+gap+(i-14)*one_cell.width(),start_pos.y()+one_cell.height()*j+5, one_cell.width()-2,one_cell.height(), Qt::AlignVCenter|Qt::AlignRight, QString("%1").arg(QString::number(nom_data->at(i).x,'f',2))); j=2; painter.drawText(start_pos.x()+title_cell.width()+gap+(i-14)*one_cell.width(),start_pos.y()+one_cell.height()*j+5, one_cell.width()-2,one_cell.height(), Qt::AlignVCenter|Qt::AlignRight, QString("%1").arg(QString::number(nom_data->at(i).y*1000,'f',2))); j=3; painter.drawText(start_pos.x()+title_cell.width()+gap+(i-14)*one_cell.width(),start_pos.y()+one_cell.height()*j+5, one_cell.width()-2,one_cell.height(), Qt::AlignVCenter|Qt::AlignRight, QString("%1").arg(QString::number(act_data->at(i).y*1000,'f',2))); j=4; painter.drawText(start_pos.x()+title_cell.width()+gap+(i-14)*one_cell.width(),start_pos.y()+one_cell.height()*j+5, one_cell.width()-2,one_cell.height(), Qt::AlignVCenter|Qt::AlignRight, QString("%1").arg(QString::number((act_data->at(i).y-nom_data->at(i).y)*1000,'f',2))); } } //draw a header and LOGO painter.restore(); painter.drawPixmap(header_area.x()+20,header_area.y()+1,header_area.height()-2,header_area.height()-2,*logo); painter.translate(header_area.x(),header_area.y()); QFont header_font("Arial",header_area.height()*3/10,10,true); painter.setFont(header_font); painter.drawText(0,0,header_area.width(),header_area.height()*6/10,Qt::AlignHCenter|Qt::AlignBottom,QString("PROFILFORM")); header_font.setPointSize(header_area.height()*2/10); painter.setFont(header_font); painter.drawText(0,0,header_area.width(),header_area.height()*9/10,Qt::AlignHCenter|Qt::AlignBottom,QString("ISO 1101")); header_font.setItalic(false); header_font.setPointSize(9); header_font.setFixedPitch(true); painter.setFont(header_font); painter.drawText(header_area.width()*8/10,header_area.height()*2/10,header_area.width()*2/10,header_area.height()*0.2, Qt::AlignLeft|Qt::AlignVCenter, QString("Inspector ")); painter.drawText(header_area.width()*8/10,header_area.height()*4/10,header_area.width()*2/10,header_area.height()*0.2, Qt::AlignLeft|Qt::AlignVCenter, QString("Date ")); painter.drawText(header_area.width()*8/10,header_area.height()*6/10,header_area.width()*2/10,header_area.height()*0.2, Qt::AlignLeft|Qt::AlignVCenter, QString("Time ")); painter.drawText(header_area.width()*9/10,header_area.height()*2/10,header_area.width()*1/10,header_area.height()*0.2, Qt::AlignLeft|Qt::AlignVCenter, QString(": %1").arg(xml_info->paras.value("operid"))); painter.drawText(header_area.width()*9/10,header_area.height()*4/10,header_area.width()*1/10,header_area.height()*0.2, Qt::AlignLeft|Qt::AlignVCenter, QString(": %1").arg(xml_info->paras.value("date"))); painter.drawText(header_area.width()*9/10,header_area.height()*6/10,header_area.width()*1/10,header_area.height()*0.2, Qt::AlignLeft|Qt::AlignVCenter, QString(": %1").arg(xml_info->paras.value("time"))); }
void PlaylistView::paintEvent(QPaintEvent* event) { // Reimplemented to draw the background image. // Reimplemented also to draw the drop indicator // When the user is dragging some stuff over the playlist paintEvent gets // called for the entire viewport every time the user moves the mouse. // The drawTree is kinda expensive, so we cache the result and draw from the // cache while the user is dragging. The cached pixmap gets invalidated in // dragLeaveEvent, dropEvent and scrollContentsBy. // Draw background if (background_image_type_ == Custom || background_image_type_ == AlbumCover) { if (!background_image_.isNull() || !previous_background_image_.isNull()) { QPainter background_painter(viewport()); // Check if we should recompute the background image if (height() != last_height_ || width() != last_width_ || force_background_redraw_) { if (background_image_.isNull()) { cached_scaled_background_image_ = QPixmap(); } else { cached_scaled_background_image_ = QPixmap::fromImage(background_image_.scaled( width(), height(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation)); } last_height_ = height(); last_width_ = width(); force_background_redraw_ = false; } // Actually draw the background image if (!cached_scaled_background_image_.isNull()) { // Set opactiy only if needed, as this deactivate hardware acceleration if (!qFuzzyCompare(previous_background_image_opacity_, qreal(0.0))) { background_painter.setOpacity(1.0 - previous_background_image_opacity_); } background_painter.drawPixmap( (width() - cached_scaled_background_image_.width()) / 2, (height() - cached_scaled_background_image_.height()) / 2, cached_scaled_background_image_); } // Draw the previous background image if we're fading if (!previous_background_image_.isNull()) { background_painter.setOpacity(previous_background_image_opacity_); background_painter.drawPixmap( (width() - previous_background_image_.width()) / 2, (height() - previous_background_image_.height()) / 2, previous_background_image_); } } } QPainter p(viewport()); if (drop_indicator_row_ != -1) { if (cached_tree_.isNull()) { cached_tree_ = QPixmap(size()); cached_tree_.fill(Qt::transparent); QPainter cache_painter(&cached_tree_); drawTree(&cache_painter, event->region()); } p.drawPixmap(0, 0, cached_tree_); } else { drawTree(&p, event->region()); return; } const int first_column = header_->logicalIndex(0); // Find the y position of the drop indicator QModelIndex drop_index = model()->index(drop_indicator_row_, first_column); int drop_pos = -1; switch (dropIndicatorPosition()) { case QAbstractItemView::OnItem: return; // Don't draw anything case QAbstractItemView::AboveItem: drop_pos = visualRect(drop_index).top(); break; case QAbstractItemView::BelowItem: drop_pos = visualRect(drop_index).bottom() + 1; break; case QAbstractItemView::OnViewport: if (model()->rowCount() == 0) drop_pos = 1; else drop_pos = 1 + visualRect(model()->index(model()->rowCount() - 1, first_column)).bottom(); break; } // Draw a nice gradient first QColor line_color(QApplication::palette().color(QPalette::Highlight)); QColor shadow_color(line_color.lighter(140)); QColor shadow_fadeout_color(shadow_color); shadow_color.setAlpha(255); shadow_fadeout_color.setAlpha(0); QLinearGradient gradient(QPoint(0, drop_pos - kDropIndicatorGradientWidth), QPoint(0, drop_pos + kDropIndicatorGradientWidth)); gradient.setColorAt(0.0, shadow_fadeout_color); gradient.setColorAt(0.5, shadow_color); gradient.setColorAt(1.0, shadow_fadeout_color); QPen gradient_pen(QBrush(gradient), kDropIndicatorGradientWidth * 2); p.setPen(gradient_pen); p.drawLine(QPoint(0, drop_pos), QPoint(width(), drop_pos)); // Now draw the line on top QPen line_pen(line_color, kDropIndicatorWidth); p.setPen(line_pen); p.drawLine(QPoint(0, drop_pos), QPoint(width(), drop_pos)); }