void TagViewer::paintEvent( QPaintEvent* /*e*/ ) { QPainter p( this ); float scale_f = scale_factor(); QRect drawing_area( 0, 0, size().width(), size().height() ); if( !pix_.isNull() && !size().isNull() ) { p.drawPixmap( drawing_area, pix_ ); } else { QTextOption options( Qt::AlignLeft ); options.setWrapMode( QTextOption::WordWrap ); p.setPen( QPen( Qt::red, 4 ) ); p.drawText( QRectF( drawing_area ), "Image cannot be displayed. Check:\n" " - the same image is selected among the multiple selection (it's ok to select labels)\n" " - the image file is still at the same disk location when imported\n" " - the image format is valid and/or the file is not corrupted ", options ); return; } QFont font; font.setPointSize( 10 ); p.setFont( font ); // draw bounding boxes for( QList<TagDisplayElement>::iterator tag_itr = elts_.begin(); tag_itr != elts_.end(); ++tag_itr ) { const TagDisplayElement& tag = *tag_itr; const QList<QRect>& bbox = tag._bbox; p.setPen( QPen( tag._color, 2 ) ); for( QList<QRect>::const_iterator bbox_itr = bbox.begin(); bbox_itr != bbox.end(); ++bbox_itr ) { const QRect& box_rect = *bbox_itr; QRect scaled_box( scale_f * box_rect.topLeft(), scale_f * box_rect.bottomRight() ); p.drawRect( scaled_box ); p.drawText( scaled_box.x(), scaled_box.y(), tag._label ); } } // draw current box being tagged p.setPen( QPen( current_color_, 2 ) ); if( tagging_ && tag_start_ != tag_end_ ) { QRect current_rect( tag_start_, tag_end_ ); p.drawRect( current_rect ); p.drawText( current_rect.x(), current_rect.y(), current_label_ ); } }
/** * @brief ElementScene::mouseMoveEvent * @param e */ void ElementScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) { if (m_event_interface) { if (m_event_interface -> mouseMoveEvent(e)) { if (m_event_interface->isFinish()) { emit(partsAdded()); delete m_event_interface; m_event_interface = NULL; } return; } } QPointF event_pos = e -> scenePos(); if (!e -> modifiers() & Qt::ControlModifier) event_pos = snapToGrid(event_pos); if (behavior == PasteArea) { QRectF current_rect(paste_area_ -> rect()); current_rect.moveCenter(event_pos); paste_area_ -> setRect(current_rect); return; } QGraphicsScene::mouseMoveEvent(e); }