]> git.sesse.net Git - nageru/blob - mainwindow.h
Serialize state to disk between runs, using SQLite.
[nageru] / mainwindow.h
1 #ifndef MAINWINDOW_H
2 #define MAINWINDOW_H
3
4 #include <stdbool.h>
5 #include <sys/types.h>
6 #include <QMainWindow>
7
8 #include "db.h"
9 #include "state.pb.h"
10
11 namespace Ui {
12 class MainWindow;
13 }  // namespace Ui
14
15 class Player;
16
17 class MainWindow : public QMainWindow
18 {
19         Q_OBJECT
20
21 public:
22         MainWindow();
23
24 //private:
25         Ui::MainWindow *ui;
26
27 private:
28         Player *preview_player, *live_player;
29         DB db;
30
31         // State when doing a scrub operation on a timestamp with the mouse.
32         bool scrubbing = false;
33         int scrub_x_origin;  // In pixels on the viewport.
34         int64_t scrub_pts_origin;
35
36         // Which element (e.g. pts_in on clip 4) we are scrubbing.
37         enum ScrubType { SCRUBBING_CLIP_LIST, SCRUBBING_PLAYLIST } scrub_type;
38         int scrub_row;
39         int scrub_column;
40
41         // Used to keep track of small mouse wheel motions on the camera index in the playlist.
42         int last_mousewheel_camera_row = -1;
43         int leftover_angle_degrees = 0;
44
45         // Some operations, notably scrubbing and scrolling, happen in so large increments
46         // that we want to group them instead of saving to disk every single time.
47         // If they happen (ie., we get a callback from the model that it's changed) while
48         // currently_deferring_model_changes, we fire off this timer. If it manages to elapse
49         // before some other event happens, we count the event. (If the other event is of the
50         // same kind, we just fire off the timer anew instead of taking any action.)
51         QTimer *defer_timeout;
52         std::string deferred_change_id;
53         StateProto deferred_state;
54
55         // Before a change that should be deferred (see above), currently_deferring_model_changes
56         // must be set to true, and current_change_id must be given contents describing what's
57         // changed to avoid accidental grouping.
58         bool currently_deferring_model_changes = false;
59         std::string current_change_id;
60
61         void cue_in_clicked();
62         void cue_out_clicked();
63         void queue_clicked();
64         void preview_clicked();
65         void preview_angle_clicked(unsigned stream_idx);
66         void play_clicked();
67         void live_player_clip_done();
68         void live_player_clip_progress(double played_this_clip, double total_length);
69         void playlist_duplicate();
70         void playlist_remove();
71         void playlist_move(int delta);
72
73         void defer_timer_expired();
74         void content_changed();  // In clip_list or play_list.
75         void state_changed(const StateProto &state);  // Called post-filtering.
76
77         enum Rounding { FIRST_AT_OR_AFTER, LAST_BEFORE };
78         void preview_single_frame(int64_t pts, unsigned stream_idx, Rounding rounding);
79
80         // Also covers when the playlist itself changes.
81         void playlist_selection_changed();
82
83         void resizeEvent(QResizeEvent *event) override;
84         bool eventFilter(QObject *watched, QEvent *event) override;
85
86 private slots:
87         void relayout();
88 };
89
90 extern MainWindow *global_mainwindow;
91
92 #endif
93