A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
graphlib.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Hide protected methods in generated doc.
[graphlib.git]
/
DrawingWindow.cpp
diff --git
a/DrawingWindow.cpp
b/DrawingWindow.cpp
index
554e7fb
..
3234441
100644
(file)
--- a/
DrawingWindow.cpp
+++ b/
DrawingWindow.cpp
@@
-1,5
+1,5
@@
/*
/*
- * Copyright (c) 2007-201
0
, Arnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
+ * Copyright (c) 2007-201
3
, 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-201
0
+ * \date 2007-201
3
*
* 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,14
+142,14
@@
public:
{ }
};
{ }
};
-//! Demande de tracé de texte.
+//! Demande de tracé de texte.
class DrawTextEvent: public QEvent {
public:
const int x;
const int y;
const char *text;
const int flags;
class DrawTextEvent: public QEvent {
public:
const int x;
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<QEvent::Type>(DrawTextRequest))
, x(x_), y(y_), text(text_), flags(flags_)
{ }
: QEvent(static_cast<QEvent::Type>(DrawTextRequest))
, x(x_), y(y_), text(text_), flags(flags_)
{ }
@@
-345,11
+345,24
@@
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
*/
-const QFont
&
DrawingWindow::getFont() const
+const QFont
&
DrawingWindow::getFont() const
{
return painter->font();
}
{
return painter->font();
}
@@
-358,11
+371,25
@@
const QFont& DrawingWindow::getFont() const
/*!
* \see QFont, getFont
*/
/*!
* \see QFont, getFont
*/
-void DrawingWindow::setFont(const QFont
&
font)
+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.
@@
-545,6
+580,7
@@
void DrawingWindow::fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3)
* \param text texte à écrire
* \param flags paramètres d'alignement
*
* \param text texte à écrire
* \param flags paramètres d'alignement
*
+ * \see drawText(int, int, const std::string &, int)
* \see drawTextBg, setColor
* \see QPainter::drawText
*/
* \see drawTextBg, setColor
* \see QPainter::drawText
*/
@@
-558,6
+594,15
@@
void DrawingWindow::drawText(int x, int y, const char *text, int flags)
safeUnlock(syncMutex);
}
safeUnlock(syncMutex);
}
+//! Écrit du texte.
+/*!
+ * \see drawText(int, int, const char *, int)
+ */
+void DrawingWindow::drawText(int x, int y, const std::string &text, int flags)
+{
+ drawText(x, y, text.c_str(), flags);
+}
+
//! Écrit du texte sur fond coloré.
/*!
* Écrit du texte comme drawText, mais l'arrière-plan est coloré avec
//! Écrit du texte sur fond coloré.
/*!
* Écrit du texte comme drawText, mais l'arrière-plan est coloré avec
@@
-567,6
+612,7
@@
void DrawingWindow::drawText(int x, int y, const char *text, int flags)
* \param text texte à écrire
* \param flags paramètres d'alignement
*
* \param text texte à écrire
* \param flags paramètres d'alignement
*
+ * \see drawTextBg(int, int, const std::string &, int)
* \see drawText, setColor, setColorBg
*/
void DrawingWindow::drawTextBg(int x, int y, const char *text, int flags)
* \see drawText, setColor, setColorBg
*/
void DrawingWindow::drawTextBg(int x, int y, const char *text, int flags)
@@
-576,6
+622,14
@@
void DrawingWindow::drawTextBg(int x, int y, const char *text, int flags)
painter->setBackgroundMode(Qt::TransparentMode);
}
painter->setBackgroundMode(Qt::TransparentMode);
}
+//! Écrit du texte sur fond coloré.
+/*!
+ * \see drawTextBg(int, int, const char *, int)
+ */
+void DrawingWindow::drawTextBg(int x, int y, const std::string &text, int flags)
+{
+ drawTextBg(x, y, text.c_str(), flags);
+}
//! Retourne la couleur d'un pixel.
/*!
//! Retourne la couleur d'un pixel.
/*!
@@
-588,7
+642,7
@@
void DrawingWindow::drawTextBg(int x, int y, const char *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);
}
@@
-611,11
+665,11
@@
bool DrawingWindow::waitMousePress(int &x, int &y, int &button,
unsigned long time)
{
bool pressed;
unsigned long time)
{
bool pressed;
- safeLock(
mouse
Mutex);
+ safeLock(
input
Mutex);
if (terminateThread) {
pressed = false;
} else {
if (terminateThread) {
pressed = false;
} else {
- pressed =
mouseCondition.wait(&mouseMutex, time)
;
+ pressed =
inputCondition.wait(&inputMutex, time) && !terminateThread
;
if (pressed) {
x = mousePos.x();
y = mousePos.y();
if (pressed) {
x = mousePos.x();
y = mousePos.y();
@@
-629,7
+683,7
@@
bool DrawingWindow::waitMousePress(int &x, int &y, int &button,
button = 0;
}
}
button = 0;
}
}
- safeUnlock(
mouse
Mutex);
+ safeUnlock(
input
Mutex);
return pressed;
}
return pressed;
}
@@
-691,15
+745,18
@@
void DrawingWindow::usleep(unsigned long usecs)
DrawingThread::usleep(usecs);
}
DrawingThread::usleep(usecs);
}
+//--- DrawingWindow (protected methods) --------------------------------
+//! \cond show_protected
+
/*!
* \see QWidget
*/
void DrawingWindow::closeEvent(QCloseEvent *ev)
{
timer.stop();
/*!
* \see QWidget
*/
void DrawingWindow::closeEvent(QCloseEvent *ev)
{
timer.stop();
- thread->
terminate
();
+ thread->
exit
();
syncMutex.lock();
syncMutex.lock();
-
mouse
Mutex.lock();
+
input
Mutex.lock();
terminateThread = true; // this flag is needed for the case
// where the following wakeAll() call
// occurs between the
terminateThread = true; // this flag is needed for the case
// where the following wakeAll() call
// occurs between the
@@
-707,11
+764,14
@@
void DrawingWindow::closeEvent(QCloseEvent *ev)
// mutex lock in safeLock() called
// from sync()
syncCondition.wakeAll();
// mutex lock in safeLock() called
// from sync()
syncCondition.wakeAll();
-
mouse
Condition.wakeAll();
-
mouse
Mutex.unlock();
+
input
Condition.wakeAll();
+
input
Mutex.unlock();
syncMutex.unlock();
QWidget::closeEvent(ev);
syncMutex.unlock();
QWidget::closeEvent(ev);
- thread->wait();
+ if (!thread->wait(250)) {
+ thread->terminate();
+ thread->wait();
+ }
}
/*!
}
/*!
@@
-727,7
+787,7
@@
void DrawingWindow::customEvent(QEvent *ev)
close();
break;
case DrawTextRequest:
close();
break;
case DrawTextRequest:
- DrawTextEvent
*
tev = dynamic_cast<DrawTextEvent *>(ev);
+ DrawTextEvent
*
tev = dynamic_cast<DrawTextEvent *>(ev);
realDrawText(tev->x, tev->y, tev->text, tev->flags);
break;
}
realDrawText(tev->x, tev->y, tev->text, tev->flags);
break;
}
@@
-740,12
+800,12
@@
void DrawingWindow::customEvent(QEvent *ev)
*/
void DrawingWindow::mousePressEvent(QMouseEvent *ev)
{
*/
void DrawingWindow::mousePressEvent(QMouseEvent *ev)
{
-
mouse
Mutex.lock();
+
input
Mutex.lock();
mousePos = ev->pos();
mouseButton = ev->button();
ev->accept();
mousePos = ev->pos();
mouseButton = ev->button();
ev->accept();
-
mouse
Condition.wakeAll();
-
mouse
Mutex.unlock();
+
input
Condition.wakeAll();
+
input
Mutex.unlock();
}
/*!
}
/*!
@@
-753,17
+813,10
@@
void DrawingWindow::mousePressEvent(QMouseEvent *ev)
*/
void DrawingWindow::keyPressEvent(QKeyEvent *ev)
{
*/
void DrawingWindow::keyPressEvent(QKeyEvent *ev)
{
- bool accept = true;
- switch (ev->key()) {
- case Qt::Key_Escape:
+ if (ev->key() == Qt::Key_Escape) {
+ ev->accept();
close();
close();
- break;
- default:
- accept = false;
- break;
}
}
- if (accept)
- ev->accept();
}
/*!
}
/*!
@@
-804,6
+857,8
@@
void DrawingWindow::timerEvent(QTimerEvent *ev)
}
}
}
}
+// \endcond
+
//--- DrawingWindow (private methods) ----------------------------------
//! Fonction d'initialisation.
//--- DrawingWindow (private methods) ----------------------------------
//! Fonction d'initialisation.
@@
-837,7
+892,7
@@
void DrawingWindow::initialize(DrawingWindow::ThreadFunction fun)
* \param color couleur
*/
inline
* \param color couleur
*/
inline
-void DrawingWindow::setColor(const QColor
&
color)
+void DrawingWindow::setColor(const QColor
&
color)
{
QPen pen(painter->pen());
pen.setColor(color);
{
QPen pen(painter->pen());
pen.setColor(color);
@@
-849,7
+904,7
@@
void DrawingWindow::setColor(const QColor& color)
* \param color couleur
*/
inline
* \param color couleur
*/
inline
-void DrawingWindow::setBgColor(const QColor
&
color)
+void DrawingWindow::setBgColor(const QColor
&
color)
{
painter->setBackground(color);
}
{
painter->setBackground(color);
}