void KMahjongg::setupKAction() { KStandardGameAction::gameNew(this, SLOT(startNewGame()), actionCollection()); KStandardGameAction::load(this, SLOT(loadGame()), actionCollection()); KStandardGameAction::save(this, SLOT(saveGame()), actionCollection()); KStandardGameAction::quit(this, SLOT(close()), actionCollection()); KStandardGameAction::restart(this, SLOT(restartGame()), actionCollection()); QAction * newNumGame = actionCollection()->addAction(QStringLiteral("game_new_numeric")); newNumGame->setText(i18n("New Numbered Game...")); connect(newNumGame, &QAction::triggered, this, &KMahjongg::startNewNumeric); QAction * action = KStandardGameAction::hint(m_gameView, SLOT(helpMove()), this); actionCollection()->addAction(action->objectName(), action); QAction * shuffle = actionCollection()->addAction(QStringLiteral("move_shuffle")); shuffle->setText(i18n("Shu&ffle")); shuffle->setIcon(QIcon::fromTheme(QStringLiteral("view-refresh"))); connect(shuffle, &QAction::triggered, m_gameView, &GameView::shuffle); QAction * angleccw = actionCollection()->addAction(QStringLiteral("view_angleccw")); angleccw->setText(i18n("Rotate View Counterclockwise")); angleccw->setIcon(QIcon::fromTheme(QStringLiteral("object-rotate-left"))); actionCollection()->setDefaultShortcut(angleccw, Qt::Key_F); connect(angleccw, &QAction::triggered, m_gameView, &GameView::angleSwitchCCW); QAction * anglecw = actionCollection()->addAction(QStringLiteral("view_anglecw")); anglecw->setText(i18n("Rotate View Clockwise")); anglecw->setIcon(QIcon::fromTheme(QStringLiteral("object-rotate-right"))); actionCollection()->setDefaultShortcut(anglecw, Qt::Key_G); connect(anglecw, &QAction::triggered, m_gameView, &GameView::angleSwitchCW); m_demoAction = KStandardGameAction::demo(this, SLOT(demoMode()), actionCollection()); KStandardGameAction::highscores(this, SLOT(showHighscores()), actionCollection()); m_pauseAction = KStandardGameAction::pause(this, SLOT(pause()), actionCollection()); // move m_undoAction = KStandardGameAction::undo(this, SLOT(undo()), actionCollection()); m_redoAction = KStandardGameAction::redo(this, SLOT(redo()), actionCollection()); // edit QAction * boardEdit = actionCollection()->addAction(QStringLiteral("game_board_editor")); boardEdit->setText(i18n("&Board Editor")); connect(boardEdit, &QAction::triggered, this, &KMahjongg::slotBoardEditor); // settings KStandardAction::preferences(this, SLOT(showSettings()), actionCollection()); setupGUI(qApp->desktop()->availableGeometry().size() * 0.7); }
MainWindow::MainWindow(QWidget *parent) : KXmlGuiWindow(parent) , m_gameState(new KDiamond::GameState) , m_game(0) , m_view(new KDiamond::View) , m_infoBar(0) , m_newAct(new KActionMenu(KIcon( QLatin1String( "document-new") ), i18nc("new game", "&New" ), this)) , m_newTimedAct(new KAction(i18n("Timed game"), this)) , m_newUntimedAct(new KAction(i18n("Untimed game"), this)) , m_selector(KDiamond::renderer()->themeProvider(), KgThemeSelector::EnableNewStuffDownload) { KDiamond::renderer()->setDefaultPrimaryView(m_view); //init GUI - "New Action" m_newAct->setShortcut(KStandardShortcut::openNew()); m_newAct->setToolTip(i18n("Start a new game")); m_newAct->setWhatsThis(i18n("Start a new game.")); actionCollection()->addAction( QLatin1String( "game_new" ), m_newAct); connect(m_newAct, SIGNAL(triggered()), this, SLOT(startGameDispatcher())); m_newAct->addAction(m_newTimedAct); connect(m_newTimedAct, SIGNAL(triggered()), this, SLOT(startGameDispatcher())); m_newAct->addAction(m_newUntimedAct); connect(m_newUntimedAct, SIGNAL(triggered()), this, SLOT(startGameDispatcher())); //init GUI - the other actions KStandardGameAction::highscores(this, SLOT(showHighscores()), actionCollection()); m_pauseAct = KStandardGameAction::pause(this, SLOT(pausedAction(bool)), actionCollection()); KStandardGameAction::quit(kapp, SLOT(quit()), actionCollection()); m_hintAct = KStandardGameAction::hint(0, 0, actionCollection()); KStandardAction::preferences(&m_selector, SLOT(showAsDialog()), actionCollection()); KStandardAction::configureNotifications(this, SLOT(configureNotifications()), actionCollection()); //difficulty KgDifficultyGUI::init(this); connect(Kg::difficulty(), SIGNAL(currentLevelChanged(const KgDifficultyLevel*)), SLOT(startGameDispatcher())); //late GUI initialisation setupGUI(QSize(300, 400)); //TODO: find better solution for a minimum size setCaption(i18nc("The application's name", "KDiamond")); setCentralWidget(m_view); //init statusbar m_infoBar = new KDiamond::InfoBar(statusBar()); connect(m_gameState, SIGNAL(stateChanged(KDiamond::State)), this, SLOT(stateChange(KDiamond::State))); connect(m_gameState, SIGNAL(pointsChanged(int)), m_infoBar, SLOT(updatePoints(int))); connect(m_gameState, SIGNAL(leftTimeChanged(int)), m_infoBar, SLOT(updateRemainingTime(int))); //init game startGameDispatcher(); }
// --------------------------------------------------------- void KMahjongg::setupKAction() { // game KStdGameAction::gameNew(this, SLOT(newGame()), actionCollection()); KStdGameAction::load(this, SLOT(loadGame()), actionCollection()); KStdGameAction::save(this, SLOT(saveGame()), actionCollection()); KStdGameAction::quit(this, SLOT(close()), actionCollection()); KStdGameAction::restart(this, SLOT(restartGame()), actionCollection()); new KAction(i18n("New Numbered Game..."), "newnum", 0, this, SLOT(startNewNumeric()), actionCollection(), "game_new_numeric"); new KAction(i18n("Open Th&eme..."), 0, this, SLOT(openTheme()), actionCollection(), "game_open_theme"); new KAction(i18n("Open &Tileset..."), 0, this, SLOT(openTileset()), actionCollection(), "game_open_tileset"); new KAction(i18n("Open &Background..."), 0, this, SLOT(openBackground()), actionCollection(), "game_open_background"); new KAction(i18n("Open La&yout..."), 0, this, SLOT(openLayout()), actionCollection(), "game_open_layout"); new KAction(i18n("Sa&ve Theme..."), 0, this, SLOT(saveTheme()), actionCollection(), "game_save_theme"); // originally "file" ends here KStdGameAction::hint(bw, SLOT(helpMove()), actionCollection()); new KAction(i18n("Shu&ffle"), "reload", 0, bw, SLOT(shuffle()), actionCollection(), "move_shuffle"); demoAction = KStdGameAction::demo(this, SLOT(demoMode()), actionCollection()); showMatchingTilesAction = new KToggleAction(i18n("Show &Matching Tiles"), 0, this, SLOT(showMatchingTiles()), actionCollection(), "options_show_matching_tiles"); showMatchingTilesAction->setCheckedState(i18n("Hide &Matching Tiles")); showMatchingTilesAction->setChecked(Prefs::showMatchingTiles()); bw->setShowMatch( Prefs::showMatchingTiles() ); KStdGameAction::highscores(this, SLOT(showHighscores()), actionCollection()); pauseAction = KStdGameAction::pause(this, SLOT(pause()), actionCollection()); // TODO: store the background ; open on startup // TODO: same about layout // TODO: same about theme // move undoAction = KStdGameAction::undo(this, SLOT(undo()), actionCollection()); redoAction = KStdGameAction::redo(this, SLOT(redo()), actionCollection()); // edit new KAction(i18n("&Board Editor"), 0, this, SLOT(slotBoardEditor()), actionCollection(), "edit_board_editor"); // settings KStdAction::preferences(this, SLOT(showSettings()), actionCollection()); setupGUI(); }
void App::setupActions() { // Game KStandardGameAction::gameNew(this, SIGNAL(invokeNewGame()), actionCollection()); KStandardGameAction::restart(this, SLOT(restartGame()), actionCollection()); KStandardGameAction::pause(this, SLOT(togglePause()), actionCollection()); KStandardGameAction::highscores(this, SLOT(showHighscores()), actionCollection()); KStandardGameAction::quit(this, SLOT(close()), actionCollection()); // Move KStandardGameAction::undo(this, SLOT(undo()), actionCollection()); KStandardGameAction::redo(this, SLOT(redo()), actionCollection()); KStandardGameAction::hint(this, SLOT(hint()), actionCollection()); auto soundAction = new KToggleAction(QIcon::fromTheme(QStringLiteral("speaker")), i18n("Play Sounds"), this); soundAction->setChecked(Prefs::sounds()); actionCollection()->addAction(QStringLiteral("sounds"), soundAction); connect(soundAction, &KToggleAction::triggered, m_board, &Board::setSoundsEnabled); // Settings KStandardAction::preferences(this, SLOT(showSettingsDialog()), actionCollection()); connect(m_board, &Board::cheatStatusChanged, this, &App::updateCheatDisplay); connect(m_board, &Board::changed, this, &App::updateItems); connect(m_board, &Board::tilesDoNotMatch, this, &App::notifyTilesDoNotMatch); connect(m_board, &Board::invalidMove, this, &App::notifyInvalidMove); connect(m_board, &Board::selectATile, this, &App::notifySelectATile); connect(m_board, &Board::selectAMatchingTile, this, &App::notifySelectAMatchingTile); connect(m_board, &Board::selectAMove, this, &App::notifySelectAMove); auto timer = new QTimer(this); connect(timer, &QTimer::timeout, this, &App::updateTimeDisplay); timer->start(1000); connect(m_board, &Board::tileCountChanged, this, &App::updateTileDisplay); connect(m_board, &Board::endOfGame, this, &App::slotEndOfGame); connect(this, &App::invokeNewGame, m_board, &Board::newGame); connect(m_board, &Board::newGameStarted, this, &App::newGame); }
MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags wf) : QMainWindow(parent, wf) { //setMinimumSize(geometry().size()); //setMaximumSize(geometry().size()); contrdirs[Cell::U] = Cell::D; contrdirs[Cell::R] = Cell::L; contrdirs[Cell::D] = Cell::U; contrdirs[Cell::L] = Cell::R; #ifndef QTOPIA_PHONE QString appdir = qApp->applicationDirPath(); soundpath = appdir + "/sounds/"; if(!QFile::exists(soundpath)) soundpath = appdir + "/../share/qnetwalk/sounds/"; winsound = new QSound(soundpath + "win.wav"); turnsound = new QSound(soundpath + "turn.wav"); clicksound = new QSound(soundpath + "click.wav"); startsound = new QSound(soundpath + "start.wav"); connectsound = new QSound(soundpath + "connect.wav"); #else QString appdir = qApp->applicationDirPath(); soundpath = ":sound/qnetwalk/"; winsound = new QSound(soundpath + "win"); turnsound = new QSound(soundpath + "turn"); clicksound = new QSound(soundpath + "click"); startsound = new QSound(soundpath + "start"); connectsound = new QSound(soundpath + "connect"); #endif QSettings settings("QNetEor", "QNetEor"); settings.beginGroup("QNetEor"); username = settings.value("Username", getenv("USER")).toString(); bool issound = settings.value("Sound", true).toBool(); highscores = settings.value("Highscores").toStringList(); if(highscores.count() != NumHighscores * 8) { highscores.clear(); for(int i = 1; i < 5; i++) { for(int scores = 20 * i; scores < 30 * i; scores += i) { highscores.append("..."); highscores.append(QString::number(scores)); } } } skill = settings.value("Skill", Novice).toInt(); if(skill != Novice && skill != Normal && skill != Expert) skill = Master; settings.endGroup(); for(int i = 1; i < qApp->argc(); i++) { QString argument = qApp->argv()[i]; if(argument == "-novice") skill = Novice; else if(argument == "-amateur") skill = Normal; else if(argument == "-expert") skill = Expert; else if(argument == "-master") skill = Master; else if(argument == "-nosound") issound = false; } setWindowTitle(tr("QNeoroid")); setWindowIcon(QPixmap(":/computer2.png")); #ifdef QTOPIA_PHONE QMenu *m = QSoftMenuBar::menuFor(this); #else QMenu *m = menuBar()->addMenu(tr("Options")); #endif soundaction = new QAction(tr("&Sound"), this); soundaction->setCheckable(true); soundaction->setChecked(issound); gamemenu = m->addMenu(tr("&Game")); gamemenu->addAction(QPixmap(":/newgame.png"), tr("&New"), this, SLOT(newGame())); gamemenu->addAction(QPixmap(":/highscores.png"), tr("&Highscores"), this, SLOT(showHighscores())); gamemenu->addAction(soundaction); #ifndef QTOPIA_PHONE gamemenu->addSeparator(); gamemenu->addAction(QPixmap(":/quit.png"), tr("&Quit"), qApp, SLOT(closeAllWindows())); #endif skillmenu = m->addMenu(tr("&Skill")); skillActionGroup = new QActionGroup(this); QAction* action; action = skillActionGroup->addAction(tr("&Novice")); action->setCheckable(true); if(skill == Novice) action->setChecked(true); connect(action, SIGNAL(triggered()), this, SLOT(setSkillNovice())); action = skillActionGroup->addAction(tr("&Amateur")); action->setCheckable(true); if(skill == Normal) action->setChecked(true); connect(action, SIGNAL(triggered()), this, SLOT(setSkillNormal())); action = skillActionGroup->addAction(tr("&Expert")); action->setCheckable(true); if(skill == Expert) action->setChecked(true); connect(action, SIGNAL(triggered()), this, SLOT(setSkillExpert())); action = skillActionGroup->addAction(tr("&Master")); action->setCheckable(true); if(skill == Master) action->setChecked(true); connect(action, SIGNAL(triggered()), this, SLOT(setSkillMaster())); skillmenu->addActions(skillActionGroup->actions()); QMenu* helpmenu = m->addMenu(tr("&Help")); helpmenu->addAction(tr("&Rules of Play"), this, SLOT(help())); helpmenu->addAction(QPixmap(":/homepage.png"), tr("&Homepage"), this, SLOT(openHomepage())); helpmenu->addSeparator(); helpmenu->addAction(QPixmap(":/qnetwalk.png"), tr("&About QNeoroid"), this, SLOT(about())); helpmenu->addAction(tr("About &Qt"), qApp, SLOT(aboutQt())); QToolBar* toolbar = new QToolBar(this); toolbar->setFloatable(false); toolbar->setMovable(false); toolbar->addAction(QPixmap(":/newgame.png"), tr("New Game"), this, SLOT(newGame())); toolbar->addAction(QPixmap(":/highscores.png"), tr("Show Highscores"), this, SLOT(showHighscores())); //toolbar->addWidget(new QLabel(tr("Moves"),this)); lcd = new QLCDNumber(toolbar); lcd->setFrameStyle(QFrame::Plain); toolbar->addWidget(lcd); //toolbar->addWidget(new QLabel(tr("Left:"),this)); cellsLcd = new QLCDNumber(toolbar); cellsLcd->setFrameStyle(QFrame::Plain); toolbar->addWidget(cellsLcd); addToolBar(toolbar); Cell::initPixmaps(); srand(time(0)); setSkill(skill); installEventFilter(this); resize(240,320); }
MainWindow::MainWindow(QWidget *parent, const char* name, WFlags /*fl*/) : KMainWindow(parent, name, WStyle_NoBorder) { m_clickcount = 0; contrdirs[Cell::U] = Cell::D; contrdirs[Cell::R] = Cell::L; contrdirs[Cell::D] = Cell::U; contrdirs[Cell::L] = Cell::R; KNotifyClient::startDaemon(); KStdGameAction::gameNew(this, SLOT(slotNewGame()), actionCollection()); KStdGameAction::highscores(this, SLOT(showHighscores()), actionCollection()); KStdGameAction::quit(this, SLOT(close()), actionCollection()); KStdGameAction::configureHighscores(this, SLOT(configureHighscores()), actionCollection()); m_levels = KStdGameAction::chooseGameType(0, 0, actionCollection()); QStringList lst; lst += i18n("Novice"); lst += i18n("Normal"); lst += i18n("Expert"); lst += i18n("Master"); m_levels->setItems(lst); setFixedSize(minimumSizeHint()); statusBar()->insertItem("abcdefghijklmnopqrst: 0 ",1); setAutoSaveSettings(); createGUI(); connect(m_levels, SIGNAL(activated(int)), this, SLOT(newGame(int))); QWhatsThis::add(this, i18n("<h3>Rules of the Game</h3>" "<p>You are the system administrator and your goal" " is to connect each computer to the central server." "<p>Click the right mouse button to turn the cable" " in a clockwise direction, and the left mouse button" " to turn it in a counter-clockwise direction." "<p>Start the LAN with as few turns as possible!")); //const int cellsize = KGlobal::iconLoader()->loadIcon("knetwalk/background.png", KIcon::User, 32).width(); const int cellsize = 32; const int gridsize = cellsize * MasterBoardSize + 2; QGrid* grid = new QGrid(MasterBoardSize, this); grid->setFrameStyle(QFrame::Panel | QFrame::Sunken); grid->setFixedSize(gridsize, gridsize); setCentralWidget(grid); Cell::initPixmaps(); for(int i = 0; i < MasterBoardSize * MasterBoardSize; i++) { board[i] = new Cell(grid, i); board[i]->setFixedSize(cellsize, cellsize); connect(board[i], SIGNAL(lClicked(int)), SLOT(lClicked(int))); connect(board[i], SIGNAL(rClicked(int)), SLOT(rClicked(int))); connect(board[i], SIGNAL(mClicked(int)), SLOT(mClicked(int))); } srand(time(0)); slotNewGame(); }
void MainWindow::setupActions() { // Game KStandardGameAction::gameNew(this, SLOT(startNewGame()), actionCollection()); m_pauseAction = KStandardGameAction::pause(this, SLOT(pauseGame(bool)), actionCollection()); connect(Kg::difficulty(), &KgDifficulty::gameRunningChanged, m_pauseAction, &QAction::setEnabled); QAction *action = KStandardGameAction::solve(m_view, SLOT(solve()), actionCollection()); connect(Kg::difficulty(), &KgDifficulty::gameRunningChanged, action, &QAction::setEnabled); KStandardGameAction::highscores(this, SLOT(showHighscores()), actionCollection()); KStandardGameAction::quit(this, SLOT(close()), actionCollection()); // Settings KStandardAction::preferences(this, SLOT(configureSettings()), actionCollection()); action = new QAction(i18n("&Unlock All"), this); connect(action, SIGNAL(triggered()), m_view->rootObject(), SLOT(unlockAll())); connect(Kg::difficulty(), &KgDifficulty::gameRunningChanged, action, &QAction::setEnabled); actionCollection()->addAction( QStringLiteral( "unlock_all" ), action); action = new QAction(i18n("Keyboard: Field right"), this); actionCollection()->setDefaultShortcut(action, Qt::Key_Right); connect(action, SIGNAL(triggered()), m_view->rootObject(), SLOT(kbGoRight())); actionCollection()->addAction( QStringLiteral( "kb_go_right" ), action); action = new QAction(i18n("Keyboard: Field left"),this); actionCollection()->setDefaultShortcut(action, Qt::Key_Left); connect(action, SIGNAL(triggered()), m_view->rootObject(), SLOT(kbGoLeft())); actionCollection()->addAction( QStringLiteral( "kb_go_left" ), action); action = new QAction(i18n("Keyboard: Field up"),this); actionCollection()->setDefaultShortcut(action, Qt::Key_Up); connect(action, SIGNAL(triggered()), m_view->rootObject(), SLOT(kbGoUp())); actionCollection()->addAction( QStringLiteral( "kb_go_up" ), action); action = new QAction(i18n("Keyboard: Field down"),this); actionCollection()->setDefaultShortcut(action, Qt::Key_Down); connect(action, SIGNAL(triggered()), m_view->rootObject(), SLOT(kbGoDown())); actionCollection()->addAction( QStringLiteral( "kb_go_down" ), action); action = new QAction(i18n("Keyboard: Turn clockwise"),this); actionCollection()->setDefaultShortcut(action, Qt::Key_Return); connect(action, SIGNAL(triggered()), m_view->rootObject(), SLOT(rotateClockwise())); actionCollection()->addAction( QStringLiteral( "kb_turn_clockwise" ), action); action = new QAction(i18n("Keyboard: Turn counterclockwise"),this); actionCollection()->setDefaultShortcut(action, Qt::CTRL + Qt::Key_Return); connect(action, SIGNAL(triggered()), m_view->rootObject(), SLOT(rotateCounterclockwise())); actionCollection()->addAction( QStringLiteral( "kb_turn_counterclockwise" ), action); action = new QAction(i18n("Keyboard: Toggle lock"),this); actionCollection()->setDefaultShortcut(action, Qt::Key_Space); connect(action, SIGNAL(triggered()), m_view->rootObject(), SLOT(toggleLock())); actionCollection()->addAction( QStringLiteral( "kb_lock" ), action); }