CAVAPA-GUI  30.5.2014
 All Classes Namespaces Functions Variables Typedefs Enumerations Pages
mainwindow.h
1 /****************************************************************************
2  * Copyright (c) 2014, Joel Kivelä, Erkki Koskenkorva, Oskari Leppäaho,
3  * Mika Lehtinen and Petri Partanen.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * * Neither the name of the copyright holders nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 ****************************************************************************/
30 #ifndef MAINWINDOW_H
31 #define MAINWINDOW_H
32 
33 #include <memory>
34 
35 #include <QMainWindow>
36 #include <QPushButton>
37 #include <QSlider>
38 
39 #include "userinterface.h"
40 #include "common.h"
41 #include "controller.h"
42 #include "scenewidget.h"
43 
44 using cavapa::CalibrationPoint;
45 
46 namespace Ui
47 {
48 class MainWindow;
49 }
50 
51 namespace cavapa_gui
52 {
58 class MainWindow : public QMainWindow, public UserInterface
59 {
60  Q_OBJECT
61 public:
66  explicit MainWindow(QMainWindow* parent = 0);
67  ~MainWindow();
68 
69  void addSource(SourceID source, SourceType type, FrameTime length,
70  const std::string& description) override;
71 
72  void calculationCanceled() override;
73 
74  void calculationCompleted() override;
75 
76  void calculationContinued() override;
77 
78  void calculationPaused() override;
79 
80  void calculationStarted() override;
81 
82  void calculationStopped() override;
83 
84  std::vector<std::string> getMarkerHistory() override;
85 
86  void newMeasurement() override;
87 
88  void openMeasurement() override;
89 
90  void removeSource(SourceID source) override;
91 
93  SourceID source,
94  const std::vector<CalibrationPoint>& points) override;
95 
96  void setCanPause(bool flag) override;
97 
98  void setCanSaveVideos(bool flag) override;
99 
100  void setLocation(int x, int y) override;
101 
102  void setMarkerHistory(const std::vector<std::string>& history) override;
103 
104  void setSize(int width, int height, bool fullscreen) override;
105 
106  void showMessage(const std::string& message,
107  ErrorLevel errorLevel) override;
108 
109  void sourcePaused(SourceID source) override;
110 
111  void sourcePlayStarted(SourceID source) override;
112 
113  void startInterface() override;
114 
115  void updateFrame(const FrameCapture& frame) override;
116 
117  void updateCalculation(const FrameStats& statistics) override;
118 
119  void updateGeneralSettings(const GeneralSettings& settings) override;
120 
121  void updateMarkers(const std::vector<GraphMarker>& markers) override;
122 
123  void updateMetadata(const Metadata& metadata) override;
124 
125  void updateSourceSettings(SourceID source,
126  const SourceSettings& settings) override;
127 
128  void updateStatistics(const std::vector<FrameStats>& stats) override;
129 
130 private:
136  bool askConfirmation(const std::string& question) override;
137 
143  std::shared_ptr<SceneWidget> getScene(SourceID id) const;
144 
150  void setAddCalibrationPointsEnabled(bool enable);
151 
157  void setGraphVisible(bool visible);
158 
166  void setSliderValueFromLineEdit(QObject* lineEdit, float scale,
167  QSlider* slider);
168 
173  void updateSlidersFromScene();
174 
175  std::vector<std::shared_ptr<SceneWidget>> scenes; // Holds the scenes
176  Ui::MainWindow* ui;
177  bool calculationInProgress = false;
178  bool canPause = false;
179  bool canAddCalibrationPoints = false;
180  GeneralSettings generalSettings;
181  SceneWidget* activeScene;
182 
183 private slots:
188  void emitMarkersReady();
189 
193  void graphSettingsChanged();
194 
198  void removeScenes();
199 
208  void requestStatistics(FrameTime start, FrameTime stop, int points)
209  {
210  emit statisticsRequested(start, stop, points);
211  }
212 
218  void changeActiveScene(SceneWidget* newActiveScene);
219 
220  void on_buttonStart_clicked();
221 
222  void on_actionOpen_video_triggered();
223 
224  void on_actionRefresh_cameras_triggered();
225 
226  void on_cancelButton_clicked();
227 
228  void on_actionSettings_triggered();
229 
230  void on_actionOpen_link_triggered();
231 
232  void on_actionAbout_triggered();
233 
234  void on_addStreamButton_clicked();
235 
236  void on_addVideoFileButton_clicked();
237 
238  void on_stopButton_clicked();
239 
240  void on_horizontalSliderHeight_sliderMoved(int position);
241 
242  void on_lineEditHeight_returnPressed();
243 
244  void on_horizontalSliderXRot_sliderMoved(int position);
245 
246  void on_lineEditXRot_returnPressed();
247 
248  void on_horizontalSliderYRot_sliderMoved(int position);
249 
250  void on_lineEditYRot_returnPressed();
251 
252  void on_horizontalSliderZRot_sliderMoved(int position);
253 
254  void on_lineEditZRot_returnPressed();
255 
256  void on_horizontalSliderFov_sliderMoved(int position);
257 
258  void on_lineEditFov_returnPressed();
259 
260  void on_actionOpen_existing_measurement_triggered();
261 
262  void on_actionNew_measurement_triggered();
263 
264  void on_sourceList_itemSelectionChanged();
265 
266  void on_actionRedo_current_measurement_triggered();
267 
268  void on_pauseButton_clicked();
269 
270  void on_continueButton_clicked();
271 
272  void on_pushButtonDefaultConfig_clicked();
273 
274 protected:
279  virtual void changeEvent(QEvent* event);
280 
285  virtual void closeEvent(QCloseEvent* event);
286 
291  virtual void moveEvent(QMoveEvent* event);
292 
297  virtual void resizeEvent(QResizeEvent* event);
298 
299 signals:
304 
309 
314 
319 
324 
329  const std::vector<cavapa::CalibrationPoint>& points);
330 
334  void generalSettingsChanged(const GeneralSettings& settings);
335 
339  void graphPositionSelected(FrameTime time);
340 
344  void locationChanged(int x, int y);
345 
349  void markersReady(const std::vector<GraphMarker>& markers);
350 
354  void metadataOpened(const std::string& path);
355 
359  void metadataReady(const Metadata& metadata);
360 
365 
369  void openMeasurementRequested(const std::string& path);
370 
375 
379  void refreshRequested();
380 
384  void sizeChanged(int width, int height, bool fullscreen);
385 
389  void sourceAddRequested(const std::string& path);
390 
394  void sourcePauseRequested(SourceID source);
395 
399  void sourcePlayRequested(SourceID source);
400 
404  void sourceRemoveRequested(SourceID source);
405 
409  void sourceSeekRequested(SourceID source, FrameTime position);
410 
414  void sourceSettingsChanged(SourceID source, const SourceSettings& settings);
415 
419  void sourceStepBackward(SourceID source);
420 
424  void sourceStepForward(SourceID source);
425 
429  void statisticsRequested(FrameTime start, FrameTime stop, int points);
430 
434  void interfaceClosed();
435 
439  void exportRequested(const ExportOptions& options);
440 };
441 } // namespace
442 
443 #endif // MAINWINDOW_H
A widget that holds the output and media controls of a video source.
Definition: scenewidget.h:53
void sourceSettingsChanged(SourceID source, const SourceSettings &settings)
Emitted when the user changes a setting for a source.
void sourceAddRequested(const std::string &path)
Emitted when the user adds a new video source.
void setMarkerHistory(const std::vector< std::string > &history) override
Sets the history of previously input markers.
Definition: mainwindow.cpp:311
void interfaceClosed()
Emitted when the user closes the interface.
void calculationCanceled() override
Informs the interface that the calculation was cancelled.
Definition: mainwindow.cpp:166
void setSize(int width, int height, bool fullscreen) override
Sets the size of the interface.
Definition: mainwindow.cpp:316
void sourcePauseRequested(SourceID source)
Emitted when the user requests to pause a source.
void sourceRemoveRequested(SourceID source)
Emitted when the user removes a source.
void calculationContinued() override
Informs the interface that the calculation was continued.
Definition: mainwindow.cpp:184
void updateMetadata(const Metadata &metadata) override
Updates the metadata to the interface.
Definition: mainwindow.cpp:585
void sizeChanged(int width, int height, bool fullscreen)
Emitted when the size of the interface changes.
void sourceStepBackward(SourceID source)
Emitted when the user steps a video one frame back.
void calculationStartRequested()
Emitted when the user requests to start the calculation.
virtual void resizeEvent(QResizeEvent *event)
Reimplemented for handling a window resize event.
Definition: mainwindow.cpp:355
Structure for holding frame statistics on activity.
Definition: common.h:285
void setLocation(int x, int y) override
Sets the location of the interface.
Definition: mainwindow.cpp:303
unsigned int SourceID
Used to indicate unique source ID-numbers.
Definition: common.h:229
void calculationContinueRequested()
Emitted when the user requests to continue the calculation.
void openMeasurement() override
Informs the interface that a measurement has been opened.
Definition: mainwindow.cpp:249
void calibrationPointsReady(const std::vector< cavapa::CalibrationPoint > &points)
Emitted when the user has set all the calibration points.
void calculationStopRequested()
Emitted when the user requests to stop the calculation.
void sourcePlayStarted(SourceID source) override
Informs the interface that playing was started for a source.
Definition: mainwindow.cpp:512
void setCalibrationPoints(SourceID source, const std::vector< CalibrationPoint > &points) override
Sets the calibration points for the specified source.
Definition: mainwindow.cpp:286
void updateGeneralSettings(const GeneralSettings &settings) override
Updates the general settings for the interface.
Definition: mainwindow.cpp:574
virtual void changeEvent(QEvent *event)
Reimplemented for handling a state change event.
Definition: mainwindow.cpp:361
void statisticsRequested(FrameTime start, FrameTime stop, int points)
Emitted when the user wants the frame statistics to be retrieved.
void generalSettingsChanged(const GeneralSettings &settings)
Emitted when the user changes a general setting.
void metadataOpened(const std::string &path)
Emitted when the user requests to open a metadata file.
void calculationCompleted() override
Informs the interface that the calculation has completed.
Definition: mainwindow.cpp:177
Represents the metadata associated with a measurement.
Definition: metadata.h:91
void markersReady(const std::vector< GraphMarker > &markers)
Emitted when the user has placed all the markers.
void setCanPause(bool flag) override
Informs the interface whether the calculation can be paused.
Definition: mainwindow.cpp:293
void calculationCancelRequested()
Emitted when the user requests to cancel the calculation.
void updateFrame(const FrameCapture &frame) override
Updates the frame for a source.
Definition: mainwindow.cpp:559
Represents the settings for a video source.
Definition: sourcesettings.h:46
virtual void closeEvent(QCloseEvent *event)
Reimplemented for handling a window close event.
Definition: mainwindow.cpp:325
SourceType
Available source types are the following ones: CAMERA = hardware or network camera, NOTHING = not a working source, STREAM = network stream, VIDEO = video file and VIDEOSET = set of multiple files.
Definition: common.h:68
void startInterface() override
Starts the interface.
Definition: mainwindow.cpp:554
Represents the general settings of the application.
Definition: generalsettings.h:43
void sourceSeekRequested(SourceID source, FrameTime position)
Emitted when the user requests to seek a source to a certain position.
virtual void moveEvent(QMoveEvent *event)
Reimplemented for handling a window move event.
Definition: mainwindow.cpp:349
void exportRequested(const ExportOptions &options)
Emitted when the user requests to export data from the graph.
std::uint64_t FrameTime
Used to store milliseconds interval in frame times.
Definition: common.h:138
void locationChanged(int x, int y)
Emitted when the interface is moved.
void newMeasurementRequested()
Emitted when the user wants to start a new measurement.
void calculationPaused() override
Informs the interface that the calculation was paused.
Definition: mainwindow.cpp:192
void sourcePaused(SourceID source) override
Informs the interface that a source was paused.
Definition: mainwindow.cpp:506
The structure is used for storing a single source frame.
Definition: common.h:241
void addSource(SourceID source, SourceType type, FrameTime length, const std::string &description) override
Adds a new source to the interface.
Definition: mainwindow.cpp:109
void showMessage(const std::string &message, ErrorLevel errorLevel) override
Displays a message in the interface.
Definition: mainwindow.cpp:466
void graphPositionSelected(FrameTime time)
Emitted when the user selects a position in the activity graph.
void updateSourceSettings(SourceID source, const SourceSettings &settings) override
Updates the settings of the speficied source.
Definition: mainwindow.cpp:590
The main window for the CAVAPA-GUI application.
Definition: mainwindow.h:58
std::vector< std::string > getMarkerHistory() override
Returns the history of the recently used markers.
Definition: mainwindow.cpp:229
The structure holds CSV export options.
Definition: common.h:183
void setCanSaveVideos(bool flag) override
Sets whether videos can be saved.
Definition: mainwindow.cpp:298
void updateStatistics(const std::vector< FrameStats > &stats) override
Updates the interface with the frame statistics from a certain period.
Definition: mainwindow.cpp:603
void calculationStarted() override
Informs the interface that the calculation has started.
Definition: mainwindow.cpp:200
void openMeasurementRequested(const std::string &path)
Emitted when the user wants to open an existing measurement.
void refreshRequested()
Emitted when the user requests to refresh cameras.
void updateCalculation(const FrameStats &statistics) override
Updates the calculation data.
Definition: mainwindow.cpp:568
void newMeasurement() override
Informs the interface that the user wants to start a new measurement.
Definition: mainwindow.cpp:234
MainWindow(QMainWindow *parent=0)
Constructs a new MainWindow having the specified parent.
Definition: mainwindow.cpp:43
void redoMeasurementRequested()
Emitted when the user wants to redo the measurement.
void calculationStopped() override
Informs the interface that the calculation has stopped.
Definition: mainwindow.cpp:215
void updateMarkers(const std::vector< GraphMarker > &markers) override
Updates the graph markers.
Definition: mainwindow.cpp:580
ErrorLevel
Error level indicator.
Definition: common.h:77
void calculationPauseRequested()
Emitted when the user requests to pause the calculation.
void sourceStepForward(SourceID source)
Emitted when the user steps a video one frame forward.
void metadataReady(const Metadata &metadata)
Emitted when the user has input all the metadata.
The UserInterface class defines the methods and signals that a user interface needs to have...
Definition: userinterface.h:52
void removeSource(SourceID source) override
Removes the specified source from the interface.
Definition: mainwindow.cpp:264
void sourcePlayRequested(SourceID source)
Emitted when the user requests to play a source.