Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.6KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Middle-click draggable QGraphicsView
  4. # Copyright (C) 2016 Filipe Coelho <falktx@falktx.com>
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License as
  8. # published by the Free Software Foundation; either version 2 of
  9. # the License, or any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # For a full copy of the GNU General Public License see the doc/GPL.txt file.
  17. # ------------------------------------------------------------------------------------------------------------
  18. # Imports (Config)
  19. from carla_config import *
  20. # ------------------------------------------------------------------------------------------------------------
  21. # Imports (Global)
  22. if config_UseQt5:
  23. from PyQt5.QtCore import Qt
  24. from PyQt5.QtGui import QCursor, QMouseEvent
  25. from PyQt5.QtWidgets import QGraphicsView
  26. else:
  27. from PyQt4.QtCore import Qt
  28. from PyQt4.QtGui import QCursor, QGraphicsView, QMouseEvent
  29. # ------------------------------------------------------------------------------------------------------------
  30. # Widget Class
  31. class DraggableGraphicsView(QGraphicsView):
  32. def __init__(self, parent):
  33. QGraphicsView.__init__(self, parent)
  34. self.fPanning = False
  35. self.fCtrlDown = False
  36. try:
  37. self.fMiddleButton = Qt.MiddleButton
  38. except:
  39. self.fMiddleButton = Qt.MidButton
  40. def mousePressEvent(self, event):
  41. if event.button() == self.fMiddleButton and not self.fCtrlDown:
  42. self.fPanning = True
  43. self.setDragMode(QGraphicsView.ScrollHandDrag)
  44. event = QMouseEvent(event.type(), event.pos(), Qt.LeftButton, Qt.LeftButton, event.modifiers())
  45. QGraphicsView.mousePressEvent(self, event)
  46. def mouseReleaseEvent(self, event):
  47. QGraphicsView.mouseReleaseEvent(self, event)
  48. if not self.fPanning:
  49. return
  50. self.fPanning = False
  51. self.setDragMode(QGraphicsView.NoDrag)
  52. self.setCursor(QCursor(Qt.ArrowCursor))
  53. def keyPressEvent(self, event):
  54. if event.key() == Qt.Key_Control:
  55. self.fCtrlDown = True
  56. QGraphicsView.keyPressEvent(self, event)
  57. def keyReleaseEvent(self, event):
  58. if event.key() == Qt.Key_Control:
  59. self.fCtrlDown = False
  60. QGraphicsView.keyReleaseEvent(self, event)