NDEVR
API Documentation
PhysicalCameraView.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Widgets
28File: PhysicalCameraView
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#if NDEVR_VIEWPORT
35#include <NDEVR/CameraView.h>
36#include <NDEVR/ViewportFactory.h>
37#include <NDEVR/QCustomStackedWidget.h>
38#include <NDEVR/Camera.h>
39#include <NDEVR/Pointer.h>
40#include <NDEVR/ApplicationOptions.h>
41#include <NDEVR/TranslatedString.h>
42#include <NDEVR/File.h>
43QT_BEGIN_NAMESPACE
44namespace Ui { class PhysicalCameraViewUI; }
45QT_END_NAMESPACE
46namespace NDEVR
47{
48 class Toolbar;
49 class Button;
50 class Ruler;
51 class InfoPipe;
52 class WindowContainer;
54 class TimeSpan;
56 class CameraRulerMenu;
57 class QCustomSlider;
62 class DESIGN_WIDGETS_API PhysicalCameraView : public CameraView
63 {
64 Q_OBJECT
65 public:
75
83
91
110 protected:
120 PhysicalCameraView(const DynamicPointer<Camera>& camera, QWidget* parent = nullptr);
121 public:
122 virtual ~PhysicalCameraView();
124 virtual void updateView() override;
127 virtual void setTouchTheme(bool touch_theme) override;
130 virtual void setSwapMode(SwapMode mode) override;
140 void setVideoOutputPath(const File& file);
143 virtual void showToolRibbon(bool show_ribbon) override;
145 virtual void resetToolRibbon() override;
150 virtual void startNewRecording(StringView file_name = StringView());
154 virtual void stopAndSaveRecording();
157 void mouseReleaseEvent(QMouseEvent *releaseEvent) override;
162 QWidget* activeWidget() const;
165 void leaveEvent(QEvent* leave) override;
169 bool event(QEvent* event) override;
172 virtual void setIconSizeMultiplier(fltp04 multiplier) override;
175 virtual void addWidget(const QPointer<QWidget>& button) override;
178 virtual void removeWidget(const QPointer<QWidget>& button) override;
183 void setErrorState(bool is_in_error_state);
188 void setupForCaptureMode(bool capture_mode);
193 void setAutoRotateCamera(bool auto_rotate);
217 void takeImage();
227 LogPtr log() const { return m_log; }
237 void setConnectingIcon(const StringView& image);
242 void setErrorIcon(const StringView& image);
247 void setScreenshotFileName(const StringView& file_name);
252 virtual void setRecordingState(RecordingState recording_state);
257 RecordingState recordingState() const override { return m_recording_state; }
262 virtual QImage grabFramebuffer();
267 virtual UUID id() const override { return m_camera->get<NDPO::guid>(); }
272 virtual ConstPointer<Camera> camera() const override { return m_camera; };
277 virtual DynamicPointer<Camera> camera() override { return m_camera; };
287 QWidget* stack() const;
298 void setSettingsWidget(QWidget* settings_widget, bool is_popup = false);
304 void setSettingsVisible(bool visible, PopupInfo info);
343 virtual QPointer<QWidget> lightingSliderWidget();
349 public:
364 protected:
366 virtual void init();
379 virtual bool startRecord(const File& file);
385 virtual bool finishRecord(File file);
392 virtual bool pauseRecord(bool paused, const File& file);
398 virtual bool takeImage(const File& file);
400 virtual void refreshInstance() {}
407 virtual File recordPath(StringView name, bool is_finished_recording) const;
414 virtual void cleanup();
418 virtual int heightForWidth(int w) const override;
421 virtual QSize sizeHint() const override;
424 virtual QWidget* cameraToolbar() override;
430 virtual bool setCameraSource(const StringView& camera_info);
432 virtual void handleError();
449 void pause();
451 void stop();
454 void setMuted(bool);
463 virtual void invertScreenColors(bool invert);
466 void setExposureCompensation(int index);
469 void processCapturedImage(const QPixmap& img);
485 virtual QPointer<QWidget> settingsWidget();
488 void keyPressEvent(QKeyEvent* event) override;
491 void keyReleaseEvent(QKeyEvent* event) override;
494 void closeEvent(QCloseEvent* event) override;
495 signals:
496 void requestLight(bool light_on);
498 public slots:
504 void setReadyForImageCapture(bool ready);
508 void mediaEnd();
517 protected:
519 Ui::PhysicalCameraViewUI *ui;
529 QPointer<QWidget> m_settings_widget;
530 QPointer<QWidget> m_brightness_slider_widget;
531 QPointer<QCustomSlider> m_brightness_slider;
532 RecordingState m_recording_state = RecordingState::e_stopped;
538 Toolbar* m_toolbar = nullptr;
539 QTimer* m_timeout_timer = nullptr;
541 Ruler* m_side_ruler = nullptr;
542 Ruler* m_top_ruler = nullptr;
544 QPointer<CameraRulerMenu> m_ruler_combo;
545 bool m_is_capturing_image = false;
547 bool m_is_black_and_white = false;
548 bool m_is_inverted_color = false;
549 bool m_lock_controls = false;
550 bool m_show_edge_ruler = false;
551 bool m_show_top_ruler = false;
552 bool m_tool_temp_showing = false;
553 bool m_is_in_error_state = false;
554 bool m_is_playing = false;
555 bool m_settings_popup = true;
556 public:
558 public:
571 };
572
589 DESIGN_WIDGETS_T_API template class DESIGN_WIDGETS_API StringStream<PhysicalCameraView::OutputMux>;
590 DESIGN_WIDGETS_T_API template class DESIGN_WIDGETS_API StringStream<PhysicalCameraView::OutputCodec>;
591}
592#endif
593
The default object to store data of any type that should persist through sessions of the application.
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
A core widget that allows the user to click one of many button types.
Definition Button.h:68
A menu that provides options for configuring ruler visibility, grid display, and camera locking for a...
Definition Ruler.h:244
Provides a constant, unmodifiable pointer that has shared ownership of a dynamically allocated object...
Definition Pointer.hpp:276
A hash-based key-value store, useful for quick associative lookups.
Definition Dictionary.h:64
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:356
Logic for reading or writing to a file as well as navigating filesystems or other common file operati...
Definition File.h:53
A light-weight base class for Log that allows processes to update, without the need for additional in...
A light-weight wrapper that will be a no-op if there is not a valid log reference,...
Factory for creating PhysicalCameraView instances and querying supported output formats.
virtual Buffer< PhysicalCameraView::OutputCodec > supportedOutputCodecs()
Returns the list of video codecs supported by this factory.
virtual Buffer< PhysicalCameraView::OutputMux > supportedOutputMuxes()
Returns the list of container/muxer formats supported by this factory.
virtual QImage grabFramebuffer()
Captures the current frame as a QImage.
bool m_is_inverted_color
Whether the display colors are inverted.
static ApplicationOption< uint04 > default_output_bitrate
Default video output bitrate.
String m_output_codec
The active video codec identifier.
virtual void setTouchTheme(bool touch_theme) override
Enables or disables the touch-optimized theme.
void setSettingsVisible(bool visible, PopupInfo info)
Shows or hides the settings widget.
TranslatedString m_connecting_message
The message displayed while connecting.
bool m_show_top_ruler
Whether the top ruler is visible.
void keyPressEvent(QKeyEvent *event) override
Handles key press events for camera shortcuts.
virtual void stopAndSaveRecording()
Stops the current recording and saves the video file.
Button * takeImageButton() const
Returns the screenshot capture button.
void requestLightBrightness(fltp04 percent)
Emitted to request a specific light brightness level.
File screenshotPath() const
Returns the configured screenshot output path.
static ApplicationOption< bool > write_video_to_memory
Whether to buffer video in memory before writing to disk.
QPointer< CameraRulerMenu > m_ruler_combo
The ruler configuration menu widget.
static ApplicationOption< Angle< fltp08 > > default_camera_angle_offset
Default camera rotation angle offset.
void mouseReleaseEvent(QMouseEvent *releaseEvent) override
Handles mouse release events for the camera view.
static ApplicationOption< TimeSpan > default_buffer_time
Default video buffer duration.
StringView activeCodec() const
Returns the currently active codec identifier.
void stop()
Stops the camera stream completely.
void setErrorState(bool is_in_error_state)
Sets whether the camera is in an error state, updating the display accordingly.
bool m_settings_popup
Whether the settings widget displays as a popup.
virtual ConstPointer< Camera > camera() const override
Returns a read-only pointer to the Camera.
void setVideoOutputPath(const File &file)
Sets the file path used for saving recorded video.
virtual void updateView() override
Refreshes the camera view display.
void startCamera()
Starts the camera stream.
bool m_tool_temp_showing
Whether the toolbar is temporarily shown on hover.
static ApplicationOption< String > default_output_mux
Default video container/muxer format.
virtual bool pauseRecord(bool paused, const File &file)
Pauses or resumes the current recording.
void displayFinder(QCustomStackedWidget::StackAnimationDirection=QCustomStackedWidget::e_automatic)
Displays the connection/finder panel.
Button * invertImageButton() const
Returns the invert colors button.
String m_output_mux
The active video container/muxer identifier.
void sourceChanged()
Handles a change in the camera source.
virtual void init()
Initializes the UI, toolbar, and internal state after construction.
String m_screenshot_file_name
Base file name template for screenshots.
void setupRulers()
Creates and configures the measurement ruler overlays.
bool m_is_capturing_image
Whether an image capture is in progress.
virtual bool startRecord(const File &file)
Begins recording video to the specified file.
ToolButtonSettings m_tool_button_settings
Current toolbar button visibility configuration.
virtual bool setCameraSource(const StringView &camera_info)
Sets the camera source by connection string or identifier.
File videoPath() const
Returns the configured video output path.
ToolButtonSettings buttonSettings() const
Returns the current toolbar button visibility settings.
virtual QPointer< QWidget > settingsWidget()
Returns the settings widget for this camera view.
LogPtr log() const
Returns the current logger.
virtual QPointer< QWidget > lightingSliderWidget()
Returns the lighting brightness slider widget.
QPointer< QWidget > m_brightness_slider_widget
Container widget for the brightness slider.
Toolbar * m_toolbar
The camera toolbar widget.
void setScreenshotFileName(const StringView &file_name)
Sets the base file name used for screenshot files.
String m_connecting_icon
Resource identifier for the connecting state icon.
virtual void handleError()
Handles a camera error by updating the display and notifying the user.
LogPtr m_log
Logger for camera events and errors.
bool m_application_exiting
Whether the application is shutting down.
static Resource< File > default_screenshot_folder
Default folder for saving screenshots.
Button * m_ruler_button
The button to toggle ruler visibility.
virtual DynamicPointer< Camera > camera() override
Returns a mutable pointer to the Camera.
QWidget * activeWidget() const
Returns the currently active widget in the stacked display.
void mediaEnd()
Slot called when media playback reaches the end.
virtual void displayCurrentViewTab(QCustomStackedWidget::StackAnimationDirection=QCustomStackedWidget::e_automatic)
Switches to the appropriate view tab based on the current view mode.
void stopCamera()
Stops the camera stream.
virtual QSize sizeHint() const override
Returns the recommended size for this widget.
void updateRulers()
Updates the ruler display to match the current zoom and position.
void setMuted(bool)
Mutes or unmutes the audio from the camera stream.
virtual void setRecordingState(RecordingState recording_state)
Sets the video recording state and updates the UI accordingly.
void mediaError()
Slot called when a media playback error occurs.
TranslatedString m_last_error
The most recent error message.
bool m_is_black_and_white
Whether the display is in black and white mode.
static Buffer< PhysicalCameraView::OutputMux > SupportedOutputMuxes()
Returns a list of all container/muxer formats supported by the current backend.
void setupForCaptureMode(bool capture_mode)
Configures the view for image capture mode, adjusting UI elements.
void updateCameraRotation()
Updates the camera rotation based on device orientation or user settings.
virtual void addWidget(const QPointer< QWidget > &button) override
Adds an overlay widget to the camera view.
QTimer * m_timeout_timer
Timer for connection timeout detection.
virtual void cleanup()
Performs cleanup of camera resources before destruction.
bool event(QEvent *event) override
Processes a Qt event.
virtual QWidget * cameraToolbar() override
Returns the camera toolbar widget.
void leaveEvent(QEvent *leave) override
Handles the mouse leaving the widget area.
void takeImage()
Captures a screenshot from the current camera frame.
PhysicalCameraView()
Default constructor for subclass use only.
virtual bool finishRecord(File file)
Finalizes a recording and saves the output file.
bool m_lock_controls
Whether the camera controls are locked.
String m_error_icon
Resource identifier for the error state icon.
static void ResetSettingsToDefaults()
Resets all camera-related application settings to their defaults.
virtual ToolButtonSettings defaultButtonSettings() const
Returns the default toolbar button visibility settings for this camera type.
virtual void refreshInstance()
Refreshes the camera instance, reconnecting if needed.
virtual void startNewRecording(StringView file_name=StringView())
Begins a new video recording session.
Ruler * m_side_ruler
The side measurement ruler overlay.
void displayCamera(QCustomStackedWidget::StackAnimationDirection=QCustomStackedWidget::e_automatic)
Displays the live camera panel.
void mediaStopped()
Slot called when media playback is stopped.
static Resource< File > default_video_folder
Default folder for saving recorded videos.
void setReadyForImageCapture(bool ready)
Sets whether the camera is ready to capture an image.
void tryToConnect()
Attempts to establish a connection to the camera source.
DynamicPointer< Camera > m_camera
The camera being displayed.
virtual bool takeImage(const File &file)
Captures a single image and saves it to the specified file.
void networkRequestReady()
Handles a completed network request for the camera stream.
void setButtonSettings(const ToolButtonSettings &settings)
Applies new toolbar button visibility settings.
void setErrorIcon(const StringView &image)
Sets the icon shown when the camera is in an error state.
static Buffer< PhysicalCameraView::OutputCodec > SupportedOutputCodecs()
Returns a list of all video codecs supported by the current backend.
Button * refreshButton() const
Returns the refresh/reconnect button.
ViewMode
Describes the current display mode of the camera view.
@ e_loading
The camera is loading or connecting.
@ e_error
An error occurred with the camera stream.
@ e_camera
The camera stream is actively displayed.
void requestLight(bool light_on)
Emitted to request turning the camera light on or off.
void displayError(const TranslatedString &error, QCustomStackedWidget::StackAnimationDirection=QCustomStackedWidget::e_automatic)
Displays the error panel with a message.
virtual void setIconSizeMultiplier(fltp04 multiplier) override
Sets a multiplier for toolbar icon sizes.
static Dictionary< UUID, PhysicalCameraView * > s_active_logging
Registry of camera views with active logging.
QCustomStackedWidget * stackedWidget() const
Returns the stacked widget used for switching between view panels.
void mediaOpening()
Slot called when media is opening/buffering.
ViewMode m_view_mode
The current display mode of the view.
bool m_is_in_error_state
Whether the camera is in an error state.
void closeEvent(QCloseEvent *event) override
Handles the widget close event, performing cleanup.
virtual void showToolRibbon(bool show_ribbon) override
Shows or hides the tool ribbon overlay.
QPointer< QCustomSlider > m_brightness_slider
The slider controlling light brightness.
void pause()
Pauses the camera stream playback.
static ApplicationOption< uint04 > default_output_fps
Default video output frames per second.
virtual File recordPath(StringView name, bool is_finished_recording) const
Computes the file path for a recording.
void toggleLock()
Toggles the lock state of the camera controls.
QPointer< QWidget > m_settings_widget
The optional settings widget for camera configuration.
virtual void setSwapMode(SwapMode mode) override
Sets the buffer swap mode for rendering.
virtual int heightForWidth(int w) const override
Returns the preferred height for the given width, maintaining aspect ratio.
String m_file_name
The current recording file name.
virtual void removeWidget(const QPointer< QWidget > &button) override
Removes an overlay widget from the camera view.
fltp08 maxZoomOut() const
Returns the maximum zoom-out factor for this camera.
void mediaPlayingSlot()
Slot called when media playback begins.
void windowCapturedEvent(QEvent *event)
Handles events forwarded from the embedded window container.
void setLightBrightness(fltp04 percent)
Sets the brightness level of the camera light.
virtual void resetToolRibbon() override
Resets the tool ribbon to its default configuration.
void setConnectingIcon(const StringView &image)
Sets the icon shown while the camera is connecting.
static ApplicationOption< String > default_camera_server_location
Default camera server URL or address.
virtual UUID id() const override
Returns the unique identifier for this camera view.
void setRecordingElapsedTime(const TimeSpan &span)
Updates the displayed recording elapsed time.
WindowContainer * m_view_panel
The container holding the camera rendering surface.
File m_video_path
The directory path for saving videos.
static ApplicationOption< String > default_camera_server_password
Default camera server password.
PhysicalCameraView(const DynamicPointer< Camera > &camera, QWidget *parent=nullptr)
Constructs a PhysicalCameraView for the given camera.
void processCapturedImage(const QPixmap &img)
Processes a captured image for saving or display.
RecordingState recordingState() const override
Returns the current recording state.
void updateCameraWindowSize()
Resizes the camera rendering surface to match the widget dimensions.
RecordingState m_recording_state
The current video recording state.
bool m_show_edge_ruler
Whether the side ruler is visible.
File m_screenshot_path
The directory path for saving screenshots.
void mediaStateChanged()
Slot called when the media player state changes.
Button * lightButton() const
Returns the light toggle button.
QWidget * stack() const
Returns the stacked widget used for switching between view modes.
bool m_is_playing
Whether the camera stream is currently playing.
virtual void invertScreenColors(bool invert)
Inverts the screen colors for the camera display.
void setConnectingMessage(const TranslatedString &message)
Sets the message displayed while the camera is connecting.
Ui::PhysicalCameraViewUI * ui
The auto-generated UI form.
void setAutoRotateCamera(bool auto_rotate)
Enables or disables automatic camera rotation based on device orientation.
StringView activeVideoMux() const
Returns the currently active video muxer identifier.
void setExposureCompensation(int index)
Sets the exposure compensation level.
Ruler * m_top_ruler
The top measurement ruler overlay.
void setLog(LogPtr log)
Sets the logger for this camera view.
File m_active_record_path
The file path of the active recording.
WindowContainer * windowContainer() const
Returns the window container holding the camera rendering surface.
void setSettingsWidget(QWidget *settings_widget, bool is_popup=false)
Sets a custom settings widget for camera configuration.
void keyReleaseEvent(QKeyEvent *event) override
Handles key release events.
static ApplicationOption< String > default_output_extension
Default video file extension.
static ApplicationOption< String > default_output_codec
Default video codec.
void setScreenshotPath(const File &file)
Sets the file path used for saving screenshots.
The slider is the classic widget for controlling a bounded value.
StackAnimationDirection
Defines the direction of slide animations between stacked pages.
@ e_automatic
Automatically determine direction based on index order.
The main class for a layout where all widgets occupy the same same and only one widget is shown at a ...
A core part of the engine, stores variables that can be listened to with ResourceListener which will ...
Definition Resource.h:42
A widget meant to be placed beside a camera view showing either directional or measurement markings d...
Definition Ruler.h:54
The core String View class for the NDEVR API.
Definition StringView.h:58
The core String class for the NDEVR API.
Definition String.h:95
Stores a time span, or difference between two times, with an optional start time.
Definition TimeSpan.h:46
Class which displays progress and the current action being performed.
Definition Toolbar.h:15
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:61
A service which can generate Viewports based on Camera data.
A (hacky) class for storing a window into a container.
The primary namespace for the NDEVR SDK.
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
double fltp08
Defines an alias representing an 8 byte floating-point number.
@ guid
A 128-bit globally unique identifier for the object.
@ file
The source file path associated with this object.
Describes a video output codec with an identifier and display name.
TranslatedString name
The user-facing display name of the codec.
String id
The internal codec identifier string.
Describes a video output muxer/container format with an identifier and display name.
String id
The internal muxer identifier string.
TranslatedString name
The user-facing display name of the muxer.
Configuration flags controlling which tool buttons are visible in the camera toolbar.
bool show_light_button
Whether to show the light on/off button.
bool show_orient_camera_button
Whether to show the camera orientation button.
bool show_refresh_button
Whether to show the refresh/reconnect button.
bool show_record_button
Whether to show the video record button.
bool show_light_brightness_slider
Whether to show the light brightness slider.
bool show_swap_camera_button
Whether to show the swap camera button.
bool show_invert_image_button
Whether to show the invert colors button.
bool show_moveable_button
Whether to show the moveable/undock button.
bool show_take_image_button
Whether to show the screenshot capture button.
bool show_pause_record_button
Whether to show the pause recording button.
bool show_settings_button
Whether to show the settings button.
bool show_zoom_button
Whether to show the zoom button.
bool show_compass_button
Whether to show the compass orientation button.
Class which is used to pass arguments and requests for creating a popup dialog or widget.
Definition PopupInfo.h:16