49 #ifndef QT_WIDGET_UPDATE 50 #define QT_WIDGET_UPDATE 85 still_running(false) { start(); }
89 still_running =
false;
117 QRect
region(
const QPoint& pos,
const bool big =
false)
const {
118 static const int offset = 2 + (big ? 5 : 0);
119 return QRect(pos, pos).adjusted(-offset, -offset, offset, offset);
125 void modify(QPoint& variable,
const QPoint& value) {
127 const QRect change = region(variable,
true)
128 | region(value,
true);
143 void updatePosition(
const int dist) {
147 const QPointF new_pos = position, vector = new_pos - aimed;
148 const qreal x = vector.x(), y = vector.y(),
149 distance = sqrt(x * x + y * y);
151 modify( position, (new_pos - vector * dist /
152 distance).toPoint() );
166 setBackgroundRole(QPalette::Base);
169 this, SLOT( updatePosition(
const int) ) );
178 const QPoint center(width() / 2, height() / 2);
179 modify(position, center);
180 modify(aimed, center);
189 void paintEvent(QPaintEvent *event);
194 void mouseMoveEvent(QMouseEvent *event);
198 #endif // QT_WIDGET_UPDATE
bool still_running
Should the thread continue to run?
This separated thread updates regularly the position drawn towards the aimed one, either directly (if...
void stop()
Stops the thread.
Updater()
The thread's constructor.
void updatePosRequest(const int dist)
Sends a signal to ask for an update of the widget.
void run()
The main method of this thread.