-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMainWindow.h
592 lines (475 loc) · 17.3 KB
/
MainWindow.h
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
/*
* 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>
#if QT_VERSION >= 0x050500
#include <QtWidgets>
#include <QCameraInfo>
#endif
#include <QTimer>
#include <QElapsedTimer>
#include <QVariant>
#include <QMap>
#include <QMessageLogger>
#include "MM.h"
#include "MapperGLCanvas.h"
#include "MapperGLCanvasToolbar.h"
#ifdef HAVE_OSC
#include "OscInterface.h"
#endif
#include "OutputGLWindow.h"
#include "ConsoleWindow.h"
#include "MappingManager.h"
#include "MappingItemDelegate.h"
#include "MappingListModel.h"
#include "qtpropertymanager.h"
#include "qtvariantproperty.h"
#include "qttreepropertybrowser.h"
#include "qtgroupboxpropertybrowser.h"
#include "PaintGui.h"
namespace mmp {
class PreferenceDialog;
class AboutDialog;
/**
* 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);
// 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 duplicateMappingItem();
void deleteMappingItem();
void renameMappingItem();
void setMappingItemLocked(bool locked);
void setMappingItemHide(bool hide);
void setMappingItemSolo(bool solo);
// Context menu for paints
void deletePaintItem();
void renamePaintItem();
void paintListEditEnd(QWidget* editor);
// Output menu
void setupOutputScreen();
void updateScreenCount();
// Widget callbacks.
void handlePaintItemSelectionChanged();
// void handleItemDoubleClicked(QListWidgetItem* item);
void handleMappingItemSelectionChanged(const QModelIndex &index);
void handleMappingItemChanged(const QModelIndex &index);
void handleMappingIndexesMoved();
void handlePaintItemSelected(QListWidgetItem* item);
void handlePaintChanged(Paint::ptr paint);
void mappingPropertyChanged(uid id, QString propertyName, QVariant value);
void paintPropertyChanged(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("http://mapmap.info/tiki-index.php?page=Documentation#section-documentation")); }
// Send us feedback
void sendFeedback() { QDesktopServices::openUrl(QUrl("mailto:[email protected]")); }
// Technical support
void technicalSupport() { QDesktopServices::openUrl(
QUrl("http://mapmap.info/tiki-index.php?page=HomePage#section-support")); }
// Report an issues
void reportBug() { QDesktopServices::openUrl(
QUrl("https://github.com/mapmapteam/mapmap/issues/new")); }
public slots:
// CRUD.
/// Clears all mappings and paints.
bool clearProject();
/// Create or replace a media paint (or image).
uid createMediaPaint(uid paintId, QString uri, float x, float y, bool isImage, VideoType type, double rate=1.0);
/// Create or replace a color paint.
uid createColorPaint(uid paintId, QColor color);
// TODO: Remove all these unsed fonctions below
/*======= Start of Unsed fonctions =======*/
/// Creates a textured mesh.
uid createMeshTextureMapping(uid mappingId,
uid paintId,
int nColumns, int nRows,
const QVector<QPointF> &src, const QVector<QPointF> &dst);
/// Creates a textured triangle.
uid createTriangleTextureMapping(uid mappingId,
uid paintId,
const QVector<QPointF> &src, const QVector<QPointF> &dst);
/// Creates a textured ellipse.
uid createEllipseTextureMapping(uid mappingId,
uid paintId,
const QVector<QPointF> &src, const QVector<QPointF> &dst);
/// Creates a color quad.
uid createQuadColorMapping(uid mappingId,
uid paintId,
const QVector<QPointF> &dst);
/// Creates a color triangle.
uid createTriangleColorMapping(uid mappingId,
uid paintId,
const QVector<QPointF> &dst);
/// Creates a color ellipse.
uid createEllipseColorMapping(uid mappingId,
uid paintId,
const QVector<QPointF> &dst);
/*======= End of Unsed fonctions =======*/
/// Sets visibility of mapping.
void setMappingVisible(uid mappingId, bool visible);
/// Sets solo status of mapping.
void setMappingSolo(uid mappingId, bool solo);
/// Sets locked attribute of mapping.
void setMappingLocked(uid mappingId, bool locked);
/// Deletes/removes a mapping.
void deleteMapping(uid mappingId);
/// Clone/duplicate a mapping
void duplicateMapping(uid mappingId);
/// Deletes/removes a paint and all associated mappigns.
void deletePaint(uid paintId, bool replace = false);
/// Updates all canvases.
void updateCanvases();
/**
* 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 paints
* that are visible.
*/
void updatePlayingState();
// Editing toggles.
void setFramesPerSecond(qreal fps);
void enableDisplayControls(bool display);
void enableDisplayPaintControls(bool display);
void enableStickyVertices(bool display);
void displayUndoHistory(bool display);
// Show Mapping Context Menu
void showMappingContextMenu(const QPoint &point);
// Show Paint Context Menu
void showPaintContextMenu(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 createMappingContextMenu();
void createPaintContextMenu();
void createToolBars();
void createStatusBar();
void updateRecentFileActions();
void updateRecentVideoActions();
void updateScreenActions();
// 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);
bool addColorPaint(const QColor& color);
void addMappingItem(uid mappingId);
void removeMappingItem(uid mappingId);
void addPaintItem(uid paintId, const QIcon& icon, const QString& name);
void updatePaintItem(uid paintId, const QIcon& icon, const QString& name);
void removePaintItem(uid paintId);
void renameMapping(uid mappingId, const QString& name);
void renamePaint(uid paintId, const QString& name);
void clearWindow();
// Check if the file exists
bool fileExists(const QString& file);
// Check if the file is supported
bool fileSupported(const QString& file, bool isImage);
// 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 paint icon depending on play/pause state.
static const QIcon getPaintIcon(Paint::ptr paint);
private:
// Connects/disconnects project-specific widgets (paints 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 currentMappingItemId() 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 *mappingContextMenu;
QMenu *paintContextMenu;
// Some menus when need to be separated
QMenu *sourceMenu;
QMenu *destinationMenu;
// Toolbar.
QToolBar *mainToolBar;
// Actions.
QAction *separatorAction;
QAction *newAction;
QAction *openAction;
QAction *importMediaAction;
QAction *openCameraAction;
QAction *addColorAction;
QAction *saveAction;
QAction *saveAsAction;
QAction *exitAction;
QAction *undoAction;
QAction *redoAction;
// Mappings context menu actions
QAction *cloneMappingAction;
QAction *deleteMappingAction;
QAction *renameMappingAction;
QAction *mappingSoloAction;
QAction *mappingLockedAction;
QAction *mappingHideAction;
// Paints context menu action
QAction *deletePaintAction;
QAction *renamePaintAction;
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 *displayPaintControlsAction;
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;
// Screen output action
QList<QAction *> screenActions;
QActionGroup *screenActionGroup;
// Widgets and layout.
QTabWidget* contentTab;
QSplitter* paintSplitter;
QListWidget* paintList;
QStackedWidget* paintPropertyPanel;
QSplitter* mappingSplitter;
QTableView* mappingList;
QStackedWidget* mappingPropertyPanel;
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;
MappingListModel *mappingListModel;
MappingItemDelegate *mappingItemDelegate;
// OSC.
#ifdef HAVE_OSC
OscInterface::ptr osc_interface;
#endif
int oscListeningPort;
QTimer *osc_timer;
// View.
// The view counterpart of Mappings.
QMap<uid, MappingGui::ptr> mappers;
QMap<uid, PaintGui::ptr> paintGuis;
// Current selected paint/mapping.
uid currentPaintId;
uid currentMappingId;
bool _hasCurrentMapping;
bool _hasCurrentPaint;
// 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 paint.
bool _displayPaintControls;
// 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 paint or mapping.
QListWidgetItem* currentSelectedItem;
QModelIndex currentSelectedIndex;
QTimer *videoTimer;
QElapsedTimer *systemTimer;
// Preference dialog
PreferenceDialog* _preferenceDialog;
// About dialog
AboutDialog *_aboutDialog;
// UndoStack
QUndoStack *undoStack;
// Labels for status bar
QLabel *destinationZoomLabel;
QLabel *sourceZoomLabel;
QLabel *lastActionLabel;
QLabel *currentMessageLabel;
QLabel *mousePosLabel;
QLabel *trueFramesPerSecondsLabel;
public:
// Accessor/mutators for the view. ///////////////////////////////////////////////////////////////////
MappingManager& getMappingManager() const { return *mappingManager; }
MappingGui::ptr getMappingGuiByMappingId(uint id) const { return mappers[id]; }
PaintGui::ptr getPaintGuiByPaintId(uint id) const { return paintGuis[id]; }
uid getCurrentPaintId() const { return currentPaintId; }
uid getCurrentMappingId() const { return currentMappingId; }
Mapping::ptr getCurrentMapping() const { return mappingManager->getMappingById(currentMappingId); }
Paint::ptr getCurrentPaint() const { return mappingManager->getPaintById(currentPaintId); }
bool hasCurrentPaint() const { return _hasCurrentPaint; }
bool hasCurrentMapping() const { return _hasCurrentMapping; }
void setCurrentPaint(int uid);
void setCurrentMapping(int uid);
void removeCurrentPaint();
void removeCurrentMapping();
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 paint.
bool displayPaintControls() const { return _displayPaintControls; }
/// 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 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_ */