/* * 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 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(":/images/icon.png")); 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); // Update canvases. updateCanvases(); } void MainWindow::handleMappingItemSelectionChanged() { if (mappingList->selectedItems().empty()) { removeCurrentMapping(); /* Disable some menus and buttons when * no mapping was selected */ sourceCanvas->enableZoomToolBar(false); sourceMenu->setEnabled(false); destinationCanvas->enableZoomToolBar(false); destinationMenu->setEnabled(false); } else { QListWidgetItem* item = mappingList->currentItem(); currentSelectedItem = item; // Set current paint and mappings. uid mappingId = getItemId(*item); Mapping::ptr mapping = mappingManager->getMappingById(mappingId); uid paintId = mapping->getPaint()->getId(); setCurrentMapping(mappingId); setCurrentPaint(paintId); // Enable some menus and buttons sourceCanvas->enableZoomToolBar(true); sourceMenu->setEnabled(true); destinationCanvas->enableZoomToolBar(true); destinationMenu->setEnabled(true); } // Update canvases. updateCanvases(); } void MainWindow::handleMappingItemChanged(QListWidgetItem* item) { // Get item. uid mappingId = getItemId(*item); // Sync name. Mapping::ptr mapping = mappingManager->getMappingById(mappingId); Q_CHECK_PTR(mapping); mapping->setName(item->text()); } void MainWindow::handleMappingIndexesMoved() { // Reorder mappings. QVector newOrder; for (int row=mappingList->count()-1; row>=0; row--) { uid layerId = mappingList->item(row)->data(Qt::UserRole).toInt(); newOrder.push_back(layerId); } mappingManager->reorderMappings(newOrder); // Update canvases according to new order. updateCanvases(); } void MainWindow::handleItemSelected(QListWidgetItem* item) { Q_UNUSED(item); // Change currently selected item. currentSelectedItem = item; } //void MainWindow::handleItemDoubleClicked(QListWidgetItem* item) //{ // // Change currently selected item. // Paint::ptr paint = mappingManager->getPaintById(getItemId(*item)); // uid curMappingId = getCurrentMappingId(); // removeCurrentMapping(); // removeCurrentPaint(); // // //qDebug() << "DOUBLE CLICK! " << endl; // videoTimer->stop(); // if (paint->getType() == "media") { // QString fileName = QFileDialog::getOpenFileName(this, // tr("Import media source file"), "."); // // Restart video playback. XXX Hack // videoTimer->start(); // if (!fileName.isEmpty()) // importMediaFile(fileName, paint, false); // } // if (paint->getType() == "image") { // QString fileName = QFileDialog::getOpenFileName(this, // tr("Import media source file"), "."); // // Restart video playback. XXX Hack // videoTimer->start(); // if (!fileName.isEmpty()) // importMediaFile(fileName, paint, true); // } // else if (paint->getType() == "color") { // // Pop-up color-choosing dialog to choose color paint. // QColor initialColor; // QColor color = QColorDialog::getColor(initialColor, this); // videoTimer->start(); // if (color.isValid()) // addColorPaint(color, paint); // } // // if (curMappingId != NULL_UID) // setCurrentMapping(curMappingId); //} 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