Commits

Aleš Erjavec committed 5f54d6c

Moved gradient functions into gui.utils.

  • Participants
  • Parent commits 4b7fba2

Comments (0)

Files changed (4)

File Orange/OrangeCanvas/application/widgettoolbox.py

 
 from PyQt4.QtCore import  pyqtSignal as Signal, pyqtProperty as Property
 
-from ..gui.toolbox import ToolBox, create_tab_gradient
+from ..gui.toolbox import ToolBox
 from ..gui.toolgrid import ToolGrid
 from ..gui.quickhelp import StatusTipPromoter
+from ..gui.utils import create_gradient
 from ..registry.qt import QtWidgetRegistry
 
 
             brush = self.palette().brush(QPalette.Button)
 
         if not brush.gradient():
-            gradient = create_tab_gradient(brush.color())
+            gradient = create_gradient(brush.color())
             brush = QBrush(gradient)
 
         palette = button.palette()

File Orange/OrangeCanvas/document/quickmenu.py

 from ..gui.framelesswindow import FramelessWindow
 from ..gui.lineedit import LineEdit
 from ..gui.tooltree import ToolTree, FlattenedTreeItemModel
-from ..gui.toolgrid import ToolButtonEventListener
-from ..gui.toolbox import create_tab_gradient
-from ..gui.utils import StyledWidget_paintEvent
+from ..gui.utils import StyledWidget_paintEvent, create_css_gradient
 
 from ..registry.qt import QtWidgetRegistry
 
             y = window_size.height() - size.height()
 
         self.move(x, y)
-
-
-def create_css_gradient(base_color):
-    """
-    Create a Qt css linear gradient fragment based on the `base_color`.
-    """
-    grad = create_tab_gradient(base_color)
-    stops = grad.stops()
-    stops = "\n".join("    stop: {0:f} {1}".format(stop, color.name())
-                      for stop, color in stops)
-    return ("qlineargradient(\n"
-            "    x1: 0, y1: 0, x2: 0, y2: 1,\n"
-            "{0})").format(stops)

File Orange/OrangeCanvas/gui/toolbox.py

 from PyQt4.QtGui import (
     QWidget, QFrame, QSizePolicy, QIcon, QFontMetrics, QPainter, QStyle,
     QStyleOptionToolButton, QStyleOptionToolBoxV2, QPalette, QBrush, QPen,
-    QLinearGradient, QColor, QScrollArea, QVBoxLayout, QToolButton,
-    QAction, QActionGroup
+    QColor, QScrollArea, QVBoxLayout, QToolButton, QAction, QActionGroup
 )
 
 from PyQt4.QtCore import (
 FOCUS_OUTLINE_COLOR = "#609ED7"
 
 
-def create_tab_gradient(base_color):
-    """
-    Create a default background gradient for a tab button from a single
-    color.
-
-    """
-    grad = QLinearGradient(0, 0, 0, 1)
-    grad.setStops([(0.0, base_color),
-                   (0.5, base_color),
-                   (0.8, base_color.darker(105)),
-                   (1.0, base_color.darker(110)),
-                   ])
-    grad.setCoordinateMode(QLinearGradient.ObjectBoundingMode)
-    return grad
-
-
 class ToolBoxTabButton(QToolButton):
     """
     A tab button for an item in a :class:`ToolBox`.

File Orange/OrangeCanvas/gui/utils.py

 Helper utilities
 
 """
-import os
+
 import sys
 import traceback
 
     QPainter, QStyleOption, QStyle
 )
 
+from PyQt4.QtCore import QPointF
+
 import sip
 
 QWIDGETSIZE_MAX = ((1 << 24) - 1)
         return brush
 
 
+def create_gradient(base_color, stop=QPointF(0, 0),
+                    finalStop=QPointF(0, 1)):
+    """
+    Create a default linear gradient using `base_color` .
+
+    """
+    grad = QLinearGradient(stop, finalStop)
+    grad.setStops([(0.0, base_color),
+                   (0.5, base_color),
+                   (0.8, base_color.darker(105)),
+                   (1.0, base_color.darker(110)),
+                   ])
+    grad.setCoordinateMode(QLinearGradient.ObjectBoundingMode)
+    return grad
+
+
+def create_css_gradient(base_color, stop=QPointF(0, 0),
+                        finalStop=QPointF(0, 1)):
+    """
+    Create a Qt css linear gradient fragment based on the `base_color`.
+    """
+    gradient = create_gradient(base_color, stop, finalStop)
+    return css_gradient(gradient)
+
+
+def css_gradient(gradient):
+    """
+    Given an instance of a `QLinearGradient` return an equivalent qt css
+    gradient fragment.
+
+    """
+    stop, finalStop = gradient.start(), gradient.finalStop()
+    x1, y1, x2, y2 = stop.x(), stop.y(), finalStop.x(), finalStop.y()
+    stops = gradient.stops()
+    stops = "\n".join("    stop: {0:f} {1}".format(stop, color.name())
+                      for stop, color in stops)
+    return ("qlineargradient(\n"
+            "    x1: {x1}, y1: {y1}, x2: {x1}, y2: {y2},\n"
+            "{stops})").format(x1=x1, y1=y1, x2=x2, y2=y2, stops=stops)
+
+
 def message_critical(text, title=None, informative_text=None, details=None,
                      buttons=None, default_button=None, exc_info=False,
                      parent=None):