]> git.sesse.net Git - nageru/blob - futatabi/mainwindow.h
Make the UI programmatically dependent on NUM_CAMERAS.
[nageru] / futatabi / mainwindow.h
1 #ifndef MAINWINDOW_H
2 #define MAINWINDOW_H
3
4 #include "clip_list.h"
5 #include "db.h"
6 #include "state.pb.h"
7
8 #include <deque>
9 #include <memory>
10 #include <mutex>
11 #include <QLabel>
12 #include <QMainWindow>
13 #include <stdbool.h>
14 #include <sys/types.h>
15 #include <string>
16 #include <utility>
17
18 namespace Ui {
19 class MainWindow;
20 }  // namespace Ui
21
22 struct FrameOnDisk;
23 class JPEGFrameView;
24 class Player;
25 class QPushButton;
26 class QTableView;
27
28 class MainWindow : public QMainWindow {
29         Q_OBJECT
30
31 public:
32         MainWindow();
33         ~MainWindow();
34
35         // HTTP callback. TODO: Does perhaps not belong to MainWindow?
36         std::pair<std::string, std::string> get_queue_status() const;
37
38         void display_frame(unsigned stream_idx, const FrameOnDisk &frame);
39
40 private:
41         Ui::MainWindow *ui;
42
43         QLabel *disk_free_label;
44         std::unique_ptr<Player> preview_player, live_player;
45         DB db;
46
47         // State when doing a scrub operation on a timestamp with the mouse.
48         bool scrubbing = false;
49         int scrub_x_origin;  // In pixels on the viewport.
50         int64_t scrub_pts_origin;
51
52         // Which element (e.g. pts_in on clip 4) we are scrubbing.
53         enum ScrubType { SCRUBBING_CLIP_LIST, SCRUBBING_PLAYLIST } scrub_type;
54         int scrub_row;
55         int scrub_column;
56
57         // Used to keep track of small mouse wheel motions on the camera index in the playlist.
58         int last_mousewheel_camera_row = -1;
59         int leftover_angle_degrees = 0;
60
61         // Some operations, notably scrubbing and scrolling, happen in so large increments
62         // that we want to group them instead of saving to disk every single time.
63         // If they happen (ie., we get a callback from the model that it's changed) while
64         // currently_deferring_model_changes, we fire off this timer. If it manages to elapse
65         // before some other event happens, we count the event. (If the other event is of the
66         // same kind, we just fire off the timer anew instead of taking any action.)
67         QTimer *defer_timeout;
68         std::string deferred_change_id;
69         StateProto deferred_state;
70
71         // NOTE: The undo stack always has the current state on top.
72         std::deque<StateProto> undo_stack, redo_stack;
73
74         // Before a change that should be deferred (see above), currently_deferring_model_changes
75         // must be set to true, and current_change_id must be given contents describing what's
76         // changed to avoid accidental grouping.
77         bool currently_deferring_model_changes = false;
78         std::string current_change_id;
79
80         mutable std::mutex queue_status_mu;
81         std::string queue_status;  // Under queue_status_mu.
82
83         struct FrameAndDisplay {
84                 QFrame *frame;
85                 JPEGFrameView *display;
86                 QPushButton *preview_btn;
87         };
88         std::vector<FrameAndDisplay> displays;
89
90         void cue_in_clicked();
91         void cue_out_clicked();
92         void queue_clicked();
93         void preview_clicked();
94         void preview_angle_clicked(unsigned stream_idx);
95         void play_clicked();
96         void stop_clicked();
97         void live_player_clip_done();
98         std::pair<Clip, size_t> live_player_get_next_clip();
99         void live_player_clip_progress(const std::map<size_t, double> &progress);
100         void set_output_status(const std::string &status);
101         void playlist_duplicate();
102         void playlist_remove();
103         void playlist_move(int delta);
104
105         void defer_timer_expired();
106         void content_changed();  // In clip_list or play_list.
107         void state_changed(const StateProto &state);  // Called post-filtering.
108         void save_settings();
109
110         enum Rounding { FIRST_AT_OR_AFTER, LAST_BEFORE };
111         void preview_single_frame(int64_t pts, unsigned stream_idx, Rounding rounding);
112
113         // Also covers when the playlist itself changes.
114         void playlist_selection_changed();
115
116         void clip_list_selection_changed(const QModelIndex &current, const QModelIndex &previous);
117
118         void resizeEvent(QResizeEvent *event) override;
119         bool eventFilter(QObject *watched, QEvent *event) override;
120
121         void report_disk_space(off_t free_bytes, double estimated_seconds_left);
122         void exit_triggered();
123         void export_cliplist_clip_multitrack_triggered();
124         void export_playlist_clip_interpolated_triggered();
125         void manual_triggered();
126         void about_triggered();
127         void undo_triggered();
128         void redo_triggered();
129         void quality_toggled(int quality, bool checked);
130
131         void highlight_camera_input(int stream_idx);
132
133         template <class Model>
134         void replace_model(QTableView *view, Model **model, Model *new_model);
135
136 private slots:
137         void relayout();
138 };
139
140 extern MainWindow *global_mainwindow;
141
142 #endif