campaignview.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * campaignview.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "campaignview.h"
  12. CampaignScene::CampaignScene():
  13. QGraphicsScene(nullptr)
  14. {
  15. }
  16. CampaignView::CampaignView(QWidget * parent):
  17. QGraphicsView(parent)
  18. {
  19. setAcceptDrops(true);
  20. }
  21. void CampaignView::dragEnterEvent(QDragEnterEvent *event)
  22. {
  23. if(event->mimeData()->hasUrls())
  24. {
  25. for(const QUrl& url : event->mimeData()->urls())
  26. {
  27. QString path = url.toLocalFile();
  28. if(path.endsWith(".h3c", Qt::CaseInsensitive) || path.endsWith(".vcmp", Qt::CaseInsensitive))
  29. {
  30. event->acceptProposedAction();
  31. return;
  32. }
  33. }
  34. }
  35. }
  36. void CampaignView::dragMoveEvent(QDragMoveEvent *event)
  37. {
  38. if(event->mimeData()->hasUrls())
  39. {
  40. for(const QUrl& url : event->mimeData()->urls())
  41. {
  42. QString path = url.toLocalFile();
  43. if(path.endsWith(".h3c", Qt::CaseInsensitive) || path.endsWith(".vcmp", Qt::CaseInsensitive))
  44. {
  45. event->acceptProposedAction();
  46. return;
  47. }
  48. }
  49. }
  50. }
  51. void CampaignView::dropEvent(QDropEvent *event)
  52. {
  53. if(event->mimeData()->hasUrls())
  54. {
  55. for(const QUrl& url : event->mimeData()->urls())
  56. {
  57. QString path = url.toLocalFile();
  58. if(path.endsWith(".h3c", Qt::CaseInsensitive) || path.endsWith(".vcmp", Qt::CaseInsensitive))
  59. {
  60. Q_EMIT fileDropped(path);
  61. event->acceptProposedAction();
  62. return;
  63. }
  64. }
  65. }
  66. }
  67. ClickablePixmapItem::ClickablePixmapItem(const QPixmap &pixmap, const std::function<void()> & clickedCallback, const std::function<void()> & doubleClickedCallback, const std::function<void(QGraphicsSceneContextMenuEvent *)> & contextMenuCallback):
  68. QGraphicsPixmapItem(pixmap),
  69. clickedCallback(clickedCallback),
  70. doubleClickedCallback(doubleClickedCallback),
  71. contextMenuCallback(contextMenuCallback)
  72. {
  73. }
  74. void ClickablePixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
  75. {
  76. if(clickedCallback)
  77. clickedCallback();
  78. }
  79. void ClickablePixmapItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
  80. {
  81. if(doubleClickedCallback)
  82. doubleClickedCallback();
  83. }
  84. void ClickablePixmapItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
  85. {
  86. if(contextMenuCallback)
  87. contextMenuCallback(event);
  88. }