Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. void mousePressEvent(QMouseEvent *e)
  2. {
  3. QColor colours[10] = { QColor(255,0,0), QColor(0,255,0), QColor(0,0,255),
  4. QColor(0,0,0), QColor(255,255,255),
  5. QColor(0,128,64) };
  6. static int i;
  7. switch (e->button())
  8. {
  9. case Qt::LeftButton:
  10. clusters.push_back(new Cluster(e->x() %width(), e->y() %height(), colours[i]));
  11. Cluster* cc;
  12. for each(KPoint* p in kpoints)
  13. {
  14. double minim=1000;
  15. for each (Cluster* c in clusters)
  16. {
  17. double dist = abs(sqrt(((p->x - c->x)*(p->x - c->x)) + ((p->y - c->y)*(p->y - c->y))));
  18. if (dist < minim)
  19. {
  20. minim = dist;
  21. cc = c;
  22. }
  23. }
  24. p->parentCluster = cc;
  25. }
  26.  
  27. update(); //redesenarea ferestrei (se apeleaza paintEvent())
  28. break;
  29. case Qt::RightButton:
  30.  
  31.  
  32.  
  33. update();
  34. break;
  35. }
  36. i++;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement