forked from MrBesen/lolautoaccept
108 lines
2.7 KiB
C++
108 lines
2.7 KiB
C++
#include "stagesettings.h"
|
|
#include "ui_stagesettings.h"
|
|
|
|
#include <QLocale>
|
|
|
|
#include <Log.h>
|
|
|
|
StageSettings::StageSettings(QWidget *parent) : QWidget(parent), ui(new Ui::StageSettings) {
|
|
ui->setupUi(this);
|
|
setMinimumSize(ui->gridLayout->minimumSize());
|
|
|
|
rescaleImage();
|
|
}
|
|
|
|
StageSettings::~StageSettings() {
|
|
delete ui;
|
|
}
|
|
|
|
QString StageSettings::getName() const {
|
|
return ui->groupBox->title();
|
|
}
|
|
|
|
void StageSettings::setName(const QString& n) {
|
|
ui->groupBox->setTitle(n);
|
|
ui->checkBox->setText(tr("Enable %1").arg(n));
|
|
}
|
|
|
|
bool StageSettings::getState() const {
|
|
return ui->checkBox->checkState() == Qt::CheckState::Checked;
|
|
}
|
|
|
|
void StageSettings::setState(bool b) {
|
|
ui->checkBox->setCheckState(b ? Qt::CheckState::Checked : Qt::CheckState::Unchecked);
|
|
emit toggled(b);
|
|
}
|
|
|
|
QString StageSettings::getChampion() const {
|
|
return ""; // ui->lineEdit->text();
|
|
}
|
|
|
|
void StageSettings::setChampion(const QString& str) {
|
|
// ui->lineEdit->setText(str);
|
|
championChangedinternal(str);
|
|
}
|
|
|
|
void StageSettings::setDataDragon(DataDragon* dd_) {
|
|
dd = dd_;
|
|
}
|
|
|
|
void StageSettings::resizeEvent([[maybe_unused]] QResizeEvent* event) {
|
|
rescaleImage();
|
|
}
|
|
|
|
void StageSettings::championChangedinternal(const QString& str) {
|
|
if(dd) {
|
|
int count = 0;
|
|
const DataDragon::ChampData& cd = dd->getBestMatchingChamp(str.toStdString(), &count);
|
|
if(cd.key != currentdisplayedChampKey) {
|
|
applyChampion(cd);
|
|
}
|
|
//ui->champcount->setText(tr("Champions matched: %1").arg(QString::fromStdString(std::to_string(count))));
|
|
} else {
|
|
emit championChanged(str);
|
|
}
|
|
}
|
|
|
|
void StageSettings::toggledinternal(int state) {
|
|
emit toggled(state == Qt::CheckState::Checked);
|
|
}
|
|
|
|
void StageSettings::rescaleImage() {
|
|
if(img.isNull()) {
|
|
//ui->champImg->setPixmap(QPixmap());
|
|
return;
|
|
}
|
|
|
|
//auto qimg = QImage((uchar*) img.data, img.cols, img.rows, img.step, QImage::Format_RGB888);
|
|
// auto p = QPixmap::fromImage(qimg);
|
|
|
|
// get label dimensions
|
|
//int w = ui->champImg->width();
|
|
//int h = ui->champImg->height();
|
|
|
|
// set a scaled pixmap to a w x h window keeping its aspect ratio
|
|
//ui->champImg->setPixmap(p.scaled(w, h, Qt::KeepAspectRatio)); //
|
|
}
|
|
|
|
void StageSettings::applyChampion(const DataDragon::ChampData& cd) {
|
|
dd->getImageAsnyc(cd.id, [this, cd](QPixmap img) {
|
|
this->img = img;
|
|
currentdisplayedChampKey = cd.key;
|
|
rescaleImage();
|
|
|
|
QIcon icon(this->img);
|
|
ui->championList->addItem(new QListWidgetItem(icon, "Champ", nullptr, 0));
|
|
|
|
emit championChanged(QString::fromStdString(cd.name));
|
|
});
|
|
|
|
if(cd.key >= 0) {
|
|
#define QS(A) arg(QString::fromStdString(A))
|
|
//ui->champImg->setToolTip(tr("Champion: %1\nType: %2\nTitle: %3\nID: %4").QS(cd.name).QS(cd.partype).QS(cd.title).arg(cd.key));
|
|
#undef QS
|
|
} else {
|
|
//ui->champImg->setToolTip("");
|
|
}
|
|
}
|