void BAMseek::setupFileMenu(){ QMenu *fileMenu = new QMenu(tr("&File"), this); menuBar()->addMenu(fileMenu); QAction *openAction = fileMenu->addAction(tr("&Open...")); openAction->setShortcuts(QKeySequence::Open); connect(openAction, SIGNAL(triggered()), this, SLOT(openFile())); QAction *dockAction = fileMenu->addAction(tr("&Dock/Undock Header")); dockAction->setShortcuts(QKeySequence::AddTab); connect(dockAction, SIGNAL(triggered()), this, SLOT(dockHeader())); QAction *copyAction = fileMenu->addAction(tr("&Copy Selected Cells")); copyAction->setShortcuts(QKeySequence::Copy); connect(copyAction, SIGNAL(triggered()), this, SLOT(copyCells())); }
int main(short int argc, char** argv) { al_init(); al_install_keyboard(); al_install_mouse(); al_init_image_addon(); al_init_font_addon(); al_init_ttf_addon(); ALLEGRO_MONITOR_INFO oMonitorInfo; al_get_monitor_info(0, &oMonitorInfo); short int iDisplayWidth = oMonitorInfo.x2 * 0.70f; short int iDisplayHeight = oMonitorInfo.y2 * 0.70f; short int iAppWidth = iDisplayWidth * 0.95f; short int iAppHeight = iDisplayHeight * 0.95f; short int iMarginHorizontal = (iDisplayWidth - iAppWidth) / 2; short int iMarginVertical = ((iDisplayHeight - iAppHeight) / 2); int iGenerations = 0; short int iFPS = 30; float iLifeMin = 3.0f; float iLifeMax = 37.0f; short int iFontSize = (iDisplayWidth > 1024) ? 12 : 10; if (iDisplayWidth < 800) { iFontSize = 8; } long int iSimulations = 1; std::random_device rd; std::mt19937 mt(rd()); std::uniform_real_distribution<double> dist(iLifeMin, iLifeMax); int iLifeScarcity = std::round(dist(mt)); bool** pCells = new bool*[iAppWidth]; bool** pNextGenCells = new bool*[iAppWidth]; initCells(pCells, pNextGenCells, iAppWidth, iAppHeight, iLifeScarcity); ALLEGRO_DISPLAY* pDisplay = al_create_display(iDisplayWidth, iDisplayHeight); ALLEGRO_EVENT_QUEUE* pQueue = al_create_event_queue(); ALLEGRO_TIMER* pTimer = al_create_timer(1.0f / iFPS); ALLEGRO_TIMER* pSecondBySecondTimer = al_create_timer(1.0f); ALLEGRO_BITMAP* pBuffer = al_create_bitmap(iAppWidth, iAppHeight); ALLEGRO_COLOR oBackgroundColor = al_map_rgb(0, 0, 0); ALLEGRO_COLOR oCellColor = al_map_rgb(randr(150, 255), randr(150, 255), randr(150, 255)); ALLEGRO_FONT* oFont = al_load_ttf_font("VeraMono.ttf", iFontSize, 0); ALLEGRO_FONT* oFontLarge = al_load_ttf_font("VeraMono.ttf", (iFontSize * 3), 0); al_inhibit_screensaver(true); al_register_event_source(pQueue, al_get_keyboard_event_source()); al_register_event_source(pQueue, al_get_mouse_event_source()); al_register_event_source(pQueue, al_get_timer_event_source(pTimer)); al_register_event_source(pQueue, al_get_timer_event_source(pSecondBySecondTimer)); al_set_target_backbuffer(pDisplay); al_clear_to_color(oBackgroundColor); al_flip_display(); al_start_timer(pTimer); al_start_timer(pSecondBySecondTimer); ALLEGRO_EVENT oEvent; short int iBufferUsed = 0; short int iBufferDrawn = 0; bool bRedraw = false; std::string sHeaderStatistics = "GEN [GENXXXXX] FPS [FPSXXXXX] CELLS [CELLSXXXXX] GENS/S [GENSSXXXXX] SCARCTY [SCARXXXXX] TIME [TIMEXXXXX]"; std::string sHeaderStats = ""; /* std::string sHeaderText_2 = ""; std::string sHeaderText_3 = ""; std::string sHeaderText_4 = ""; std::string sHeaderText_5 = ""; std::string sHeaderText_6 = ""; */ std::string sCountdownText = ""; std::string sSimulations = ""; std::string sStats = "CELLS: "; sStats.append(std::to_string((iAppWidth * iAppHeight))); sStats.append(", MAP SIZE (KB): "); sStats.append(std::to_string((iAppWidth * iAppHeight * sizeof(bool)) / 1024)); sStats.append(" (SPACE) Pause (C)olor, (R)eload, (S)carcity, (F) +1 FPS, (G) -1 FPS, (ESC) Exit"); long int iTotalAlive = 0; int iPatternStableBuffer = (iFPS * 4); long int* iTotalPatternStable = new long int[iPatternStableBuffer]; short int iTotalPatternCounter = 0; long int iSecondsRunning = 0; float fPosText2 = (iAppWidth * 0.15); float fPosText3 = (iAppWidth * 0.30); float fPosText4 = (iAppWidth * 0.50); float fPosText5 = (iAppWidth * 0.70); float fPosText6 = (iAppWidth * 0.85); float fPosTextSim = (iAppWidth * 0.75); bool bPatternIsStable = false; int iCountdownSeconds = 10; bool bDrawingOn = false; bool bTimerStopped = false; ALLEGRO_COLOR oRandColor = al_map_rgb(randr(0, 255), randr(0, 255), randr(0, 255)); while (true) { al_wait_for_event(pQueue, &oEvent); if (oEvent.type == ALLEGRO_EVENT_TIMER) { if (!bTimerStopped) { if (oEvent.timer.source == pTimer) { iTotalAlive = 0; redrawCells(pBuffer, pCells, pNextGenCells, iAppWidth, iAppHeight, oCellColor, oBackgroundColor); nextGeneration(pCells, pNextGenCells, iAppWidth, iAppHeight, iTotalAlive); al_set_target_backbuffer(pDisplay); al_clear_to_color(oBackgroundColor); al_draw_bitmap(pBuffer, iMarginHorizontal, iMarginVertical, 0); sHeaderStats = ReplaceString(sHeaderStatistics, "[GENXXXXX]", std::to_string(iGenerations)); sHeaderStats = ReplaceString(sHeaderStats, "[FPSXXXXX]", std::to_string(iFPS)); sHeaderStats = ReplaceString(sHeaderStats, "[CELLSXXXXX]", std::to_string(iTotalAlive)); sHeaderStats = ReplaceString(sHeaderStats, "[SCARXXXXX]", std::to_string(iLifeScarcity)); sHeaderStats = ReplaceString(sHeaderStats, "[TIMEXXXXX]", std::to_string(iSecondsRunning)); if (iGenerations > 0 && iSecondsRunning > 0) { sHeaderStats = ReplaceString(sHeaderStats, "[GENSSXXXXX]", std::to_string(iGenerations / iSecondsRunning)); } else { sHeaderStats = ReplaceString(sHeaderStats, "[GENSSXXXXX]", "0"); } sSimulations = "SIMS "; sSimulations.append(std::to_string(iSimulations)); int iLengthSims = al_get_text_width(oFont, sSimulations.c_str()); int iLengthStats = al_get_text_width(oFont, sHeaderStats.c_str()); al_draw_text(oFont, oCellColor, ((iAppWidth - iLengthStats) / 2), 1.0f, 0, sHeaderStats.c_str()); al_draw_text(oFont, oCellColor, (iDisplayWidth - (iLengthSims + 25.0f)), (iAppHeight + iMarginVertical + 5.0f), 0, sSimulations.c_str()); al_draw_text(oFont, oCellColor, 25.0f, (iAppHeight + iMarginVertical + 5.0f), 0, sStats.c_str()); if (bPatternIsStable == true) { sCountdownText.clear(); sCountdownText.append("PATTERN STABILIZED, RESTARTING IN... "); int iLengthStr = al_get_text_width(oFontLarge, sCountdownText.c_str()); sCountdownText.append(std::to_string(iCountdownSeconds)); al_draw_text(oFontLarge, oRandColor, ((iAppWidth - iLengthStr) / 2), (iAppHeight * 0.45f), 0, sCountdownText.c_str()); } al_flip_display(); ++iGenerations; copyCells(pCells, pNextGenCells, iAppWidth, iAppHeight); if (iTotalPatternCounter == iPatternStableBuffer) { bPatternIsStable = isPatternStable(iTotalPatternStable, iPatternStableBuffer); delete iTotalPatternStable; iTotalPatternStable = new long int[iPatternStableBuffer]; iTotalPatternCounter = 0; } iTotalPatternStable[iTotalPatternCounter] = iTotalAlive; ++iTotalPatternCounter; } if (oEvent.timer.source == pSecondBySecondTimer) { if (bPatternIsStable == true) { if (iCountdownSeconds > 1) { --iCountdownSeconds; } else { bPatternIsStable = false; iTotalPatternCounter = 0; iGenerations = 0; iSecondsRunning = 0; iCountdownSeconds = 10; ++iSimulations; clearCells(pCells, pNextGenCells, iAppWidth, iAppHeight); randomCells(pCells, iAppWidth, iAppHeight, iLifeScarcity); } } else { iCountdownSeconds = 10; } ++iSecondsRunning; oRandColor = al_map_rgb(randr(0, 255), randr(0, 255), randr(0, 255)); } } } if (oEvent.type == ALLEGRO_EVENT_KEY_DOWN) { if (oEvent.keyboard.keycode == ALLEGRO_KEY_ESCAPE) { break; } if (oEvent.keyboard.keycode == ALLEGRO_KEY_SPACE) { if (!bTimerStopped) { bTimerStopped = true; al_stop_timer(pTimer); } else { bTimerStopped = false; al_start_timer(pTimer); } } if (oEvent.keyboard.keycode == ALLEGRO_KEY_R) { bPatternIsStable = false; iTotalPatternCounter = 0; iGenerations = 0; iSecondsRunning = 0; iCountdownSeconds = 10; ++iSimulations; clearCells(pCells, pNextGenCells, iAppWidth, iAppHeight); randomCells(pCells, iAppWidth, iAppHeight, iLifeScarcity); } if (oEvent.keyboard.keycode == ALLEGRO_KEY_S) { bPatternIsStable = false; iTotalPatternCounter = 0; iGenerations = 0; iSecondsRunning = 0; iCountdownSeconds = 10; iLifeScarcity = randr(iLifeMin, iLifeMax); ++iSimulations; clearCells(pCells, pNextGenCells, iAppWidth, iAppHeight); randomCells(pCells, iAppWidth, iAppHeight, iLifeScarcity); } if (oEvent.keyboard.keycode == ALLEGRO_KEY_M) { bPatternIsStable = false; iTotalPatternCounter = 0; iGenerations = 0; iSecondsRunning = 0; iCountdownSeconds = 10; iLifeScarcity = iLifeMin; ++iSimulations; clearCells(pCells, pNextGenCells, iAppWidth, iAppHeight); randomCells(pCells, iAppWidth, iAppHeight, iLifeScarcity); } if (oEvent.keyboard.keycode == ALLEGRO_KEY_N) { bPatternIsStable = false; iTotalPatternCounter = 0; iGenerations = 0; iSecondsRunning = 0; iCountdownSeconds = 10; iLifeScarcity = iLifeMax; ++iSimulations; clearCells(pCells, pNextGenCells, iAppWidth, iAppHeight); randomCells(pCells, iAppWidth, iAppHeight, iLifeScarcity); } if (oEvent.keyboard.keycode == ALLEGRO_KEY_F) { ++iFPS; al_set_timer_speed(pTimer, (1.0f / iFPS)); } if (oEvent.keyboard.keycode == ALLEGRO_KEY_G) { if(iFPS > 3) { --iFPS; } al_set_timer_speed(pTimer, (1.0f / iFPS)); } if (oEvent.keyboard.keycode == ALLEGRO_KEY_C) { int iRCell = randr(0, 255); int iGCell = randr(0, 255); int iBCell = randr(0, 255); oCellColor = al_map_rgb(iRCell, iGCell, iBCell); } } } // End main loop al_destroy_event_queue(pQueue); al_destroy_display(pDisplay); delete iTotalPatternStable; for (short int i = 0; i < iAppWidth; i++) { delete pCells[i]; delete pNextGenCells[i]; } delete[] pCells; delete[] pNextGenCells; return 0; }
void TableWidget::contextMenu(const QPoint &p, bool init ){ /* QModelIndex index = this->indexAt(p); int col = index.column(); //int row = index.row(); QString str = "file"; ColumnType t = ORIGIN; if(col==TRACK || col==TITLE){ str = "result"; t = RESULT; } */ QMenu *c = new QMenu(this); QAction* selectAction = new QAction("Check selected rows", this); selectAction->setData(true); connect(selectAction, SIGNAL(triggered()), this, SLOT(checkRows())); QAction* deselectAction = new QAction("Uncheck selected rows", this); deselectAction->setData(false); connect(deselectAction, SIGNAL(triggered()), this, SLOT(checkRows())); //move up/down actions for this QAction* moveResultUpAction = new QAction("Move result up", this); moveResultUpAction->setData(RESULT); moveResultUpAction->setShortcut(tr("Ctrl+U")); connect(moveResultUpAction, SIGNAL(triggered()), this, SLOT(moveRowUp())); QAction* moveResultDownAction = new QAction("Move result down", this); moveResultDownAction->setData(RESULT); moveResultDownAction->setShortcut(tr("Ctrl+D")); connect(moveResultDownAction, SIGNAL(triggered()), this, SLOT(moveRowDown())); QAction* moveResultToAction = new QAction("Move result to...", this); moveResultToAction->setData(RESULT); moveResultToAction->setShortcut(tr("Ctrl+T")); connect(moveResultToAction, SIGNAL(triggered()), this, SLOT(moveRowTo())); QAction* moveOriginUpAction = new QAction("Move file up", this); moveOriginUpAction->setData(ORIGIN); moveOriginUpAction->setShortcut(tr("Ctrl+Alt+U")); connect(moveOriginUpAction, SIGNAL(triggered()), this, SLOT(moveRowUp())); QAction* moveOriginDownAction = new QAction("Move file down", this); moveOriginDownAction->setData(ORIGIN); moveOriginDownAction->setShortcut(tr("Ctrl+Alt+D")); connect(moveOriginDownAction, SIGNAL(triggered()), this, SLOT(moveRowDown())); QAction* moveOriginToAction = new QAction("Move file to...", this); moveOriginToAction->setData(ORIGIN); moveOriginToAction->setShortcut(tr("Ctrl+Alt+T")); connect(moveOriginToAction, SIGNAL(triggered()), this, SLOT(moveRowTo())); QAction* sortEnabledAction = new QAction(tr("Sorting enabled"), this); sortEnabledAction->setCheckable(true); sortEnabledAction->setChecked( this->isSortingEnabled() ); connect(sortEnabledAction, SIGNAL(toggled(bool)), this, SLOT(enableSorting(bool))); resizeColumnAction->setShortcut(tr("Ctrl+R")); connect(resizeColumnAction, SIGNAL(toggled(bool)), this, SLOT(resizeColumns(bool))); connect(resizeRowAction, SIGNAL(toggled(bool)), this, SLOT(resizeRows(bool))); QAction* deleteAction = new QAction(tr("Delete selected cells"), this); deleteAction->setShortcut(tr("Ctrl+Del")); connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteCells())); QAction* insertBlankFileAction = new QAction("Insert empty file", this); insertBlankFileAction->setData(ORIGIN); connect(insertBlankFileAction, SIGNAL(triggered()), this, SLOT(insertBlankRow())); QAction* insertBlankResultAction = new QAction("Insert empty result", this); insertBlankResultAction->setData(RESULT); connect(insertBlankResultAction, SIGNAL(triggered()), this, SLOT(insertBlankRow())); QAction* copyAction = new QAction(tr("Copy"), this); copyAction->setShortcut(tr("Ctrl+C")); connect(copyAction, SIGNAL(triggered()), this, SLOT(copyCells())); QAction* pasteAction = new QAction(tr("Paste"), this); pasteAction->setShortcut(tr("Ctrl+V")); connect(pasteAction, SIGNAL(triggered()), this, SLOT(paste())); QAction* resetAction = new QAction(tr("Reset"), this); connect(resetAction, SIGNAL(triggered()), this, SLOT(resetTable())); QMenu* matchByMenu = new QMenu(tr("Match results by..."), this); connect(matchByTrackAction, SIGNAL(triggered(bool)), this, SLOT(matchBy(bool))); connect(matchByTitleAction, SIGNAL(triggered(bool)), this, SLOT(matchBy(bool))); connect(dontMatchAction, SIGNAL(triggered(bool)), this, SLOT(matchBy(bool))); connect(matchByTrackTitleAction, SIGNAL(triggered(bool)), this, SLOT(matchBy(bool))); connect(matchByTitleTrackAction, SIGNAL(triggered(bool)), this, SLOT(matchBy(bool))); connect(matchByFileNameAction, SIGNAL(triggered(bool)), this, SLOT(matchBy(bool))); matchByMenu->addAction( dontMatchAction ); matchByMenu->addAction( matchByTitleAction ); matchByMenu->addAction( matchByTrackAction ); matchByMenu->addAction( matchByTrackTitleAction ); matchByMenu->addAction( matchByTitleTrackAction ); matchByMenu->addAction( matchByFileNameAction ); c->addMenu(matchByMenu); c->addSeparator(); //if(col==FILE_NAME){ c->addAction(deselectAction); c->addAction(selectAction); c->addSeparator(); //} c->addAction(moveResultUpAction); c->addAction(moveResultDownAction); c->addAction(moveResultToAction); c->addAction(moveOriginUpAction); c->addAction(moveOriginDownAction); c->addAction(moveOriginToAction); c->addSeparator(); c->addAction(resizeColumnAction); c->addAction(resizeRowAction); c->addAction(sortEnabledAction); c->addSeparator(); c->addAction(copyAction); c->addAction(pasteAction); c->addAction(deleteAction); c->addSeparator(); c->addAction(insertBlankFileAction); c->addAction(insertBlankResultAction); c->addSeparator(); c->addAction(resetAction); QPoint globalPos = this->mapToGlobal(p); //menu->exec( globalPos ); if(!init){ c->exec(globalPos); }else{ this->addAction( dontMatchAction ); this->addAction( matchByTitleAction ); this->addAction( matchByTrackAction ); this->addAction( matchByTrackTitleAction ); this->addAction( matchByTitleTrackAction ); this->addAction( matchByFileNameAction ); this->addAction(deselectAction); this->addAction(selectAction); this->addAction(moveResultUpAction); this->addAction(moveResultDownAction); this->addAction(moveResultToAction); this->addAction(moveOriginUpAction); this->addAction(moveOriginDownAction); this->addAction(moveOriginToAction); this->addAction(resizeColumnAction); this->addAction(resizeRowAction); this->addAction(sortEnabledAction); this->addAction(copyAction); this->addAction(pasteAction); this->addAction(deleteAction); this->addAction(insertBlankFileAction); this->addAction(insertBlankResultAction); } }