harita_widget.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. from PyQt5.QtWidgets import QWidget
  2. from PyQt5.QtGui import QPixmap, QPainter
  3. from PyQt5.QtCore import QPoint
  4. from .veriler.koordinatlar import koordinatlar
  5. class HaritaWidget(QWidget):
  6. def __init__(self, ebeveyn=None):
  7. super(HaritaWidget,self).__init__(ebeveyn)
  8. self.e = ebeveyn
  9. self.setFixedSize(900, 450)
  10. self.pin = QPixmap("./resimler/pin.png")
  11. self.pin_konum = QPoint(-50, -50)
  12. self.koordinat_pixelleri = {}
  13. for zone, koordinat in koordinatlar.items():
  14. pos = self.koordinat_pixel_tespiti(koordinat[1], koordinat[0], zone)
  15. self.koordinat_pixelleri[pos[0]] = pos[1]
  16. def ara(self, x, y):
  17. deger = 1000
  18. returner = ()
  19. for i in list(self.koordinat_pixelleri.keys()):
  20. deger_ = (i[0]-x)**2 + (i[1]-y)**2
  21. if deger_ < deger:
  22. deger = deger_
  23. returner = (i[0],i[1])
  24. return returner
  25. def koordinat_pixel_tespiti(self, longitude, latitude, time_zone=""):
  26. height = 450
  27. x = (self.width()/2)*(longitude/180)+(self.width()/2)
  28. y = (height/2)-((height/2)*(latitude/90))
  29. return ((x, y), time_zone)
  30. def mousePressEvent(self, event):
  31. self.pin_konum.setX(event.x()-(self.pin.width()//2))
  32. self.pin_konum.setY(event.y()-(self.pin.height()//2))
  33. bolge = self.ara(event.x(), event.y())
  34. if len(bolge):
  35. a = self.koordinat_pixelleri[bolge].split("/")
  36. b = "/".join(a[1:])
  37. self.e.harita_tiklandi((a[0], b))
  38. self.update()
  39. def pin_hareket_ettir(self, bolge_adi):
  40. pos = koordinatlar[bolge_adi]
  41. koordinat = self.koordinat_pixel_tespiti(pos[-1], pos[0])
  42. self.pin_konum.setX(koordinat[0][0] - (self.pin.width() // 2))
  43. self.pin_konum.setY(koordinat[0][1] - (self.pin.height() // 2))
  44. self.update()
  45. def paintEvent(self, event):
  46. boyayici = QPainter(self)
  47. boyayici.setRenderHints(QPainter.SmoothPixmapTransform|QPainter.Antialiasing|QPainter.HighQualityAntialiasing)
  48. boyayici.drawPixmap(QPoint(0, 0), QPixmap("./resimler/harita.png"))
  49. boyayici.drawPixmap(self.pin_konum, self.pin)