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