Debian Codegraph @

src/gui.cpp

raw
1 /*
2 * This file is part of Bino, a 3D video player.
3 *
4 * Copyright (C) 2022, 2023, 2024, 2025, 2026
5 * Martin Lambers <[email protected]>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include <QGuiApplication>
22 #include <QSettings>
23 #include <QMenu>
24 #include <QMenuBar>
25 #include <QMessageBox>
26 #include <QContextMenuEvent>
27 #include <QFileDialog>
28 #include <QFileInfo>
29 #include <QLabel>
30 #include <QLineEdit>
31 #include <QGridLayout>
32 #include <QPushButton>
33 #include <QMediaDevices>
34 #include <QRadioButton>
35 #include <QComboBox>
36 #include <QActionGroup>
37 #include <QMimeData>
38 #include <QWindowCapture>
39
40 #include "gui.hpp"
41 #include "playlist.hpp"
42 #include "playlisteditor.hpp"
43 #include "metadata.hpp"
44 #include "version.hpp"
45 #include "log.hpp"
46
47
48 QMenu* Gui::addBinoMenu(const QString& title)
49 {
50 QMenu* menu = menuBar()->addMenu(title);
51 _contextMenu->addMenu(menu);
52 return menu;
53 }
54
55 void Gui::addBinoAction(QAction* action, QMenu* menu)
56 {
57 menu->addAction(action);
58 _widget->addAction(action);
59 }
60
61 static Gui* GuiSingleton = nullptr;
62
63 Gui::Gui(OutputMode outputMode, float surroundVerticalFOV, bool fullscreen) :
64 QMainWindow(),
65 _widget(new Widget(outputMode, surroundVerticalFOV, this)),
66 _contextMenu(new QMenu(this))
67 {
68 setWindowTitle("Bino");
69 QPixmap icon;
70 if (!icon.load(":res/bino-logo-small.svg")) {
71 LOG_DEBUG("Gui: falling back to raster icon");
72 icon.load(":res/bino-logo-small-512.png");
73 }
74 setWindowIcon(QIcon(icon));
75
76 QMenu* fileMenu = addBinoMenu(tr("&File"));
77 QAction* fileOpenAction = new QAction(tr("&Open File(s)..."), this);
78 fileOpenAction->setShortcuts({ QKeySequence::Open });
79 connect(fileOpenAction, SIGNAL(triggered()), this, SLOT(fileOpen()));
80 addBinoAction(fileOpenAction, fileMenu);
81 QAction* fileOpenURLAction = new QAction(tr("Open &URL..."), this);
82 connect(fileOpenURLAction, SIGNAL(triggered()), this, SLOT(fileOpenURL()));
83 addBinoAction(fileOpenURLAction, fileMenu);
84 QAction* fileOpenCameraAction = new QAction(tr("Open &Capture Device..."), this);
85 connect(fileOpenCameraAction, SIGNAL(triggered()), this, SLOT(fileOpenCamera()));
86 addBinoAction(fileOpenCameraAction, fileMenu);
87 fileMenu->addSeparator();
88 QAction* fileQuitAction = new QAction(tr("&Quit"), this);
89 fileQuitAction->setShortcuts({ QKeySequence::Quit });
90 connect(fileQuitAction, SIGNAL(triggered()), this, SLOT(fileQuit()));
91 addBinoAction(fileQuitAction, fileMenu);
92
93 _trackMenu = addBinoMenu(tr("&Tracks"));
94 _trackVideoActionGroup = new QActionGroup(this);
95 _trackAudioActionGroup = new QActionGroup(this);
96 _trackSubtitleActionGroup = new QActionGroup(this);
97
98 QMenu* playlistMenu = addBinoMenu(tr("&Playlist"));
99 QAction* playlistLoadAction = new QAction(tr("&Load..."));
100 connect(playlistLoadAction, SIGNAL(triggered()), this, SLOT(playlistLoad()));
101 addBinoAction(playlistLoadAction, playlistMenu);
102 QAction* playlistSaveAction = new QAction(tr("&Save..."));
103 connect(playlistSaveAction, SIGNAL(triggered()), this, SLOT(playlistSave()));
104 addBinoAction(playlistSaveAction, playlistMenu);
105 QAction* playlistEditAction = new QAction(tr("&Edit..."));
106 connect(playlistEditAction, SIGNAL(triggered()), this, SLOT(playlistEdit()));
107 addBinoAction(playlistEditAction, playlistMenu);
108 playlistMenu->addSeparator();
109 QAction* playlistNextAction = new QAction(tr("&Next"));
110 playlistNextAction->setShortcuts({ Qt::Key_N });
111 connect(playlistNextAction, SIGNAL(triggered()), this, SLOT(playlistNext()));
112 addBinoAction(playlistNextAction, playlistMenu);
113 QAction* playlistPreviousAction = new QAction(tr("&Previous"));
114 playlistPreviousAction->setShortcuts({ Qt::Key_P });
115 connect(playlistPreviousAction, SIGNAL(triggered()), this, SLOT(playlistPrevious()));
116 addBinoAction(playlistPreviousAction, playlistMenu);
117 playlistMenu->addSeparator();
118 _playlistLoopActionGroup = new QActionGroup(this);
119 QAction* playlistLoopOff = new QAction(loopModeToStringUI(Loop_Off), this);
120 playlistLoopOff->setCheckable(true);
121 _playlistLoopActionGroup->addAction(playlistLoopOff)->setData(int(Loop_Off));
122 connect(playlistLoopOff, SIGNAL(triggered()), this, SLOT(playlistLoop()));
123 addBinoAction(playlistLoopOff, playlistMenu);
124 QAction* playlistLoopOne = new QAction(loopModeToStringUI(Loop_One), this);
125 playlistLoopOne->setCheckable(true);
126 _playlistLoopActionGroup->addAction(playlistLoopOne)->setData(int(Loop_One));
127 connect(playlistLoopOne, SIGNAL(triggered()), this, SLOT(playlistLoop()));
128 addBinoAction(playlistLoopOne, playlistMenu);
129 QAction* playlistLoopAll = new QAction(loopModeToStringUI(Loop_All), this);
130 playlistLoopAll->setCheckable(true);
131 _playlistLoopActionGroup->addAction(playlistLoopAll)->setData(int(Loop_All));
132 connect(playlistLoopAll, SIGNAL(triggered()), this, SLOT(playlistLoop()));
133 addBinoAction(playlistLoopAll, playlistMenu);
134 playlistMenu->addSeparator();
135 _playlistWaitActionGroup = new QActionGroup(this);
136 QAction* playlistWaitOff = new QAction(waitModeToStringUI(Wait_Off), this);
137 playlistWaitOff->setCheckable(true);
138 _playlistWaitActionGroup->addAction(playlistWaitOff)->setData(int(Wait_Off));
139 connect(playlistWaitOff, SIGNAL(triggered()), this, SLOT(playlistWait()));
140 addBinoAction(playlistWaitOff, playlistMenu);
141 QAction* playlistWaitOn = new QAction(waitModeToStringUI(Wait_On), this);
142 playlistWaitOn->setCheckable(true);
143 _playlistWaitActionGroup->addAction(playlistWaitOn)->setData(int(Wait_On));
144 connect(playlistWaitOn, SIGNAL(triggered()), this, SLOT(playlistWait()));
145 addBinoAction(playlistWaitOn, playlistMenu);
146
147 QMenu* threeDMenu = addBinoMenu(tr("&3D Modes"));
148 _3dSurroundActionGroup = new QActionGroup(this);
149 QAction* threeDSurroundOff = new QAction(surroundModeToStringUI(Surround_Off), this);
150 threeDSurroundOff->setCheckable(true);
151 _3dSurroundActionGroup->addAction(threeDSurroundOff)->setData(int(Surround_Off));
152 connect(threeDSurroundOff, SIGNAL(triggered()), this, SLOT(threeDSurround()));
153 addBinoAction(threeDSurroundOff, threeDMenu);
154 QAction* threeDSurround180 = new QAction(surroundModeToStringUI(Surround_180), this);
155 threeDSurround180->setCheckable(true);
156 _3dSurroundActionGroup->addAction(threeDSurround180)->setData(int(Surround_180));
157 connect(threeDSurround180, SIGNAL(triggered()), this, SLOT(threeDSurround()));
158 addBinoAction(threeDSurround180, threeDMenu);
159 QAction* threeDSurround360 = new QAction(surroundModeToStringUI(Surround_360), this);
160 threeDSurround360->setCheckable(true);
161 _3dSurroundActionGroup->addAction(threeDSurround360)->setData(int(Surround_360));
162 connect(threeDSurround360, SIGNAL(triggered()), this, SLOT(threeDSurround()));
163 addBinoAction(threeDSurround360, threeDMenu);
164 threeDMenu->addSeparator();
165 _3dInputActionGroup = new QActionGroup(this);
166 QAction* threeDInMono = new QAction(tr("Input 2D"), this);
167 threeDInMono->setCheckable(true);
168 _3dInputActionGroup->addAction(threeDInMono)->setData(int(Input_Mono));
169 connect(threeDInMono, SIGNAL(triggered()), this, SLOT(threeDInput()));
170 addBinoAction(threeDInMono, threeDMenu);
171 QMenu* threeDInputAboveBelowMenu = threeDMenu->addMenu(tr("Input 3D above-below"));
172 QAction* threeDInTopBottom = new QAction(inputModeToStringUI(Input_Top_Bottom), this);
173 threeDInTopBottom->setCheckable(true);
174 _3dInputActionGroup->addAction(threeDInTopBottom)->setData(int(Input_Top_Bottom));
175 connect(threeDInTopBottom, SIGNAL(triggered()), this, SLOT(threeDInput()));
176 addBinoAction(threeDInTopBottom, threeDInputAboveBelowMenu);
177 QAction* threeDInTopBottomHalf = new QAction(inputModeToStringUI(Input_Top_Bottom_Half), this);
178 threeDInTopBottomHalf->setCheckable(true);
179 _3dInputActionGroup->addAction(threeDInTopBottomHalf)->setData(int(Input_Top_Bottom_Half));
180 connect(threeDInTopBottomHalf, SIGNAL(triggered()), this, SLOT(threeDInput()));
181 addBinoAction(threeDInTopBottomHalf, threeDInputAboveBelowMenu);
182 QAction* threeDInBottomTop = new QAction(inputModeToStringUI(Input_Bottom_Top), this);
183 threeDInBottomTop->setCheckable(true);
184 _3dInputActionGroup->addAction(threeDInBottomTop)->setData(int(Input_Bottom_Top));
185 connect(threeDInBottomTop, SIGNAL(triggered()), this, SLOT(threeDInput()));
186 addBinoAction(threeDInBottomTop, threeDInputAboveBelowMenu);
187 QAction* threeDInBottomTopHalf = new QAction(inputModeToStringUI(Input_Bottom_Top_Half), this);
188 threeDInBottomTopHalf->setCheckable(true);
189 _3dInputActionGroup->addAction(threeDInBottomTopHalf)->setData(int(Input_Bottom_Top_Half));
190 connect(threeDInBottomTopHalf, SIGNAL(triggered()), this, SLOT(threeDInput()));
191 addBinoAction(threeDInBottomTopHalf, threeDInputAboveBelowMenu);
192 QMenu* threeDInputSideBySideMenu = threeDMenu->addMenu(tr("Input 3D side-by-side"));
193 QAction* threeDInLeftRight = new QAction(inputModeToStringUI(Input_Left_Right), this);
194 threeDInLeftRight->setCheckable(true);
195 _3dInputActionGroup->addAction(threeDInLeftRight)->setData(int(Input_Left_Right));
196 connect(threeDInLeftRight, SIGNAL(triggered()), this, SLOT(threeDInput()));
197 addBinoAction(threeDInLeftRight, threeDInputSideBySideMenu);
198 QAction* threeDInLeftRightHalf = new QAction(inputModeToStringUI(Input_Left_Right_Half), this);
199 threeDInLeftRightHalf->setCheckable(true);
200 _3dInputActionGroup->addAction(threeDInLeftRightHalf)->setData(int(Input_Left_Right_Half));
201 connect(threeDInLeftRightHalf, SIGNAL(triggered()), this, SLOT(threeDInput()));
202 addBinoAction(threeDInLeftRightHalf, threeDInputSideBySideMenu);
203 QAction* threeDInRightLeft = new QAction(inputModeToStringUI(Input_Right_Left), this);
204 threeDInRightLeft->setCheckable(true);
205 _3dInputActionGroup->addAction(threeDInRightLeft)->setData(int(Input_Right_Left));
206 connect(threeDInRightLeft, SIGNAL(triggered()), this, SLOT(threeDInput()));
207 addBinoAction(threeDInRightLeft, threeDInputSideBySideMenu);
208 QAction* threeDInRightLeftHalf = new QAction(inputModeToStringUI(Input_Right_Left_Half), this);
209 threeDInRightLeftHalf->setCheckable(true);
210 _3dInputActionGroup->addAction(threeDInRightLeftHalf)->setData(int(Input_Right_Left_Half));
211 connect(threeDInRightLeftHalf, SIGNAL(triggered()), this, SLOT(threeDInput()));
212 addBinoAction(threeDInRightLeftHalf, threeDInputSideBySideMenu);
213 QMenu* threeDInputAlternatingMenu = threeDMenu->addMenu(tr("Input 3D alternating"));
214 QAction* threeDInAlternatingLR = new QAction(inputModeToStringUI(Input_Alternating_LR), this);
215 threeDInAlternatingLR->setCheckable(true);
216 _3dInputActionGroup->addAction(threeDInAlternatingLR)->setData(int(Input_Alternating_LR));
217 connect(threeDInAlternatingLR, SIGNAL(triggered()), this, SLOT(threeDInput()));
218 addBinoAction(threeDInAlternatingLR, threeDInputAlternatingMenu);
219 QAction* threeDInAlternatingRL = new QAction(inputModeToStringUI(Input_Alternating_RL), this);
220 threeDInAlternatingRL->setCheckable(true);
221 _3dInputActionGroup->addAction(threeDInAlternatingRL)->setData(int(Input_Alternating_RL));
222 connect(threeDInAlternatingRL, SIGNAL(triggered()), this, SLOT(threeDInput()));
223 addBinoAction(threeDInAlternatingRL, threeDInputAlternatingMenu);
224 threeDMenu->addSeparator();
225 _3dOutputActionGroup = new QActionGroup(this);
226 QAction* threeDOutLeft = new QAction(outputModeToStringUI(Output_Left), this);
227 threeDOutLeft->setCheckable(true);
228 _3dOutputActionGroup->addAction(threeDOutLeft)->setData(int(Output_Left));
229 connect(threeDOutLeft, SIGNAL(triggered()), this, SLOT(threeDOutput()));
230 addBinoAction(threeDOutLeft, threeDMenu);
231 QAction* threeDOutRight = new QAction(outputModeToStringUI(Output_Right), this);
232 threeDOutRight->setCheckable(true);
233 _3dOutputActionGroup->addAction(threeDOutRight)->setData(int(Output_Right));
234 connect(threeDOutRight, SIGNAL(triggered()), this, SLOT(threeDOutput()));
235 addBinoAction(threeDOutRight, threeDMenu);
236 QAction* threeDOutStereo = new QAction(outputModeToStringUI(Output_OpenGL_Stereo), this);
237 threeDOutStereo->setCheckable(true);
238 _3dOutputActionGroup->addAction(threeDOutStereo)->setData(int(Output_OpenGL_Stereo));
239 connect(threeDOutStereo, SIGNAL(triggered()), this, SLOT(threeDOutput()));
240 addBinoAction(threeDOutStereo, threeDMenu);
241 QAction* threeDOutAlternating = new QAction(outputModeToStringUI(Output_Alternating), this);
242 threeDOutAlternating->setCheckable(true);
243 _3dOutputActionGroup->addAction(threeDOutAlternating)->setData(int(Output_Alternating));
244 connect(threeDOutAlternating, SIGNAL(triggered()), this, SLOT(threeDOutput()));
245 addBinoAction(threeDOutAlternating, threeDMenu);
246 QAction* threeDOutHDMIFramePack = new QAction(outputModeToStringUI(Output_HDMI_Frame_Pack), this);
247 threeDOutHDMIFramePack->setCheckable(true);
248 _3dOutputActionGroup->addAction(threeDOutHDMIFramePack)->setData(int(Output_HDMI_Frame_Pack));
249 connect(threeDOutHDMIFramePack, SIGNAL(triggered()), this, SLOT(threeDOutput()));
250 addBinoAction(threeDOutHDMIFramePack, threeDMenu);
251 QMenu* threeDOutputSideBySideMenu = threeDMenu->addMenu(tr("Output 3D side-by-side"));
252 QAction* threeDOutLR = new QAction(outputModeToStringUI(Output_Left_Right), this);
253 threeDOutLR->setCheckable(true);
254 _3dOutputActionGroup->addAction(threeDOutLR)->setData(int(Output_Left_Right));
255 connect(threeDOutLR, SIGNAL(triggered()), this, SLOT(threeDOutput()));
256 addBinoAction(threeDOutLR, threeDOutputSideBySideMenu);
257 QAction* threeDOutLRH = new QAction(outputModeToStringUI(Output_Left_Right_Half), this);
258 threeDOutLRH->setCheckable(true);
259 _3dOutputActionGroup->addAction(threeDOutLRH)->setData(int(Output_Left_Right_Half));
260 connect(threeDOutLRH, SIGNAL(triggered()), this, SLOT(threeDOutput()));
261 addBinoAction(threeDOutLRH, threeDOutputSideBySideMenu);
262 QAction* threeDOutRL = new QAction(outputModeToStringUI(Output_Right_Left), this);
263 threeDOutRL->setCheckable(true);
264 _3dOutputActionGroup->addAction(threeDOutRL)->setData(int(Output_Right_Left));
265 connect(threeDOutRL, SIGNAL(triggered()), this, SLOT(threeDOutput()));
266 addBinoAction(threeDOutRL, threeDOutputSideBySideMenu);
267 QAction* threeDOutRLH = new QAction(outputModeToStringUI(Output_Right_Left_Half), this);
268 threeDOutRLH->setCheckable(true);
269 _3dOutputActionGroup->addAction(threeDOutRLH)->setData(int(Output_Right_Left_Half));
270 connect(threeDOutRLH, SIGNAL(triggered()), this, SLOT(threeDOutput()));
271 addBinoAction(threeDOutRLH, threeDOutputSideBySideMenu);
272 QMenu* threeDOutputAboveBelowMenu = threeDMenu->addMenu(tr("Output 3D above-below"));
273 QAction* threeDOutTB = new QAction(outputModeToStringUI(Output_Top_Bottom), this);
274 threeDOutTB->setCheckable(true);
275 _3dOutputActionGroup->addAction(threeDOutTB)->setData(int(Output_Top_Bottom));
276 connect(threeDOutTB, SIGNAL(triggered()), this, SLOT(threeDOutput()));
277 addBinoAction(threeDOutTB, threeDOutputAboveBelowMenu);
278 QAction* threeDOutTBH = new QAction(outputModeToStringUI(Output_Top_Bottom_Half), this);
279 threeDOutTBH->setCheckable(true);
280 _3dOutputActionGroup->addAction(threeDOutTBH)->setData(int(Output_Top_Bottom_Half));
281 connect(threeDOutTBH, SIGNAL(triggered()), this, SLOT(threeDOutput()));
282 addBinoAction(threeDOutTBH, threeDOutputAboveBelowMenu);
283 QAction* threeDOutBT = new QAction(outputModeToStringUI(Output_Bottom_Top), this);
284 threeDOutBT->setCheckable(true);
285 _3dOutputActionGroup->addAction(threeDOutBT)->setData(int(Output_Bottom_Top));
286 connect(threeDOutBT, SIGNAL(triggered()), this, SLOT(threeDOutput()));
287 addBinoAction(threeDOutBT, threeDOutputAboveBelowMenu);
288 QAction* threeDOutBTH = new QAction(outputModeToStringUI(Output_Bottom_Top_Half), this);
289 threeDOutBTH->setCheckable(true);
290 _3dOutputActionGroup->addAction(threeDOutBTH)->setData(int(Output_Bottom_Top_Half));
291 connect(threeDOutBTH, SIGNAL(triggered()), this, SLOT(threeDOutput()));
292 addBinoAction(threeDOutBTH, threeDOutputAboveBelowMenu);
293 QMenu* threeDOutputInterleavedMenu = threeDMenu->addMenu(tr("Output 3D interleaved"));
294 QAction* threeDOutEOR = new QAction(outputModeToStringUI(Output_Even_Odd_Rows), this);
295 threeDOutEOR->setCheckable(true);
296 _3dOutputActionGroup->addAction(threeDOutEOR)->setData(int(Output_Even_Odd_Rows));
297 connect(threeDOutEOR, SIGNAL(triggered()), this, SLOT(threeDOutput()));
298 addBinoAction(threeDOutEOR, threeDOutputInterleavedMenu);
299 QAction* threeDOutEOC = new QAction(outputModeToStringUI(Output_Even_Odd_Columns), this);
300 threeDOutEOC->setCheckable(true);
301 _3dOutputActionGroup->addAction(threeDOutEOC)->setData(int(Output_Even_Odd_Columns));
302 connect(threeDOutEOC, SIGNAL(triggered()), this, SLOT(threeDOutput()));
303 addBinoAction(threeDOutEOC, threeDOutputInterleavedMenu);
304 QAction* threeDOutCheckerboard = new QAction(outputModeToStringUI(Output_Checkerboard), this);
305 threeDOutCheckerboard->setCheckable(true);
306 _3dOutputActionGroup->addAction(threeDOutCheckerboard)->setData(int(Output_Checkerboard));
307 connect(threeDOutCheckerboard, SIGNAL(triggered()), this, SLOT(threeDOutput()));
308 addBinoAction(threeDOutCheckerboard, threeDOutputInterleavedMenu);
309 QMenu* threeDOutputAnaglyphMenu = threeDMenu->addMenu(tr("Output 3D anaglyph"));
310 QAction* threeDOutRCD = new QAction(outputModeToStringUI(Output_Red_Cyan_Dubois), this);
311 threeDOutRCD->setCheckable(true);
312 _3dOutputActionGroup->addAction(threeDOutRCD)->setData(int(Output_Red_Cyan_Dubois));
313 connect(threeDOutRCD, SIGNAL(triggered()), this, SLOT(threeDOutput()));
314 addBinoAction(threeDOutRCD, threeDOutputAnaglyphMenu);
315 QAction* threeDOutRCF = new QAction(outputModeToStringUI(Output_Red_Cyan_FullColor), this);
316 threeDOutRCF->setCheckable(true);
317 _3dOutputActionGroup->addAction(threeDOutRCF)->setData(int(Output_Red_Cyan_FullColor));
318 connect(threeDOutRCF, SIGNAL(triggered()), this, SLOT(threeDOutput()));
319 addBinoAction(threeDOutRCF, threeDOutputAnaglyphMenu);
320 QAction* threeDOutRCH = new QAction(outputModeToStringUI(Output_Red_Cyan_HalfColor), this);
321 threeDOutRCH->setCheckable(true);
322 _3dOutputActionGroup->addAction(threeDOutRCH)->setData(int(Output_Red_Cyan_HalfColor));
323 connect(threeDOutRCH, SIGNAL(triggered()), this, SLOT(threeDOutput()));
324 addBinoAction(threeDOutRCH, threeDOutputAnaglyphMenu);
325 QAction* threeDOutRCM = new QAction(outputModeToStringUI(Output_Red_Cyan_Monochrome), this);
326 threeDOutRCM->setCheckable(true);
327 _3dOutputActionGroup->addAction(threeDOutRCM)->setData(int(Output_Red_Cyan_Monochrome));
328 connect(threeDOutRCM, SIGNAL(triggered()), this, SLOT(threeDOutput()));
329 addBinoAction(threeDOutRCM, threeDOutputAnaglyphMenu);
330 QAction* threeDOutGMD = new QAction(outputModeToStringUI(Output_Green_Magenta_Dubois), this);
331 threeDOutGMD->setCheckable(true);
332 _3dOutputActionGroup->addAction(threeDOutGMD)->setData(int(Output_Green_Magenta_Dubois));
333 connect(threeDOutGMD, SIGNAL(triggered()), this, SLOT(threeDOutput()));
334 addBinoAction(threeDOutGMD, threeDOutputAnaglyphMenu);
335 QAction* threeDOutGMF = new QAction(outputModeToStringUI(Output_Green_Magenta_FullColor), this);
336 threeDOutGMF->setCheckable(true);
337 _3dOutputActionGroup->addAction(threeDOutGMF)->setData(int(Output_Green_Magenta_FullColor));
338 connect(threeDOutGMF, SIGNAL(triggered()), this, SLOT(threeDOutput()));
339 addBinoAction(threeDOutGMF, threeDOutputAnaglyphMenu);
340 QAction* threeDOutGMH = new QAction(outputModeToStringUI(Output_Green_Magenta_HalfColor), this);
341 threeDOutGMH->setCheckable(true);
342 _3dOutputActionGroup->addAction(threeDOutGMH)->setData(int(Output_Green_Magenta_HalfColor));
343 connect(threeDOutGMH, SIGNAL(triggered()), this, SLOT(threeDOutput()));
344 addBinoAction(threeDOutGMH, threeDOutputAnaglyphMenu);
345 QAction* threeDOutGMM = new QAction(outputModeToStringUI(Output_Green_Magenta_Monochrome), this);
346 threeDOutGMM->setCheckable(true);
347 _3dOutputActionGroup->addAction(threeDOutGMM)->setData(int(Output_Green_Magenta_Monochrome));
348 connect(threeDOutGMM, SIGNAL(triggered()), this, SLOT(threeDOutput()));
349 addBinoAction(threeDOutGMM, threeDOutputAnaglyphMenu);
350 QAction* threeDOutABD = new QAction(outputModeToStringUI(Output_Amber_Blue_Dubois), this);
351 threeDOutABD->setCheckable(true);
352 _3dOutputActionGroup->addAction(threeDOutABD)->setData(int(Output_Amber_Blue_Dubois));
353 connect(threeDOutABD, SIGNAL(triggered()), this, SLOT(threeDOutput()));
354 addBinoAction(threeDOutABD, threeDOutputAnaglyphMenu);
355 QAction* threeDOutABF = new QAction(outputModeToStringUI(Output_Amber_Blue_FullColor), this);
356 threeDOutABF->setCheckable(true);
357 _3dOutputActionGroup->addAction(threeDOutABF)->setData(int(Output_Amber_Blue_FullColor));
358 connect(threeDOutABF, SIGNAL(triggered()), this, SLOT(threeDOutput()));
359 addBinoAction(threeDOutABF, threeDOutputAnaglyphMenu);
360 QAction* threeDOutABH = new QAction(outputModeToStringUI(Output_Amber_Blue_HalfColor), this);
361 threeDOutABH->setCheckable(true);
362 _3dOutputActionGroup->addAction(threeDOutABH)->setData(int(Output_Amber_Blue_HalfColor));
363 connect(threeDOutABH, SIGNAL(triggered()), this, SLOT(threeDOutput()));
364 addBinoAction(threeDOutABH, threeDOutputAnaglyphMenu);
365 QAction* threeDOutABM = new QAction(outputModeToStringUI(Output_Amber_Blue_Monochrome), this);
366 threeDOutABM->setCheckable(true);
367 _3dOutputActionGroup->addAction(threeDOutABM)->setData(int(Output_Amber_Blue_Monochrome));
368 connect(threeDOutABM, SIGNAL(triggered()), this, SLOT(threeDOutput()));
369 addBinoAction(threeDOutABM, threeDOutputAnaglyphMenu);
370 QAction* threeDOutRGM = new QAction(outputModeToStringUI(Output_Red_Green_Monochrome), this);
371 threeDOutRGM->setCheckable(true);
372 _3dOutputActionGroup->addAction(threeDOutRGM)->setData(int(Output_Red_Green_Monochrome));
373 connect(threeDOutRGM, SIGNAL(triggered()), this, SLOT(threeDOutput()));
374 addBinoAction(threeDOutRGM, threeDOutputAnaglyphMenu);
375 QAction* threeDOutRBM = new QAction(outputModeToStringUI(Output_Red_Blue_Monochrome), this);
376 threeDOutRBM->setCheckable(true);
377 _3dOutputActionGroup->addAction(threeDOutRBM)->setData(int(Output_Red_Blue_Monochrome));
378 connect(threeDOutRBM, SIGNAL(triggered()), this, SLOT(threeDOutput()));
379 addBinoAction(threeDOutRBM, threeDOutputAnaglyphMenu);
380
381 QMenu* mediaMenu = addBinoMenu(tr("&Media"));
382 _mediaToggleVolumeMuteAction = new QAction(tr("Mute audio"), this);
383 _mediaToggleVolumeMuteAction->setShortcuts({ Qt::Key_M });
384 _mediaToggleVolumeMuteAction->setCheckable(true);
385 connect(_mediaToggleVolumeMuteAction, SIGNAL(triggered()), this, SLOT(mediaToggleVolumeMute()));
386 addBinoAction(_mediaToggleVolumeMuteAction, mediaMenu);
387 _mediaVolumeIncAction = new QAction(tr("Increase audio volume"), this);
388 _mediaVolumeIncAction->setShortcuts({ Qt::Key_VolumeUp });
389 connect(_mediaVolumeIncAction, SIGNAL(triggered()), this, SLOT(mediaVolumeInc()));
390 addBinoAction(_mediaVolumeIncAction, mediaMenu);
391 _mediaVolumeDecAction = new QAction(tr("Decrease audio volume"), this);
392 _mediaVolumeDecAction->setShortcuts({ Qt::Key_VolumeDown });
393 connect(_mediaVolumeDecAction, SIGNAL(triggered()), this, SLOT(mediaVolumeDec()));
394 addBinoAction(_mediaVolumeDecAction, mediaMenu);
395 mediaMenu->addSeparator();
396 _mediaTogglePauseAction = new QAction(tr("Pause"), this);
397 _mediaTogglePauseAction->setShortcuts({ Qt::Key_Space });
398 _mediaTogglePauseAction->setCheckable(true);
399 connect(_mediaTogglePauseAction, SIGNAL(triggered()), this, SLOT(mediaTogglePause()));
400 addBinoAction(_mediaTogglePauseAction, mediaMenu);
401 _mediaSeekFwd1SecAction = new QAction(tr("Seek forward 1 second"), this);
402 _mediaSeekFwd1SecAction->setShortcuts({ Qt::Key_Period });
403 connect(_mediaSeekFwd1SecAction, SIGNAL(triggered()), this, SLOT(mediaSeekFwd1Sec()));
404 addBinoAction(_mediaSeekFwd1SecAction, mediaMenu);
405 _mediaSeekBwd1SecAction = new QAction(tr("Seek backwards 1 second"), this);
406 _mediaSeekBwd1SecAction->setShortcuts({ Qt::Key_Comma });
407 connect(_mediaSeekBwd1SecAction, SIGNAL(triggered()), this, SLOT(mediaSeekBwd1Sec()));
408 addBinoAction(_mediaSeekBwd1SecAction, mediaMenu);
409 _mediaSeekFwd10SecsAction = new QAction(tr("Seek forward 10 seconds"), this);
410 _mediaSeekFwd10SecsAction->setShortcuts({ Qt::Key_Right });
411 connect(_mediaSeekFwd10SecsAction, SIGNAL(triggered()), this, SLOT(mediaSeekFwd10Secs()));
412 addBinoAction(_mediaSeekFwd10SecsAction, mediaMenu);
413 _mediaSeekBwd10SecsAction = new QAction(tr("Seek backwards 10 seconds"), this);
414 _mediaSeekBwd10SecsAction->setShortcuts({ Qt::Key_Left });
415 connect(_mediaSeekBwd10SecsAction, SIGNAL(triggered()), this, SLOT(mediaSeekBwd10Secs()));
416 addBinoAction(_mediaSeekBwd10SecsAction, mediaMenu);
417 _mediaSeekFwd1MinAction = new QAction(tr("Seek forward 1 minute"), this);
418 _mediaSeekFwd1MinAction->setShortcuts({ Qt::Key_Up });
419 connect(_mediaSeekFwd1MinAction, SIGNAL(triggered()), this, SLOT(mediaSeekFwd1Min()));
420 addBinoAction(_mediaSeekFwd1MinAction, mediaMenu);
421 _mediaSeekBwd1MinAction = new QAction(tr("Seek backwards 1 minute"), this);
422 _mediaSeekBwd1MinAction->setShortcuts({ Qt::Key_Down });
423 connect(_mediaSeekBwd1MinAction, SIGNAL(triggered()), this, SLOT(mediaSeekBwd1Min()));
424 addBinoAction(_mediaSeekBwd1MinAction, mediaMenu);
425 _mediaSeekFwd10MinsAction = new QAction(tr("Seek forward 10 minutes"), this);
426 _mediaSeekFwd10MinsAction->setShortcuts({ Qt::Key_PageUp });
427 connect(_mediaSeekFwd10MinsAction, SIGNAL(triggered()), this, SLOT(mediaSeekFwd10Mins()));
428 addBinoAction(_mediaSeekFwd10MinsAction, mediaMenu);
429 _mediaSeekBwd10MinsAction = new QAction(tr("Seek backwards 10 minutes"), this);
430 _mediaSeekBwd10MinsAction->setShortcuts({ Qt::Key_PageDown });
431 connect(_mediaSeekBwd10MinsAction, SIGNAL(triggered()), this, SLOT(mediaSeekBwd10Mins()));
432 addBinoAction(_mediaSeekBwd10MinsAction, mediaMenu);
433
434 QMenu* viewMenu = addBinoMenu(tr("&View"));
435 _viewToggleFullscreenAction = new QAction(tr("&Fullscreen"), this);
436 _viewToggleFullscreenAction->setShortcuts({ Qt::Key_F11, Qt::Key_F, QKeySequence::FullScreen });
437 _viewToggleFullscreenAction->setCheckable(true);
438 connect(_viewToggleFullscreenAction, SIGNAL(triggered()), this, SLOT(viewToggleFullscreen()));
439 addBinoAction(_viewToggleFullscreenAction, viewMenu);
440 _viewToggleSwapEyesAction = new QAction(tr("&Swap eyes"), this);
441 _viewToggleSwapEyesAction->setShortcuts({ Qt::Key_F7 });
442 _viewToggleSwapEyesAction->setCheckable(true);
443 connect(_viewToggleSwapEyesAction, SIGNAL(triggered()), this, SLOT(viewToggleSwapEyes()));
444 addBinoAction(_viewToggleSwapEyesAction, viewMenu);
445 viewMenu->addSeparator();
446 _viewResetSurroundAction = new QAction(tr("Reset surround view"), this);
447 _viewResetSurroundAction->setShortcuts({ Qt::Key_Z });
448 connect(_viewResetSurroundAction, SIGNAL(triggered()), this, SLOT(viewResetSurround()));
449 addBinoAction(_viewResetSurroundAction, viewMenu);
450
451 QMenu* helpMenu = addBinoMenu(tr("&Help"));
452 QAction* helpAboutAction = new QAction(tr("&About..."), this);
453 connect(helpAboutAction, SIGNAL(triggered()), this, SLOT(helpAbout()));
454 addBinoAction(helpAboutAction, helpMenu);
455
456 updateActions();
457 connect(Bino::instance(), SIGNAL(stateChanged()), this, SLOT(updateActions()));
458
459 connect(_widget, SIGNAL(toggleFullscreen()), this, SLOT(viewToggleFullscreen()));
460 setCentralWidget(_widget);
461 _widget->show();
462 _widget->setFocus();
463
464 connect(Bino::instance(), SIGNAL(wantQuit()), this, SLOT(fileQuit()));
465
466 setMinimumSize(menuBar()->sizeHint().width(), menuBar()->sizeHint().width() / 2);
467 setAcceptDrops(true);
468
469 if (fullscreen)
470 viewToggleFullscreen();
471
472 Q_ASSERT(!GuiSingleton);
473 GuiSingleton = this;
474
475 // Use this to make a 800x450 screenshot for the website and Flathub:
476 //resize(800 - 24, 450 - 70);
477 }
478
479 Gui* Gui::instance()
480 {
481 return GuiSingleton;
482 }
483
484 void Gui::fileOpen()
485 {
486 QSettings settings;
487 QString lastOpenDir = settings.value("Directory").toString();
488 QStringList names = QFileDialog::getOpenFileNames(this, QString(), lastOpenDir);
489 if (!names.isEmpty()) {
490 if (names.size() == 1) {
491 QUrl url = QUrl::fromLocalFile(names[0]);
492 MetaData metaData;
493 QString errMsg;
494 if (metaData.detectCached(url, &errMsg)) {
495 settings.setValue("Directory", QFileInfo(names.last()).absolutePath());
496 Bino::instance()->startPlaylistMode();
497 Playlist::instance()->clear();
498 Playlist::instance()->append(url);
499 Playlist::instance()->start();
500 } else {
501 QMessageBox::critical(this, tr("Error"), errMsg);
502 }
503 } else {
504 bool playlistWasEmpty = Playlist::instance()->length() == 0;
505 Bino::instance()->startPlaylistMode();
506 for (int i = 0; i < names.size(); i++) {
507 QUrl url = QUrl::fromLocalFile(names[i]);
508 MetaData metaData;
509 QString errMsg;
510 if (metaData.detectCached(url, &errMsg)) {
511 settings.setValue("Directory", QFileInfo(names.last()).absolutePath());
512 Playlist::instance()->append(url);
513 } else {
514 QMessageBox::critical(this, tr("Error"), errMsg);
515 }
516 }
517 Playlist::instance()->setWaitModeAuto();
518 if (playlistWasEmpty)
519 Playlist::instance()->next();
520 }
521 }
522 }
523
524 void Gui::fileOpenURL()
525 {
526 QDialog *dialog = new QDialog(this);
527 dialog->setWindowTitle(tr("Open URL"));
528 QLabel *label = new QLabel(tr("URL:"));
529 QLineEdit *edit = new QLineEdit("");
530 edit->setMinimumWidth(256);
531 QPushButton *cancelBtn = new QPushButton(tr("Cancel"));
532 QPushButton *okBtn = new QPushButton(tr("OK"));
533 okBtn->setDefault(true);
534 connect(cancelBtn, SIGNAL(clicked()), dialog, SLOT(reject()));
535 connect(okBtn, SIGNAL(clicked()), dialog, SLOT(accept()));
536 QGridLayout *layout = new QGridLayout();
537 layout->addWidget(label, 0, 0);
538 layout->addWidget(edit, 0, 1, 1, 3);
539 layout->addWidget(cancelBtn, 2, 2);
540 layout->addWidget(okBtn, 2, 3);
541 layout->setColumnStretch(1, 1);
542 dialog->setLayout(layout);
543 dialog->exec();
544 if (dialog->result() == QDialog::Accepted && !edit->text().isEmpty()) {
545 QUrl url = QUrl::fromUserInput(edit->text());
546 MetaData metaData;
547 QString errMsg;
548 if (metaData.detectCached(url, &errMsg)) {
549 Bino::instance()->startPlaylistMode();
550 Playlist::instance()->clear();
551 Playlist::instance()->append(url);
552 Playlist::instance()->start();
553 } else {
554 QMessageBox::critical(this, tr("Error"), errMsg);
555 }
556 }
557 }
558
559 void Gui::fileOpenCamera()
560 {
561 QGuiApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
562 QList<QAudioDevice> audioOutputDevices = QMediaDevices::audioOutputs();
563 QList<QAudioDevice> audioInputDevices = QMediaDevices::audioInputs();
564 QList<QCameraDevice> videoInputDevices = QMediaDevices::videoInputs();
565 QList<QScreen*> screenInputDevices = QGuiApplication::screens();
566 QList<QCapturableWindow> windowInputDevices = QWindowCapture::capturableWindows();
567 QGuiApplication::restoreOverrideCursor();
568
569 QDialog *dialog = new QDialog(this);
570 dialog->setWindowTitle(tr("Open Capture Device"));
571
572 QRadioButton *videoBtn = new QRadioButton(tr("Camera Input:"));
573 QComboBox* videoBox = new QComboBox;
574 videoBox->addItem(tr("Default"));
575 for (int i = 0; i < videoInputDevices.size(); i++)
576 videoBox->addItem(videoInputDevices[i].description());
577
578 QRadioButton *screenBtn = new QRadioButton(tr("Screen Input:"));
579 QComboBox* screenBox = new QComboBox;
580 for (int i = 0; i < screenInputDevices.size(); i++)
581 screenBox->addItem(screenInputDevices[i]->name());
582
583 QRadioButton *windowBtn = new QRadioButton(tr("Window Input:"));
584 QComboBox* windowBox = new QComboBox;
585 for (int i = 0; i < windowInputDevices.size(); i++)
586 windowBox->addItem(windowInputDevices[i].description());
587
588 videoBtn->setChecked(true);
589 screenBtn->setChecked(false);
590 windowBtn->setChecked(false);
591 if (screenInputDevices.size() == 0) {
592 screenBtn->setEnabled(false);
593 screenBox->setEnabled(false);
594 }
595 if (windowInputDevices.size() == 0) {
596 windowBtn->setEnabled(false);
597 windowBox->setEnabled(false);
598 }
599
600 QLabel *audioLabel = new QLabel(tr("Audio Input:"));
601 QComboBox* audioBox = new QComboBox;
602 audioBox->addItem(tr("None"));
603 audioBox->addItem(tr("Default"));
604 for (int i = 0; i < audioInputDevices.size(); i++)
605 audioBox->addItem(audioInputDevices[i].description());
606
607 QPushButton *cancelBtn = new QPushButton(tr("Cancel"));
608 QPushButton *okBtn = new QPushButton(tr("OK"));
609 okBtn->setDefault(true);
610 connect(cancelBtn, SIGNAL(clicked()), dialog, SLOT(reject()));
611 connect(okBtn, SIGNAL(clicked()), dialog, SLOT(accept()));
612
613 QGridLayout *layout = new QGridLayout();
614 layout->addWidget(videoBtn, 0, 0);
615 layout->addWidget(videoBox, 0, 1, 1, 3);
616 layout->addWidget(screenBtn, 1, 0);
617 layout->addWidget(screenBox, 1, 1, 1, 3);
618 layout->addWidget(windowBtn, 2, 0);
619 layout->addWidget(windowBox, 2, 1, 1, 3);
620 layout->addWidget(audioLabel, 3, 0);
621 layout->addWidget(audioBox, 3, 1, 1, 3);
622 layout->addWidget(cancelBtn, 4, 2);
623 layout->addWidget(okBtn, 4, 3);
624 layout->setColumnStretch(1, 1);
625 dialog->setLayout(layout);
626 dialog->exec();
627
628 if (dialog->result() == QDialog::Accepted) {
629 int audioInputDeviceIndex = audioBox->currentIndex() - 2;
630 if (videoBtn->isChecked()) {
631 int videoInputDeviceIndex = videoBox->currentIndex() - 1;
632 Bino::instance()->startCaptureModeCamera(audioInputDeviceIndex >= -1,
633 audioInputDeviceIndex >= 0
634 ? audioInputDevices[audioInputDeviceIndex]
635 : QMediaDevices::defaultAudioInput(),
636 videoInputDeviceIndex >= 0
637 ? videoInputDevices[videoInputDeviceIndex]
638 : QMediaDevices::defaultVideoInput(),
639 Input_Unknown);
640 } else if (screenBtn->isChecked()) {
641 int screenInputDeviceIndex = screenBox->currentIndex();
642 Bino::instance()->startCaptureModeScreen(audioInputDeviceIndex >= -1,
643 audioInputDeviceIndex >= 0
644 ? audioInputDevices[audioInputDeviceIndex]
645 : QMediaDevices::defaultAudioInput(),
646 screenInputDevices[screenInputDeviceIndex],
647 Input_Unknown);
648 } else if (windowBtn->isChecked()) {
649 int windowInputDeviceIndex = windowBox->currentIndex();
650 Bino::instance()->startCaptureModeWindow(audioInputDeviceIndex >= -1,
651 audioInputDeviceIndex >= 0
652 ? audioInputDevices[audioInputDeviceIndex]
653 : QMediaDevices::defaultAudioInput(),
654 windowInputDevices[windowInputDeviceIndex],
655 Input_Unknown);
656 }
657 }
658 }
659
660 void Gui::fileQuit()
661 {
662 close();
663 }
664
665 void Gui::trackVideo()
666 {
667 QAction* a = _trackVideoActionGroup->checkedAction();
668 if (a)
669 Bino::instance()->setVideoTrack(a->data().toInt());
670 }
671
672 void Gui::trackAudio()
673 {
674 QAction* a = _trackAudioActionGroup->checkedAction();
675 if (a)
676 Bino::instance()->setAudioTrack(a->data().toInt());
677 }
678
679 void Gui::trackSubtitle()
680 {
681 QAction* a = _trackSubtitleActionGroup->checkedAction();
682 if (a)
683 Bino::instance()->setSubtitleTrack(a->data().toInt());
684 }
685
686 void Gui::playlistLoad()
687 {
688 QSettings settings;
689 QString lastOpenDir = settings.value("Directory").toString();
690 QString name = QFileDialog::getOpenFileName(this, QString(), lastOpenDir, tr("Playlists (*.m3u)"));
691 if (!name.isEmpty()) {
692 QString errStr;
693 if (!Playlist::instance()->load(name, errStr)) {
694 QMessageBox::critical(this, tr("Error"), errStr);
695 } else {
696 settings.setValue("Directory", QFileInfo(name).absolutePath());
697 }
698 }
699 }
700
701 void Gui::playlistSave()
702 {
703 QSettings settings;
704 QString lastOpenDir = settings.value("Directory").toString();
705 QFileDialog fileDialog(this, QString(), lastOpenDir, tr("Playlists (*.m3u)"));
706 fileDialog.setDefaultSuffix(".m3u");
707 fileDialog.setAcceptMode(QFileDialog::AcceptSave);
708 if (fileDialog.exec()) {
709 QString name = fileDialog.selectedFiles().front();
710 QString errStr;
711 if (!Playlist::instance()->save(name, errStr)) {
712 QMessageBox::critical(this, tr("Error"), errStr);
713 } else {
714 settings.setValue("Directory", QFileInfo(name).absolutePath());
715 }
716 }
717 }
718
719 void Gui::playlistEdit()
720 {
721 PlaylistEditor editor(this);
722 editor.exec();
723 }
724
725 void Gui::playlistNext()
726 {
727 Playlist::instance()->next();
728 }
729
730 void Gui::playlistPrevious()
731 {
732 Playlist::instance()->prev();
733 }
734
735 void Gui::playlistLoop()
736 {
737 QAction* a = _playlistLoopActionGroup->checkedAction();
738 if (a)
739 Playlist::instance()->setLoopMode(static_cast<LoopMode>(a->data().toInt()));
740 }
741
742 void Gui::playlistWait()
743 {
744 QAction* a = _playlistWaitActionGroup->checkedAction();
745 if (a)
746 Playlist::instance()->setWaitMode(static_cast<WaitMode>(a->data().toInt()));
747 }
748
749 void Gui::threeDSurround()
750 {
751 QAction* a = _3dSurroundActionGroup->checkedAction();
752 if (a) {
753 Bino::instance()->setSurroundMode(static_cast<SurroundMode>(a->data().toInt()));
754 _widget->update();
755 }
756 }
757
758 void Gui::threeDInput()
759 {
760 QAction* a = _3dInputActionGroup->checkedAction();
761 if (a) {
762 Bino::instance()->setInputMode(static_cast<InputMode>(a->data().toInt()));
763 _widget->update();
764 }
765 }
766
767 void Gui::threeDOutput()
768 {
769 QAction* a = _3dOutputActionGroup->checkedAction();
770 if (a) {
771 _widget->setOutputMode(static_cast<OutputMode>(a->data().toInt()));
772 QSettings settings;
773 settings.setValue("OutputMode", outputModeToString(_widget->outputMode()));
774 _widget->update();
775 }
776 }
777
778 void Gui::mediaTogglePause()
779 {
780 Bino::instance()->togglePause();
781 }
782
783 void Gui::mediaToggleVolumeMute()
784 {
785 Bino::instance()->toggleMute();
786 }
787
788 void Gui::mediaVolumeInc()
789 {
790 Bino::instance()->changeVolume(+0.05f);
791 }
792
793 void Gui::mediaVolumeDec()
794 {
795 Bino::instance()->changeVolume(-0.05f);
796 }
797
798 void Gui::mediaSeekFwd1Sec()
799 {
800 Bino::instance()->seek(+1000);
801 }
802
803 void Gui::mediaSeekBwd1Sec()
804 {
805 Bino::instance()->seek(-1000);
806 }
807
808 void Gui::mediaSeekFwd10Secs()
809 {
810 Bino::instance()->seek(+10000);
811 }
812
813 void Gui::mediaSeekBwd10Secs()
814 {
815 Bino::instance()->seek(-10000);
816 }
817
818 void Gui::mediaSeekFwd1Min()
819 {
820 Bino::instance()->seek(+60000);
821 }
822
823 void Gui::mediaSeekBwd1Min()
824 {
825 Bino::instance()->seek(-60000);
826 }
827
828 void Gui::mediaSeekFwd10Mins()
829 {
830 Bino::instance()->seek(+600000);
831 }
832
833 void Gui::mediaSeekBwd10Mins()
834 {
835 Bino::instance()->seek(-600000);
836 }
837
838 void Gui::viewToggleFullscreen()
839 {
840 if (windowState() & Qt::WindowFullScreen) {
841 showNormal();
842 menuBar()->show();
843 activateWindow();
844 _widget->setFocus();
845 QGuiApplication::processEvents();
846 } else {
847 menuBar()->hide();
848 showFullScreen();
849 activateWindow();
850 _widget->setFocus();
851 QGuiApplication::processEvents();
852 }
853 }
854
855 void Gui::viewToggleSwapEyes()
856 {
857 Bino::instance()->toggleSwapEyes();
858 _widget->update();
859 }
860
861 void Gui::viewResetSurround()
862 {
863 _widget->resetSurroundView();
864 _widget->update();
865 }
866
867 void Gui::helpAbout()
868 {
869 QMessageBox::about(this, tr("About Bino"),
870 QString("<p>")
871 + tr("Bino version %1").arg(BINO_VERSION)
872 + QString("<br>")
873 + QString("<a href=\"https://bino3d.org\">https://bino3d.org</a>")
874 + QString("</p><p>")
875 + tr("Copyright (C) %1 Martin Lambers").arg(2026)
876 + QString("<br>")
877 + tr("This is free software. You may redistribute copies of it "
878 "under the terms of the <a href=\"http://www.gnu.org/licenses/gpl.html\">"
879 "GNU General Public License</a>. "
880 "There is NO WARRANTY, to the extent permitted by law.")
881 + QString("</p>"));
882 }
883
884 void Gui::updateActions()
885 {
886 LOG_DEBUG("updating Gui menu state");
887
888 _viewToggleSwapEyesAction->setChecked(Bino::instance()->swapEyes());
889 _mediaTogglePauseAction->setChecked(Bino::instance()->paused());
890 _mediaToggleVolumeMuteAction->setChecked(Bino::instance()->muted());
891
892 _trackMenu->clear();
893 QUrl url = Bino::instance()->url();
894 MetaData metaData;
895 if (!url.isEmpty() && metaData.detectCached(url)) {
896 for (int i = 0; i < metaData.videoTracks.size(); i++) {
897 QString s = QString(tr("Video track %1")).arg(i + 1);
898 QLocale::Language l = static_cast<QLocale::Language>(metaData.videoTracks[i].value(QMediaMetaData::Language).toInt());
899 if (l != QLocale::AnyLanguage)
900 s += QString(tr(" (%1)")).arg(QLocale::languageToString(l));
901 QAction* a = new QAction(s, this);
902 a->setCheckable(true);
903 _trackVideoActionGroup->addAction(a)->setData(i);
904 connect(a, SIGNAL(triggered()), this, SLOT(trackVideo()));
905 addBinoAction(a, _trackMenu);
906 a->setChecked(Bino::instance()->videoTrack() == i);
907 }
908 if (metaData.videoTracks.size() > 0)
909 _trackMenu->addSeparator();
910 for (int i = 0; i < metaData.audioTracks.size(); i++) {
911 QString s = QString(tr("Audio track %1")).arg(i + 1);
912 QLocale::Language l = static_cast<QLocale::Language>(metaData.audioTracks[i].value(QMediaMetaData::Language).toInt());
913 if (l != QLocale::AnyLanguage)
914 s += QString(tr(" (%1)")).arg(QLocale::languageToString(l));
915 QAction* a = new QAction(s, this);
916 a->setCheckable(true);
917 _trackAudioActionGroup->addAction(a)->setData(i);
918 connect(a, SIGNAL(triggered()), this, SLOT(trackAudio()));
919 addBinoAction(a, _trackMenu);
920 a->setChecked(Bino::instance()->audioTrack() == i);
921 }
922 if (metaData.subtitleTracks.size() > 0) {
923 if (metaData.audioTracks.size() > 0 || metaData.videoTracks.size() > 0)
924 _trackMenu->addSeparator();
925 QAction* a = new QAction(tr("No subtitles"), this);
926 a->setCheckable(true);
927 _trackSubtitleActionGroup->addAction(a)->setData(-1);
928 connect(a, SIGNAL(triggered()), this, SLOT(trackSubtitle()));
929 addBinoAction(a, _trackMenu);
930 a->setChecked(Bino::instance()->subtitleTrack() < 0);
931 for (int i = 0; i < metaData.subtitleTracks.size(); i++) {
932 QString s = QString(tr("Subtitle track %1")).arg(i + 1);
933 QLocale::Language l = static_cast<QLocale::Language>(metaData.subtitleTracks[i].value(QMediaMetaData::Language).toInt());
934 if (l != QLocale::AnyLanguage)
935 s += QString(" (%1)").arg(QLocale::languageToString(l));
936 QAction* a = new QAction(s, this);
937 a->setCheckable(true);
938 _trackSubtitleActionGroup->addAction(a)->setData(i);
939 connect(a, SIGNAL(triggered()), this, SLOT(trackSubtitle()));
940 addBinoAction(a, _trackMenu);
941 a->setChecked(Bino::instance()->subtitleTrack() == i);
942 }
943 }
944 } else {
945 QAction* a = new QAction(tr("None"), this);
946 a->setEnabled(false);
947 addBinoAction(a, _trackMenu);
948 }
949 _trackVideoActionGroup->setEnabled(Bino::instance()->playlistMode() && !Bino::instance()->stopped());
950 _trackAudioActionGroup->setEnabled(Bino::instance()->playlistMode() && !Bino::instance()->stopped());
951 _trackSubtitleActionGroup->setEnabled(Bino::instance()->playlistMode() && !Bino::instance()->stopped());
952
953 LoopMode loopMode = Playlist::instance()->loopMode();
954 for (int i = 0; i < _playlistLoopActionGroup->actions().size(); i++) {
955 QAction* a = _playlistLoopActionGroup->actions()[i];
956 a->setChecked(a->data().toInt() == int(loopMode));
957 }
958
959 WaitMode waitMode = Playlist::instance()->waitMode();
960 for (int i = 0; i < _playlistWaitActionGroup->actions().size(); i++) {
961 QAction* a = _playlistWaitActionGroup->actions()[i];
962 a->setChecked(a->data().toInt() == int(waitMode));
963 }
964
965 SurroundMode surroundMode = Bino::instance()->assumeSurroundMode();
966 _viewResetSurroundAction->setEnabled(surroundMode != Surround_Off);
967 for (int i = 0; i < _3dSurroundActionGroup->actions().size(); i++) {
968 QAction* a = _3dSurroundActionGroup->actions()[i];
969 a->setChecked(a->data().toInt() == int(surroundMode));
970 }
971 InputMode inputMode = Bino::instance()->assumeInputMode();
972 for (int i = 0; i < _3dInputActionGroup->actions().size(); i++) {
973 QAction* a = _3dInputActionGroup->actions()[i];
974 a->setChecked(a->data().toInt() == int(inputMode));
975 }
976 for (int i = 0; i < _3dOutputActionGroup->actions().size(); i++) {
977 QAction* a = _3dOutputActionGroup->actions()[i];
978 if (Bino::instance()->assumeStereoInputMode()) {
979 a->setEnabled(true);
980 a->setChecked(a->data().toInt() == int(_widget->outputMode()));
981 OutputMode outputMode = static_cast<OutputMode>(a->data().toInt());
982 if (outputMode == Output_OpenGL_Stereo)
983 a->setEnabled(_widget->isOpenGLStereo());
984 } else {
985 a->setEnabled(false);
986 a->setChecked(false);
987 }
988 }
989
990 _mediaTogglePauseAction->setEnabled(Bino::instance()->playlistMode() && !Bino::instance()->stopped());
991 _mediaSeekFwd1SecAction->setEnabled(Bino::instance()->playlistMode() && !Bino::instance()->stopped());
992 _mediaSeekBwd1SecAction->setEnabled(Bino::instance()->playlistMode() && !Bino::instance()->stopped());
993 _mediaSeekFwd10SecsAction->setEnabled(Bino::instance()->playlistMode() && !Bino::instance()->stopped());
994 _mediaSeekBwd10SecsAction->setEnabled(Bino::instance()->playlistMode() && !Bino::instance()->stopped());
995 _mediaSeekFwd1MinAction->setEnabled(Bino::instance()->playlistMode() && !Bino::instance()->stopped());
996 _mediaSeekBwd1MinAction->setEnabled(Bino::instance()->playlistMode() && !Bino::instance()->stopped());
997 _mediaSeekFwd10MinsAction->setEnabled(Bino::instance()->playlistMode() && !Bino::instance()->stopped());
998 _mediaSeekBwd10MinsAction->setEnabled(Bino::instance()->playlistMode() && !Bino::instance()->stopped());
999
1000 _widget->update();
1001 }
1002
1003 void Gui::setOutputMode(OutputMode mode)
1004 {
1005 _widget->setOutputMode(mode);
1006 _widget->update();
1007 }
1008
1009 void Gui::setSurroundVerticalFieldOfView(float vfov)
1010 {
1011 _widget->setSurroundVerticalFieldOfView(vfov);
1012 _widget->update();
1013 }
1014
1015 void Gui::setFullscreen(bool f)
1016 {
1017 if (f && !(windowState() & Qt::WindowFullScreen)) {
1018 viewToggleFullscreen();
1019 } else if (!f && (windowState() & Qt::WindowFullScreen)) {
1020 viewToggleFullscreen();
1021 }
1022 }
1023
1024 void Gui::dragEnterEvent(QDragEnterEvent* event)
1025 {
1026 if (event->mimeData()->hasUrls())
1027 event->acceptProposedAction();
1028 }
1029
1030 void Gui::dropEvent(QDropEvent* event)
1031 {
1032 if (event->mimeData()->hasUrls() && event->mimeData()->urls().size() > 0) {
1033 QUrl url = event->mimeData()->urls()[0];
1034 MetaData metaData;
1035 QString errMsg;
1036 if (metaData.detectCached(url, &errMsg)) {
1037 Bino::instance()->startPlaylistMode();
1038 Playlist::instance()->clear();
1039 Playlist::instance()->append(url);
1040 Playlist::instance()->start();
1041 } else {
1042 QMessageBox::critical(this, tr("Error"), errMsg);
1043 }
1044 event->acceptProposedAction();
1045 }
1046 }
1047
1048 #ifndef QT_NO_CONTEXTMENU
1049 void Gui::contextMenuEvent(QContextMenuEvent* event)
1050 {
1051 _contextMenu->exec(event->globalPos());
1052 }
1053 #endif // QT_NO_CONTEXTMENU
1054
1055 void Gui::moveEvent(QMoveEvent*)
1056 {
1057 if (_widget->outputMode() == Output_Even_Odd_Rows
1058 || _widget->outputMode() == Output_Even_Odd_Columns
1059 || _widget->outputMode() == Output_Checkerboard) {
1060 _widget->update();
1061 }
1062 }