/* * MainWindow.cpp * * (c) 2013 Sofian Audry -- info(@)sofianaudry(.)com * (c) 2013 Alexandre Quessy -- alexandre(@)quessy(.)net * * 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 . */ #include "MainWindow.h" #include "Commands.h" #include "ProjectWriter.h" #include "ProjectReader.h" #include #include MM_BEGIN_NAMESPACE MainWindow::MainWindow() { // Create model. #if QT_VERSION >= 0x050500 QMessageLogger(__FILE__, __LINE__, 0).info() << "Video support: " << (Video::hasVideoSupport() ? "yes" : "no"); #else QMessageLogger(__FILE__, __LINE__, 0).debug() << "Video support: " << (Video::hasVideoSupport() ? "yes" : "no"); #endif mappingManager = new MappingManager; // Initialize internal variables. currentPaintId = NULL_UID; currentMappingId = NULL_UID; // TODO: not sure we need this anymore since we have NULL_UID _hasCurrentPaint = false; _hasCurrentMapping = false; currentSelectedItem = NULL; // Play state. _isPlaying = false; // Editing toggles. _displayControls = true; _stickyVertices = true; _displayTestSignal = false; _displayUndoStack = false; _showMenuBar = true; // Show menubar by default // UndoStack undoStack = new QUndoStack(this); // Create everything. createLayout(); createActions(); createMenus(); createMappingContextMenu(); createPaintContextMenu(); createToolBars(); createStatusBar(); updateRecentFileActions(); updateRecentVideoActions(); // Load settings. readSettings(); // Start osc. startOscReceiver(); // Defaults. setWindowIcon(QIcon(":/mapmap-logo")); setCurrentFile(""); // Create and start timer. videoTimer = new QTimer(this); videoTimer->setInterval( int( 1000 / MM::FRAMES_PER_SECOND ) ); connect(videoTimer, SIGNAL(timeout()), this, SLOT(updateCanvases())); videoTimer->start(); // Start playing by default. play(); // after readSettings(): _preferences_dialog = new PreferencesDialog(this, this); } MainWindow::~MainWindow() { delete mappingManager; // delete _facade; #ifdef HAVE_OSC delete osc_timer; #endif // ifdef } void MainWindow::handlePaintItemSelectionChanged() { // Set current paint. QListWidgetItem* item = paintList->currentItem(); currentSelectedItem = item; // Is a paint item selected? bool paintItemSelected = (item ? true : false); if (paintItemSelected) { // Set current paint. uid paintId = getItemId(*item); // Unselect current mapping. if (currentPaintId != paintId) removeCurrentMapping(); // Set current paint. setCurrentPaint(paintId); } else removeCurrentPaint(); // Enable/disable creation of mappings depending on whether a paint is selected. addMeshAction->setEnabled(paintItemSelected); addTriangleAction->setEnabled(paintItemSelected); addEllipseAction->setEnabled(paintItemSelected); // Enable some menus and buttons sourceCanvasToolbar->enableZoomToolBar(paintItemSelected); sourceMenu->setEnabled(paintItemSelected); // Update canvases. updateCanvases(); } void MainWindow::handleMappingItemSelectionChanged(const QModelIndex &index) { // Set current paint and mappings. uid mappingId = mappingListModel->getItemId(index); Mapping::ptr mapping = mappingManager->getMappingById(mappingId); uid paintId = mapping->getPaint()->getId(); // Set current mapping and paint setCurrentMapping(mappingId); setCurrentPaint(paintId); // Update canvases. updateCanvases(); } void MainWindow::handleMappingItemChanged(const QModelIndex &index) { // Get item. uid mappingId = mappingListModel->getItemId(index); // Sync name. Mapping::ptr mapping = mappingManager->getMappingById(mappingId); Q_CHECK_PTR(mapping); // Change properties. mapping->setName(index.data(Qt::EditRole).toString()); mapping->setVisible(index.data(Qt::CheckStateRole).toBool()); mapping->setSolo(index.data(Qt::CheckStateRole+1).toBool()); mapping->setLocked(index.data(Qt::CheckStateRole+2).toBool()); } void MainWindow::handleMappingIndexesMoved() { // Reorder mappings. QVector newOrder; for (int row=mappingListModel->rowCount()-1; row>=0; row--) { uid layerId = mappingListModel->getIndexFromRow(row).data(Qt::UserRole).toInt(); newOrder.push_back(layerId); } mappingManager->reorderMappings(newOrder); // Update canvases according to new order. updateCanvases(); } void MainWindow::handlePaintItemSelected(QListWidgetItem* item) { Q_UNUSED(item); // Change currently selected item. currentSelectedItem = item; } void MainWindow::handleMappingItemSelected(const QModelIndex &index) { if (index.isValid()) { if (index.column() == MM::HideColumn) { mappingListModel->setVisibility(index); } } } void MainWindow::handlePaintChanged(Paint::ptr paint) { // Change currently selected item. uid curMappingId = getCurrentMappingId(); removeCurrentMapping(); removeCurrentPaint(); uid paintId = mappingManager->getPaintId(paint); if (paint->getType() == "media") { QSharedPointer