MRU1/vvodnomeratrace.cpp
2025-07-02 08:18:27 +03:00

97 lines
2.3 KiB
C++

#include "vvodnomeratrace.h"
vvodnomeratrace::vvodnomeratrace(QWidget *parent) :
QDialog(parent)
{
setWindowTitle(QString::fromLocal8Bit("Íîìåð òðàññû"));
// setAttribute(Qt::WA_DeleteOnClose);
setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
setResult(-1);
QFrame *fr=new QFrame(this);
fr->setGeometry(20,20,200,54);
fr->setFrameShape(QFrame::Box);
fr->setFrameShadow(QFrame::Sunken);
fr->setLineWidth(2);
QLabel *lb= new QLabel(this);
lb->setGeometry(50,30,130,20);
lb->setText(QString::fromLocal8Bit("Íîìåð òðàññû"));
le = new QLineEdit(this);
le->setGeometry(170, 30, 35, 20);
le->setText("0");
le->setInputMask("00");
QPushButton *pbOk = new QPushButton(this);
pbOk->setGeometry(40,85, 65, 23);
pbOk->setText(QString::fromLocal8Bit("Ââîä"));
connect(pbOk, SIGNAL(clicked()), this, SLOT(msOk()));
QPushButton *pbCancel = new QPushButton(this);
pbCancel->setGeometry(150,85, 65, 23);
pbCancel->setText(QString::fromLocal8Bit("Îòêàç"));
connect(pbCancel, SIGNAL(clicked()), this, SLOT(msCancel()));
}
void vvodnomeratrace::setTitle(QString s)
{
setWindowTitle(s);
}
void vvodnomeratrace::msOk()
{
int r = le->text().toInt();
if ((r<=0)||(r>(((Widget*)parent())->targets.size())))
{
QMessageBox msg(this);
msg.setWindowTitle(QString::fromLocal8Bit("Îøèáêà"));
msg.setIcon(QMessageBox::Information);
msg.setText(QString::fromLocal8Bit("Òðàññà %1 íå ñóùåñòâóåò").arg(r));
msg.addButton(QString::fromLocal8Bit("Äà"),QMessageBox::AcceptRole);
msg.exec();
}
else
{
if (((Widget*)parent())->targets.at(r-1)->exist)
this->done(r);
else
{
QMessageBox msg(this);
msg.setWindowTitle(QString::fromLocal8Bit("Îøèáêà2"));
msg.setIcon(QMessageBox::Information);
msg.setText(QString::fromLocal8Bit("Òðàññà %1 íå ñóùåñòâóåò").arg(r));
msg.addButton(QString::fromLocal8Bit("Äà"),QMessageBox::AcceptRole);
msg.exec();
}
}
}
void vvodnomeratrace::msCancel()
{
this->done(-1);
}
void vvodnomeratrace::keyPressEvent(QKeyEvent *e)
{
if (e->key() == Qt::Key_Escape)
{
msCancel();
}
e->accept();
}