Exemplo n.º 1
0
void MainWindow::init()
{
    /* MenuBar */
    setMenuBar(new MenuBar(addToolBar(tr("")), this));
    connect(menuBar(), SIGNAL(newTabTriggered()), this, SLOT(newTab()));
    connect(menuBar(), SIGNAL(openTriggered()), this, SLOT(openTriggered()));
    connect(menuBar(), SIGNAL(openClipboardTriggered()), this, SLOT(openClipboardTriggered()));
    connect(menuBar(), SIGNAL(saveAsTriggered()), this, SLOT(saveAsTriggered()));
    connect(menuBar(), SIGNAL(saveHtmlTriggered()), this, SLOT(saveHtmlTriggered()));
    connect(menuBar(), SIGNAL(printTriggered()), this, SLOT(printTriggered()));
    connect(menuBar(), SIGNAL(closeTabTriggered()), this, SLOT(closeTabTriggered()));
    connect(menuBar(), SIGNAL(quitTriggered()), this, SLOT(close()));
    connect(menuBar(), SIGNAL(findNextTriggered()), this, SLOT(findNextTriggered()));
    connect(menuBar(), SIGNAL(findPreviousTriggered()), this, SLOT(findPreviousTriggered()));
    connect(menuBar(), SIGNAL(gotoLineTriggered()), this, SLOT(gotoLineTriggered()));
    connect(menuBar(), SIGNAL(reloadTriggered()), this, SLOT(reloadTriggered()));
    connect(menuBar(), SIGNAL(zoomInTriggered()), this, SLOT(zoomInTriggered()));
    connect(menuBar(), SIGNAL(zoomOutTriggered()), this, SLOT(zoomOutTriggered()));
    connect(menuBar(), SIGNAL(zoomNormalTriggered()), this, SLOT(zoomNormalTriggered()));
    connect(menuBar(), SIGNAL(lineWrapTriggered()), this, SLOT(lineWrapTriggered()));
    connect(menuBar(), SIGNAL(optionTriggered()), this, SLOT(optionTriggered()));
    connect(menuBar(), SIGNAL(updateTriggered()), this, SLOT(updateTriggered()));
    connect(menuBar(), SIGNAL(reportBugTriggered()), this, SLOT(reportBugTriggered()));
    connect(menuBar(), SIGNAL(requestFeatureTriggered()), this, SLOT(requestFeatureTriggered()));
    connect(menuBar(), SIGNAL(aboutTriggered()), this, SLOT(aboutTriggered()));
    connect(menuBar(), SIGNAL(openRecentFiles(QAction*)), this, SLOT(openRecentFiles(QAction*)));
    connect(menuBar(), SIGNAL(fileBrowserVisibleChanged(bool)), this, SLOT(fileBrowserVisibleChanged(bool)));
    connect(menuBar(), SIGNAL(resultViewVisibleChanged(bool)), this, SLOT(resultViewVisibleChanged(bool)));
    connect(menuBar(), SIGNAL(chartViewVisibleChanged(bool)), this, SLOT(chartViewVisibleChanged(bool)));
    connect(static_cast<MenuBar*>(menuBar())->searchLineEdit(), SIGNAL(returnPressed()), this, SLOT(findNextTriggered()));

    /* StatusBar */
    setStatusBar(new StatusBar(this));
    connect(static_cast<StatusBar*>(statusBar()), SIGNAL(textEncodingChanged(QString)), this, SLOT(textEncodingChanged(QString)));

    /* TabWidget */
    m_tabWidget = new TabWidget(this);
    connect(m_tabWidget, SIGNAL(newTab()), this, SLOT(newTab()));
    connect(m_tabWidget, SIGNAL(closeAll()), this, SLOT(closeAll()));
    connect(m_tabWidget, SIGNAL(closeOthers(int)), this, SLOT(closeOthers(int)));
    connect(m_tabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int)));
    connect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)));
    newTab();

    setCentralWidget(m_tabWidget);

    /* DockWidget */
    createDockWidget();

    /* Keyword Button Group */
    connect(keywordButtonGroup(), SIGNAL(buttonReloaded()), LOGVIEWERMANAGER(), SLOT(keywordButtonGroupReloaded()));
    connect(keywordButtonGroup(), SIGNAL(buttonClicked(QWidget*,QButtonGroup*)), LOGVIEWERMANAGER(), SLOT(keywordButtonGroupClicked(QWidget*,QButtonGroup*)));
    connect(keywordButtonGroup(), SIGNAL(buttonAdded(QStringList&)), LOGVIEWERMANAGER(), SLOT(keywordButtonGroupAdded(QStringList&)));
    connect(keywordButtonGroup(), SIGNAL(buttonRemoved(QStringList&)), LOGVIEWERMANAGER(), SLOT(keywordButtonGroupRemoved(QStringList&)));

    /* File Load Manager */
    connect(FILELOADMANAGER(), SIGNAL(loadStarted(QWidget*)), this, SLOT(fileLoadStarted(QWidget*)));
    connect(FILELOADMANAGER(), SIGNAL(loadProgress(QWidget*,QString*,int)), this, SLOT(fileLoadProgress(QWidget*,QString*,int)));
    connect(FILELOADMANAGER(), SIGNAL(loadFinished(QWidget*,QString*)), this, SLOT(fileLoadProgress(QWidget*,QString*)));
    connect(FILELOADMANAGER(), SIGNAL(codecDected(QString)), this, SLOT(codecDected(QString)));
    connect(FILELOADMANAGER(), SIGNAL(loadStarted(QWidget*)), m_tabWidget, SLOT(fileLoadStarted(QWidget*)));
    connect(FILELOADMANAGER(), SIGNAL(loadFinished(QWidget*,QString*)), m_tabWidget, SLOT(fileLoadFinished(QWidget*)));
    connect(FILELOADMANAGER(), SIGNAL(loadStarted(QWidget*)), LOGVIEWERMANAGER(), SLOT(fileLoadStarted(QWidget*)));
    connect(FILELOADMANAGER(), SIGNAL(loadFinished(QWidget*,QString*)), LOGVIEWERMANAGER(), SLOT(fileLoadFinished(QWidget*)));
    connect(FILELOADMANAGER(), SIGNAL(fileSizeNotify(QWidget*,long)), LOGVIEWERMANAGER(), SLOT(fileSizeNotified(QWidget*,long)));
    connect(FILELOADMANAGER(), SIGNAL(fileNameNotify(QWidget*,QString)), LOGVIEWERMANAGER(), SLOT(fileNameNotified(QWidget*,QString)));

    /* Log Viewer */
    connect(LOGVIEWERMANAGER(), SIGNAL(selectionChanged(QWidget*)), this, SLOT(selectionChanged(QWidget*)));
    connect(LOGVIEWERMANAGER(), SIGNAL(cursorPositionChanged(QWidget*)), this, SLOT(cursorPositionChanged(QWidget*)));
    connect(LOGVIEWERMANAGER(), SIGNAL(fileDropped(QString)), this, SLOT(fileDropped(QString)));
    connect(LOGVIEWERMANAGER(), SIGNAL(modelCreated(QWidget*, QStandardItemModel*)), this, SLOT(modelCreated(QWidget*, QStandardItemModel*)));
    connect(LOGVIEWERMANAGER(), SIGNAL(chartLoaded(QWidget*, QPixmap*)), this, SLOT(chartLoaded(QWidget*, QPixmap*)));
}
Exemplo n.º 2
0
CMainWindow::CMainWindow(QGLWidget *glwidget, QWidget *parent)
 : QStackedWidget(parent),
   m_main_menu(0),
   m_single_player(0),
   m_multi_player(0),
   m_glwidget(glwidget),
   m_pexeso_view(0),
   m_pexeso_scene(0),
   m_machine(0)
{
  PEXESO_ASSERT(m_glwidget != 0);

  /* create widgets */
  m_main_menu = new CMainMenuWidget;
  m_single_player = new CSinglePlayerMenuWidget;
  m_multi_player = new CMultiPlayerMenuWidget;
  /*
     according to dumentation it is possible to associate a single scene with multiple views,
     thus QGraphicsView will not take an ownership over scene and we must do it manually.
     Also this SO post confirms this:
     http://stackoverflow.com/questions/4955743/does-a-qgraphicsview-take-ownership-over-its-associated-graphics-scene
  */
  m_pexeso_scene = new CPexesoScene(this);
  m_pexeso_view = new CPexesoView(m_glwidget, m_pexeso_scene);
  //m_pexeso->makeCurrent(); // this sadly does not work from constructor

  addWidget(m_main_menu);
  addWidget(m_single_player);
  addWidget(m_multi_player);
  addWidget(m_pexeso_view);

  /* create the state machine and states */
  m_machine = new QStateMachine(this);
  connect(m_machine, SIGNAL(finished()), SLOT(close()));

  QState *s_main_menu = new QState;
  QState *s_sp_menu = new QState;
  QState *s_mp_menu = new QState;
  QState *s_load = new QState;        // the game is loading
  QState *s_game = new QState;        // the game has begun
  QFinalState *sf = new QFinalState;  // final state

  /* assign actions to states */
  s_main_menu->assignProperty(this, "currentIndex", 0);  // main menu screen has index 0
  //s_main_menu->assignProperty(this, "windowTitle", "s_main_menu");

  s_sp_menu->assignProperty(this, "currentIndex", 1);    // single player screen has index 1
  //s_sp_menu->assignProperty(this, "windowTitle", "s_sp_menu");
  connect(s_sp_menu, SIGNAL(exited()), m_single_player, SLOT(clearError()));  // clear any errors when this state is exited

  s_mp_menu->assignProperty(this, "currentIndex", 2);    // multi player screen has index 2
  //s_mp_menu->assignProperty(this, "windowTitle", "s_mp_menu");

  connect(s_load, SIGNAL(entered()), SLOT(handleGameLoadTrans()));
  //s_load->assignProperty(this, "windowTitle", "s_load");

  s_game->assignProperty(this, "currentIndex", 3);       // game widget screen
  //s_game->assignProperty(this, "windowTitle", "s_game");

  /* transitions from main menu */
  s_main_menu->addTransition(m_main_menu, SIGNAL(exitTriggered()), sf);
  s_main_menu->addTransition(m_main_menu, SIGNAL(singlePlayerTriggered()), s_sp_menu);
  s_main_menu->addTransition(m_main_menu, SIGNAL(multiPlayerTriggered()), s_mp_menu);

  /* transitions from single player menu */
  s_sp_menu->addTransition(m_single_player, SIGNAL(backTriggered()), s_main_menu);
  s_sp_menu->addTransition(m_single_player, SIGNAL(startGameTriggered()), s_load);

  /* transitions from multiplayer menu */
  /* these transitions work like this: when in state s_mp_menu and multiplayer
     menu screen triggeres a signal backTriggered() then the state machine will
     transition to s_main_menu state */
  s_mp_menu->addTransition(m_multi_player, SIGNAL(backTriggered()), s_main_menu);

  /* load transitions */
  s_load->addTransition(m_pexeso_scene, SIGNAL(errorTriggered()), s_sp_menu);
  s_load->addTransition(m_pexeso_scene, SIGNAL(startTriggered()), s_game);

  /* transitons from in-game menu */
  s_game->addTransition(m_pexeso_scene, SIGNAL(mainMenuTriggered()), s_main_menu);
  s_game->addTransition(m_pexeso_scene, SIGNAL(quitTriggered()), sf);
  s_game->addTransition(m_pexeso_scene, SIGNAL(gameOverTriggered()), s_main_menu);

  /* add states to state machine and start it */
  m_machine->addState(s_main_menu);
  m_machine->addState(s_sp_menu);
  m_machine->addState(s_mp_menu);
  m_machine->addState(s_load);
  m_machine->addState(s_game);
  m_machine->addState(sf);

  m_machine->setInitialState(s_main_menu);

  m_machine->start();
}