#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(); }