X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/graphlib.git/blobdiff_plain/49c1dd920c3d23d19d2a0de75066865057589129..5094246bbd6b66b06521cf1c1a08578f8c16d0de:/DrawingWindow.cpp diff --git a/DrawingWindow.cpp b/DrawingWindow.cpp index ae740b7..6fad2c0 100644 --- a/DrawingWindow.cpp +++ b/DrawingWindow.cpp @@ -149,7 +149,7 @@ public: const int y; const char *text; const int flags; - DrawTextEvent(int x_, int y_, const char* text_, int flags_) + DrawTextEvent(int x_, int y_, const char *text_, int flags_) : QEvent(static_cast(DrawTextRequest)) , x(x_), y(y_), text(text_), flags(flags_) { } @@ -345,6 +345,24 @@ void DrawingWindow::setBgColor(float red, float green, float blue) setBgColor(QColor::fromRgbF(red, green, blue)); } +//! Retourne la fonte courante utilisée pour dessiner du texte. +/*! + * \see QFont, setFont + */ +const QFont &DrawingWindow::getFont() const +{ + return painter->font(); +} + +//! Applique une nouvelle font pour dessiner du texte. +/*! + * \see QFont, getFont + */ +void DrawingWindow::setFont(const QFont &font) +{ + painter->setFont(font); +} + //! Efface la fenêtre. /*! * La fenêtre est effacée avec la couleur de fond courante. @@ -473,6 +491,47 @@ void DrawingWindow::fillCircle(int x, int y, int r) painter->setBrush(Qt::NoBrush); } +//! Dessine un triangle. +/*! + * Dessine un triangle défini par les coordonnées de ses sommets: + * (x1, y1), (x2, y2) et (x3, y3). Utilise la couleur de dessin + * courante. + * + * \param x1, y1 coordonnées du premier sommet du triangle + * \param x2, y2 coordonnées du deuxième sommet du triangle + * \param x3, y3 coordonnées du troisième sommet du triangle + * + * \see fillTriangle, setColor + */ +void DrawingWindow::drawTriangle(int x1, int y1, int x2, int y2, int x3, int y3) +{ + QPolygon poly(3); + poly.putPoints(0, 3, x1, y1, x2, y2, x3, y3); + safeLock(imageMutex); + painter->drawConvexPolygon(poly); + dirty(poly.boundingRect()); + safeUnlock(imageMutex); +} + +//! Dessine un triangle plein. +/*! + * Dessine un triangle plein défini par les coordonnées de ses + * sommets: (x1, y1), (x2, y2) et (x3, y3). Utilise la couleur de + * dessin courante. + * + * \param x1, y1 coordonnées du premier sommet du triangle + * \param x2, y2 coordonnées du deuxième sommet du triangle + * \param x3, y3 coordonnées du troisième sommet du triangle + * + * \see drawTriangle, setColor + */ +void DrawingWindow::fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3) +{ + painter->setBrush(getColor()); + drawTriangle(x1, y1, x2, y2, x3, y3); + painter->setBrush(Qt::NoBrush); +} + //! Écrit du texte. /*! * Écrit le texte text, aux coordonnées (x, y) et avec les paramètres @@ -517,7 +576,6 @@ void DrawingWindow::drawTextBg(int x, int y, const char *text, int flags) painter->setBackgroundMode(Qt::TransparentMode); } - //! Retourne la couleur d'un pixel. /*! * Retourne la couleur du pixel de coordonnées (x, y). La valeur @@ -668,7 +726,7 @@ void DrawingWindow::customEvent(QEvent *ev) close(); break; case DrawTextRequest: - DrawTextEvent* tev = dynamic_cast(ev); + DrawTextEvent *tev = dynamic_cast(ev); realDrawText(tev->x, tev->y, tev->text, tev->flags); break; } @@ -778,7 +836,7 @@ void DrawingWindow::initialize(DrawingWindow::ThreadFunction fun) * \param color couleur */ inline -void DrawingWindow::setColor(const QColor& color) +void DrawingWindow::setColor(const QColor &color) { QPen pen(painter->pen()); pen.setColor(color); @@ -790,7 +848,7 @@ void DrawingWindow::setColor(const QColor& color) * \param color couleur */ inline -void DrawingWindow::setBgColor(const QColor& color) +void DrawingWindow::setBgColor(const QColor &color) { painter->setBackground(color); } @@ -975,7 +1033,7 @@ void DrawingWindow::realDrawText(int x, int y, const char *text, int flags) r.setTop(y); } syncMutex.lock(); - painter->drawText(r, flags, text, &r); + painter->drawText(r, flags, QString::fromUtf8(text), &r); dirty(r); syncCondition.wakeAll(); syncMutex.unlock();