]> git.sesse.net Git - nageru/blob - futatabi/mainwindow.h
Only enable the queue button if we can actually queue something.
[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         DB db;
47         unsigned num_cameras;
48
49         // State when doing a scrub operation on a timestamp with the mouse.
50         bool scrubbing = false;
51         int scrub_x_origin;  // In pixels on the viewport.
52         int64_t scrub_pts_origin;
53
54         // Which element (e.g. pts_in on clip 4) we are scrubbing.
55         enum ScrubType { SCRUBBING_CLIP_LIST,
56                          SCRUBBING_PLAYLIST } scrub_type;
57         int scrub_row;
58         int scrub_column;
59
60         // Used to keep track of small mouse wheel motions on the camera index in the playlist.
61         int last_mousewheel_camera_row = -1;
62         int leftover_angle_degrees = 0;
63
64         // Some operations, notably scrubbing and scrolling, happen in so large increments
65         // that we want to group them instead of saving to disk every single time.
66         // If they happen (ie., we get a callback from the model that it's changed) while
67         // currently_deferring_model_changes, we fire off this timer. If it manages to elapse
68         // before some other event happens, we count the event. (If the other event is of the
69         // same kind, we just fire off the timer anew instead of taking any action.)
70         QTimer *defer_timeout;
71         std::string deferred_change_id;
72         StateProto deferred_state;
73
74         // NOTE: The undo stack always has the current state on top.
75         std::deque<StateProto> undo_stack, redo_stack;
76
77         // Before a change that should be deferred (see above), currently_deferring_model_changes
78         // must be set to true, and current_change_id must be given contents describing what's
79         // changed to avoid accidental grouping.
80         bool currently_deferring_model_changes = false;
81         std::string current_change_id;
82
83         mutable std::mutex queue_status_mu;
84         std::string queue_status;  // Under queue_status_mu.
85
86         struct FrameAndDisplay {
87                 QFrame *frame;
88                 JPEGFrameView *display;
89                 QPushButton *preview_btn;
90         };
91         std::vector<FrameAndDisplay> displays;
92
93         // Used to get tally information, if a tally URL is set.
94         QNetworkAccessManager http;
95         QNetworkReply *http_reply = nullptr;
96
97         void change_num_cameras();
98         void cue_in_clicked();
99         void cue_out_clicked();
100         void queue_clicked();
101         void preview_clicked();
102         void preview_angle_clicked(unsigned stream_idx);
103         void play_clicked();
104         void stop_clicked();
105         void live_player_done();
106         void live_player_clip_progress(const std::map<uint64_t, double> &progress, double time_remaining);
107         void set_output_status(const std::string &status);
108         void playlist_duplicate();
109         void playlist_remove();
110         void playlist_move(int delta);
111
112         void defer_timer_expired();
113         void content_changed();  // In clip_list or play_list.
114         void state_changed(const StateProto &state);  // Called post-filtering.
115         void save_settings();
116
117         enum Rounding { FIRST_AT_OR_AFTER,
118                         LAST_BEFORE };
119         void preview_single_frame(int64_t pts, unsigned stream_idx, Rounding rounding);
120
121         // Also covers when the playlist itself changes.
122         void playlist_selection_changed();
123
124         void clip_list_selection_changed(const QModelIndex &current, const QModelIndex &previous);
125
126         void resizeEvent(QResizeEvent *event) override;
127         bool eventFilter(QObject *watched, QEvent *event) override;
128
129         void report_disk_space(off_t free_bytes, double estimated_seconds_left);
130         void exit_triggered();
131         void export_cliplist_clip_multitrack_triggered();
132         void export_playlist_clip_interpolated_triggered();
133         void manual_triggered();
134         void about_triggered();
135         void undo_triggered();
136         void redo_triggered();
137         void quality_toggled(int quality, bool checked);
138         void padding_toggled(double seconds, bool checked);
139
140         void highlight_camera_input(int stream_idx);
141         void enable_or_disable_preview_button();
142         void enable_or_disable_queue_button();
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