Example #1
0
//**********************************************************************
void TulipApp::startTulip() {
  // adjust size if needed
  QRect sRect = QApplication::desktop()->availableGeometry();
  QRect wRect(this->geometry());
  QRect fRect(this->frameGeometry());
  int deltaWidth = fRect.width() - wRect.width();
  int deltaHeight = fRect.height() - wRect.height();

  // adjust width
  if (fRect.width() > sRect.width()) {
    wRect.setWidth(sRect.width() - deltaWidth);
  }

  // screen width centering
  wRect.moveLeft(sRect.left() +
                 (sRect.width() - wRect.width())/2);

  // adjust height
  if (fRect.height() > sRect.height()) {
    wRect.setHeight(sRect.height() - deltaHeight);
  }

  // screen height centering
  wRect.moveTop(sRect.top() + (deltaHeight - deltaWidth)/2 +
                (sRect.height() - wRect.height())/2);
  // adjust geometry
  this->setGeometry(wRect.x(), wRect.y(),
                    wRect.width(), wRect.height());

  UpdatePlugin::installWhenRestartTulip();

  AppStartUp *appStart=new AppStartUp(this);
  QDialog *errorDlg;
  std::string errors;
  appStart->show();
  appStart->initTulip(&pluginLoader,errors);

  //delete appStart;
  if (errors.size() > 0) {
    errorDlg = new QDialog(this);
    errorDlg->setWindowTitle("Errors when loading Tulip plugins !!!");
    QVBoxLayout* errorDlgLayout = new QVBoxLayout(errorDlg);
    errorDlgLayout->setMargin(11);
    errorDlgLayout->setSpacing(6);
    QFrame *frame = new QFrame(errorDlg);
    QHBoxLayout* frameLayout = new QHBoxLayout(frame);
    frameLayout->setMargin(0);
    frameLayout->setSpacing(0);
    QSpacerItem* spacer  = new QSpacerItem( 180, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
    frameLayout->addItem( spacer );
    QTextEdit* textWidget = new QTextEdit(QString(""),errorDlg);
    textWidget->setReadOnly(true);
    textWidget->setLineWrapMode(QTextEdit::NoWrap);
    errorDlgLayout->addWidget( textWidget );
    QPushButton * closeB = new QPushButton( "Close", frame);
    frameLayout->addWidget( closeB );
    errorDlgLayout->addWidget( frame );
    QWidget::connect(closeB, SIGNAL(clicked()), errorDlg, SLOT(hide()));
    errorDlg->resize( QSize(400, 250).expandedTo(errorDlg->minimumSizeHint()) );
    textWidget->setText(QString::fromUtf8(errors.c_str()));
    errorDlg->exec();
  }

  if(ControllerFactory::factory->objMap.empty()) {
    QMessageBox::critical(this,tr("No controller found"),tr("No controller was found in Tulip plugins directory.\n Tulip cannot work without a controller."));
    exit(-1);
  }

  buildMenus();
  this->show();
  enableElements(false);

  /*Load preference*/
  PreferenceDialog::loadPreference();

  OpenGlErrorViewer *oldErrorViewer=OpenGlConfigManager::getInst().setErrorViewer(new QtOpenGlErrorViewer);
  delete oldErrorViewer;

  if(PreferenceManager::getInst().getNetworkConnection()) {
    pluginsUpdateChecker = new PluginsUpdateChecker(pluginLoader.pluginsList,this);
    connect(pluginsUpdateChecker,SIGNAL(updateFinished()),this,SLOT(displayRestartForPlugins()));
    multiServerManager = pluginsUpdateChecker->getMultiServerManager();
  }
  else {
    pluginsUpdateChecker=NULL;
  }

  /*QWidget *centralwidget = new QWidget(this);
  QGridLayout *gridLayout = new QGridLayout(centralwidget);
  tabWidget=new QTabWidget(centralwidget);
  centralwidget->setSizePolicy(QSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred));
  tabWidget->setGeometry(0,0,800,600);
  //tabWidget->setSizePolicy(QSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum));*/
  tabWidget->removeTab(0);
  connect(tabWidget,SIGNAL(currentChanged(int)),this,SLOT(tabChanged(int)));
  // set workspace background
  //newWorkspace->setBackground(QBrush(QPixmap(QString::fromUtf8(":/background_logo.png"))));

  aboutWidget=NULL;

  //=======================================
  //MDI
  //newWorkspace->setScrollBarsEnabled( true );

  // Window Menu
  connect(windowsMenu, SIGNAL( aboutToShow() ),
          this, SLOT( windowsMenuAboutToShow() ) );
  connect(windowsMenu, SIGNAL(triggered(QAction*)),
          this, SLOT( windowsMenuActivated(QAction*)));

  assistantProcess= new QProcess(this);
  std::string assistantPath(tlp::TulipLibDir);
  assistantPath += string("../");
#if defined(__linux__)
  assistantPath += string("bin");

  // check if we are in a bundle
  if (QDir(assistantPath.c_str()).exists("assistant"))
    // assistant is in the bundle bin directory
    assistantProcessApp = QString::fromUtf8(assistantPath.c_str()) +
                          "/assistant";
  else
    // assistant is in the Qt binaries install directory
    assistantProcessApp = QLibraryInfo::location(QLibraryInfo::BinariesPath)+ "/assistant";

#else
#if defined(_WIN32)
  assistantPath.append("bin/assistant.exe");
#else
  assistantPath.append("Assistant.app/Contents/MacOS/Assistant");
#endif
  assistantProcessApp = assistantPath.c_str();
#endif
  /*saveActions(menuBar(),NULL,controllerToMenu);
  saveActions(toolBar,NULL,controllerToToolBar);*/
  tabIndexToController[-1]=NULL;
  saveInterface(-1);

  OpenGlErrorViewer *oldViewer=GlTextureManager::getInst().setErrorViewer(new QtOpenGlErrorViewer(this));
  delete oldViewer;

  TemplateFactory<ControllerFactory, Controller, ControllerContext>::ObjectCreator::const_iterator it;
  it=ControllerFactory::factory->objMap.begin();
  string name=(*it).first;
  ++it;

  if(it==ControllerFactory::factory->objMap.end()) {
    controllerAutoLoad=false;
    createController(name,newName());
    currentTabIndex=0;
    Controller::currentActiveController(tabIndexToController[currentTabIndex]);
    controllerAutoLoad=true;
  }
  else {
    controllerAutoLoad=false;
  }

  int argc = qApp->argc();

  if (argc>1) {
    char ** argv = qApp->argv();

    for (int i=1; i<argc; ++i) {
      if(string(argv[i])=="--width") {
        int width = atoi(argv[i+1]);
        wRect.setWidth(width);
        ++i;
        continue;
      }

      if(string(argv[i])=="--height") {
        int height = atoi(argv[i+1]);
        wRect.setHeight(height);
        ++i;
        continue;
      }

      if(string(argv[i])=="--x") {
        int x = atoi(argv[i+1]);
        wRect.setX(x);
        ++i;
        continue;
      }

      if(string(argv[i])=="--y") {
        int y = atoi(argv[i+1]);
        wRect.setY(y);
        ++i;
        continue;
      }

      QFileInfo info(QString::fromUtf8(argv[i]));
      QString s = info.absoluteFilePath();
      fileOpen(0, s);
    }
  }

  this->setGeometry(wRect.x(), wRect.y(),wRect.width(), wRect.height());

}