| 561 | } |
| 562 | |
| 563 | void DatapickerImageView::updateMagnificationWindow() { |
| 564 | m_image->m_magnificationWindow->setVisible(false); |
| 565 | QPointF pos = mapToScene(mapFromGlobal(QCursor::pos())); |
| 566 | |
| 567 | // copy the part of the view to be shown magnified |
| 568 | const int size = Worksheet::convertToSceneUnits(2.0, Worksheet::Unit::Centimeter) / transform().m11(); |
| 569 | const QRectF copyRect(pos.x() - size / (2 * magnificationFactor), |
| 570 | pos.y() - size / (2 * magnificationFactor), |
| 571 | size / magnificationFactor, |
| 572 | size / magnificationFactor); |
| 573 | QPixmap px = grab(mapFromScene(copyRect).boundingRect()); |
| 574 | px = px.scaled(size, size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); |
| 575 | |
| 576 | // draw the bounding rect |
| 577 | QPainter painter(&px); |
| 578 | const QPen pen = QPen(Qt::lightGray, 2 / transform().m11()); |
| 579 | painter.setPen(pen); |
| 580 | QRect rect = px.rect(); |
| 581 | rect.setWidth(rect.width() - pen.widthF() / 2); |
| 582 | rect.setHeight(rect.height() - pen.widthF() / 2); |
| 583 | painter.drawRect(rect); |
| 584 | |
| 585 | // set the pixmap |
| 586 | m_image->m_magnificationWindow->setPixmap(px); |
| 587 | m_image->m_magnificationWindow->setPos(pos.x() - px.width() / 2, pos.y() - px.height() / 2); |
| 588 | |
| 589 | m_image->m_magnificationWindow->setVisible(true); |
| 590 | } |
| 591 | |
| 592 | void DatapickerImageView::contextMenuEvent(QContextMenuEvent*) { |
| 593 | // no need to propagate the event to the scene and graphics items |