Ejemplo n.º 1
0
void MainWindow::openRecentFile()
{
	QAction* action = qobject_cast<QAction*>(sender());
	if(action) {
		QString fileName = action->data().toString();
		if(QFile::exists(fileName)) {
			if(fileName.endsWith(".chmvp"))
			{
				openProject(fileName);
				currentSaveFile = fileName;
			}
			else
			{
				parser->setFileName(fileName);
				loadFile();
				currentSaveFile = "";
			}
			recentlyOpenedFiles.removeAll(fileName);
			recentlyOpenedFiles.prepend(fileName);
			updateRecentFiles();
		} else {
			error("Unable to open " + fileName + ". The file has been moved.");
			updateRecentFiles();
		}
	}
}
Ejemplo n.º 2
0
bool
Gui::saveProject()
{
    ProjectPtr project = getApp()->getProject();

    if ( project->hasProjectBeenSavedByUser() ) {
        QString projectFilename = project->getProjectFilename();
        QString projectPath = project->getProjectPath();

        if ( !_imp->checkProjectLockAndWarn(projectPath, projectFilename) ) {
            return false;
        }

        bool ret = project->saveProject(projectPath, projectFilename, 0);

        ///update the open recents
        if ( !projectPath.endsWith( QLatin1Char('/') ) ) {
            projectPath.append( QLatin1Char('/') );
        }
        if (ret) {
            QString file = projectPath + projectFilename;
            updateRecentFiles(file);
        }

        return ret;
    } else {
        return saveProjectAs();
    }
}
Ejemplo n.º 3
0
void GPXLab::saveFile(QString fileName)
{
    if (fileName.isEmpty())
        fileName = QFileDialog::getSaveFileName(this, tr("Save File"), gpxmw->getFileName(), "GPX (*.gpx)");
    if (!fileName.isEmpty())
    {
        // save file
        lblStatus->setText(tr("Saving file: ") + fileName);
        if (gpxmw->save(fileName) == GPX_model::GPXM_OK)
        {
            // clear undo stack
            undoStack->clear();

            // set window title
            setMainWindowTitle();

            // add file to recent file list
            settings->addToRecentFile(fileName);
            updateRecentFiles();
        }
        else
        {
            QMessageBox::critical(this, appName, tr("Failed to save \"") + fileName + "\".");
        }
        lblStatus->setText("");
    }
}
Ejemplo n.º 4
0
RecentFiles::RecentFiles(QMainWindow *parent)
    : QObject(parent)
    , m_recentMenu(new QMenu(parent))
    , m_recentMenuTriggeredAction(NULL)

{
    // create the sub-menu
    m_recentMenu->setTitle("Open Recent...");
    m_recentMenu->setObjectName("RecentMenu");

    // create an action for all possible entries in the sub-menu
    for (int i=0 ; i < MaxRecentFiles; i++) {
        m_recentFileActions[i] = new QAction(m_recentMenu);
        m_recentFileActions[i]->setText("---");
        m_recentFileActions[i]->setVisible(false);
        connect(m_recentFileActions[i], SIGNAL(triggered()),
                this, SLOT(openRecentFile()));
        m_recentMenu->addAction(m_recentFileActions[i]);
    }

    // Set some defaults
    QSettings settings;

    if (! settings.value(recentFileCount).isValid() )
        settings.setValue(recentFileCount, QVariant(4));

    // If there are no recent files, initialize an empty list
    if (! settings.allKeys().contains(recentFileListId)) {
        settings.setValue(recentFileListId, QVariant(QStringList()));
    }

    updateRecentFiles(settings);
}
Ejemplo n.º 5
0
void MainWindow::saveProject(QString filename)
{
	if(filename.isEmpty())
		return;
	if(!filename.endsWith(".chmvp"))
		filename += ".chmvp";

	QFile file(filename);
	if(!file.open(QIODevice::WriteOnly))
	{
		// error
		return;
	}

	QXmlStreamWriter writer(&file);
	writer.setAutoFormatting(true);
	writer.writeStartDocument();
	writer.writeStartElement("cheMVP");
	writer.writeAttribute("version", CHEMVP_VERSION);
	parser->serialize(&writer);
	drawingInfo->serialize(&writer);
	canvas->serialize(&writer);
	writer.writeEndDocument();
	file.close();

	if(file.exists())
	{
		recentlyOpenedFiles.removeAll(filename);
		recentlyOpenedFiles.prepend(filename);
		updateRecentFiles();
	}
}
Ejemplo n.º 6
0
void GLShaderDev::clearFileRecent()
{
    QSettings settings;

    settings.setValue("recentFiles", QStringList());
    updateRecentFiles();
}
Ejemplo n.º 7
0
    void MainWindow::setCurrentFile(const QString& filename)
    {
        setWindowModified(false);
        if(filename.isEmpty())
        {
            setWindowFilePath("untitled.chr");
        }
        else
        {
            setWindowFilePath(filename);

            QSettings settings;
            QStringList recentFiles(settings.value("recentFiles").toStringList());
            recentFiles.removeAll(filename);
            recentFiles.prepend(filename);
            while(recentFiles.size() > MaxRecentCount)
            {
                recentFiles.removeLast();
            }

            settings.setValue("recentFiles", recentFiles);
            updateRecentFiles();
        }
        currentFile = filename;
    }
Ejemplo n.º 8
0
    MainWindow::MainWindow()
    {
        resize(640, 640);

        scroll = new QScrollArea();
        scroll->setWidgetResizable(true);
        setCentralWidget(scroll);

        editor = new EditorWidget();
        scroll->setWidget(editor);

        statusBar()->showMessage(tr("%1 - by Overkill.").arg(AppName), 2000);
        statusBar()->setStyleSheet(
            "QStatusBar {"
            "   border-top: 1px solid #CCCCCC;"
            "   background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #DADBDE, stop: 1 #F6F7FA);"
            "   padding: 4px;"
            "   color: #777777;"
            "}"
        );

#ifdef Q_WS_WIN
        QKeySequence quitSequence(Qt::ALT + Qt::Key_F4);
#else
        QKeySequence quitSequence(QKeySequence::Quit);
#endif

        fileMenu = menuBar()->addMenu(tr("&File"));
        newAction = createAction(fileMenu, tr("&New"), tr("Create a new CHR."), QKeySequence::New);
        openAction = createAction(fileMenu, tr("&Open..."), tr("Open an existing CHR."), QKeySequence::Open);
        createSeparator(fileMenu);
        saveAction = createAction(fileMenu, tr("&Save..."), tr("Save the current CHR."), QKeySequence::Save);
        saveAsAction = createAction(fileMenu, tr("Save &As..."), tr("Save a copy of the current CHR."), QKeySequence::SaveAs);
        createSeparator(fileMenu);
        for(int i = 0; i < MaxRecentCount; ++i)
        {
            auto action = createAction(fileMenu, QKeySequence(Qt::ALT + Qt::Key_1 + i));
            action->setDisabled(true);
            recentFileActions[i] = action;
            connect(action, SIGNAL(triggered()), this, SLOT(openRecentFile()));
        }
        clearRecentAction = createAction(fileMenu, tr("Clear &Recent Files"), tr("Clear all recently opened files."), QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Delete));
        updateRecentFiles();
        createSeparator(fileMenu);
        exitAction = createAction(fileMenu, tr("E&xit"), tr("Exit the program."), quitSequence);

        helpMenu = menuBar()->addMenu(tr("&Help"));
        aboutAction = createAction(helpMenu, tr("&About..."), tr("About %1.").arg(AppName), QKeySequence::HelpContents);

        connect(newAction, SIGNAL(triggered()), this, SLOT(newFile()));
        connect(openAction, SIGNAL(triggered()), this, SLOT(openFile()));
        connect(saveAction, SIGNAL(triggered()), this, SLOT(saveFile()));
        connect(saveAsAction, SIGNAL(triggered()), this, SLOT(saveFileAs()));
        connect(clearRecentAction, SIGNAL(triggered()), this, SLOT(clearRecentFiles()));
        connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
        connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));

        QTimer::singleShot(0, this, SLOT(newFile()));
    }
Ejemplo n.º 9
0
 void MainWindow::clearRecentFiles()
 {
     QSettings settings;
     auto recentFiles = settings.value("recentFiles").toStringList();
     recentFiles.clear();
     settings.setValue("recentFiles", recentFiles);
     updateRecentFiles();
 }
void StoredSettings::updateGlobalPreferences()
{
    // update global settings editable from the global preferences window
    updateAppearanceSettings();

    // update 'invisible' global settings
    updateRecentFiles();
    updateKeyMappings();
}
Ejemplo n.º 11
0
void GLShaderDev::initializeActions()
{
    QSettings settings;

    QMenu* recent;
    QMenu* fileMenu = menuBar()->addMenu(tr("&File"));
    fileMenu->addAction(QIcon(":/document-new.png"), tr("&New..."), _newFileDialog, SLOT(exec()), QKeySequence::New);
    connect(_newFileDialog, SIGNAL(accepted()), this, SLOT(newFile()));
    fileMenu->addAction(QIcon(":/document-open.png"), tr("&Open..."), this, SLOT(openFileDialog()), QKeySequence::Open);
    recent = fileMenu->addMenu(QIcon(":/document-open-recent.png"), tr("Open &Recent"));

    for (int i = 0; i < MaxRecentFiles; ++i)
        (_recentFileActions[i] = recent->addAction(tr("<Empty>"), this, SLOT(openRecentFile())))->setVisible(true);
    (_recentFileActions[MaxRecentFiles] = recent->addSeparator())->setVisible(true);
    (_recentFileActions[MaxRecentFiles + 1] = recent->addAction(tr("&Clear List"), this, SLOT(clearFileRecent())))->setEnabled(false);
    updateRecentFiles();

    fileMenu->addSeparator();
    fileMenu->addAction(QIcon(":/document-save-all.png"), tr("Save Al&l"), _editor, SLOT(saveAll()));
    fileMenu->addAction(QIcon(":/document-save.png"), tr("&Save"), _editor, SLOT(save()), QKeySequence::Save);
    fileMenu->addAction(QIcon(":/document-save-as.png"), tr("Save &As..."), this, SLOT(saveFileAs()), QKeySequence::SaveAs);
    fileMenu->addSeparator();
    fileMenu->addAction(QIcon(":/dialog-close.png"), tr("&Close"), _editor, SLOT(closeCurrentTab()), tr("Ctrl+W"));
    fileMenu->addAction(QIcon(":/dialog-close.png"), tr("Cl&ose All"), _editor, SLOT(closeAllTabs()), tr("Ctrl+Shift+W"));
    fileMenu->addSeparator();
    fileMenu->addAction(QIcon(":/application-exit.png"), tr("&Quit"), this, SLOT(close()), QKeySequence::Quit);

    QMenu* projectMenu = menuBar()->addMenu(tr("&Project"));
    projectMenu->addAction(QIcon(":/project-development-new-template.png"), tr("&New Project"), this, SLOT(newProject()));
    projectMenu->addAction(QIcon(":/project-open.png"), tr("&Open Project..."), this, SLOT(openProjectDialog()));
    recent = projectMenu->addMenu(QIcon(":/document-open-recent.png"), tr("Open &Recent"));

    for (int i = 0; i < MaxRecentProjects; ++i)
        (_recentProjectActions[i] = recent->addAction(tr("<Empty>"), this, SLOT(openRecentProject())))->setVisible(true);
    (_recentProjectActions[MaxRecentProjects] = recent->addSeparator())->setVisible(true);
    (_recentProjectActions[MaxRecentProjects + 1] = recent->addAction(tr("&Clear List"), this, SLOT(clearProjectRecent())))->setEnabled(false);
    updateRecentProjects();

    projectMenu->addSeparator();
    projectMenu->addAction(QIcon(":/configure.png"), tr("Open &Configuration..."), this, SLOT(openProjectConfiguration()));
    projectMenu->addAction(QIcon(":/run-build.png"), tr("&Build Current"), this, SLOT(buildCurrentProject()), tr("F8"));
    projectMenu->addSeparator();
    projectMenu->addAction(QIcon(":/project-development-close.png"), tr("&Close Project"), this, SLOT(closeProject()));

    menuBar()->addMenu("|")->setEnabled(false);

    QMenu* toolsMenu = menuBar()->addMenu(tr("&Tools"));
    toolsMenu->addAction(QIcon(":/preferences-other.png"), tr("&OpenGL Info..."), this, SLOT(showGLInfo()));

    QMenu* settingsMenu = menuBar()->addMenu(tr("&Settings"));
    settingsMenu->addAction(QIcon(":/preferences-other.png"), tr("&Preferences..."), this, SLOT(showPreferences()));

    QMenu* helpMenu = menuBar()->addMenu(tr("&Help"));
    helpMenu->addAction(QIcon(":/glsd-icon.png"), tr("&About GLShaderDev"), this, SLOT(about()));
    helpMenu->addAction(QIcon(":/qt-icon.png"), tr("About &Qt"), qApp, SLOT(aboutQt()));
}
Ejemplo n.º 12
0
void RecentFiles::setNumOfRecentFiles(int n)
{
    QSettings settings;

    settings.setValue(recentFileCount, QVariant(n));

    updateRecentFiles(settings);

    // So a preference panel can be updated to show new value...
    emit newMaxFilesShown(n);
}
Ejemplo n.º 13
0
bool GPXLab::openFile(QString fileName)
{
    bool retValue = false;
    GPX_model::fileType_e fileType = GPX_model::GPXM_FILE_AUTOMATIC;

    if (fileName.isEmpty())
    {
        QString selectedFilter;
        fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "", "GPX (*.gpx);;NMEA (*.txt *.nmea);; SpoQ (*.act *.xml)", &selectedFilter);
        if (selectedFilter == "GPX (*.gpx)")
            fileType = GPX_model::GPXM_FILE_GPX;
        else if (selectedFilter == "NMEA (*.txt *.nmea)")
            fileType = GPX_model::GPXM_FILE_NMEA;
        else if (selectedFilter == "SpoQ (*.act *.xml)")
            fileType = GPX_model::GPXM_FILE_ACT;
    }

    if (!fileName.isEmpty())
    {
        // clear undo stack
        undoStack->clear();

        // initialize GPX_model wrapper
        gpxmw->init(appName);

        // load file
        lblStatus->setText(tr("Loading file: ") + fileName);
        if (gpxmw->load(fileName, fileType, true) == GPX_model::GPXM_OK)
        {
            // set window title
            setMainWindowTitle();

            // add file to recent file list
            settings->addToRecentFile(fileName);
            updateRecentFiles();

            // select first track
            gpxmw->select(0);

            // enable actions
            updateActions(true);   

            retValue = true;
        }
        else
        {
            QMessageBox::critical(this, appName, tr("Failed to open \"") + fileName + "\".");
            closeFile();
        }
        lblStatus->setText("");
    }
    return retValue;
}
Ejemplo n.º 14
0
void GLShaderDev::addRecentFile(const QString& filename)
{
    QSettings settings;
    QStringList   recentFiles = settings.value("recentFiles").toStringList();

    recentFiles.removeAll(filename);
    recentFiles.prepend(filename);
    while (recentFiles.size() > MaxRecentFiles)
        recentFiles.removeLast();
    settings.setValue("recentFiles", recentFiles);
    updateRecentFiles();
}
Ejemplo n.º 15
0
CMainWindow::CMainWindow(QWidget* parent)
 :	QMainWindow(parent)
{
	setupUi(this);
	
	iniDockWidget();
	iniStatusBar();
	iniConnect();
	updateRecentFiles();
	showMaximized();
	
	isUntitled = true;
	curFile = tr("untitled");
	setWindowTitle(curFile + "[*]");	
}
Ejemplo n.º 16
0
void MainWindow::readSettings()
{
    QSettings settings("Software Inc.", "Spreadsheet");

    restoreGeometry(settings.value("geometry").toByteArray());

    bool showGrid = settings.value("showGrid", true).toBool();
    ui->actionShowGrid->setChecked(showGrid);

    bool autoRecalc = settings.value("autoRecalc", true).toBool();
    ui->actionAutoRecalculate->setChecked(autoRecalc);

    recentFiles = settings.value("recentFiles").toStringList();
    updateRecentFiles();
}
Ejemplo n.º 17
0
//////////////////////////////////////////////////////////////////
//单文档实现。
void CMainWindow::setCurrentFile(const QString& fileName)
{
	curFile = QFileInfo(fileName).canonicalFilePath();
	isUntitled = false;
	setWindowTitle(curFile + "[*]");	
	textEdit->document()->setModified(false);
	setWindowModified(false);
	
	QSettings settings("709", "SDI example");
	QStringList files = settings.value("recentFiles").toStringList();
	files.removeAll(fileName);
	files.prepend(fileName);
	while (files.size() > MaxRecentFiles)
		files.removeLast();
	settings.setValue("recentFiles", files);

	updateRecentFiles();
}
Ejemplo n.º 18
0
void MainWindow::openFile()
{
	QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), QDir::homePath());
	if(fileName != 0) {
		if(fileName.endsWith(".chmvp"))
		{
			openProject(fileName);
			currentSaveFile = fileName;
		}
		else
		{
		   parser->setFileName(fileName);
		   loadFile();
		   currentSaveFile = "";
		}
		recentlyOpenedFiles.removeAll(fileName);
		recentlyOpenedFiles.prepend(fileName);
		updateRecentFiles();
	}
}
Ejemplo n.º 19
0
void RecentFiles::setMostRecentFile(const QString fileName)
{
    if (fileName.isEmpty())
        return;

    QSettings settings;
    QStringList recentFileList = settings.value(recentFileListId).toStringList();

    recentFileList.removeAll(fileName);
    recentFileList.prepend(fileName);
    settings.setValue(recentFileListId, QVariant(recentFileList));

    updateRecentFiles(settings);

    qApp->setProperty("currentDirectory",
                      QVariant(
                          QFileInfo(fileName)
                          .absoluteDir()
                          .absolutePath()
                          ));
}
Ejemplo n.º 20
0
bool
Gui::saveProjectAs(const std::string& filename)
{
    std::string fileCopy = filename;

    if (fileCopy.find("." NATRON_PROJECT_FILE_EXT) == std::string::npos) {
        fileCopy.append("." NATRON_PROJECT_FILE_EXT);
    }
    std::string path = SequenceParsing::removePath(fileCopy);

    if ( !_imp->checkProjectLockAndWarn( QString::fromUtf8( path.c_str() ), QString::fromUtf8( fileCopy.c_str() ) ) ) {
        return false;
    }
    _imp->_lastSaveProjectOpenedDir = QString::fromUtf8( path.c_str() );

    bool ret = getApp()->getProject()->saveProject(QString::fromUtf8( path.c_str() ), QString::fromUtf8( fileCopy.c_str() ), 0);

    if (ret) {
        QString filePath = QString::fromUtf8( path.c_str() ) + QString::fromUtf8( fileCopy.c_str() );
        updateRecentFiles(filePath);
    }

    return ret;
}
Ejemplo n.º 21
0
void BrowerWebkitHandler::domReady()
{
    updateRecentFiles();
}
Ejemplo n.º 22
0
PowerGui::PowerGui(): PowerGui_class()
{
	setupUi(this);
	
	windowMapper = new QSignalMapper(this);
  splash->showMessage("Loading user menu...",Qt::AlignLeft | Qt::AlignBottom);
	loadUserMenus();

  splash->showMessage("Loading libraries...",Qt::AlignLeft | Qt::AlignBottom);
  loadLibrary();
	addDockWidget(Qt::LeftDockWidgetArea, &dockLib);
  
  createRecentFiles();
  updateRecentFiles();
  #ifdef UNDO
  	createUndoActions();
  #endif
  updateMenus();

  connect(mdiArea, SIGNAL(subWindowActivated(QMdiSubWindow*)), this, SLOT(updateMenus()));
  #ifdef UNDO
  connect(mdiArea, SIGNAL(subWindowActivated(QMdiSubWindow*)), this, SLOT(setActiveUndoStack()));
  #endif
  connect(windowMapper, SIGNAL(mapped(QWidget*)), this, SLOT(setActiveSubWindow(QWidget*)));
  QString scilabPath = getSetting("scilabPath").toString(); 
  bool startScilab = getSetting("startScilab").toBool(); 
  if (startScilab) { 
    splash->showMessage("Starting Scilab...",Qt::AlignLeft | Qt::AlignBottom);
    QString outputPath = getSetting("Path/outputPath").toString(); 
    qDebug() << "Starting Scilab from " << scilabPath << " in directory " << outputPath << " with arg " << getSetting("scilabArg").toString();
#ifndef Q_OS_WIN32

    bool scilabRunning = system("ps -e | grep scilab") == 0;
    if (scilabRunning) {
      struct sockaddr_in service;
      int sock=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
      service.sin_family = AF_INET;
      service.sin_addr.s_addr = inet_addr("127.0.0.1");
      int actual_port = 27020+(getuid() % 10000);
      service.sin_port = htons(actual_port);
      if (::connect(sock,(struct sockaddr*)&service,sizeof(service)) == -1) {
	      scilabRunning=false;
      }
      ::close(sock);
    }
 

    
#else
    bool scilabRunning = false;
#endif
    if (!scilabRunning) {
      if (getSetting("scilabArg").toString().trimmed().size())
        QProcess::startDetached(scilabPath, QStringList() << "-f" << getSetting("scilabArg").toString().replace("$HOMEAPP",QCoreApplication::applicationDirPath()), outputPath); 
      else
        QProcess::startDetached(scilabPath, QStringList(), outputPath); 
    } else {
      qDebug() << "Scilab is already running";
    }
  }
}
Ejemplo n.º 23
0
void
Gui::saveAndIncrVersion()
{
    ProjectPtr project = getApp()->getProject();
    QString path = project->getProjectPath();
    QString name = project->getProjectFilename();
    int currentVersion = 0;
    int positionToInsertVersion;
    bool mustAppendFileExtension = false;

    // extension is everything after the last '.'
    int lastDotPos = name.lastIndexOf( QLatin1Char('.') );

    if (lastDotPos == -1) {
        positionToInsertVersion = name.size();
        mustAppendFileExtension = true;
    } else {
        //Extract the current version number if any
        QString versionStr;
        int i = lastDotPos - 1;
        while ( i >= 0 && name.at(i).isDigit() ) {
            versionStr.prepend( name.at(i) );
            --i;
        }

        ++i; //move back the head to the first digit

        if ( !versionStr.isEmpty() ) {
            name.remove( i, versionStr.size() );
            --i; //move 1 char backward, if the char is a '_' remove it
            if ( (i >= 0) && ( name.at(i) == QLatin1Char('_') ) ) {
                name.remove(i, 1);
            }
            currentVersion = versionStr.toInt();
        }

        positionToInsertVersion = i;
    }

    //Incr version
    ++currentVersion;

    QString newVersionStr = QString::number(currentVersion);

    //Add enough 0s in the beginning of the version number to have at least 3 digits
    int nb0s = 3 - newVersionStr.size();
    nb0s = std::max(0, nb0s);

    QString toInsert( QLatin1Char('_') );
    for (int c = 0; c < nb0s; ++c) {
        toInsert.append( QLatin1Char('0') );
    }
    toInsert.append(newVersionStr);
    if (mustAppendFileExtension) {
        toInsert.append( QString::fromUtf8("." NATRON_PROJECT_FILE_EXT) );
    }

    if ( positionToInsertVersion >= name.size() ) {
        name.append(toInsert);
    } else {
        name.insert(positionToInsertVersion, toInsert);
    }

    project->saveProject(path, name, 0);

    QString filename = path + QLatin1Char('/') + name;
    updateRecentFiles(filename);
} // Gui::saveAndIncrVersion
Ejemplo n.º 24
0
GPXLab::GPXLab(const QString &fileName, QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::GPXLab),
    closing(false)
{
    // setup UI
    ui->setupUi(this);

    // create GPX_model wrapper
    gpxmw = new GPX_wrapper(appName);
    connect(gpxmw, SIGNAL(fileLoaded()), this, SLOT(fileLoaded()));
    connect(gpxmw, SIGNAL(fileSaved()), this, SLOT(fileSaved()));
    connect(gpxmw, SIGNAL(modelCleared()), this, SLOT(modelCleared()));
    connect(gpxmw, SIGNAL(modelPropertiesChanged()), this, SLOT(modelPropertiesChanged()));
    connect(gpxmw, SIGNAL(modelMetadataChanged()), this, SLOT(modelMetadataChanged()));
    connect(gpxmw, SIGNAL(trackMetadataChanged(int)), this, SLOT(trackMetadataChanged(int)));
    connect(gpxmw, SIGNAL(trackInserted(int, const GPX_trkType&)), this, SLOT(trackInserted(int, const GPX_trkType&)));
    connect(gpxmw, SIGNAL(trackDeleted(int)), this, SLOT(trackDeleted(int)));
    connect(gpxmw, SIGNAL(trackMovedUp(int)), this, SLOT(trackMovedUp(int)));
    connect(gpxmw, SIGNAL(trackMovedDown(int)), this, SLOT(trackMovedDown(int)));
    connect(gpxmw, SIGNAL(trackSplited(int)), this, SLOT(trackSplited(int)));
    connect(gpxmw, SIGNAL(trackCombined(int)), this, SLOT(trackCombined(int)));
    connect(gpxmw, SIGNAL(trackTimeShifted(int, long)), this, SLOT(trackTimeShifted(int, long)));
    connect(gpxmw, SIGNAL(trackSelectionChanged(int, int, int, const GPX_wptType*)), this, SLOT(trackSelectionChanged(int, int, int, const GPX_wptType*)));
    connect(gpxmw, SIGNAL(pointEdited(int, int, int, GPX_wrapper::TrackPointProperty)), this, SLOT(pointEdited(int, int, int, GPX_wrapper::TrackPointProperty)));
    connect(gpxmw, SIGNAL(pointInserted(int, int, int, const GPX_wptType&)), this, SLOT(pointInserted(int, int, int, const GPX_wptType&)));
    connect(gpxmw, SIGNAL(pointDeleted(int, int, int)), this, SLOT(pointDeleted(int, int, int)));
    connect(gpxmw, SIGNAL(pointSelectionChanged(int, const GPX_wptType*)), this, SLOT(pointSelectionChanged(int, const GPX_wptType*)));

    // set window title
    setMainWindowTitle();

    // load settings
    settings = new Settings(this);
    settings->load();
    ui->actionFollow_Item->setChecked(settings->getValue("FollowItem").toBool());
    ui->actionShow_Only_Selected_Track->setChecked(settings->getValue("ShowOnlySelectedItem").toBool());

    // undo stack
    undoStack = new QUndoStack(this);
    undoStack->setUndoLimit(settings->undoLimit);
    QAction *undoAction = undoStack->createUndoAction(this, tr("&Undo"));
    undoAction->setShortcuts(QKeySequence::Undo);
    undoAction->setIcon(QIcon(":/images/undo.png"));
    QAction *redoAction = undoStack->createRedoAction(this, tr("&Redo"));
    redoAction->setShortcuts(QKeySequence::Redo);
    redoAction->setIcon(QIcon(":/images/redo.png"));
    connect(undoStack, SIGNAL(indexChanged(int)), this, SLOT(setMainWindowTitle()));

    // tree widget
    connect(ui->treeTracks, SIGNAL(itemDoubleClicked(QTreeWidgetItem* , int)), this, SLOT(tree_doubleClicked(QTreeWidgetItem*, int)));

    // map widget
    ui->mapWidget->init(gpxmw, undoStack, settings->doPersistentCaching, settings->cachePath);
    ui->mapWidget->setContextMenuPolicy(Qt::CustomContextMenu);
    connect(ui->mapWidget, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(map_showContextMenu(const QPoint&)));
    connect(ui->mapWidget, SIGNAL(viewChanged(const QPointF&, int)), this, SLOT(map_viewChanged(const QPointF&, int)));

    // calendar widget
    ui->calendarWidget->init(gpxmw);

    // table widget
    ui->tableWidgetPoints->init(gpxmw, undoStack);
    connect(settings, SIGNAL(settingsChanged(bool)), ui->tableWidgetPoints, SLOT(settingsChanged(bool)));

    // diagram widget
    ui->diagramWidget->addAction(ui->dockWidgetDiagrams->toggleViewAction());
    ui->diagramWidget->init(gpxmw);

    // status bar widgets
    lblCoordinates = new QLabel();
    statusBar()->addWidget(lblCoordinates);
    lblStatus = new QLabel();
    statusBar()->addWidget(lblStatus);

    // zoom slider widget
    zoomSlider = new QSlider(Qt::Horizontal, this);
    zoomSlider->setMinimumWidth(10);
    zoomSlider->setMaximumWidth(100);
    zoomSlider->setMinimum(0);
    zoomSlider->setMaximum(0);
    ui->mainToolBar->insertWidget(ui->actionMapZoom, zoomSlider);
    connect(zoomSlider, SIGNAL(valueChanged(int)), this, SLOT(zoom_valueChanged(int)));

    // build recent files action
    actionOpenRecentFile = new QAction*[settings->maxRecentFiles];
    for (int i = 0; i < settings->maxRecentFiles; ++i)
    {
        actionOpenRecentFile[i] = new QAction(this);
        actionOpenRecentFile[i]->setVisible(false);
        connect(actionOpenRecentFile[i], SIGNAL(triggered()), this, SLOT(openRecentFile()));
        ui->menuFile->insertAction(ui->actionExit, actionOpenRecentFile[i]);
    }
    ui->menuFile->insertSeparator(ui->actionExit);
    updateRecentFiles();

    // menu edit
    ui->menuEdit->addAction(undoAction);
    ui->menuEdit->addAction(redoAction);

    // menu view
    ui->menuView->addAction(ui->dockWidgetFile->toggleViewAction());
    ui->menuView->addAction(ui->dockWidgetTracks->toggleViewAction());
    ui->menuView->addAction(ui->dockWidgetDiagrams->toggleViewAction());
    ui->menuView->addAction(ui->dockWidgetPoints->toggleViewAction());
    ui->menuView->addAction(ui->mainToolBar->toggleViewAction());
    ui->menuView->addSeparator();
    ui->menuView->addAction(ui->actionRestore_Default_View);

    // install event filters for dock widgets to catch resize events
    ui->dockWidgetFile->installEventFilter(this);
    ui->dockWidgetTracks->installEventFilter(this);
    ui->dockWidgetDiagrams->installEventFilter(this);
    ui->dockWidgetPoints->installEventFilter(this);

    // dock file
    ui->dockWidgetFile->addAction(ui->dockWidgetFile->toggleViewAction());
    ui->dockWidgetFile->addAction(ui->actionEdit_File_Properties);

    // dock tracks
    ui->dockWidgetTracks->addAction(ui->dockWidgetTracks->toggleViewAction());
    ui->dockWidgetTracks->addAction(ui->actionEdit_Track_Properties);
    ui->dockWidgetTracks->addAction(ui->actionGetAltitudeFromSRTM);
    ui->dockWidgetTracks->addAction(ui->actionSetStartTime);

    // dock diagram
    ui->dockWidgetDiagrams->addActions(ui->diagramWidget->actions());

    // dock points
    ui->dockWidgetPoints->addAction(ui->dockWidgetPoints->toggleViewAction());
    ui->dockWidgetPoints->addAction(ui->actionInsert_Point);
    ui->dockWidgetPoints->addAction(ui->actionDelete_Point);

    // default context menu
    addActions(ui->menuView->actions());

    // connect signals for track and point selection
    connect(ui->diagramWidget, SIGNAL(selectionChanged(time_t)), this, SLOT(diagram_selectionChanged(time_t)));
    connect(ui->mapWidget, SIGNAL(selectionChanged(int, int, double, double)), this, SLOT(map_selectionChanged(int, int, double, double)));
    connect(ui->mapWidget, SIGNAL(selectionChanged(int)), this, SLOT(map_selectionChanged(int)));
    connect(ui->tableWidgetPoints, SIGNAL(selectionChanged(int)), this, SLOT(table_selectionChanged(int)));
    connect(ui->treeTracks, SIGNAL(itemSelectionChanged()), this, SLOT(tree_selectionChanged()));
    connect(ui->calendarWidget, SIGNAL(selectionChanged(int)), this, SLOT(cal_selectionChanged(int)));

    // disable actions
    updateActions(false);

    // open file if any passed as argument
    if (!fileName.isEmpty())
    {
        openFile(fileName);
    }
}
Ejemplo n.º 25
0
MainWindow::MainWindow(QWidget *parent)
	: QMainWindow(parent)
	, ui(new Ui::MainWindow)
	, userSettings(QSettings::UserScope, "Jason Gedge", "StereoReconstruction")
	, trayIcon(nullptr)
    , recentFiles(userSettings.value("recentFileList").toStringList())
{
    ui->setupUi(this);

	//
	// Recent Files
	//
	QSignalMapper *recentFilesMapper = new QSignalMapper(this);
	connect(recentFilesMapper, SIGNAL(mapped(int)), SLOT(openRecentFile(int)));

	for(int index = 0; index < NUM_RECENT_FILES; ++index) {
		recentFileActions[index] = ui->menuOpen_Recent->addAction(
				QString("%1: <No File>").arg(index + 1),
				recentFilesMapper,
				SLOT(map()) );

		recentFileActions[index]->setVisible(false);
		recentFilesMapper->setMapping(recentFileActions[index], index);
	}
	{
		// Move separator + "clear recent files" to end
		QAction *act = ui->menuOpen_Recent->actions().first();
		ui->menuOpen_Recent->removeAction(act);
		ui->menuOpen_Recent->addAction(act);

		act = ui->menuOpen_Recent->actions().first();
		ui->menuOpen_Recent->removeAction(act);
		ui->menuOpen_Recent->addAction(act);
	}

	//
	//
	//
	trayIcon = new QSystemTrayIcon(this);

#ifndef HAS_IMAGE_CAPTURE
	ui->menuBar->removeAction(ui->menuCapture->menuAction());
#endif
#ifndef HAS_HDR
	ui->menuBar->removeAction(ui->menuHDR->menuAction());
#endif

	//
	//
	//
	projectExplorerDock = new QDockWidget(tr("Project Explorer"), this);
	projectExplorerDock->setObjectName(QString::fromUtf8("projectExplorerDock"));
	projectExplorerDock->setMinimumWidth(200);
	projectExplorerDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
	addDockWidget(Qt::LeftDockWidgetArea, projectExplorerDock);
	projectExplorerDock->hide();

	projectExplorer = new ProjectExplorer(this);
	projectExplorerDock->setWidget(projectExplorer);
	connect(projectExplorer, SIGNAL(customContextMenuRequested(QPoint)), SLOT(showProjectMenu(QPoint)));

	//
	//
	//
	imageSetTable = new ImageSetTable(this);
	imageSetTable->setEnabled(false);

	cameraInfoWidget = new CameraInfoWidget(this);
	cameraInfoWidget->setEnabled(false);

	inspectorDock = new QDockWidget(tr("Inspector"), this);
	inspectorDock->setObjectName(QString::fromUtf8("inspectorDock"));
	inspectorDock->setMinimumWidth(350);
	inspectorDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
	addDockWidget(Qt::RightDockWidgetArea, inspectorDock);
	inspectorDock->hide();

	inspector = new QStackedWidget(inspectorDock);
	inspector->addWidget(new QWidget(this));
	inspector->addWidget(cameraInfoWidget);
	inspector->addWidget(imageSetTable);
	inspectorDock->setWidget(inspector);

	//
	//
	//
	taskList = new QWidget(this);
	taskList->setAutoFillBackground(true);
	taskList->setBackgroundRole(QPalette::Light);
	taskList->setObjectName(QString::fromUtf8("taskList"));
	taskList->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
	taskList->setMinimumHeight(50); // XXX necessary?

	taskListLayout = new QVBoxLayout(taskList);
	taskListLayout->setMargin(0);
	taskListLayout->addStretch(1);

	taskListDock = new QDockWidget(tr("Task List"), this);
	taskListDock->setObjectName(QString::fromUtf8("taskListDock"));
	taskListDock->setWidget(taskList);
	taskListDock->setAllowedAreas(Qt::AllDockWidgetAreas);
	addDockWidget(Qt::BottomDockWidgetArea, taskListDock);
	taskListDock->hide();

	//
	// TODO move these to the ui files
	//
	connect(projectExplorer,
			SIGNAL(cameraSelected(CameraPtr)),
			SLOT(cameraSelected(CameraPtr)) );

	connect(projectExplorer,
			SIGNAL(imageSetSelected(ImageSetPtr)),
			SLOT(imageSetSelected(ImageSetPtr)) );

	connect(projectExplorerDock,
			SIGNAL(visibilityChanged(bool)),
			SLOT(on_actionShowHide_Project_Explorer_triggered(bool)) );

	connect(inspectorDock,
			SIGNAL(visibilityChanged(bool)),
			SLOT(on_actionShowHide_Inspector_triggered(bool)) );

	projectExplorer->connect(this,
			SIGNAL(projectLoaded(ProjectPtr)),
			SLOT(setProject(ProjectPtr)) );

	cameraInfoWidget->connect(this,
							  SIGNAL(projectLoaded(ProjectPtr)),
							  SLOT(setProject(ProjectPtr)) );

	cameraInfoWidget->connect(projectExplorer,
							  SIGNAL(cameraSelected(CameraPtr)),
							  SLOT(setCamera(CameraPtr)) );

	imageSetTable->connect(this,
						   SIGNAL(projectLoaded(ProjectPtr)),
						   SLOT(setProject(ProjectPtr)) );

	imageSetTable->connect(projectExplorer,
						   SIGNAL(imageSetSelected(ImageSetPtr)),
						   SLOT(setImageSet(ImageSetPtr)) );

	ui->stereoWidget->connect(this,
							  SIGNAL(projectLoaded(ProjectPtr)),
							  SLOT(setProject(ProjectPtr)) );

	//
	// Set up initial window state
	//
	restoreGeometry(userSettings.value("mainWindowGeometry").toByteArray());
	restoreState(userSettings.value("mainWindowState").toByteArray());
	updateRecentFiles();
	ui->actionView_Nothing->trigger();
	ui->actionNew->trigger();
}