void PokeSelection::setNum(const Pokemon::uniqueId &num) { if (m_num == num) { return; } m_num = num; ui->pokeEdit->setText(PokemonInfo::Name(num)); ui->pokemonList->setCurrentIndex(proxy->mapFromSource(sourceModel->index(num.pokenum, 1))); ui->pokemonList->scrollTo(ui->pokemonList->currentIndex()); ui->baseStats->setNum(num); if (PokemonInfo::HasFormes(num) && PokemonInfo::AFormesShown(num)) { QMenu *m = new QMenu(ui->altForme); QList<Pokemon::uniqueId> formes = PokemonInfo::Formes(num, getGen()); QSignalMapper *mapper = new QSignalMapper(m); foreach(Pokemon::uniqueId forme, formes) { QAction *ac = m->addAction(PokemonInfo::Name(forme), mapper, SLOT(map())); ac->setCheckable(true); if (forme == num) { ac->setChecked(true); } mapper->setMapping(ac, forme.toPokeRef()); }
PokeSelection::PokeSelection(Pokemon::uniqueId pokemon, QAbstractItemModel *pokemonModel) : ui(new Ui::PokeSelection), search(NULL), newwidth(0) { ui->setupUi(this); QSortFilterProxyModel *proxy = new QSortFilterProxyModel(this); proxy->setFilterRegExp("."); proxy->setSourceModel(pokemonModel); this->sourceModel = pokemonModel; this->proxy = proxy; ui->pokemonList->setModel(proxy); QCompleter *completer = new QCompleter(proxy, ui->pokeEdit); completer->setCompletionColumn(1); completer->setCompletionRole(Qt::DisplayRole); completer->setCaseSensitivity(Qt::CaseInsensitive); completer->setCompletionMode(QCompleter::PopupCompletion); ui->pokeEdit->setCompleter(completer); setNum(pokemon); ui->pokemonList->setCurrentIndex(pokemonModel->index(pokemon.pokenum, 1)); ui->pokemonList->scrollTo(ui->pokemonList->currentIndex()); updateSprite(); updateTypes(); if (getGen() <= 1) { ui->shiny->hide(); } else { ui->shiny->show(); } ui->baseStats->setGen(getGen()); connect(completer, SIGNAL(activated(QModelIndex)), SLOT(setPokemon(QModelIndex))); connect(ui->shiny, SIGNAL(toggled(bool)), SLOT(updateSprite())); connect(ui->pokemonList, SIGNAL(pokemonSelected(Pokemon::uniqueId)), SLOT(setNum(Pokemon::uniqueId))); connect(ui->pokemonList, SIGNAL(pokemonSelected(Pokemon::uniqueId)), SLOT(updateSprite())); connect(ui->pokemonList, SIGNAL(pokemonSelected(Pokemon::uniqueId)), SLOT(updateTypes())); connect(ui->pokemonList, SIGNAL(pokemonActivated(Pokemon::uniqueId)), SLOT(finish())); connect(ui->changeSpecies, SIGNAL(clicked()), SLOT(finish())); connect(ui->pokemonFrame, SIGNAL(clicked()), SLOT(toggleSearchWindow())); }
Real Gaussian_<Real>::next() const { // The standard Box-Muller transformation is performed, // producing two independent normally-distributed random deviates. // One is returned, the other is discarded. // choose a pair of uniformly distributed deviates, one for the // distance and one for the angle, and perform transformations Double dist = Alge_d::sqrt( -2 * Alge_d::log(Uniform::nextStd(getGen())) ); Double angle = 2 * Double_::pi * Uniform::nextStd(getGen()); // the first deviate, not used //Double deviate = dist*Trig_d::cos(angle); // return second deviate Double deviate = dist*Trig_d::sin(angle); return deviate*sigma + mu; }
void PokeSelection::toggleSearchWindow() { if (search) { QGridLayout *gl = (QGridLayout*)layout(); gl->removeWidget(search); search->deleteLater(); search = NULL; setFixedWidth(oldwidth); move(oldx, y()); } else { //Tricks to get a window at the correct size. Qt is annoying, not allowing resize() to work //properly on windows, i have to use setFixedWidth on the top level window :( oldwidth = width(); oldx = x(); QGridLayout *gl = (QGridLayout*)layout(); search = new AdvancedSearch(this); search->setGen(getGen()); ui->pokemonList->setFixedWidth(ui->pokemonList->width()); ui->pokeEdit->setFixedWidth(ui->pokeEdit->width()); ui->changeSpecies->setFixedWidth(ui->changeSpecies->width()); search->setResultsWidth(ui->pokemonList->width()); if (newwidth) { setFixedWidth(newwidth); } gl->addWidget(search, 0, 4, gl->rowCount(), 1); search->show(); if (newwidth == 0) { newwidth = width(); } connect(search, SIGNAL(pokemonSelected(Pokemon::uniqueId)), SLOT(setNum(Pokemon::uniqueId))); /* Moving the widget if it goes out of bounds */ QWidget *top = ((QWidget*)parent())->window(); if (x() + width() > top->x() + top->width()) { move(std::max(top->x(), top->x()+(top->width()-width())/2), y()); } } }