Commit 132f21b7 authored by Aurelien Dufour's avatar Aurelien Dufour
Browse files

modification du design des arbres

parent 1e39eaa5
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ class BinaryTreeToPlanarTreeGui(LevelGui):

    def createPlanarTreeView(self):
        self.planarTreeScene = QGraphicsScene()
        self.planarTreeView = TreeView(self.planarTreeScene, controller=self.controller)
        self.planarTreeView = TreeView(self.planarTreeScene, controller=self.controller, root=True)
        self.planarTreeView.drawTree()

    def error(self, index: int, nodeType: str):
+1 −1
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ class PlanarTreeToBinaryTreeGui(LevelGui):

    def createPlanarTreeView(self):
        self.planarTreeScene = QGraphicsScene()
        self.planarTreeView = TreeView(self.planarTreeScene, controller=self.controller, model=True)
        self.planarTreeView = TreeView(self.planarTreeScene, controller=self.controller, model=True, root=True)
        self.planarTreeView.drawTree()

    def error(self, index: int, nodeType: str):
+25 −12
Original line number Diff line number Diff line
import math

from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt, QObject, pyqtSignal

from model.node import Leaf, EmptyNode, BinaryNode, IncompleteNode
from model.node import Leaf, EmptyNode, BinaryNode, IncompleteNode, PlanarNode
from model.tree import Tree


@@ -70,10 +72,21 @@ class TreeView(QGraphicsView):
        self.scene().setSceneRect(self.treeItemsGroup.sceneBoundingRect())

    def drawTreeRec(self, tree, nodeWidth, lineWidth, heightRatio, widthRatio, root):
        branchPen = QPen(QColor(113, 125, 126))
        nodePen = QPen(QColor(21, 67, 96))
        branchPen = QPen(QColor(21, 67, 96))
        if not root:
            if isinstance(tree, PlanarNode):
                nodeColor = QColor(245, 183, 177)
            else:
                nodeColor = QColor(169, 204, 227)
        else:
            nodeColor = QColor(187, 143, 206)
            nodePen.setWidth(0.1 * nodeWidth)
            space = nodeWidth / 15.356667
            branchPen.setDashPattern([space, space])
            nodePen.setDashPattern([space, space])
        branchPen.setWidth(lineWidth)
        branchPen.setCapStyle(Qt.RoundCap)
        nodePen = QPen(QColor(113, 125, 126))
        nodePen.setWidth(0.1 * nodeWidth)

        if isinstance(tree, Leaf):
@@ -87,7 +100,7 @@ class TreeView(QGraphicsView):
            leaf.setOpacity(0)
            self.treeItemsGroup.addToGroup(leaf)
            leafButton = LeafButton(self.controller, self.indexChildButton, 0.1 * nodeWidth)
            nodeButton = NodeButton(self.controller, self.indexChildButton, 0.1 * nodeWidth)
            nodeButton = NodeButton(self.controller, self.indexChildButton, 0.1 * nodeWidth, nodeColor)
            self.indexChildButton += 1
            leafButton.setRect(tree.x * widthRatio - nodeWidth / 2 - 0.05 * nodeWidth,
                               tree.y * heightRatio + nodeWidth / 4,
@@ -114,7 +127,7 @@ class TreeView(QGraphicsView):
                node = QGraphicsEllipseItem()
                node.setRect(tree.x * widthRatio - nodeWidth / 2, tree.y * heightRatio, nodeWidth, nodeWidth)
                node.setPen(nodePen)
                node.setBrush(QColor(174, 214, 241))
                node.setBrush(nodeColor)
                self.treeItemsGroup.addToGroup(node)
                self.drawTreeRec(tree.left, nodeWidth, lineWidth, heightRatio, widthRatio, False)
                self.drawTreeRec(tree.right, nodeWidth, lineWidth, heightRatio, widthRatio, False)
@@ -127,7 +140,7 @@ class TreeView(QGraphicsView):
                    branchButton = BranchButton(self.controller, self.indexChildButton, 0.1 *
                                                nodeWidth, tree.x * widthRatio + 0.05 * nodeWidth, tree.y * heightRatio + nodeWidth / 4,
                    nodeWidth / 2 - 0.1 * nodeWidth)
                    nodeButton = NodeButton(self.controller, self.indexChildButton, 0.1 * nodeWidth)
                    nodeButton = NodeButton(self.controller, self.indexChildButton, 0.1 * nodeWidth, nodeColor)
                    self.indexChildButton += 1
                    nodeButton.setRect(tree.x * widthRatio - nodeWidth / 2 - 0.05 * nodeWidth, tree.y * heightRatio +
                                       nodeWidth / 4, nodeWidth / 2 - 0.1 * nodeWidth, nodeWidth / 2 - 0.1 * nodeWidth)
@@ -146,7 +159,7 @@ class TreeView(QGraphicsView):
                        node = QGraphicsEllipseItem()
                        node.setRect(tree.x * widthRatio - nodeWidth / 2, tree.y * heightRatio, nodeWidth, nodeWidth)
                        node.setPen(nodePen)
                        node.setBrush(QColor(174, 214, 241))
                        node.setBrush(nodeColor)
                        self.treeItemsGroup.addToGroup(node)
                    for child in tree.children:
                        self.drawTreeRec(child, nodeWidth, lineWidth, heightRatio, widthRatio, False)
@@ -155,7 +168,7 @@ class TreeView(QGraphicsView):
                        node = QGraphicsEllipseItem()
                        node.setRect(tree.x * widthRatio - nodeWidth / 2, tree.y * heightRatio, nodeWidth, nodeWidth)
                        node.setPen(nodePen)
                        node.setBrush(QColor(174, 214, 241))
                        node.setBrush(nodeColor)
                        self.treeItemsGroup.addToGroup(node)


@@ -172,7 +185,7 @@ class LeafButton(QGraphicsRectItem):
        self.clickableObject = Clickable()
        self.index = buttonIndex
        self.controller = controller
        self.pen = QPen(QColor(113, 125, 126))
        self.pen = QPen(QColor(21, 67, 96))
        self.pen.setWidth(width)
        self.setPen(self.pen)
        self.connect()
@@ -189,13 +202,13 @@ class LeafButton(QGraphicsRectItem):


class NodeButton(QGraphicsEllipseItem):
    def __init__(self, controller, buttonIndex, width):
    def __init__(self, controller, buttonIndex, width, color):
        super(QGraphicsEllipseItem, self).__init__()
        self.clickableObject = Clickable()
        self.index = buttonIndex
        self.controller = controller
        self.setBrush(QColor(174, 214, 241))
        self.pen = QPen(QColor(113, 125, 126))
        self.setBrush(color)
        self.pen = QPen(QColor(21, 67, 96))
        self.pen.setWidth(width)
        self.setPen(self.pen)
        self.connect()