fehawfdhper02

Untitled

Nov 14th, 2020
957
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "widget.h"
  2. #include "ui_widget.h"
  3. #include <QMessageBox>
  4. #include <QPalette>
  5. #include "cmath"
  6.  
  7. Widget::Widget(QWidget *parent) :
  8.     QWidget(parent),
  9.     ui(new Ui::Widget)
  10. {
  11.     ui->setupUi(this);
  12.     ui->per->setReadOnly(true);
  13.     ui->sqr->setReadOnly(true);
  14. }
  15.  
  16. Widget::~Widget()
  17. {
  18.     delete ui;
  19. }
  20.  
  21. void Widget::on_pushButton_clicked()
  22. {
  23.  
  24.     bool ok1, ok2, ok3, ok4, ok5, ok6;
  25.     QString op1 = ui->x1->text();
  26.     double x1 = op1.toDouble(&ok1);
  27.     QString op2 = ui->x2->text();
  28.     double x2 = op2.toDouble(&ok2);
  29.     QString op3 = ui->x3->text();
  30.     double x3 = op3.toDouble(&ok3);
  31.     QString op4 = ui->y1->text();
  32.     double y1 = op4.toDouble(&ok4);
  33.     QString op5 = ui->y2->text();
  34.     double y2 = op5.toDouble(&ok5);
  35.     QString op6 = ui->y3->text();
  36.     double y3 = op6.toDouble(&ok6);
  37.  
  38.  
  39.     ui->per->setText("");
  40.     ui->sqr->setText("");
  41.  
  42.  
  43.     QPalette *palette = new QPalette();
  44.     palette->setColor(QPalette::Base,Qt::white);
  45.     ui->x1->setPalette(*palette);
  46.     ui->x2->setPalette(*palette);
  47.     ui->x3->setPalette(*palette);
  48.     ui->y1->setPalette(*palette);
  49.     ui->y2->setPalette(*palette);
  50.     ui->y3->setPalette(*palette);
  51.  
  52.     if (ok1 && ok2 && ok3 && ok4 && ok5 && ok6){
  53.  
  54.         double l1 = sqrt(((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)));
  55.         double l2 = sqrt(((x2-x3)*(x2-x3))+((y2-y3)*(y2-y3)));
  56.         double l3 = sqrt(((x3-x1)*(x3-x1))+((y3-y1)*(y3-y1)));
  57.         double perimetre = l1+l2+l3;
  58.         QString perim = QString::number(perimetre);
  59.         ui->per->setText(perim);
  60.  
  61.         double square = (abs(((x1-x3)*(y2-y3))-((x2-x3)*(y1-y3))))/2;
  62.         QString squar = QString::number(square);
  63.         ui->sqr->setText(squar);
  64.  
  65.  
  66.     } else {
  67.         QMessageBox::critical(this,"Ошибка","Некорректно введена(-ы) координата(-ы)");
  68.         if (!ok1){
  69.             QPalette *palette = new QPalette();
  70.             palette->setColor(QPalette::Base,Qt::red);
  71.             ui->x1->setPalette(*palette);
  72.         }
  73.         if (!ok2){
  74.             QPalette *palette = new QPalette();
  75.             palette->setColor(QPalette::Base,Qt::red);
  76.             ui->x2->setPalette(*palette);
  77.         }
  78.         if (!ok3){
  79.             QPalette *palette = new QPalette();
  80.             palette->setColor(QPalette::Base,Qt::red);
  81.             ui->x3->setPalette(*palette);
  82.         }
  83.         if (!ok4){
  84.             QPalette *palette = new QPalette();
  85.             palette->setColor(QPalette::Base,Qt::red);
  86.             ui->y1->setPalette(*palette);
  87.         }
  88.         if (!ok5){
  89.             QPalette *palette = new QPalette();
  90.             palette->setColor(QPalette::Base,Qt::red);
  91.             ui->y2->setPalette(*palette);
  92.         }
  93.         if (!ok6){
  94.             QPalette *palette = new QPalette();
  95.             palette->setColor(QPalette::Base,Qt::red);
  96.             ui->y3->setPalette(*palette);
  97.         }
  98.     }
  99.  
  100.  
  101.  
  102.  
  103. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×