Browse Source

Make canvas draggable with mouse middle-click

Closes #292
tags/1.9.7
falkTX 10 years ago
parent
commit
9e687476ff
4 changed files with 68 additions and 1 deletions
  1. +1
    -0
      .gitignore
  2. +3
    -0
      Makefile
  3. +6
    -1
      resources/ui/carla_host.ui
  4. +58
    -0
      source/widgets/draggablegraphicsview.py

+ 1
- 0
.gitignore View File

@@ -59,6 +59,7 @@ ui_*.py
source/canvaspreviewframe.py
source/carla_config.py
source/digitalpeakmeter.py
source/draggablegraphicsview.py
source/ledbutton.py
source/paramspinbox.py
source/pianoroll.py


+ 3
- 0
Makefile View File

@@ -266,6 +266,7 @@ RES = \
bin/resources/carla_widgets.py \
bin/resources/canvaspreviewframe.py \
bin/resources/digitalpeakmeter.py \
bin/resources/draggablegraphicsview.py \
bin/resources/externalui.py \
bin/resources/ledbutton.py \
bin/resources/paramspinbox.py \
@@ -354,6 +355,7 @@ endif
WIDGETS = \
source/canvaspreviewframe.py \
source/digitalpeakmeter.py \
source/draggablegraphicsview.py \
source/ledbutton.py \
source/paramspinbox.py \
source/pianoroll.py \
@@ -628,6 +630,7 @@ endif
$(LINK) $(DATADIR)/carla/carla_widgets.py $(DESTDIR)$(DATADIR)/carla/resources
$(LINK) $(DATADIR)/carla/canvaspreviewframe.py $(DESTDIR)$(DATADIR)/carla/resources
$(LINK) $(DATADIR)/carla/digitalpeakmeter.py $(DESTDIR)$(DATADIR)/carla/resources
$(LINK) $(DATADIR)/carla/draggablegraphicsview.py $(DESTDIR)$(DATADIR)/carla/resources
$(LINK) $(DATADIR)/carla/externalui.py $(DESTDIR)$(DATADIR)/carla/resources
$(LINK) $(DATADIR)/carla/ledbutton.py $(DESTDIR)$(DATADIR)/carla/resources
$(LINK) $(DATADIR)/carla/paramspinbox.py $(DESTDIR)$(DATADIR)/carla/resources


+ 6
- 1
resources/ui/carla_host.ui View File

@@ -127,7 +127,7 @@
<number>1</number>
</property>
<item row="0" column="1">
<widget class="QGraphicsView" name="graphicsView"/>
<widget class="DraggableGraphicsView" name="graphicsView"/>
</item>
<item row="0" column="2">
<widget class="DigitalPeakMeter" name="peak_out" native="true"/>
@@ -864,6 +864,11 @@
<extends>QListWidget</extends>
<header>racklistwidget.h</header>
</customwidget>
<customwidget>
<class>DraggableGraphicsView</class>
<extends>QGraphicsView</extends>
<header>draggablegraphicsview.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../resources.qrc"/>


+ 58
- 0
source/widgets/draggablegraphicsview.py View File

@@ -0,0 +1,58 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Middle-click draggable QGraphicsView
# Copyright (C) 2016 Filipe Coelho <falktx@falktx.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License, or any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# For a full copy of the GNU General Public License see the doc/GPL.txt file.

# ------------------------------------------------------------------------------------------------------------
# Imports (Config)

from carla_config import *

# ------------------------------------------------------------------------------------------------------------
# Imports (Global)

if config_UseQt5:
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QCursor
from PyQt5.QtWidgets import QGraphicsView, QMouseEvent
else:
from PyQt4.QtCore import Qt
from PyQt4.QtGui import QCursor, QGraphicsView, QMouseEvent

# ------------------------------------------------------------------------------------------------------------
# Widget Class

class DraggableGraphicsView(QGraphicsView):
def __init__(self, parent):
QGraphicsView.__init__(self, parent)

self.fPanning = False

def mousePressEvent(self, event):
if event.button() == Qt.MiddleButton:
self.fPanning = True
self.setDragMode(QGraphicsView.ScrollHandDrag)
event = QMouseEvent(event.type(), event.pos(), Qt.LeftButton, Qt.LeftButton, event.modifiers())

QGraphicsView.mousePressEvent(self, event)

def mouseReleaseEvent(self, event):
if self.fPanning:
self.fPanning = False
self.setDragMode(QGraphicsView.NoDrag)
self.setCursor(QCursor(Qt.ArrowCursor))

QGraphicsView.mouseReleaseEvent(self, event)

Loading…
Cancel
Save