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()));
}
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());
        }
    }
}
Beispiel #3
0
void TB_PokeChoice::selectedCell(const QModelIndex &index)
{
    int num = model()->data(index, CustomModel::PokenumRole).toInt();

    emit pokemonSelected(Pokemon::uniqueId(num, 0));
}