|
@@ -0,0 +1,163 @@
|
|
|
|
+/*********************************************************************/
|
|
|
|
+/* */
|
|
|
|
+/* Copyright 2022-2023 Rémi Synave - remi.synave@univ-littoral.fr */
|
|
|
|
+/* */
|
|
|
|
+/* This file is part of DSL. */
|
|
|
|
+/* This software uses Qt to build the Graphical User Interface */
|
|
|
|
+/* https://www.qt.io/ */
|
|
|
|
+/* */
|
|
|
|
+/* DSL 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. */
|
|
|
|
+/* */
|
|
|
|
+/* DSL 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 DSL. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
+/* */
|
|
|
|
+/*********************************************************************/
|
|
|
|
+
|
|
|
|
+#include <QFile>
|
|
|
|
+#include <QColor>
|
|
|
|
+#include <QTextStream>
|
|
|
|
+#include <QJsonObject>
|
|
|
|
+#include <QJsonArray>
|
|
|
|
+#include <QJsonDocument>
|
|
|
|
+#include <QPalette>
|
|
|
|
+
|
|
|
|
+#include <QDebug>
|
|
|
|
+#include <QStringList>
|
|
|
|
+
|
|
|
|
+#include <iostream>
|
|
|
|
+
|
|
|
|
+#include "WorkArea.hpp"
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+WorkArea::WorkArea (int screenSizeX, int screenSizeY, QWidget * parent):QWidget(parent)
|
|
|
|
+{
|
|
|
|
+ this->screenSizeX = screenSizeX;
|
|
|
|
+ this->screenSizeY = screenSizeY;
|
|
|
|
+ this->setGeometry(0,0,screenSizeX,screenSizeY);
|
|
|
|
+
|
|
|
|
+ QPalette pal = QPalette();
|
|
|
|
+ pal.setColor(QPalette::Window, Qt::gray);
|
|
|
|
+
|
|
|
|
+ this->setAutoFillBackground(true);
|
|
|
|
+ this->setPalette(pal);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ setFixedSize (screenSizeX, screenSizeY);
|
|
|
|
+
|
|
|
|
+ indexPointClicked = -1;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+WorkArea::~WorkArea ()
|
|
|
|
+{
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+void
|
|
|
|
+WorkArea::addSL (const StrengthLine *sl)
|
|
|
|
+{
|
|
|
|
+ liste_points << new QPoint((int)(sl->getP1()->x()), (int)(sl->getP1()->y()));
|
|
|
|
+ liste_points << new QPoint((int)(sl->getP2()->x()), (int)(sl->getP2()->y()));
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+void
|
|
|
|
+WorkArea::paintEvent (QPaintEvent * event)
|
|
|
|
+{
|
|
|
|
+ QPainter painter (this);
|
|
|
|
+ paint (painter);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void
|
|
|
|
+WorkArea::paint (QPainter & painter)
|
|
|
|
+{
|
|
|
|
+ for (int i = 0; i < liste_points.length (); i++)
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ painter.setBrush (QBrush (Qt::green));
|
|
|
|
+ painter.setPen (QPen (Qt::black));
|
|
|
|
+ painter.drawEllipse (liste_points[i]->x () - taillePoint / 2,
|
|
|
|
+ liste_points[i]->y () - taillePoint / 2,
|
|
|
|
+ taillePoint, taillePoint);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if ((i % 2) == 1)
|
|
|
|
+ {
|
|
|
|
+ painter.setPen (QPen (Qt::red, epaisseurLigne));
|
|
|
|
+ std::pair < QPoint *, QPoint * >endPoints =
|
|
|
|
+ StrengthLine (liste_points[i - 1], liste_points[i]).toDraw (this->screenSizeX, this->screenSizeY);
|
|
|
|
+ painter.drawLine (*(std::get < 0 > (endPoints)),
|
|
|
|
+ *(std::get < 1 > (endPoints)));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void
|
|
|
|
+WorkArea::mousePressEvent (QMouseEvent * event)
|
|
|
|
+{
|
|
|
|
+ // Est ce qu'on a cliqué sur un point existant ?
|
|
|
|
+ indexPointClicked = -1;
|
|
|
|
+ for (int i = 0; i < liste_points.length (); i++)
|
|
|
|
+ {
|
|
|
|
+ QPoint point = event->pos () - *(liste_points[i]);
|
|
|
|
+ if (point.manhattanLength () < taillePoint)
|
|
|
|
+ {
|
|
|
|
+ indexPointClicked = i;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Clic gauche
|
|
|
|
+ /*if (event->button () == Qt::LeftButton)
|
|
|
|
+ {
|
|
|
|
+ if (indexPointClicked == -1)
|
|
|
|
+ {
|
|
|
|
+ if((maxLines == 0) || (liste_points.size()<(maxLines*2))){
|
|
|
|
+ indexPointClicked = liste_points.size ();
|
|
|
|
+ liste_points << new QPoint (event->x (), event->y ());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }*/
|
|
|
|
+
|
|
|
|
+ repaint ();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void
|
|
|
|
+WorkArea::mouseMoveEvent (QMouseEvent * event)
|
|
|
|
+{
|
|
|
|
+ if (indexPointClicked != -1)
|
|
|
|
+ {
|
|
|
|
+ liste_points[indexPointClicked]->setX (event->x ());
|
|
|
|
+ liste_points[indexPointClicked]->setY (event->y ());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ repaint ();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void
|
|
|
|
+WorkArea::mouseReleaseEvent (QMouseEvent * event)
|
|
|
|
+{
|
|
|
|
+ indexPointClicked = -1;
|
|
|
|
+
|
|
|
|
+ emit click();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+double
|
|
|
|
+WorkArea::getDistance() const
|
|
|
|
+{
|
|
|
|
+ StrengthLine *sl1 = new StrengthLine(liste_points[0], liste_points[1]);
|
|
|
|
+ StrengthLine *sl2 = new StrengthLine(liste_points[2], liste_points[3]);
|
|
|
|
+ return sl1->distance(sl2);
|
|
|
|
+}
|