2021-12-26 23:18:28 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2021-11-04 09:07:06 +08:00
|
|
|
#include "ojproblempropertywidget.h"
|
|
|
|
#include "ui_ojproblempropertywidget.h"
|
2022-12-13 08:49:20 +08:00
|
|
|
#include "../problems/ojproblemset.h"
|
2021-11-04 09:07:06 +08:00
|
|
|
|
|
|
|
OJProblemPropertyWidget::OJProblemPropertyWidget(QWidget *parent) :
|
|
|
|
QDialog(parent),
|
|
|
|
ui(new Ui::OJProblemPropertyWidget)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
QFont f = ui->lbName->font();
|
2021-12-16 19:14:14 +08:00
|
|
|
f.setPixelSize(f.pixelSize()+2);
|
2021-11-04 09:07:06 +08:00
|
|
|
f.setBold(true);
|
|
|
|
ui->lbName->setFont(f);
|
2022-12-13 08:49:20 +08:00
|
|
|
ui->cbTimeLimitUnit->addItem(tr("sec"));
|
|
|
|
ui->cbTimeLimitUnit->addItem(tr("ms"));
|
|
|
|
ui->cbMemoryLimitUnit->addItem(tr("KB"));
|
|
|
|
ui->cbMemoryLimitUnit->addItem(tr("MB"));
|
|
|
|
ui->cbMemoryLimitUnit->addItem(tr("GB"));
|
2022-12-24 12:09:28 +08:00
|
|
|
ui->txtDescription->setFocus();
|
2021-11-04 09:07:06 +08:00
|
|
|
}
|
|
|
|
|
2022-12-13 08:49:20 +08:00
|
|
|
OJProblemPropertyWidget::~OJProblemPropertyWidget()
|
2021-11-04 09:07:06 +08:00
|
|
|
{
|
2022-12-13 08:49:20 +08:00
|
|
|
delete ui;
|
2021-11-04 09:07:06 +08:00
|
|
|
}
|
|
|
|
|
2022-12-13 08:49:20 +08:00
|
|
|
void OJProblemPropertyWidget::loadFromProblem(POJProblem problem)
|
2021-11-04 09:07:06 +08:00
|
|
|
{
|
2022-12-13 08:49:20 +08:00
|
|
|
if (!problem)
|
|
|
|
return;
|
|
|
|
ui->lbName->setText(problem->name);
|
|
|
|
ui->txtURL->setText(problem->url);
|
|
|
|
ui->txtDescription->setHtml(problem->description);
|
|
|
|
ui->spinMemoryLimit->setValue(problem->memoryLimit);
|
|
|
|
ui->spinTimeLimit->setValue(problem->timeLimit);
|
|
|
|
switch(problem->timeLimitUnit) {
|
|
|
|
case ProblemTimeLimitUnit::Seconds:
|
|
|
|
ui->cbTimeLimitUnit->setCurrentText(tr("sec"));
|
|
|
|
break;
|
|
|
|
case ProblemTimeLimitUnit::Milliseconds:
|
|
|
|
ui->cbTimeLimitUnit->setCurrentText(tr("ms"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch(problem->memoryLimitUnit) {
|
|
|
|
case ProblemMemoryLimitUnit::KB:
|
2022-12-24 12:08:13 +08:00
|
|
|
ui->cbMemoryLimitUnit->setCurrentText(tr("KB"));
|
2022-12-13 08:49:20 +08:00
|
|
|
break;
|
|
|
|
case ProblemMemoryLimitUnit::MB:
|
2022-12-24 12:08:13 +08:00
|
|
|
ui->cbMemoryLimitUnit->setCurrentText(tr("MB"));
|
2022-12-13 08:49:20 +08:00
|
|
|
break;
|
|
|
|
case ProblemMemoryLimitUnit::GB:
|
2022-12-24 12:08:13 +08:00
|
|
|
ui->cbMemoryLimitUnit->setCurrentText(tr("GB"));
|
2022-12-13 08:49:20 +08:00
|
|
|
break;
|
|
|
|
}
|
2021-11-04 09:07:06 +08:00
|
|
|
}
|
|
|
|
|
2022-12-13 08:49:20 +08:00
|
|
|
void OJProblemPropertyWidget::saveToProblem(POJProblem problem)
|
2021-11-04 09:07:06 +08:00
|
|
|
{
|
2022-12-13 08:49:20 +08:00
|
|
|
if (!problem)
|
|
|
|
return;
|
|
|
|
problem->name = ui->lbName->text();
|
|
|
|
problem->url = ui->txtURL->text();
|
|
|
|
problem->description = ui->txtDescription->toHtml();
|
|
|
|
problem->memoryLimit = ui->spinMemoryLimit->value();
|
|
|
|
problem->timeLimit = ui->spinTimeLimit->value();
|
2023-03-03 18:17:26 +08:00
|
|
|
if (ui->cbTimeLimitUnit->currentText()==tr("sec"))
|
2022-12-13 08:49:20 +08:00
|
|
|
problem->timeLimitUnit = ProblemTimeLimitUnit::Seconds;
|
|
|
|
else
|
|
|
|
problem->timeLimitUnit = ProblemTimeLimitUnit::Milliseconds;
|
2023-03-03 18:17:26 +08:00
|
|
|
if (ui->cbMemoryLimitUnit->currentText()==tr("KB"))
|
2022-12-13 08:49:20 +08:00
|
|
|
problem->memoryLimitUnit = ProblemMemoryLimitUnit::KB;
|
2023-03-03 18:17:26 +08:00
|
|
|
else if (ui->cbMemoryLimitUnit->currentText()==tr("MB"))
|
2022-12-13 08:49:20 +08:00
|
|
|
problem->memoryLimitUnit = ProblemMemoryLimitUnit::MB;
|
|
|
|
else
|
|
|
|
problem->memoryLimitUnit = ProblemMemoryLimitUnit::GB;
|
2021-11-04 09:07:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void OJProblemPropertyWidget::on_btnOk_clicked()
|
|
|
|
{
|
|
|
|
this->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OJProblemPropertyWidget::on_btnCancel_clicked()
|
|
|
|
{
|
|
|
|
this->reject();
|
|
|
|
}
|
|
|
|
|