Exemplo n.º 1
0
void MainWindow::scanWorlds() {
  ui->menuOpen_World->clear();
  bool enabled = false;
  int key = 0;
  for (const QString &worldDir : settings->getWorlds()) {
    QDir dir(worldDir);
  
    QDirIterator it(dir);
    QList<QAction *> actions;
    while (it.hasNext()) {
      it.next();
      if (it.fileName().endsWith(".wld")) {
        QString name = worldName(it.filePath());
        if (!name.isNull()) {
          QAction *w = new QAction(this);
          w->setText(name);
          w->setData(it.filePath());
          if (key < 9) {
            w->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_1 + key++));
            w->setShortcutContext(Qt::ApplicationShortcut);
          }
          connect(w, SIGNAL(triggered()),
                  this, SLOT(openWorld()));
          actions.append(w);
        }
      }
    }
    if (!actions.isEmpty()) {
      ui->menuOpen_World->addSection(worldDir);
      ui->menuOpen_World->addActions(actions);
      enabled = true;
    }
  }
  ui->menuOpen_World->setDisabled(!enabled);
}
Exemplo n.º 2
0
void MainWindow::createActions()
{
	// Map menu:
	createWorldActions();

	m_actNewGen = new QAction(tr("&New generator"), this);
	m_actNewGen->setShortcut(tr("Ctrl+N"));
	m_actNewGen->setStatusTip(tr("Open a generator INI file and display the generated biomes"));
	connect(m_actNewGen, SIGNAL(triggered()), this, SLOT(newGenerator()));

	m_actOpenGen = new QAction(tr("&Open generator..."), this);
	m_actOpenGen->setShortcut(tr("Ctrl+G"));
	m_actOpenGen->setStatusTip(tr("Open a generator INI file and display the generated biomes"));
	connect(m_actOpenGen, SIGNAL(triggered()), this, SLOT(openGenerator()));

	m_actOpenWorld = new QAction(tr("&Open world..."), this);
	m_actOpenWorld->setShortcut(tr("Ctrl+O"));
	m_actOpenWorld->setStatusTip(tr("Open an existing world and display its biomes"));
	connect(m_actOpenWorld, SIGNAL(triggered()), this, SLOT(openWorld()));

	m_actReload = new QAction(tr("&Reload"), this);
	m_actReload->setShortcut(tr("F5"));
	m_actReload->setStatusTip(tr("Clear the view cache and force a reload of all the data"));
	connect(m_actReload, SIGNAL(triggered()), m_BiomeView, SLOT(reload()));

	m_actExit = new QAction(tr("E&xit"), this);
	m_actExit->setShortcut(tr("Alt+X"));
	m_actExit->setStatusTip(tr("Exit %1").arg(QApplication::instance()->applicationName()));
	connect(m_actExit, SIGNAL(triggered()), this, SLOT(close()));

	// View menu:
	m_actViewCenter = new QAction(tr("&Reset to center"), this);
	m_actViewCenter->setStatusTip(tr("Scrolls the view back to the map center"));
	connect(m_actViewCenter, SIGNAL(triggered()), this, SLOT(centerView()));

	QActionGroup * zoomGroup = new QActionGroup(this);
	for (int i = 0; i < ARRAYCOUNT(m_ViewZooms); i++)
	{
		m_actViewZoom[i] = new QAction(tr("&Zoom %1%").arg(std::floor(m_ViewZooms[i] * 100)), this);
		m_actViewZoom[i]->setCheckable(true);
		m_actViewZoom[i]->setData(QVariant(i));
		zoomGroup->addAction(m_actViewZoom[i]);
		connect(m_actViewZoom[i], SIGNAL(triggered()), this, SLOT(setViewZoom()));
	}
	m_actViewZoom[m_CurrentZoomLevel]->setChecked(true);
}