class PenGraphItem : public AbstractGraphItem{ blablabla private: QList<QPoint> *m_lstBuff; // создается в конструкторе bool *m_stopThreadBuff; // создается в конструкторе};
void pCreateBufferPoint(QList<QPoint> *lstPoint, bool *stop){ while(!(*stop)) { lstPoint->append(QCursor::pos()); QEventLoop loop; QTimer::singleShot(10,&loop,SLOT(quit())); loop.exec(); }}void PenGraphItem::mousePressEvent(QGraphicsSceneMouseEvent *event){ (*m_stopThreadBuff) = false; m_bufferPoint->clear(); QtConcurrent::run(pCreateBufferPoint,m_bufferPoint,m_stopThreadBuff);}void PenGraphItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event){ for (int i = 0; i < m_bufferPoint->count(); ++i) { paint(m_bufferPoint->at(i)); } paint(event->pos()); m_bufferPoint->clear();}void PenGraphItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ (*m_stopThreadBuff) = true;}
void PenGraphItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event){... m_bufferPoint->clear();}
void pCreateBufferPoint(QList<QPoint> *lstPoint, bool *stop){ QMutex mutex; while(!(*stop)) { mutex.lock(); if (lstPoint->count() > 0) { if (lstPoint->last() != QCursor::pos()) lstPoint->append(QCursor::pos()); }else lstPoint->append(QCursor::pos()); mutex.unlock(); QEventLoop loop; QTimer::singleShot(10,&loop,SLOT(quit())); loop.exec(); }}