! Constructor of the class. Creates a view for the DatapickerImage \c image and initializes the internal model. */
| 51 | Creates a view for the DatapickerImage \c image and initializes the internal model. |
| 52 | */ |
| 53 | DatapickerImageView::DatapickerImageView(DatapickerImage* image) |
| 54 | : QGraphicsView() |
| 55 | , m_image(image) |
| 56 | , m_datapicker(dynamic_cast<Datapicker*>(m_image->parentAspect())) |
| 57 | , m_transform(new Transform()) { |
| 58 | setScene(m_image->scene()); |
| 59 | |
| 60 | setRenderHint(QPainter::Antialiasing); |
| 61 | setRubberBandSelectionMode(Qt::ContainsItemBoundingRect); |
| 62 | setTransformationAnchor(QGraphicsView::AnchorUnderMouse); |
| 63 | setResizeAnchor(QGraphicsView::AnchorViewCenter); |
| 64 | setMinimumSize(16, 16); |
| 65 | setFocusPolicy(Qt::StrongFocus); |
| 66 | |
| 67 | viewport()->setAttribute(Qt::WA_OpaquePaintEvent); |
| 68 | viewport()->setAttribute(Qt::WA_NoSystemBackground); |
| 69 | setCacheMode(QGraphicsView::CacheBackground); |
| 70 | |
| 71 | initActions(); |
| 72 | initMenus(); |
| 73 | m_image->setSegmentsHoverEvent(true); |
| 74 | setInteractive(true); |
| 75 | |
| 76 | changeZoom(zoomOriginAction); |
| 77 | currentZoomAction = zoomInViewAction; |
| 78 | |
| 79 | if (m_image->plotPointsType() == DatapickerImage::PointsType::AxisPoints) |
| 80 | setAxisPointsAction->setChecked(true); |
| 81 | else if (m_image->plotPointsType() == DatapickerImage::PointsType::CurvePoints) |
| 82 | setCurvePointsAction->setChecked(true); |
| 83 | else |
| 84 | selectSegmentAction->setChecked(true); |
| 85 | |
| 86 | handleImageActions(); |
| 87 | changeRotationAngle(); |
| 88 | |
| 89 | // signal/slot connections |
| 90 | // for general actions |
| 91 | connect(m_image, &DatapickerImage::requestProjectContextMenu, this, &DatapickerImageView::createContextMenu); |
| 92 | connect(m_image, &DatapickerImage::requestUpdate, this, &DatapickerImageView::updateBackground); |
| 93 | connect(m_image, &DatapickerImage::requestUpdateActions, this, &DatapickerImageView::handleImageActions); |
| 94 | connect(m_datapicker, &Datapicker::requestUpdateActions, this, &DatapickerImageView::handleImageActions); |
| 95 | connect(m_image, &DatapickerImage::rotationAngleChanged, this, &DatapickerImageView::changeRotationAngle); |
| 96 | |
| 97 | // resize the view to make the complete scene visible. |
| 98 | // no need to resize the view when the project is being opened, |
| 99 | // all views will be resized to the stored values at the end |
| 100 | if (!m_image->isLoading()) { |
| 101 | float w = Worksheet::convertFromSceneUnits(sceneRect().width(), Worksheet::Unit::Inch); |
| 102 | float h = Worksheet::convertFromSceneUnits(sceneRect().height(), Worksheet::Unit::Inch); |
| 103 | w *= GuiTools::dpi(this).first; |
| 104 | h *= GuiTools::dpi(this).second; |
| 105 | resize(w * 1.1, h * 1.1); |
| 106 | } |
| 107 | |
| 108 | // rescale to the original size |
| 109 | static const float hscale = GuiTools::dpi(this).first / (Worksheet::convertToSceneUnits(1, Worksheet::Unit::Inch)); |
| 110 | static const float vscale = GuiTools::dpi(this).second / (Worksheet::convertToSceneUnits(1, Worksheet::Unit::Inch)); |
nothing calls this directly
no test coverage detected