void Battleship::slotStartGame() { if (round > 0) { /*** Reset ***/ console->clear(); slotPrintToConsole("New Round...\n"); slotSetEwoMode(false); pushButtonEwo->setChecked(false); pushButtonEwo->setEnabled(false); blockBoxSignals(false); // Reset Players humanPlayer->reset(); enemyPlayer->reset(); } /*** Normal run ***/ //if (checked) emit sigPlaceFleet(); //TO: both players: slotPlaceFleet() slotPlaySound("startRound.wav"); alignment = h; // set default alignment gridLayoutEnemy->setCursor(QCursor(Qt::ForbiddenCursor)); gridLayoutHuman->setCursor(QCursor(Qt::PointingHandCursor)); console->insertPlainText("Please place your fleet:\nRight click to toggle between horizontal and vertical ship alignment\nCarrier [5 boxes]\n"); labelStatus->setText(QString::fromUtf8("Click on your field to place ship horizontally")); statusbar->showMessage("Game started...", 700); round++; // next Round return; }
void Battleship::toggleAlignment() { if (alignment == h) { alignment = v; slotPlaySound("clonk.wav"); labelStatus->setText(QString::fromUtf8("Click on your field to place ship vertically")); statusbar->showMessage("Vertical ship alignment", 500); } else { alignment = h; slotPlaySound("clonk.wav"); labelStatus->setText(QString::fromUtf8("Click on your field to place ship horizontally")); statusbar->showMessage("Horizontal ship alignment", 500); } return; }
void Battleship::slotSetEwoMode(bool checked) { int col, row; if (checked) { for (row=0; row<10; row++) { for (col=0; col<10; col++) { enemyPlayer->field[row][col]->ewoMode=true; enemyPlayer->field[row][col]->updateColor(); } } statusbar->showMessage("EWO-Mode activated", 1000); slotPlaySound("easy.wav"); } else { for (row=0; row<10; row++) { for (col=0; col<10; col++) { enemyPlayer->field[row][col]->ewoMode=false; enemyPlayer->field[row][col]->updateColor(); } statusbar->showMessage("EWO-Mode deactivated", 1000); } } return; }
// Constructor Battleship::Battleship(QWidget *parent) : QMainWindow(parent) { QApplication::setStyle("plastique"); setupUi(this); gridLayoutHuman->sizePolicy().setHeightForWidth(true); gridLayoutEnemy->sizePolicy().setHeightForWidth(true); labelStatus = new QLabel(QString::fromUtf8("Press Ön to start the Game"), statusbar); statusbar->setSizeGripEnabled(true); statusbar->addWidget(labelStatus, 3); imageDialog = new ImageDialog(this); alignment = h; // set default alignment enemyPlayer = new AI(enemy, this); // Create players and their fields setupField(enemyPlayer); humanPlayer = new Human(human, this); setupField(humanPlayer); round = 0; // for first round gridLayoutHuman->installEventFilter(this); // EventFilter for right mouse button gridLayoutEnemy->setCursor(QCursor(Qt::ForbiddenCursor)); gridLayoutHuman->setCursor(QCursor(Qt::ForbiddenCursor)); // Buttons: connect(pushButtonEwo, SIGNAL(toggled(bool)), this, SLOT(slotSetEwoMode(bool))); connect(pushButtonStartGame, SIGNAL(clicked()), this, SLOT(slotStartGame())); // Place fleet & ships connect(this, SIGNAL(sigHumanPlaceShip(int, int, int)), humanPlayer, SLOT(slotPlaceShip(int, int, int))); connect(this, SIGNAL(sigPlaceFleet()), humanPlayer, SLOT(slotPlaceFleet())); connect(this, SIGNAL(sigPlaceFleet()), enemyPlayer, SLOT(slotPlaceFleet())); connect(humanPlayer, SIGNAL(sigFleetComplete()), this, SLOT(slotPlayerReady())); connect(enemyPlayer, SIGNAL(sigFleetComplete()), this, SLOT(slotPlayerReady())); // players get shot connect(this, SIGNAL(sigShotAtEnemy(int, int)), enemyPlayer, SLOT(slotShotAt(int, int))); connect(enemyPlayer, SIGNAL(sigShotAtHuman(int, int)), humanPlayer, SLOT(slotShotAt(int, int))); // toggle player turn connect(enemyPlayer, SIGNAL(sigDone(PlayerT)), this, SLOT(slotPlayerTurn(PlayerT))); connect(humanPlayer, SIGNAL(sigDone(PlayerT)), this, SLOT(slotPlayerTurn(PlayerT))); // AI shall shoot connect(this, SIGNAL(sigRequestShotFromEnemy()), enemyPlayer, SLOT(slotFire())); connect(humanPlayer, SIGNAL(sigEnemyTryAgain()), this, SLOT(slotRequestShotNow())); //Feedback of shots for AI connect(humanPlayer, SIGNAL(sigFireFeedback(int, int, ConditionT)), enemyPlayer, SLOT(slotFireFeedback(int, int, ConditionT))); // Game Over connect(enemyPlayer, SIGNAL(sigGameOver(PlayerT)), this, SLOT(slotGameOver(PlayerT))); connect(humanPlayer, SIGNAL(sigGameOver(PlayerT)), this, SLOT(slotGameOver(PlayerT))); // console output connect(humanPlayer, SIGNAL(sigPrint(QString)), this, SLOT(slotPrintToConsole(QString))); connect(enemyPlayer, SIGNAL(sigPrint(QString)), this, SLOT(slotPrintToConsole(QString))); //sound output connect(humanPlayer, SIGNAL(sigPlaySound(QString)), this, SLOT(slotPlaySound(QString))); connect(enemyPlayer, SIGNAL(sigPlaySound(QString)), this, SLOT(slotPlaySound(QString))); connect(humanPlayer, SIGNAL(sigPlayDelayedSound(QString, int)), this, SLOT(slotPlayDelayedSound(QString, int))); connect(enemyPlayer, SIGNAL(sigPlayDelayedSound(QString, int)), this, SLOT(slotPlayDelayedSound(QString, int))); // help menu -> display info infoDialog = new InfoDialog(this); connect(actionManual, SIGNAL(triggered()), infoDialog, SLOT(slotLoadTutorial())); connect(actionAbout, SIGNAL(triggered()), infoDialog, SLOT(slotLoadAbout())); connect(actionLicense, SIGNAL(triggered()), infoDialog, SLOT(slotLoadLicense())); //options menu connect(actionSound_on, SIGNAL(triggered()), this, SLOT(slotSoundOn())); if(QSound::isAvailable()) { soundAvailable = true; soundOn = true; slotPrintToConsole("Sound is availiable\n"); } else { soundAvailable = false; soundOn = false; slotPrintToConsole("Sound is not availiable\n"); } }
void Battleship::slotPlayDelayedSoundNow() { slotPlaySound(delayedSoundFile); }
ItemAction::ItemAction(QWidget * parent) : QWidget(parent) { QStringList itemList; comboBox1_ = new QComboBox(this); itemList /*<< tr("Move News to") << tr("Copy News to")*/ << tr("Mark News as Read") << tr("Add Star") << tr("Delete") << tr("Add Label") << tr("Play a Sound") << tr("Show News in Notifier"); comboBox1_->addItems(itemList); comboBox2_ = new QComboBox(this); comboBox2_->setVisible(false); soundPathEdit_ = new QLineEdit(this); selectionSound_ = new ToolButton(this); selectionSound_->setText("..."); selectionSound_->setToolTip(tr("Browse")); selectionSound_->setAutoRaise(true); playSound_ = new ToolButton(this); playSound_->setIcon(QIcon(":/images/play")); playSound_->setToolTip(tr("Play")); playSound_->setAutoRaise(true); QHBoxLayout *soundLayout = new QHBoxLayout(); soundLayout->setMargin(0); soundLayout->setSpacing(1); soundLayout->addWidget(soundPathEdit_, 1); soundLayout->addWidget(selectionSound_); soundLayout->addWidget(playSound_); soundWidget_ = new QWidget(this); soundWidget_->setLayout(soundLayout); soundWidget_->setVisible(false); colorButton_ = new ToolButton(this); colorButton_->setIconSize(QSize(16, 16)); colorButton_->setToolTip("#000000"); QPixmap pixmap(14, 14); pixmap.fill(QColor("#000000")); colorButton_->setIcon(pixmap); colorButton_->setVisible(false); addButton_ = new ToolButton(this); addButton_->setIcon(QIcon(":/images/addT")); addButton_->setToolTip(tr("Add Action")); addButton_->setAutoRaise(true); deleteButton_ = new ToolButton(this); deleteButton_->setIcon(QIcon(":/images/deleteT")); deleteButton_->setToolTip(tr("Delete Action")); deleteButton_->setAutoRaise(true); QHBoxLayout *buttonsLayout = new QHBoxLayout(); buttonsLayout->setAlignment(Qt::AlignCenter); buttonsLayout->setMargin(0); buttonsLayout->setSpacing(5); buttonsLayout->addWidget(comboBox1_); buttonsLayout->addWidget(comboBox2_); buttonsLayout->addWidget(soundWidget_, 1); buttonsLayout->addWidget(colorButton_); buttonsLayout->addStretch(); buttonsLayout->addWidget(addButton_); buttonsLayout->addWidget(deleteButton_); setLayout(buttonsLayout); connect(playSound_, SIGNAL(clicked()), this, SLOT(slotPlaySound())); connect(deleteButton_, SIGNAL(clicked()), this, SLOT(deleteFilterAction())); connect(comboBox1_, SIGNAL(currentIndexChanged(int)), this, SLOT(currentIndexChanged(int))); connect(selectionSound_, SIGNAL(clicked()), this, SLOT(selectionSound())); connect(colorButton_, SIGNAL(clicked()), this, SLOT(selectColorText())); }
UpdateFeeds::UpdateFeeds(QObject *parent, bool addFeed) : QObject(parent) , updateObject_(NULL) , requestFeed_(NULL) , parseObject_(NULL) , faviconObject_(NULL) , updateFeedThread_(NULL) , getFaviconThread_(NULL) , addFeed_(addFeed) , saveMemoryDBTimer_(NULL) { getFeedThread_ = new QThread(); getFeedThread_->setObjectName("getFeedThread_"); updateFeedThread_ = new QThread(); updateFeedThread_->setObjectName("updateFeedThread_"); Settings settings; int timeoutRequest = settings.value("Settings/timeoutRequest", 15).toInt(); int numberRequests = settings.value("Settings/numberRequest", 10).toInt(); int numberRepeats = settings.value("Settings/numberRepeats", 2).toInt(); requestFeed_ = new RequestFeed(timeoutRequest, numberRequests, numberRepeats); parseObject_ = new ParseObject(); if (addFeed_) { connect(parent, SIGNAL(signalRequestUrl(int,QString,QDateTime,QString)), requestFeed_, SLOT(requestUrl(int,QString,QDateTime,QString))); connect(requestFeed_, SIGNAL(getUrlDone(int,int,QString,QString,QByteArray,QDateTime,QString)), parent, SLOT(getUrlDone(int,int,QString,QString,QByteArray,QDateTime,QString))); connect(parent, SIGNAL(xmlReadyParse(QByteArray,int,QDateTime,QString)), parseObject_, SLOT(parseXml(QByteArray,int,QDateTime,QString))); connect(parseObject_, SIGNAL(signalFinishUpdate(int,bool,int,QString)), parent, SLOT(slotUpdateFeed(int,bool,int,QString))); } else { getFaviconThread_ = new QThread(); getFaviconThread_->setObjectName("getFaviconThread_"); updateObject_ = new UpdateObject(); faviconObject_ = new FaviconObject(); connect(updateObject_, SIGNAL(signalRequestUrl(int,QString,QDateTime,QString)), requestFeed_, SLOT(requestUrl(int,QString,QDateTime,QString))); connect(requestFeed_, SIGNAL(getUrlDone(int,int,QString,QString,QByteArray,QDateTime,QString)), updateObject_, SLOT(getUrlDone(int,int,QString,QString,QByteArray,QDateTime,QString))); connect(requestFeed_, SIGNAL(setStatusFeed(int,QString)), parent, SLOT(setStatusFeed(int,QString))); connect(parent, SIGNAL(signalStopUpdate()), requestFeed_, SLOT(stopRequest())); connect(parent, SIGNAL(signalGetFeedTimer(int)), updateObject_, SLOT(slotGetFeedTimer(int))); connect(parent, SIGNAL(signalGetAllFeedsTimer()), updateObject_, SLOT(slotGetAllFeedsTimer())); connect(parent, SIGNAL(signalGetAllFeeds()), updateObject_, SLOT(slotGetAllFeeds())); connect(parent, SIGNAL(signalGetFeed(int,QString,QDateTime,int)), updateObject_, SLOT(slotGetFeed(int,QString,QDateTime,int))); connect(parent, SIGNAL(signalGetFeedsFolder(QString)), updateObject_, SLOT(slotGetFeedsFolder(QString))); connect(parent, SIGNAL(signalImportFeeds(QByteArray)), updateObject_, SLOT(slotImportFeeds(QByteArray))); connect(updateObject_, SIGNAL(showProgressBar(int)), parent, SLOT(showProgressBar(int))); connect(updateObject_, SIGNAL(loadProgress(int)), parent, SLOT(slotSetValue(int))); connect(updateObject_, SIGNAL(signalMessageStatusBar(QString,int)), parent, SLOT(showMessageStatusBar(QString,int))); connect(updateObject_, SIGNAL(signalUpdateFeedsModel()), parent, SLOT(feedsModelReload()), Qt::BlockingQueuedConnection); connect(updateObject_, SIGNAL(xmlReadyParse(QByteArray,int,QDateTime,QString)), parseObject_, SLOT(parseXml(QByteArray,int,QDateTime,QString)), Qt::QueuedConnection); connect(parseObject_, SIGNAL(signalFinishUpdate(int,bool,int,QString)), updateObject_, SLOT(finishUpdate(int,bool,int,QString)), Qt::QueuedConnection); connect(updateObject_, SIGNAL(feedUpdated(int,bool,int,bool)), parent, SLOT(slotUpdateFeed(int,bool,int,bool))); connect(updateObject_, SIGNAL(setStatusFeed(int,QString)), parent, SLOT(setStatusFeed(int,QString))); qRegisterMetaType<FeedCountStruct>("FeedCountStruct"); connect(parseObject_, SIGNAL(feedCountsUpdate(FeedCountStruct)), parent, SLOT(slotFeedCountsUpdate(FeedCountStruct))); connect(parseObject_, SIGNAL(signalPlaySound(QString)), parent, SLOT(slotPlaySound(QString))); connect(parseObject_, SIGNAL(signalAddColorList(int,QString)), parent, SLOT(slotAddColorList(int,QString))); connect(parent, SIGNAL(signalNextUpdate(bool)), updateObject_, SLOT(slotNextUpdateFeed(bool))); connect(updateObject_, SIGNAL(signalUpdateModel(bool)), parent, SLOT(feedsModelReload(bool))); connect(updateObject_, SIGNAL(signalUpdateNews()), parent, SLOT(slotUpdateNews())); connect(updateObject_, SIGNAL(signalCountsStatusBar(int,int)), parent, SLOT(slotCountsStatusBar(int,int))); connect(parent, SIGNAL(signalRecountCategoryCounts()), updateObject_, SLOT(slotRecountCategoryCounts())); qRegisterMetaType<QList<int> >("QList<int>"); connect(updateObject_, SIGNAL(signalRecountCategoryCounts(QList<int>,QList<int>,QList<int>,QStringList)), parent, SLOT(slotRecountCategoryCounts(QList<int>,QList<int>,QList<int>,QStringList))); connect(parent, SIGNAL(signalRecountFeedCounts(int,bool)), updateObject_, SLOT(slotRecountFeedCounts(int,bool))); connect(updateObject_, SIGNAL(feedCountsUpdate(FeedCountStruct)), parent, SLOT(slotFeedCountsUpdate(FeedCountStruct))); connect(updateObject_, SIGNAL(signalFeedsViewportUpdate()), parent, SLOT(slotFeedsViewportUpdate())); connect(parent, SIGNAL(signalSetFeedRead(int,int,int,QList<int>)), updateObject_, SLOT(slotSetFeedRead(int,int,int,QList<int>))); connect(parent, SIGNAL(signalMarkFeedRead(int,bool,bool)), updateObject_, SLOT(slotMarkFeedRead(int,bool,bool))); connect(parent, SIGNAL(signalRefreshInfoTray()), updateObject_, SLOT(slotRefreshInfoTray())); connect(updateObject_, SIGNAL(signalRefreshInfoTray(int,int)), parent, SLOT(slotRefreshInfoTray(int,int))); connect(parent, SIGNAL(signalUpdateStatus(int,bool)), updateObject_, SLOT(slotUpdateStatus(int,bool))); connect(parent, SIGNAL(signalMarkAllFeedsRead()), updateObject_, SLOT(slotMarkAllFeedsRead())); connect(parent, SIGNAL(signalMarkReadCategory(int,int)), updateObject_, SLOT(slotMarkReadCategory(int,int))); connect(parent, SIGNAL(signalRefreshNewsView(int)), updateObject_, SIGNAL(signalMarkAllFeedsRead(int))); connect(updateObject_, SIGNAL(signalMarkAllFeedsRead(int)), parent, SLOT(slotRefreshNewsView(int))); connect(parent, SIGNAL(signalMarkAllFeedsOld()), updateObject_, SLOT(slotMarkAllFeedsOld())); connect(parent, SIGNAL(signalSetFeedsFilter(bool)), updateObject_, SIGNAL(signalSetFeedsFilter(bool))); connect(updateObject_, SIGNAL(signalSetFeedsFilter(bool)), parent, SLOT(setFeedsFilter(bool))); connect(mainApp, SIGNAL(signalSqlQueryExec(QString)), updateObject_, SLOT(slotSqlQueryExec(QString))); connect(mainApp, SIGNAL(signalRunUserFilter(int, int)), parseObject_, SLOT(runUserFilter(int, int))); // faviconObject_ connect(parent, SIGNAL(faviconRequestUrl(QString,QString)), faviconObject_, SLOT(requestUrl(QString,QString))); connect(faviconObject_, SIGNAL(signalIconRecived(QString,QByteArray,QString)), parent, SLOT(slotIconFeedPreparing(QString,QByteArray,QString))); connect(parent, SIGNAL(signalIconFeedReady(QString,QByteArray)), updateObject_, SLOT(slotIconSave(QString,QByteArray))); connect(updateObject_, SIGNAL(signalIconUpdate(int,QByteArray)), parent, SLOT(slotIconFeedUpdate(int,QByteArray))); updateObject_->moveToThread(updateFeedThread_); faviconObject_->moveToThread(getFaviconThread_); getFaviconThread_->start(QThread::LowPriority); startSaveTimer(); } requestFeed_->moveToThread(getFeedThread_); parseObject_->moveToThread(updateFeedThread_); getFeedThread_->start(QThread::LowPriority); updateFeedThread_->start(QThread::LowPriority); }