예제 #1
0
void AppWindow::keyPressEvent(QKeyEvent *event) {
    
    if(m_viewer->gameStatus>=0){
        if (event->key() == Qt::Key_Escape) {
            QCoreApplication::instance()->quit();
        } else if (event->key() == Qt::Key_Right) {
            moveRight();
        } else if (event->key() == Qt::Key_Left) {
            moveLeft();
        } else if (event->key() == Qt::Key_Down) {
            rotateCW();
        } else if (event->key() == Qt::Key_Up) {
            rotateCCW();
        } else if (event->key() == Qt::Key_Space) {
            dropPiece();
        } else if (event->key() == Qt::Key_Shift) {
           shiftPressed();
        }
    }




    if (event->key() == Qt::Key_1) {
        slowSpeed();
        slowSpeedAct->setChecked(true);
    }else if (event->key() == Qt::Key_2) {
        normalSpeed();
        normalSpeedAct->setChecked(true);
    }else if (event->key() == Qt::Key_3) {
        fastSpeed();
        fastSpeedAct->setChecked(true);
    }else if (event->key() == Qt::Key_W) {
        wire_frame();
        wireAct->setChecked(true);
    }else if (event->key() == Qt::Key_F) {
        face();
        faceAct->setChecked(true);
    }else if (event->key() == Qt::Key_M) {
        multi_coloured();
        multiAct->setChecked(true);
    }else if (event->key() == Qt::Key_N) {
        new_game();
    }else if (event->key() == Qt::Key_R) {
        reset();
    }else if (event->key() == Qt::Key_Q) {
        close();
    }else {
        QWidget::keyPressEvent(event);
    }
}
예제 #2
0
파일: AppWindow.cpp 프로젝트: WalrusCow/gfx
void AppWindow::createActions() {
  QAction* a;
  // Application menu
  a = newMenuAction("&New Game", nullptr,
      "Start a new game", appMenuActions, Qt::Key_N);
  connect(a, SIGNAL(triggered()), this, SLOT(newGame()));

  a = newMenuAction("&Reset", nullptr,
      "Reset the view", appMenuActions, Qt::Key_R);
  connect(a, SIGNAL(triggered()), this, SLOT(resetView()));

  a = newMenuAction("&Quit", nullptr,
      "Exit the program", appMenuActions, Qt::Key_Q);
  connect(a, SIGNAL(triggered()), this, SLOT(close()));

  // Draw menu
  QActionGroup* drawGroup = new QActionGroup(this);
  a = newMenuAction("&Face", drawGroup,
      "Fill faces", drawMenuActions, Qt::Key_F);
  connect(a, SIGNAL(triggered()), this, SLOT(faceMode()));

  a = newMenuAction("&Wire-frame", drawGroup,
      "Draw wire frames", drawMenuActions, Qt::Key_W);
  connect(a, SIGNAL(triggered()), this, SLOT(wireMode()));

  a = newMenuAction("&Multicoloured", drawGroup,
      "Each cube has 6 unique colours", drawMenuActions, Qt::Key_M);
  connect(a, SIGNAL(triggered()), this, SLOT(multiMode()));

  drawGroup->actions().first()->setChecked(true);

  // Speed menu
  QActionGroup* speedGroup = new QActionGroup(this);
  a = newMenuAction("Slow", speedGroup,
      "Slow speed", speedMenuActions, Qt::Key_1);
  connect(a, SIGNAL(triggered()), this, SLOT(slowSpeed()));

  a = newMenuAction("Medium", speedGroup,
      "Medium speed", speedMenuActions, Qt::Key_2);
  connect(a, SIGNAL(triggered()), this, SLOT(medSpeed()));

  a = newMenuAction("Fast", speedGroup,
      "Fast speed", speedMenuActions, Qt::Key_3);
  connect(a, SIGNAL(triggered()), this, SLOT(fastSpeed()));

  speedGroup->actions().first()->setChecked(true);
}
예제 #3
0
void AppWindow::createActions() {
    // Creates a new action for quiting and pushes it onto the menu actions vector
    quitAct = new QAction(tr("&Quit"), this);
    m_menu_actions.push_back(quitAct);

    // We set the accelerator keys
    // Alternatively, you could use: setShortcuts(Qt::CTRL + Qt::Key_P);
    quitAct->setShortcuts(QKeySequence::Quit);

    // Set the tip
    quitAct->setStatusTip(tr("Exits the file"));

    // Connect the action with the signal and slot designated
    connect(quitAct, SIGNAL(triggered()), this, SLOT(close()));

    newGameAct = new QAction(tr("&New Game (N)"), this);
    m_menu_actions.push_back(newGameAct);
    connect(newGameAct, SIGNAL(triggered()), this, SLOT(new_game()));

    resetAct = new QAction(tr("&Reset (R)"), this);
    m_menu_actions.push_back(resetAct);
    connect(resetAct, SIGNAL(triggered()), this, SLOT(reset()));

    wireAct = new QAction(tr("&Wire-frame (W)"), this);
    m_draw_actions.push_back(wireAct);
    wireAct->setCheckable(true);
    connect(wireAct, SIGNAL(triggered()), this, SLOT(wire_frame()));


    faceAct = new QAction(tr("&Face (F)"), this);
    m_draw_actions.push_back(faceAct);
    faceAct->setCheckable(true);
    connect(faceAct, SIGNAL(triggered()), this, SLOT(face()));


    multiAct = new QAction(tr("&Multicoloured (M)"), this);
    m_draw_actions.push_back(multiAct);
    multiAct->setCheckable(true);
    connect(multiAct, SIGNAL(triggered()), this, SLOT(multi_coloured()));

    QActionGroup* drawGroup = new QActionGroup(this);

    drawGroup->setExclusive(true);
    drawGroup->addAction(wireAct);
    drawGroup->addAction(faceAct);
    drawGroup->addAction(multiAct);

    faceAct->setChecked(true);


    slowSpeedAct = new QAction(tr("&Slow (1)"), this);
    m_speed_actions.push_back(slowSpeedAct);
    slowSpeedAct->setCheckable(true);
    connect(slowSpeedAct, SIGNAL(triggered()), this, SLOT(slowSpeed()));

    normalSpeedAct = new QAction(tr("&Medium (2)"), this);
    m_speed_actions.push_back(normalSpeedAct);
    normalSpeedAct->setCheckable(true);
    connect(normalSpeedAct, SIGNAL(triggered()), this, SLOT(normalSpeed()));

    fastSpeedAct = new QAction(tr("&Fast (3)"), this);
    m_speed_actions.push_back(fastSpeedAct);
    fastSpeedAct->setCheckable(true);
    connect(fastSpeedAct, SIGNAL(triggered()), this, SLOT(fastSpeed()));

    QActionGroup* speedGroup = new QActionGroup(this);

    speedGroup->setExclusive(true);
    speedGroup->addAction(slowSpeedAct);
    speedGroup->addAction(normalSpeedAct);
    speedGroup->addAction(fastSpeedAct);

    normalSpeedAct->setChecked(true);




}