123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- /*********************************************************************/
- /* */
- /* 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]).interpolateToEdge (this->screenSizeX, this->screenSizeY);
- QPoint *first = std::get < 0 > (endPoints);
- QPoint *last = std::get < 1 > (endPoints);
- painter.drawLine (*first,
- *last);
- painter.setBrush (QBrush (Qt::blue));
- painter.setPen (QPen (Qt::blue));
- painter.drawEllipse (*first,
- taillePoint, taillePoint);
- painter.drawEllipse (*last,
- taillePoint, taillePoint);
- }
- }
- }
- 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;
- }
- }
-
- 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->ea_score(sl2, screenSizeX, screenSizeY);
- }
|