Commits

Aleš Erjavec committed 2e29f6b

Change canvas background when the signal propagation is paused.

  • Participants
  • Parent commits 11a0d20

Comments (0)

Files changed (2)

File Orange/OrangeCanvas/canvas/view.py

 """
 import logging
 
-from PyQt4.QtGui import QGraphicsView, QCursor
-from PyQt4.QtCore import Qt, QRect, QRectF, QTimer
+from PyQt4.QtGui import QGraphicsView, QCursor, QIcon
+from PyQt4.QtCore import Qt, QRect, QSize, QRectF, QPoint, QTimer
 
 log = logging.getLogger(__name__)
 
 
 class CanvasView(QGraphicsView):
-    """Canvas View handles the zooming and panning.
+    """Canvas View handles the zooming.
     """
 
     def __init__(self, *args):
         QGraphicsView.__init__(self, *args)
         self.setAlignment(Qt.AlignTop | Qt.AlignLeft)
 
+        self.__backgroundIcon = QIcon()
+
         self.__autoScroll = False
         self.__autoScrollMargin = 16
         self.__autoScrollTimer = QTimer(self)
             self.__stopAutoScroll()
 
         log.debug("Auto scroll advance")
+
+    def setBackgroundIcon(self, icon):
+        if not isinstance(icon, QIcon):
+            raise TypeError("A QIcon expected.")
+
+        if self.__backgroundIcon != icon:
+            self.__backgroundIcon = icon
+            self.viewport().update()
+
+    def backgroundIcon(self):
+        return QIcon(self.__backgroundIcon)
+
+    def drawBackground(self, painter, rect):
+        QGraphicsView.drawBackground(self, painter, rect)
+
+        if not self.__backgroundIcon.isNull():
+            painter.setClipRect(rect)
+            vrect = QRect(QPoint(0, 0), self.viewport().size())
+            vrect = self.mapToScene(vrect).boundingRect()
+
+            pm = self.__backgroundIcon.pixmap(
+                vrect.size().toSize().boundedTo(QSize(200, 200))
+            )
+            pmrect = QRect(QPoint(0, 0), pm.size())
+            pmrect.moveCenter(vrect.center().toPoint())
+            if rect.toRect().intersects(pmrect):
+                painter.drawPixmap(pmrect, pm)

File Orange/OrangeCanvas/document/schemeedit.py

     QWidget, QVBoxLayout, QInputDialog, QMenu, QAction, QActionGroup,
     QKeySequence, QUndoStack, QGraphicsItem, QGraphicsObject,
     QGraphicsTextItem, QCursor, QFont, QPainter, QPixmap, QColor,
-    QIcon, QWhatsThisClickedEvent
+    QIcon, QWhatsThisClickedEvent, QBrush
 )
 
 from PyQt4.QtCore import (
 from ..registry.qt import whats_this_helper
 from ..gui.quickhelp import QuickHelpTipEvent
 from ..gui.utils import message_information, disabled
-from ..scheme import scheme, SchemeNode, SchemeLink, BaseSchemeAnnotation
+from ..scheme import (
+    scheme, signalmanager, SchemeNode, SchemeLink, BaseSchemeAnnotation
+)
 from ..canvas.scene import CanvasScene
 from ..canvas.view import CanvasView
 from ..canvas import items
             if self.__scheme:
                 self.__scheme.title_changed.disconnect(self.titleChanged)
                 self.__scheme.removeEventFilter(self)
+                sm = self.__scheme.findChild(signalmanager.SignalManager)
+                if sm:
+                    sm.stateChanged.disconnect(
+                        self.__signalManagerStateChanged)
 
             self.__scheme = scheme
 
                 self.__scheme.title_changed.connect(self.titleChanged)
                 self.titleChanged.emit(scheme.title)
                 self.__cleanSchemeString = scheme_to_string(scheme)
+                sm = scheme.findChild(signalmanager.SignalManager)
+                if sm:
+                    sm.stateChanged.connect(self.__signalManagerStateChanged)
+
             else:
                 self.__cleanSchemeString = None
 
         if self.__scene:
             self.__scene.setFont(font)
 
+    def __signalManagerStateChanged(self, state):
+        if state == signalmanager.SignalManager.Running:
+            self.__view.setBackgroundBrush(QBrush(Qt.NoBrush))
+#            self.__view.setBackgroundIcon(QIcon())
+        elif state == signalmanager.SignalManager.Paused:
+            self.__view.setBackgroundBrush(QBrush(QColor(235, 235, 235)))
+#            self.__view.setBackgroundIcon(QIcon("canvas_icons:Pause.svg"))
+
 
 def scheme_to_string(scheme):
     stream = StringIO()