AnimePanel::AnimePanel(QWidget *parent, Anime *anime, int score_type) : QDialog(parent), ui(new Ui::AnimePanel) { qDebug() << "Loading anime panel for anime" << anime->getTitle(); ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); this->anime = anime; this->score_type = score_type; QString airing_status = anime->getAiringStatus(); if (!airing_status.isEmpty()) { airing_status = airing_status.at(0).toUpper() + airing_status.right(airing_status.length() - 1); } QString score = anime->getMyScore(); if ((score_type == 0) || (score_type == 1)) { QSpinBox *score_container = new QSpinBox(this); score_container->setMaximum(score_type == 0 ? 10 : score_type == 1 ? 100 : 5); score_container->setMinimum(score_type == 2 ? 1 : 0); score_container->setValue(score.split(" ").at(0).toInt()); ui->myDetailForm->setWidget(2, QFormLayout::FieldRole, score_container); score_widget = score_container; } else if (score_type == 2) { QComboBox *score_container = new QComboBox(this); score_container->addItem("0 ★"); score_container->addItem("1 ★"); score_container->addItem("2 ★"); score_container->addItem("3 ★"); score_container->addItem("4 ★"); score_container->addItem("5 ★"); score_container->setCurrentText(score); ui->myDetailForm->setWidget(2, QFormLayout::FieldRole, score_container); score_widget = score_container; } else if (score_type == 3) { QComboBox *score_container = new QComboBox(this); score_container->addItem(""); score_container->addItem(":("); score_container->addItem(":|"); score_container->addItem(":)"); score_container->setCurrentText(score); ui->myDetailForm->setWidget(2, QFormLayout::FieldRole, score_container); score_widget = score_container; } else { QDoubleSpinBox *score_container = new QDoubleSpinBox(this); score_container->setMaximum(10.0); score_container->setMinimum(0); score_container->setDecimals(1); score_container->setSingleStep(0.1); score_container->setValue(score.toDouble()); ui->myDetailForm->setWidget(2, QFormLayout::FieldRole, score_container); score_widget = score_container; } ui->lblTitle->setText(anime->getTitle()); ui->txtType->setText(anime->getType()); ui->txtEpisodes->setText(QString::number(anime->getEpisodeCount())); ui->txtScore->setText(anime->getAverageScore()); ui->txtAiring->setText(airing_status); int max_ep = anime->getEpisodeCount(); if (max_ep == 0) max_ep = std::numeric_limits<int>::max(); ui->spinEps->setMaximum(max_ep); ui->spinEps->setValue(anime->getMyProgress()); ui->txtNotes->setText(anime->getMyNotes()); ui->spinRewatch->setValue(anime->getMyRewatch()); QString my_status = anime->getMyStatus(); if (User::sharedUser()->getAnimeList().contains(anime)) { my_status = my_status.at(0).toUpper() + my_status.right(my_status.length() - 1); new_entry = false; } else { new_entry = true; } if (my_status == "Plan to watch") my_status = "Plan to Watch"; ui->comboStatus->setCurrentText(my_status); if (anime->needsLoad() || anime->needsCover()) { connect(anime, SIGNAL(finishedReloading()), SLOT(refreshDisplay())); connect(anime, SIGNAL(new_image()), SLOT(update())); if (anime->needsCover()) User::sharedUser()->loadAnimeData(anime, true); else User::sharedUser()->loadAnimeData(anime, false); } else { refreshDisplay(); } }
void MainWindow::loadBrowserData() { QUrl url = API::sharedAPI()->sharedAniListAPI()->API_BROWSE; QString season = ui->comboSeason->currentText(); QString year = ui->comboYear->currentText(); QString type = ui->comboType->currentText(); QString status = ui->comboStatus->currentText(); // Clear the browser view QLayoutItem *item; while ((item = layout2->takeAt(0))) { delete item->widget(); delete item; } if (!season.isEmpty()) { url = addQuery(url, "season", season); } if (!year.isEmpty()) { url = addQuery(url, "year", year); } if (!type.isEmpty()) { url = addQuery(url, "type", type); } if (!status.isEmpty()) { url = addQuery(url, "status", status); } QStringList genres; QStringList exclude; for (int i = 0; i < ui->genreList->count(); i++) { QCheckBox *w = static_cast<QCheckBox *> (dynamic_cast<QWidgetItem *>(ui->genreList->itemAt(i))->widget()); if (w->checkState() == Qt::PartiallyChecked) { exclude.append(w->text()); } else if (w->checkState() == Qt::Checked) { genres.append(w->text()); } } if (!genres.isEmpty()) { url = addQuery(url, "genres", genres.join(",")); } if (!exclude.isEmpty()) { url = addQuery(url, "genres_exclude", exclude.join(",")); } // Load the results for the requested type QJsonArray browse_results = API::sharedAPI()->sharedAniListAPI()->get(url).array(); for (int i = 0; i <= browse_results.size(); i++) { QJsonObject anime = browse_results.at(i).toObject(); Anime *a = User::sharedUser()->getAnimeByTitle( anime.value("title_romaji").toString()); if (a == 0) { a = new Anime(); a->setID(QString::number(anime.value("id").toInt())); a->setMyProgress(0); a->setMyNotes(""); a->setMyRewatch(0); a->setMyStatus(""); if (a->getID() == "0") { delete a; continue; } } BrowseAnime *s = new BrowseAnime(this, User::sharedUser()->scoreType()); if (a->needsLoad() || a->needsCover()) { User::sharedUser()->loadAnimeData(a, true); QEventLoop evt; connect(a, SIGNAL(finishedReloading()), &evt, SLOT(quit())); evt.exec(); } s->setAnime(a); layout2->addWidget(s); // Do we need to keep loading? if (season != ui->comboSeason->currentText() || year != ui->comboYear->currentText() || type != ui->comboType->currentText() || status != ui->comboStatus->currentText()) { return; } int width = layout2->geometry().width(); int cwidth = layout2->contentsWidth(); if (cwidth < 0) { width = this->width() - 2; cwidth = this->width() - (this->width() % 200); } layout2->setContentsMargins((width-cwidth)/2, 0, 0, 0); } }
void Anime::finishReload() { emit finishedReloading(); needLoad = false; }