加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
widget.cpp 2.89 KB
一键复制 编辑 原始数据 按行查看 历史
龚智健 提交于 2024-08-01 15:40 . 修改界面结构,基本功能完成
#include "widget.h"
#include "ui_widget.h"
#include "QString"
#include "iostream"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
}
Widget::~Widget()
{
delete ui;
}
int adDamage = 0;
int apDamage = 0;
void Widget::on_adInfoAddButton_clicked()
{
bool isSuccess;
QString valueText = ui->adInfoAdd->text();
int value = valueText.toInt(&isSuccess);
if(isSuccess) {
adDamage += value;
QString qS = "ad伤害:";
qS.append(valueText);
ui->listWidget->addItem(qS);
ui->adInfoAdd->setText("");
}
}
void Widget::on_adInfoAdd_textEdited(const QString &arg1)
{
bool isSuccess;
int value = arg1.toInt(&isSuccess);
if(!isSuccess) {
ui->adInfoAdd->setText(arg1.left(arg1.length() - 1));
}
}
void Widget::on_apInfoAddButton_clicked()
{
bool isSuccess;
QString valueText = ui->apInfoAdd->text();
int value = valueText.toInt(&isSuccess);
if(isSuccess) {
apDamage += value;
QString qS = "ap伤害:";
qS.append(valueText);
ui->listWidget->addItem(qS);
ui->apInfoAdd->setText("");
}
}
void Widget::on_apInfoAdd_textEdited(const QString &arg1)
{
bool isSuccess;
int value = arg1.toInt(&isSuccess);
if(!isSuccess) {
ui->adInfoAdd->setText(arg1.left(arg1.length() - 1));
}
}
void Widget::on_adInfoAdd_returnPressed()
{
bool isSuccess;
QString valueText = ui->adInfoAdd->text();
int value = valueText.toInt(&isSuccess);
if(isSuccess) {
adDamage += value;
QString qS = "ad伤害:";
qS.append(valueText);
ui->listWidget->addItem(qS);
ui->adInfoAdd->setText("");
}
}
void Widget::on_apInfoAdd_returnPressed()
{
bool isSuccess;
QString valueText = ui->apInfoAdd->text();
int value = valueText.toInt(&isSuccess);
if(isSuccess) {
apDamage += value;
QString qS = "ap伤害:";
qS.append(valueText);
ui->listWidget->addItem(qS);
ui->apInfoAdd->setText("");
}
}
void Widget::on_startCalculate_clicked()
{
int total = 0;
int armor = ui->armorInfoAdd->text().toInt();
int adFinal = adDamage * armor / (100 + armor);
int magicResist = ui->MagicResistAdd->text().toInt();
int apFinal = apDamage * magicResist / (100 + armor);
ui->damageInfo->setText(QString::number(adFinal + apFinal));
// int apFinal = apDamage *
}
void Widget::on_listWidget_doubleClicked(const QModelIndex &index)
{
QListWidgetItem *item = ui->listWidget->takeItem(index.column());
if(item->text().contains("ap")) {
QString value = item->text().replace("ap伤害:","");
int temp = value.toInt();
apDamage -= temp;
} else {
QString value = item->text().replace("ad伤害:","");
int temp = value.toInt();
adDamage -= temp;
}
delete item;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化