void LogDelegate::paint(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const { QModelIndex sourceindex = d->proxy->mapToSource(index); QString text = d->soruce->data(sourceindex, Qt::DisplayRole).toString().replace("\n", QString(" ")+QChar(0x14A7)+" "); p->setFont(d->font); if(option.state & QStyle::State_Selected) { QItemSelectionModel *selection = d->view->selectionModel(); bool upstairsneighborselected = selection->isRowSelected(index.row()-1, index.parent()); bool downstairsneighborselected = selection->isRowSelected(index.row()+1, index.parent()); int dx = 1; int dy = 1; int dh = 2; int dw = 2; if(upstairsneighborselected) { dy--; dh--; } if(downstairsneighborselected) { dh--; } int dashoffset = 0; int number_of_upstairsneighborsselected = 0; int r = index.row()-1; if(option.rect.height()%2) { while(selection->isRowSelected(r, index.parent())) { number_of_upstairsneighborsselected++; r--; if(r < 0) break; } dashoffset = number_of_upstairsneighborsselected%2; } p->fillRect(option.rect.x()+dx, option.rect.y()+dy, option.rect.width()-dw, option.rect.height()-dh, option.palette.highlight()); QPen borderpen(Qt::CustomDashLine); borderpen.setColor(Qt::black); borderpen.setDashPattern(QVector<qreal>() << 1 << 1); borderpen.setDashOffset(dashoffset); p->setPen(borderpen); p->drawLine(option.rect.topLeft(), option.rect.bottomLeft()); p->drawLine(option.rect.topRight(), option.rect.bottomRight()); if(!upstairsneighborselected) { p->drawLine(option.rect.topLeft(), option.rect.topRight()); } if(!downstairsneighborselected) { p->drawLine(option.rect.bottomLeft(), option.rect.bottomRight()); } } if(d->soruce->isRowForErrorStatus(sourceindex.row())) { if(!d->soruce->wasSuccessfull(sourceindex.row())) { text = tr("Error: %1").arg(text); } } if(d->soruce->wasSuccessfull(sourceindex.row())) { p->setPen(QColor(0,128,0)); } else { if(option.state & QStyle::State_Selected) { p->setPen(QColor(255,0,0)); } else { p->setPen(QColor(128,0,0)); } } p->drawText( option.rect.left(), option.rect.bottom() - d->fontmetrics->boundingRect(text).height()/3.25, text ); }
void MTopologyItem::Draw(QPixmap *pixmap) { if(pixmap == NULL) return; QPainter painter(pixmap); painter.save(); //painter.setRenderHint(QPainter::Antialiasing, true); painter.fillRect(pixmap->rect(),QBrush(QColor(233,246,254))); int ypos; ypos = (pixmap->height() - normal_icon_.height())/2; QPixmap bitmapicon; QColor bordercolor; QColor innerbordercolor; QLinearGradient textGradient; QColor textcolor; switch (status_) { case status_normal: bitmapicon = normal_icon_; bordercolor = normal_border_color_; innerbordercolor = normal_inner_border_color_; textGradient = normal_gradient_; textcolor = normal_name_color_; break; case status_abnormal: bitmapicon = abnormal_icon_; bordercolor = abnormal_border_color_; innerbordercolor = abnormal_inner_border_color_; textGradient = abnormal_gradient_; textcolor = abnormal_name_color_; break; case status_notwork: bitmapicon = notwork_icon_; bordercolor = notwork_border_color_; innerbordercolor = notwork_inner_border_color_; textGradient = notwork_gradient_; textcolor = notwork_name_color_; break; case status_currentstatus: if(status_backup_ == status_normal) { bitmapicon = normal_icon_; } else if(status_backup_ == status_abnormal) { bitmapicon = abnormal_icon_; } else if(status_backup_ == status_notwork) { bitmapicon = notwork_icon_; } bordercolor = currentstatus_border_color_; innerbordercolor = currentstatus_inner_border_color_; textGradient = currentstatus_gradient_; textcolor = currentstatus_name_color_; break; default: bitmapicon = normal_icon_; bordercolor = normal_border_color_; innerbordercolor = normal_inner_border_color_; textGradient = normal_gradient_; textcolor = normal_name_color_; break; } painter.drawPixmap(0,ypos,bitmapicon); // QRect borderrect; // borderrect.setTop(0); // borderrect.setBottom(pixmap->height() - 1); // borderrect.setLeft(bitmapicon.width()); // borderrect.setRight(pixmap->width() - 1); // painter.setBrush(QBrush(bordercolor)); // painter.drawRoundedRect(borderrect,xradius_,yradius_,Qt::RelativeSize); // QRect innerborderrect; // innerborderrect.setTop(border_width_); // innerborderrect.setBottom(pixmap->height() - 1 - border_width_*2); // innerborderrect.setLeft(bitmapicon.width() + border_width_); // innerborderrect.setRight(pixmap->width() - 1 - border_width_*2); // painter.setBrush(QBrush(QColor(121,222,112))); // painter.drawRoundedRect(innerborderrect,xradius_,yradius_,Qt::RelativeSize); QRect textrect; textrect.setTop(border_width_); textrect.setBottom(pixmap->height() - 1 - border_width_*2); textrect.setLeft(bitmapicon.width() + border_width_); textrect.setRight(pixmap->width() - 1 - border_width_*2); QBrush textbrush(textGradient); QPen borderpen(bordercolor); painter.setPen(borderpen); painter.setBrush(textbrush); painter.drawRoundedRect(textrect,xradius_,yradius_,Qt::AbsoluteSize); QPen textpen(textcolor); painter.setPen(textpen); painter.drawText(textrect,Qt::AlignCenter,name_ ); painter.restore(); }