-
-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathMainWindow.h
More file actions
647 lines (520 loc) · 18.6 KB
/
Copy pathMainWindow.h
File metadata and controls
647 lines (520 loc) · 18.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
/*
* MainWindow.h
*
* (c) 2013 Sofian Audry -- info(@)sofianaudry(.)com
* (c) 2013 Alexandre Quessy -- alexandre(@)quessy(.)net
* (c) 2014 Dame Diongue -- baydamd(@)gmail(.)com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MAIN_WINDOW_H_
#define MAIN_WINDOW_H_
#include <QtGui>
#include <QtWidgets>
#include <QMediaDevices>
#include <QCameraDevice>
#include <QTimer>
#include <QElapsedTimer>
#include <QVariant>
#include <QMap>
#include <QMessageLogger>
#include "MM.h"
#include "MapperGLCanvas.h"
#include "MapperGLCanvasToolbar.h"
#include "OscInterface.h"
#include "OutputGLWindow.h"
#include "ConsoleWindow.h"
#include "MappingManager.h"
#include "LayerItemDelegate.h"
#include "LayerListModel.h"
#include "qtpropertymanager.h"
#include "qtvariantproperty.h"
#include "qttreepropertybrowser.h"
#include "qtgroupboxpropertybrowser.h"
#include "SourceGui.h"
namespace mmp {
class PreferenceDialog;
class AboutDialog;
class ShortcutWindow;
/**
* This is the main window of MapMap. It acts as both a view and a controller interface.
*/
class MainWindow: public QMainWindow
{
Q_OBJECT
public:
// Constructor.
MainWindow();
// Destructor.
~MainWindow();
// XXX Unused.
//void applyOscCommand(const QVariantList& command);
protected:
// Events ///////////////////////////////////////////////////////////////////////////////////////////////////
void closeEvent(QCloseEvent *event);
void keyPressEvent(QKeyEvent *event);
bool eventFilter(QObject *object, QEvent *event);
void dragEnterEvent(QDragEnterEvent *event);
void dragMoveEvent(QDragMoveEvent *event);
void dragLeaveEvent(QDragLeaveEvent *event);
void dropEvent(QDropEvent *event);
// Slots ////////////////////////////////////////////////////////////////////////////////////////////////////
private slots:
// Menus slots.
// File menu.
void newFile();
void open();
bool save();
bool saveAs();
void importMedia();
void openCameraDevice();
void addColor();
void about();
void updateStatusBar();
void showMenuBar(bool shown);
void openRecentFile();
void clearRecentFileList();
void openRecentVideo();
void quitMapMap();
// Edit menu.
void deleteItem();
// Context menu for mappings.
void duplicateLayerItem();
void deleteLayerItem();
void renameLayerItem();
void setLayerItemLocked(bool locked);
void setLayerItemHide(bool hide);
void setLayerItemSolo(bool solo);
void loadLayerMedia();
void transformActionLayerItem();
void reorderLayerItem();
// Context menu for sources
void deleteSourceItem();
void renameSourceItem();
void sourceListEditEnd(QWidget* editor);
// Output menu
void setupOutputScreen();
void updateScreenCount();
// Widget callbacks.
void handleSourceItemSelectionChanged();
// void handleItemDoubleClicked(QListWidgetItem* item);
void handleLayerItemSelectionChanged(const QModelIndex &index);
void handleLayerItemChanged(const QModelIndex &index);
void handleLayerIndexesMoved();
void handleSourceItemSelected(QListWidgetItem* item);
void handleSourceChanged(Source::ptr source);
void layerPropertyChanged(uid id, QString propertyName, QVariant value);
void sourcePropertyChanged(uid id, QString propertyName, QVariant value);
void addMesh();
void addTriangle();
void addEllipse();
// Other.
void windowModified();
void pollOscInterface();
void exitFullScreen();
// Some help links
void documentation() {
QDesktopServices::openUrl(QUrl(MM::WEBSITE_URL));
}
// Send us feedback
void sendFeedback() {
QDesktopServices::openUrl(QUrl("mailto:mapmap@artpluscode.com"));
}
// Technical support
void technicalSupport() {
QDesktopServices::openUrl(QUrl(MM::WEBSITE_URL));
}
// Report an issues
void reportBug() {
QDesktopServices::openUrl(QUrl("https://github.com/mapmapteam/mapmap/issues/new"));
}
void openShortcutWindow();
void updateSettings();
void updateLayerListColumnWidth();
public slots:
// CRUD.
/// Clears all mappings and sources.
bool clearProject();
/// Create or replace a media source (or image).
uid createMediaSource(uid sourceId, QString uri, float x, float y, bool isImage, VideoType type, double rate=1.0);
/// Create or replace a color source.
uid createColorSource(uid sourceId, QColor color);
// TODO: Remove all these unsed fonctions below
/*======= Start of Unsed fonctions =======*/
/// Creates a textured mesh.
uid createMeshTextureLayer(uid mappingId,
uid sourceId,
int nColumns, int nRows,
const QVector<QPointF> &src, const QVector<QPointF> &dst);
/// Creates a textured triangle.
uid createTriangleTextureLayer(uid mappingId,
uid sourceId,
const QVector<QPointF> &src, const QVector<QPointF> &dst);
/// Creates a textured ellipse.
uid createEllipseTextureLayer(uid mappingId,
uid sourceId,
const QVector<QPointF> &src, const QVector<QPointF> &dst);
/// Creates a color quad.
uid createQuadColorLayer(uid mappingId,
uid sourceId,
const QVector<QPointF> &dst);
/// Creates a color triangle.
uid createTriangleColorLayer(uid mappingId,
uid sourceId,
const QVector<QPointF> &dst);
/// Creates a color ellipse.
uid createEllipseColorLayer(uid mappingId,
uid sourceId,
const QVector<QPointF> &dst);
/*======= End of Unsed fonctions =======*/
/// Sets visibility of mapping.
void setLayerVisible(uid mappingId, bool visible);
/// Sets solo status of mapping.
void setLayerSolo(uid mappingId, bool solo);
/// Sets locked attribute of mapping.
void setLayerLocked(uid mappingId, bool locked);
/// Deletes/removes a mapping.
void deleteLayer(uid mappingId);
/// Moves a mapping to given index.
void moveLayer(uid mappingId, int idx);
/// Clone/duplicate a mapping
void duplicateLayer(uid mappingId);
/// Deletes/removes a source and all associated mappigns.
void deleteSource(uid sourceId, bool replace = false);
/// Updates all canvases.
void updateCanvases();
/// Update all mapping guis.
void updateMappers();
/**
* This function is triggered framesPerSeconds() times per second. It makes sure
* the image is refreshed (updateCanvases()) and performs other necessary operations.
*/
void processFrame();
/**
* Performs operations related to the playing state, such as making sure to play only sources
* that are visible.
*/
void updatePlayingState();
// Editing toggles.
void setFramesPerSecond(qreal fps);
void enableDisplayControls(bool display);
void enableDisplaySourceControls(bool display);
void enableStickyVertices(bool display);
void displayUndoHistory(bool display);
// Show Mapping Context Menu
void showLayerContextMenu(const QPoint &point);
// Show Source Context Menu
void showSourceContextMenu(const QPoint &point);
/// Start playback.
void play(bool updatePlayPauseActions=true);
/// Pause playback.
void pause(bool updatePlayPauseActions=true);
/// Reset playback.
void rewind();
private:
// Internal methods. //////////////////////////////////////////////////////////////////////////////////////
// Creation of view elements.
void createLayout();
void createActions();
void createMenus();
void createLayerContextMenu();
void createSourceContextMenu();
void createToolBars();
void createStatusBar();
void updateRecentFileActions();
void updateRecentVideoActions();
void updateScreenActions();
void updateMediaListActions();
void updateLayerActions();
// Settings.
void readSettings();
void writeSettings();
// OSC.
void startOscReceiver();
// Actions-related.
bool okToContinue();
public:
bool loadFile(const QString &fileName);
bool saveFile(const QString &fileName);
void setCurrentFile(const QString &fileName);
void setCurrentVideo(const QString &filename);
bool importMediaFile(const QString &fileName, bool isImage = false, bool isCamera = false);
bool addColorSource(const QColor& color);
void addLayerItem(uid mappingId);
void removeLayerItem(uid mappingId);
void moveLayerItem(uid mappingId, int steps);
void addSourceItem(uid sourceId, const QIcon& icon, const QString& name);
void updateSourceItem(uid sourceId, const QIcon& icon, const QString& name);
void removeSourceItem(uid sourceId);
void renameLayer(uid mappingId, const QString& name);
void renameSource(uid sourceId, const QString& name);
void clearWindow();
// Resync mapping manager order the same as the GUI.
void syncLayerManager();
// Check if the file exists
bool fileExists(const QString& file);
// Check if the file is supported
bool fileSupported(const QString& file, bool isImage);
bool fileSupported(const QString &file, const QString &extension);
// Locate the file not found
QString locateMediaFile(const QString& uri, bool isImage);
static MainWindow* window();
// Returns a short version of filename.
static QString strippedName(const QString &fullFileName);
// Returns the source icon depending on play/pause state.
static const QIcon getSourceIcon(Source::ptr source);
private:
// Connects/disconnects project-specific widgets (sources and mappings).
void connectProjectWidgets();
void disconnectProjectWidgets();
// Get/set id from list item.
static uid getItemId(const QListWidgetItem& item);
static void setItemId(QListWidgetItem& item, uid id);
static QListWidgetItem* getItemFromId(const QListWidget& list, uid id);
static int getItemRowFromId(const QListWidget& list, uid id);
uid currentLayerItemId() const;
static QIcon createColorIcon(const QColor& color);
static QIcon createFileIcon(const QString& filename);
static QIcon createImageIcon(const QString& filename);
// GUI elements. ////////////////////////////////////////////////////////////////////////////////////////
// Menu actions.
QMenu *fileMenu;
QMenu *editMenu;
QMenu *toolsMenu;
QMenu *viewMenu;
QMenu *windowMenu;
QMenu *helpMenu;
// Sub-menus.
QMenu *outputScreenMenu;
QMenu *recentFileMenu;
QMenu *recentVideoMenu;
QMenu *layerContextMenu;
QMenu *sourceContextMenu;
// Some menus when need to be separated
QMenu *sourceMenu;
QMenu *destinationMenu;
QMenu *_changeLayerMediaMenu;
QAction *_importLayerMediaAction;
// Toolbar.
QToolBar *mainToolBar;
// Actions.
QAction *separatorAction;
QAction *newAction;
QAction *openAction;
QAction *importMediaAction;
QAction *AddCameraAction;
QAction *addColorAction;
QAction *saveAction;
QAction *saveAsAction;
QAction *exitAction;
QAction *undoAction;
QAction *redoAction;
// Mappings context menu actions
QAction *duplicateLayerAction;
QAction *deleteLayerAction;
QAction *renameLayerAction;
QAction *layerSoloAction;
QAction *layerLockedAction;
QAction *layerHideAction;
// Transform.
QAction *layerRotate90CWAction;
QAction *layerRotate90CCWAction;
QAction *layerRotate180Action;
QAction *layerHorizontalFlipAction;
QAction *layerVerticalFlipAction;
// Layer reordering.
QAction *layerRaiseAction;
QAction *layerLowerAction;
QAction *layerRaiseToTopAction;
QAction *layerLowerToBottomAction;
// Sources context menu action
QAction *deleteSourceAction;
QAction *renameSourceAction;
QAction *preferencesAction;
QAction *aboutAction;
QAction *clearRecentFileActions;
QAction *emptyRecentVideos;
QAction *addMeshAction;
QAction *addTriangleAction;
QAction *addEllipseAction;
QAction *playAction;
QAction *pauseAction;
QAction *rewindAction;
QAction *outputFullScreenAction;
QAction *displayControlsAction;
QAction *displaySourceControlsAction;
QAction *displayTestSignalAction;
QAction *stickyVerticesAction;
QAction *displayUndoHistoryAction;
QAction *displayZoomToolAction;
QAction *openConsoleAction;
QAction *showMenuBarAction;
QAction *showToolBarAction;
QActionGroup *perspectiveActionGroup;
QAction *mainViewAction;
QAction *sourceViewAction;
QAction *destViewAction;
enum { MaxRecentFiles = 10 };
enum { MaxRecentVideo = 5 };
QAction *recentFileActions[MaxRecentFiles];
QAction *recentVideoActions[MaxRecentVideo];
// help actions
QAction *bugReportAction;
QAction *supportAction;
QAction *docAction;
QAction *feedbackAction;
QAction *shortcutAction;
// Screen output action
QList<QAction *> screenActions;
QActionGroup *screenActionGroup;
// Canvas zoom actions
QAction *zoomInAction;
QAction *zoomOutAction;
QAction *resetZoomAction;
QAction *fitToViewAction;
// Widgets and layout.
QTabWidget* contentTab;
QSplitter* sourceSplitter;
QListWidget* sourceList;
QStackedWidget* sourcePropertyPanel;
QSplitter* layerSplitter;
QTableView* layerList;
QStackedWidget* layerPropertyPanel;
QUndoView* undoView;
MapperGLCanvas* sourceCanvas;
MapperGLCanvasToolbar* sourceCanvasToolbar;
QWidget* sourcePanel;
MapperGLCanvas* destinationCanvas;
MapperGLCanvasToolbar* destinationCanvasToolbar;
QWidget* destinationPanel;
OutputGLWindow* outputWindow;
ConsoleWindow* consoleWindow;
QSplitter* mainSplitter;
QSplitter* canvasSplitter;
// Internal variables. ///////////////////////////////////////////////////////////////////////////////////
// Recent files
QStringList recentFiles;
QStringList recentVideos;
// Current filename.
QString curFile;
// Current video name
QString curVideo;
// Settings
QSettings settings;
// Model.
MappingManager* mappingManager;
LayerListModel *layerListModel;
LayerItemDelegate *layerItemDelegate;
// OSC.
OscInterface::ptr osc_interface;
int oscListeningPort;
QTimer *osc_timer;
// View.
// The view counterpart of Mappings.
QMap<uid, LayerGui::ptr> layerGuis;
QMap<uid, SourceGui::ptr> sourceGuis;
// Current selected source/mapping.
uid currentSourceId;
uid currentLayerId;
bool _hasCurrentLayer;
bool _hasCurrentSource;
// Number of frames per second.
qreal _framesPerSecond;
// True iff the play button is currently pressed.
bool _isPlaying;
// True iff we are displaying the controls.
bool _displayControls;
// True iff we are displaying the borders of all controls of all shapes related to a source.
bool _displaySourceControls;
// True iff we want vertices to stick to each other.
bool _stickyVertices;
bool _displayUndoStack;
// Menu bar hidden state
bool _showMenuBar;
// Keeps track of the current selected item, wether it's a source or mapping.
QListWidgetItem* currentSelectedItem;
QModelIndex currentSelectedIndex;
QTimer *videoTimer;
QElapsedTimer *systemTimer;
// Preference dialog
PreferenceDialog* _preferenceDialog;
// About dialog
AboutDialog *_aboutDialog;
// Shortcut Windows
ShortcutWindow *_shortcutWindow;
// UndoStack
QUndoStack *undoStack;
// Labels for status bar
QLabel *destinationZoomLabel;
QLabel *sourceZoomLabel;
QLabel *lastActionLabel;
QLabel *currentMessageLabel;
QLabel *mousePosLabel;
QLabel *trueFramesPerSecondsLabel;
typedef Source::SourceType SourceType;
typedef MShape::ShapeType ShapeType ;
public:
// Accessor/mutators for the view. ///////////////////////////////////////////////////////////////////
MappingManager& getMappingManager() const { return *mappingManager; }
LayerGui::ptr getLayerGuiByLayerId(uint id) const { return layerGuis[id]; }
SourceGui::ptr getSourceGuiBySourceId(uint id) const { return sourceGuis[id]; }
uid getCurrentSourceId() const { return currentSourceId; }
uid getCurrentLayerId() const { return currentLayerId; }
Layer::ptr getCurrentLayer() const { return mappingManager->getLayerById(currentLayerId); }
Source::ptr getCurrentSource() const { return mappingManager->getSourceById(currentSourceId); }
bool hasCurrentSource() const { return _hasCurrentSource; }
bool hasCurrentLayer() const { return _hasCurrentLayer; }
void setCurrentSource(int uid);
void setCurrentLayer(int uid);
void removeCurrentSource();
void removeCurrentLayer();
OutputGLWindow* getOutputWindow() const { return outputWindow; }
MapperGLCanvas* getSourceCanvas() const { return sourceCanvas; }
MapperGLCanvas* getDestinationCanvas() const { return destinationCanvas; }
int getPreferredScreen() const { return outputWindow->getPreferredScreen(); }
/// Returns the number of frames per second.
qreal framesPerSecond() const { return _framesPerSecond; }
/// Returns true iff MapMap is currently playing (ie. not in pause).
bool isPlaying() const { return _isPlaying; }
/// Returns true iff we should display the controls.
bool displayControls() const { return _displayControls; }
/// Returns true iff we should display all of the shapes related to a source.
bool displaySourceControls() const { return _displaySourceControls; }
/// Returns true iff we want vertices to stick to each other.
bool isStickyVertices() const { return _stickyVertices; }
// Use the same undoStack for whole program
QUndoStack* getUndoStack() const { return undoStack; }
void startFullScreen();
bool setOscPort(QString portNumber);
bool setOscPort(int portNumber);
int getOscPort() const;
void setVerbose(bool verbose);
void setOutputWindowFullScreen(bool enable);
public:
// Constants. ///////////////////////////////////////////////////////////////////////////////////////
static const int DEFAULT_WIDTH = 1360;
static const int DEFAULT_HEIGHT = 768;
static const int PAINT_LIST_ITEM_HEIGHT = 40;
static const int SHAPE_LIST_ITEM_HEIGHT = 40;
static const int PAINT_LIST_MINIMUM_HEIGHT = 290;
static const int MAPPING_LIST_MINIMUM_HEIGHT = 290;
static const int PAINT_PROPERTY_PANEL_MINIMUM_HEIGHT = 290;
static const int MAPPING_PROPERTY_PANEL_MINIMUM_HEIGHT = 290;
static const int CANVAS_MINIMUM_WIDTH = 480;
static const int CANVAS_MINIMUM_HEIGHT = 270;
static const int OUTPUT_WINDOW_MINIMUM_WIDTH = 480;
static const int OUTPUT_WINDOW_MINIMUM_HEIGHT = 270;
};
}
#endif /* MAIN_WINDOW_H_ */