API Documentation
Loading...
Searching...
No Matches
PhysicalCameraView.h
Go to the documentation of this file.
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 ProgressInfo;
52 class WindowContainer;
53 class QCustomStackedWidget;
54 class TimeSpan;
55 class PhysicalCameraViewFactory;
56 class CameraRulerMenu;
57 class QCustomSlider;
58 /**--------------------------------------------------------------------------------------------------
59 \brief A Viewport that represents a physical camera stream, or real world camera view.
60 **/
61 class DESIGN_WIDGETS_API PhysicalCameraView : public CameraView
62 {
63 Q_OBJECT
64 public:
65 enum ViewMode
66 {
67 e_loading
68 , e_error
69 , e_camera
70 };
71 struct OutputCodec
72 {
73 String id;
74 TranslatedString name;
75 };
76 struct OutputMux
77 {
78 String id;
79 TranslatedString name;
80 };
81 struct ToolButtonSettings
82 {
83 bool show_refresh_button = false;
84 bool show_take_image_button = true;
85 bool show_record_button = true;
86 bool show_pause_record_button = true;
87 bool show_invert_image_button = false;
88 bool show_orient_camera_button = true;
89 bool show_swap_camera_button = false;
90 bool show_moveable_button = false;
91 bool show_light_button = false;
92 bool show_light_brightness_slider = true;
93 bool show_zoom_button = true;
94 };
95 protected:
96 PhysicalCameraView();
97 PhysicalCameraView(const DynamicPointer<Camera>& camera, QWidget* parent = nullptr);
98 public:
99 virtual ~PhysicalCameraView();
100 virtual void updateView() override;
101 virtual void setTouchTheme(bool touch_theme) override;
102 virtual void setSwapMode(SwapMode mode) override;
103 void setScreenshotPath(const File& file) { m_screenshot_path = file; }
104 void setVideoOutputPath(const File& file);
105 virtual void showToolRibbon(bool show_ribbon) override;
106 virtual void resetToolRibbon() override;
107 virtual void startNewRecording(String file_name = String());
108 virtual void stopAndSaveRecording();
109 void mouseReleaseEvent(QMouseEvent *releaseEvent) override;
110 void leaveEvent(QEvent* leave) override;
111 bool event(QEvent* event) override;
112 virtual void setIconSizeMultiplier(fltp04 multiplier) override;
113 virtual void addWidget(const QPointer<QWidget>& button) override;
114 virtual void removeWidget(const QPointer<QWidget>& button) override;
115 void setErrorState(bool is_in_error_state);
116 void setupForCaptureMode(bool capture_mode);
117 void setAutoRotateCamera(bool auto_rotate);
118 Button* lightButton() const;
119 Button* refreshButton() const;
120 Button* takeImageButton() const;
121 Button* invertImageButton() const;
122 void takeImage();
123 void setLog(ProgressInfo* log);
124 ProgressInfo* log() const { return m_log; }
125 void setConnectingMessage(const TranslatedString& message);
126 void setConnectingIcon(const String& image);
127 void setErrorIcon(const String& image);
128 void setScreenshotFileName(const String& file_name);
129 virtual void setRecordingState(RecordingState recording_state);
130 RecordingState recordingState() const override { return m_recording_state; }
131 virtual QImage grabFramebuffer();
132 virtual UUID id() const override { return m_camera->uuid(); }
133 virtual ConstPointer<Camera> camera() const override { return m_camera; };
134 virtual DynamicPointer<Camera> camera() override { return m_camera; };
135 ToolButtonSettings buttonSettings() const { return m_tool_button_settings; };
136 void setButtonSettings(const ToolButtonSettings& settings);
137 void setSettingsWidget(QWidget* settings_widget);
138 void setRecordingElapsedTime(const TimeSpan& span);
139 void tryToConnect();
140 File screenshotPath() const;
141 File videoPath() const;
142 String activeVideoMux() const;
143 String activeCodec() const;
144 void setLightBrightness(fltp04 percent);
145 virtual QPointer<QWidget> lightingSliderWidget();
146 public:
147 static void ResetSettingsToDefaults();
148 static Buffer<PhysicalCameraView::OutputCodec> SupportedOutputCodecs();
149 static Buffer<PhysicalCameraView::OutputMux> SupportedOutputMuxes();
150 protected:
151 void init();
152 void updateCameraRotation();
153 virtual ToolButtonSettings defaultButtonSettings() const;
154 virtual bool startRecord(const File& file);
155 virtual bool finishRecord(File file);
156 virtual bool pauseRecord(bool paused, const File& file);
157 virtual bool takeImage(const File& file);
158 virtual void refreshInstance() {}
159 virtual File recordPath(String name, bool is_finished_recording) const;
160 WindowContainer* windowContainer();
161 virtual void cleanup();
162 virtual int heightForWidth(int w) const override;
163 virtual QSize sizeHint() const override;
164 virtual QWidget* cameraToolbar() override;
165 virtual bool setCameraSource(const String& camera_info);
166 virtual void handleError();
167 QCustomStackedWidget* stackedWidget() const;
168 void startCamera();
169 void stopCamera();
170 void setupRulers();
171 void updateRulers();
172 void updateCameraWindowSize();
173 void pause();
174 void stop();
175 void setMuted(bool);
176 void sourceChanged();
177 void networkRequestReady();
178 void toggleLock();
179 virtual void invertScreenColors(bool invert);
180 void setExposureCompensation(int index);
181 void processCapturedImage(const QPixmap& img);
182 virtual void displayCurrentViewTab(QCustomStackedWidget::StackAnimationDirection = QCustomStackedWidget::e_automatic);
183 void displayFinder(QCustomStackedWidget::StackAnimationDirection = QCustomStackedWidget::e_automatic);
184 void displayCamera(QCustomStackedWidget::StackAnimationDirection = QCustomStackedWidget::e_automatic);
185 void displayError(const TranslatedString& error, QCustomStackedWidget::StackAnimationDirection = QCustomStackedWidget::e_automatic);
186 virtual QPointer<QWidget> settingsWidget();
187 void keyPressEvent(QKeyEvent* event) override;
188 void keyReleaseEvent(QKeyEvent* event) override;
189 void closeEvent(QCloseEvent* event) override;
190 signals:
191 void requestLight(bool light_on);
192 void requestLightBrightness(fltp04 percent);
193 public slots:
194 void windowCapturedEvent(QEvent* event);
195 void setReadyForImageCapture(bool ready);
196 void mediaPlayingSlot();
197 void mediaEnd();
198 void mediaOpening();
199 void mediaStateChanged();
200 void mediaStopped();
201 void mediaError();
202 protected:
203 DynamicPointer<Camera> m_camera;
204 Ui::PhysicalCameraViewUI *ui;
205 WindowContainer* m_view_panel;
206 TranslatedString m_last_error;
207 String m_error_icon;
208 String m_connecting_icon;
209 String m_screenshot_file_name;
210 String m_output_mux;
211 String m_output_codec;
212 TranslatedString m_connecting_message;
213 ToolButtonSettings m_tool_button_settings;
214 QPointer<QWidget> m_settings_widget;
215 QPointer<QWidget> m_brightness_slider_widget;
216 QPointer<QCustomSlider> m_brightness_slider;
217 RecordingState m_recording_state = RecordingState::e_stopped;
218 ViewMode m_view_mode = e_loading;
219 File m_active_record_path;
220 File m_screenshot_path;
221 File m_video_path;
222 String m_file_name;
223 Toolbar* m_toolbar = nullptr;
224 QTimer* m_timeout_timer = nullptr;
225 ProgressInfo* m_log = nullptr;
226 Ruler* m_side_ruler = nullptr;
227 Ruler* m_top_ruler = nullptr;
228 Button* m_ruler_button = nullptr;
229 QPointer<CameraRulerMenu> m_ruler_combo;
230 bool m_is_capturing_image = false;
231 bool m_application_exiting = false;
232 bool m_is_black_and_white = false;
233 bool m_is_inverted_color = false;
234 bool m_lock_controls = false;
235 bool m_show_edge_ruler = false;
236 bool m_show_top_ruler = false;
237 bool m_tool_temp_showing = false;
238 bool m_is_in_error_state = false;
239 bool m_is_playing = false;
240 public:
241 static Dictionary<UUID, PhysicalCameraView*> s_active_logging;
242 public:
243 static ApplicationOption<bool> write_video_to_memory;
244 static Resource<File> default_screenshot_folder;
245 static Resource<File> default_video_folder;
246 static ApplicationOption<String> default_output_mux;
247 static ApplicationOption<String> default_output_codec;
248 static ApplicationOption<uint04> default_output_fps;
249 static ApplicationOption<uint04> default_output_bitrate;
250 static ApplicationOption<String> default_output_extension;
251 static ApplicationOption<String> default_camera_server_location;
252 static ApplicationOption<String> default_camera_server_password;
253 static ApplicationOption<Angle<fltp08>> default_camera_angle_offset;
254 };
255 class PhysicalCameraViewFactory : public ViewportFactory
256 {
257 public:
258 virtual Buffer<PhysicalCameraView::OutputCodec> supportedOutputCodecs() { return Buffer<PhysicalCameraView::OutputCodec>(); };
259 virtual Buffer<PhysicalCameraView::OutputMux> supportedOutputMuxes() { return Buffer<PhysicalCameraView::OutputMux>(); };
260 };
261 DESIGN_WIDGETS_T_API template class DESIGN_WIDGETS_API StringStream<PhysicalCameraView::OutputMux>;
262 DESIGN_WIDGETS_T_API template class DESIGN_WIDGETS_API StringStream<PhysicalCameraView::OutputCodec>;
263}
264#endif
265
#define DESIGN_WIDGETS_API
Definition DLLInfo.h:56
#define DESIGN_WIDGETS_T_API
Definition DLLInfo.h:57
Definition ACIColor.h:37
Definition FontEditor.h:6