Skip to content

Commit

Permalink
Pythagorean tree: Make border scale invariant
Browse files Browse the repository at this point in the history
  • Loading branch information
pavlin-policar committed Mar 26, 2017
1 parent 32a022b commit 3124238
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions Orange/widgets/visualize/pythagorastreeviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
from collections import namedtuple, defaultdict, deque
from math import pi, sqrt, cos, sin, degrees

from AnyQt.QtCore import Qt, QPointF, QTimer, QRectF, QSizeF
from AnyQt.QtGui import QColor, QBrush, QPen
from AnyQt.QtWidgets import (
QSizePolicy, QGraphicsItem, QGraphicsRectItem, QGraphicsWidget, QStyle
)
from AnyQt.QtGui import QColor, QBrush, QPen
from AnyQt.QtCore import Qt, QPointF, QTimer, QRectF, QSizeF

from Orange.widgets.visualize.utils.tree.treeadapter import TreeAdapter

Expand Down Expand Up @@ -245,9 +245,7 @@ def clear_tree(self):

def _calculate_tree(self, tree_adapter, weight_adjustment):
"""Actually calculate the tree squares"""
tree_builder = PythagorasTree(
weight_adjustment=weight_adjustment
)
tree_builder = PythagorasTree(weight_adjustment=weight_adjustment)
return tree_builder.pythagoras_tree(
tree_adapter, tree_adapter.root, Square(Point(0, 0), 200, -pi / 2)
)
Expand Down Expand Up @@ -367,8 +365,6 @@ class SquareGraphicsItem(QGraphicsRectItem):
The tree node the square represents.
brush : QColor, optional
The brush to be used as the backgound brush.
pen : QPen, optional
The pen to be used for the border.
"""

Expand All @@ -386,7 +382,11 @@ def __init__(self, tree_node, parent=None, **kwargs):
self.setRotation(degrees(angle))

self.setBrush(kwargs.get('brush', QColor('#297A1F')))
self.setPen(kwargs.get('pen', QPen(QColor('#000'))))
# The border should be invariant to scaling
pen = QPen(QColor(Qt.black))
pen.setWidthF(0.75)
pen.setCosmetic(True)
self.setPen(pen)

self.setAcceptHoverEvents(True)
self.setZValue(kwargs.get('zvalue', 0))
Expand Down Expand Up @@ -544,10 +544,11 @@ def paint(self, painter, option, widget=None):
super().paint(painter, option, widget)
painter.save()
pen = QPen(QColor(Qt.black))
pen.setWidth(4)
pen.setWidthF(2)
pen.setCosmetic(True)
pen.setJoinStyle(Qt.MiterJoin)
painter.setPen(pen)
painter.drawRect(rect.adjusted(2, 2, -2, -2))
painter.drawRect(rect)
painter.restore()
else:
super().paint(painter, option, widget)
Expand Down

0 comments on commit 3124238

Please sign in to comment.