void CameraBinFocus::_q_handleCameraStatusChange(QCamera::Status status) { m_cameraStatus = status; if (status == QCamera::ActiveStatus) { if (GstPad *pad = gst_element_get_static_pad(m_session->cameraSource(), "vfsrc")) { if (GstCaps *caps = qt_gst_pad_get_current_caps(pad)) { if (GstStructure *structure = gst_caps_get_structure(caps, 0)) { int width = 0; int height = 0; gst_structure_get_int(structure, "width", &width); gst_structure_get_int(structure, "height", &height); setViewfinderResolution(QSize(width, height)); } gst_caps_unref(caps); } gst_object_unref(GST_OBJECT(pad)); } if (m_focusPointMode == QCameraFocus::FocusPointCustom) { updateRegionOfInterest(m_focusRect); } } else { _q_setFocusStatus(QCamera::Unlocked, QCamera::LockLost); resetFocusPoint(); } }
void CameraBinFocus::updateRegionOfInterest(const QRectF &rectangle) { updateRegionOfInterest(QVector<QRect>() << QRect( rectangle.x() * m_viewfinderResolution.width(), rectangle.y() * m_viewfinderResolution.height(), rectangle.width() * m_viewfinderResolution.width(), rectangle.height() * m_viewfinderResolution.height())); }
void CameraBinFocus::_q_handleCameraStateChange(QCamera::State state) { m_cameraState = state; if (state != QCamera::ActiveState) { _q_setFocusStatus(QCamera::Unlocked, QCamera::LockLost); resetFocusPoint(); } else if (m_focusPointMode == QCameraFocus::FocusPointCustom) { updateRegionOfInterest(m_focusRect, 1); } }
void CameraBinFocus::resetFocusPoint() { const QRectF focusRect = m_focusRect; m_focusPoint = QPointF(0.5, 0.5); m_focusRect.moveCenter(m_focusPoint); updateRegionOfInterest(QVector<QRect>()); if (focusRect != m_focusRect) { emit customFocusPointChanged(m_focusPoint); emit focusZonesChanged(); } }
void CameraBinFocus::setCustomFocusPoint(const QPointF &point) { if (m_focusPoint != point) { m_focusPoint = point; // Bound the focus point so the focus rect remains entirely within the unit square. m_focusPoint.setX(qBound(m_focusRect.width() / 2, m_focusPoint.x(), 1 - m_focusRect.width() / 2)); m_focusPoint.setY(qBound(m_focusRect.height() / 2, m_focusPoint.y(), 1 - m_focusRect.height() / 2)); if (m_focusPointMode == QCameraFocus::FocusPointCustom) { const QRectF focusRect = m_focusRect; m_focusRect.moveCenter(m_focusPoint); updateRegionOfInterest(m_focusRect); if (focusRect != m_focusRect) { emit focusZonesChanged(); } } emit customFocusPointChanged(m_focusPoint); } }