Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Workaround bug with some versions of Qt, when the two pairs of
[graphlib.git] / DrawingWindow.cpp
index f68f43b..1ab14ee 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 2007-2010, Arnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
+ * Copyright (c) 2007-2013, Arnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -37,7 +37,7 @@
  *  \brief Fenêtre de dessin.
  *
  * \author Arnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
  *  \brief Fenêtre de dessin.
  *
  * \author Arnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
- * \date 2007-2010
+ * \date 2007-2013
  *
  * Cette classe décrit un widget Qt permettant d'écrire des
  * applications graphiques simples.  Pour cela, il faut définir une
  *
  * Cette classe décrit un widget Qt permettant d'écrire des
  * applications graphiques simples.  Pour cela, il faut définir une
@@ -142,7 +142,7 @@ public:
     { }
 };
 
     { }
 };
 
-//! Demande de tracé de texte. 
+//! Demande de tracé de texte.
 class DrawTextEvent: public QEvent {
 public:
     const int x;
 class DrawTextEvent: public QEvent {
 public:
     const int x;
@@ -345,6 +345,19 @@ void DrawingWindow::setBgColor(float red, float green, float blue)
     setBgColor(QColor::fromRgbF(red, green, blue));
 }
 
     setBgColor(QColor::fromRgbF(red, green, blue));
 }
 
+//! Change l'épaisseur du pinceau
+/*!
+ * Le pinceau à une épaisseur de 1 par défaut.
+ *
+ * \param width         épaisseur du pinceau
+ */
+void DrawingWindow::setPenWidth(int width)
+{
+    QPen pen(painter->pen());
+    pen.setWidth(width);
+    painter->setPen(pen);
+}
+
 //! Retourne la fonte courante utilisée pour dessiner du texte.
 /*!
  * \see QFont, setFont
 //! Retourne la fonte courante utilisée pour dessiner du texte.
 /*!
  * \see QFont, setFont
@@ -363,6 +376,20 @@ void DrawingWindow::setFont(const QFont &font)
     painter->setFont(font);
 }
 
     painter->setFont(font);
 }
 
+//! Active ou non l'antialiasing.
+/*!
+ * Permet de lisser le dessin.
+ * Fonctionnalité désactivée par défaut.
+ *
+ * \param state         état de l'antialiasing
+ *
+ * \bug                 expérimental
+ */
+void DrawingWindow::setAntialiasing(bool state)
+{
+    painter->setRenderHint(QPainter::Antialiasing, state);
+}
+
 //! Efface la fenêtre.
 /*!
  * La fenêtre est effacée avec la couleur de fond courante.
 //! Efface la fenêtre.
 /*!
  * La fenêtre est effacée avec la couleur de fond courante.
@@ -406,10 +433,14 @@ void DrawingWindow::drawPoint(int x, int y)
  */
 void DrawingWindow::drawLine(int x1, int y1, int x2, int y2)
 {
  */
 void DrawingWindow::drawLine(int x1, int y1, int x2, int y2)
 {
-    safeLock(imageMutex);
-    painter->drawLine(x1, y1, x2, y2);
-    dirty(x1, y1, x2, y2);
-    safeUnlock(imageMutex);
+    if (x1 == x2 && y1 == y2) {
+        drawPoint(x1, y1);
+    } else {
+        safeLock(imageMutex);
+        painter->drawLine(x1, y1, x2, y2);
+        dirty(x1, y1, x2, y2);
+        safeUnlock(imageMutex);
+    }
 }
 
 //! Dessine un rectangle.
 }
 
 //! Dessine un rectangle.
@@ -425,14 +456,18 @@ void DrawingWindow::drawLine(int x1, int y1, int x2, int y2)
  */
 void DrawingWindow::drawRect(int x1, int y1, int x2, int y2)
 {
  */
 void DrawingWindow::drawRect(int x1, int y1, int x2, int y2)
 {
-    QRect r;
-    r.setCoords(x1, y1, x2 - 1, y2 - 1);
-    r = r.normalized();
-    safeLock(imageMutex);
-    painter->drawRect(r);
-    r.adjust(0, 0, 1, 1);
-    dirty(r);
-    safeUnlock(imageMutex);
+    if (x1 == x2 && y1 == y2) {
+        drawPoint(x1, y1);
+    } else {
+        QRect r;
+        r.setCoords(x1, y1, x2 - 1, y2 - 1);
+        r = r.normalized();
+        safeLock(imageMutex);
+        painter->drawRect(r);
+        r.adjust(0, 0, 1, 1);
+        dirty(r);
+        safeUnlock(imageMutex);
+    }
 }
 
 //! Dessine un rectangle plein.
 }
 
 //! Dessine un rectangle plein.
@@ -607,7 +642,7 @@ void DrawingWindow::drawTextBg(int x, int y, const std::string &text, int flags)
  *
  * \see setColor(unsigned int), setBgColor(unsigned int)
  */
  *
  * \see setColor(unsigned int), setBgColor(unsigned int)
  */
-unsigned int DrawingWindow::getPointColor(int x, int y)
+unsigned int DrawingWindow::getPointColor(int x, int y) const
 {
     return image->pixel(x, y);
 }
 {
     return image->pixel(x, y);
 }