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