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