Changeset 6967:6c424e551981 in orange


Ignore:
Timestamp:
09/03/10 12:25:08 (4 years ago)
Author:
ales_erjavec <ales.erjavec@…>
Branch:
default
Convert:
54e0cc95a0b4ab1e88cf697b6ff57d30881c2a9a
Message:
  • limit captionItem's width
Location:
orange/OrangeCanvas
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orange/OrangeCanvas/orngCanvasItems.py

    r6966 r6967  
    99WARNING = 1 
    1010 
     11def _graphicsEffect(item): 
     12    if hasattr(item, "graphicsEffect"): 
     13        return item.graphicsEffect() 
     14    else: 
     15        return None 
     16     
    1117class TempCanvasLine(QGraphicsPathItem): 
    1218    def __init__(self, canvasDlg, canvas): 
     
    118124        if scene is not None: 
    119125            scene.addItem(self) 
    120              
    121126 
    122127    def remove(self):         
     
    156161    def boundingRect(self): 
    157162        rect = QGraphicsPathItem.boundingRect(self) 
    158         textRect = self.captionItem.boundingRect() ## Should work without this but for some reason if using graphics effects the text gets clipped 
    159         textRect.moveTo(self.captionItem.pos()) 
    160         return rect.united(textRect) 
     163        if _graphicsEffect(self): 
     164            textRect = self.captionItem.boundingRect() ## Should work without this but for some reason if using graphics effects the text gets clipped 
     165            textRect.moveTo(self.captionItem.pos()) 
     166            return rect.united(textRect) 
     167        else: 
     168            return rect 
    161169 
    162170    def paint(self, painter, option, widget = None): 
     
    247255        self.captionItem = QGraphicsTextItem(self) 
    248256        self.captionItem.setHtml("<center>%s</center>" % self.caption) 
    249         self.captionItem.document().setTextWidth(200) 
     257        self.captionItem.document().setTextWidth(min(self.captionItem.document().idealWidth(), 200)) 
    250258         
    251259        self.captionItem.setPos(-self.captionItem.boundingRect().width()/2.0 + self.widgetSize.width() / 2.0, self.widgetSize.height() + 2) 
     
    268276        if scene is not None: 
    269277            scene.addItem(self) 
    270              
    271         self.update() 
    272278 
    273279    def resetWidgetSize(self): 
     
    326332    def updateText(self, text): 
    327333        self.caption = str(text) 
     334        self.prepareGeometryChange() 
    328335        self.captionItem.setHtml("<center>%s</center>" % self.caption) 
     336        self.captionItem.document().adjustSize() 
     337        self.captionItem.document().setTextWidth(min(self.captionItem.document().idealWidth(), 200)) 
     338         
     339        self.captionItem.setPos(-self.captionItem.boundingRect().width()/2.0 + self.widgetSize.width() / 2.0, self.widgetSize.height() + 2) 
    329340        self.updateTooltip() 
    330341        self.update() 
     
    363374            y = round(y/10)*10 
    364375        self.setPos(x, y) 
     376        self.updateWidgetState() 
     377         
     378    def setPos(self, *args): 
     379        QGraphicsRectItem.setPos(self, *args) 
    365380        for line in self.inLines + self.outLines: 
    366381            line.updatePainterPath() 
    367         self.updateWidgetState() 
     382             
    368383 
    369384    # we have to increase the default bounding rect so that we also repaint the name of the widget and input/output boxes 
     
    371386        rect = QRectF(QPointF(0, 0), self.widgetSize).adjusted(-11, -6, 11, 6)#.adjusted(-100, -100, 100, 100) #(-10-width, -4, +10+width, +25) 
    372387        rect.setTop(rect.top() - 20 - 21) ## Room for progress bar and warning, error, info icons 
    373         textRect = self.captionItem.boundingRect() ## Should work without this but for some reason if using graphics effects the text gets clipped 
    374         textRect.moveTo(self.captionItem.pos()) 
    375         return rect.united(textRect)  
     388        if _graphicsEffect(self): 
     389            textRect = self.captionItem.boundingRect() ## Should work without this but for some reason if using graphics effects the text gets clipped 
     390            textRect.moveTo(self.captionItem.pos()) 
     391            return rect.united(textRect) 
     392        else: 
     393            return rect  
    376394 
    377395    # is mouse position inside the left signal channel 
     
    442460    # draw the widget 
    443461    def paint(self, painter, option, widget = None): 
    444         if self.isProcessing or self.isSelected(): 
     462        if self.isProcessing or self.isSelected() or getattr(self, "invalidPosition", False): 
    445463            painter.setPen(QPen(QBrush(QColor(125, 162, 206, 192)), 1, Qt.SolidLine, Qt.RoundCap)) 
    446464            painter.setBrush(QBrush(QColor(217, 232, 252, 192))) 
    447465            painter.drawRoundedRect(-10, -5, self.widgetSize.width()+20, self.widgetSize.height()+10, 5, 5) 
    448  
    449466 
    450467        if self.widgetInfo.inputs != []: 
  • orange/OrangeCanvas/orngView.py

    r6966 r6967  
    373373    def mouseDoubleClickEvent(self, ev): 
    374374        point = self.mapToScene(ev.pos()) 
    375         activeItem = self.scene().itemAt(point) 
     375        items = self.scene().items(QRectF(point, QSizeF(0.0, 0.0)).adjusted(-2, -2, 2, 2)) 
     376        items = [item for item in items if type(item) in [orngCanvasItems.CanvasWidget, orngCanvasItems.CanvasLine]] 
     377        activeItem = items[0] if items else None 
    376378        if type(activeItem) == orngCanvasItems.CanvasWidget:        # if we clicked on a widget 
    377379            self.tempWidget = activeItem 
Note: See TracChangeset for help on using the changeset viewer.