
    e$                     h    d dl mZmZ ddlmZ ddlmZ ddlmZm	Z	m
Z
 ddlmZ dgZ G d	 de      Zy
)    )atan2degrees   )	functions)Point)QtCoreQtGui	QtWidgets   )GraphicsObjectTextItemc                       e Zd ZdZ	 	 ddZddZd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zd ZddZd Zd Zd Zd ZddZy)r   zs
    GraphicsItem displaying unscaled text (the text will always appear normal even inside a scaled ViewBox). 
    Nc
                 4   t        |      | _        |dn
t        |      | _        t        j                  |        t        j                         | _        | j                  j                  |        d| _	        d| _
        |	rd| _        t        j                         | _        |#| j                  |       | j!                  |       n| j#                  |       t%        j&                  |      | _        t%        j*                  |      | _        | j/                  |       y)a  
        ================  =================================================================================
        **Arguments:**
        *text*            The text to display
        *color*           The color of the text (any format accepted by pg.mkColor)
        *html*            If specified, this overrides both *text* and *color*
        *anchor*          A QPointF or (x,y) sequence indicating what region of the text box will
                          be anchored to the item's position. A value of (0,0) sets the upper-left corner
                          of the text box to be at the position specified by setPos(), while a value of (1,1)
                          sets the lower-right corner.
        *border*          A pen to use when drawing the border
        *fill*            A brush to use when filling within the border
        *angle*           Angle in degrees to rotate text. Default is 0; text will be displayed upright.
        *rotateAxis*      If None, then a text angle of 0 always points along the +x axis of the scene.
                          If a QPointF or (x,y) sequence is given, then it represents a vector direction
                          in the parent's coordinate system that the 0-degree line will be aligned to. This
                          Allows text to follow both the position and orientation of its parent while still
                          discarding any scale and shear factors.
        *ensureInBounds*  Ensures that the entire TextItem will be visible when using autorange, but may
                          produce runaway scaling in certain circumstances (See issue #2642). Setting to 
                          "True" retains legacy behavior.
        ================  =================================================================================


        The effects of the `rotateAxis` and `angle` arguments are added independently. So for example:

          * rotateAxis=None, angle=0 -> normal horizontal text
          * rotateAxis=None, angle=90 -> normal vertical text
          * rotateAxis=(1, 0), angle=0 -> text aligned with x axis of its parent
          * rotateAxis=(0, 1), angle=0 -> text aligned with y axis of its parent
          * rotateAxis=(1, 0), angle=90 -> text orthogonal to x axis of its parent
        N)r   anchor
rotateAxisr   __init__r
   QGraphicsTextItemtextItemsetParentItem_lastTransform
_lastScene
dataBoundsr   QRectF_boundssetColorsetTextsetHtmlfnmkBrushfillmkPenbordersetAngle)
selftextcolorhtmlr   r"   r    angler   ensureInBoundss
             B/usr/lib/python3/dist-packages/pyqtgraph/graphicsItems/TextItem.pyr   zTextItem.__init__   s    F Fm","4$%
:K%!335##D)"
 "DO}}<MM% LLLLJJt$	hhv&e    c                 L    || j                  |       | j                  |       y)z
        Set the text of this item. 
        
        This method sets the plain text of the item; see also setHtml().
        N)r   setPlainText)r$   r%   r&   s      r*   r   zTextItem.setTextJ   s$     MM% $r+   c                     || j                         k7  r,| j                  j                  |       | j                          yy)z
        Set the plain text to be rendered by this item. 
        
        See QtWidgets.QGraphicsTextItem.setPlainText().
        N)toPlainTextr   r-   updateTextPos)r$   r%   s     r*   r-   zTextItem.setPlainTextT   s8     4##%%MM&&t,  &r+   c                 6    | j                   j                         S N)r   r/   r$   s    r*   r/   zTextItem.toPlainText^   s    }}((**r+   c                     | j                         |k7  r,| j                  j                  |       | j                          yy)z}
        Set the HTML code to be rendered by this item. 
        
        See QtWidgets.QGraphicsTextItem.setHtml().
        N)toHtmlr   r   r0   )r$   r'   s     r*   r   zTextItem.setHtmla   s5     ;;=D MM!!$'  !r+   c                 6    | j                   j                         S r2   )r   r5   r3   s    r*   r5   zTextItem.toHtmlk   s    }}##%%r+   c                 V     | j                   j                  |  | j                          y)z
        Set the width of the text.
        
        If the text requires more space than the width limit, then it will be
        wrapped into multiple lines.
        
        See QtWidgets.QGraphicsTextItem.setTextWidth().
        N)r   setTextWidthr0   r$   argss     r*   r8   zTextItem.setTextWidthn   s$     	#""D)r+   c                 V     | j                   j                  |  | j                          y)zj
        Set the font for this text. 
        
        See QtWidgets.QGraphicsTextItem.setFont().
        N)r   setFontr0   r9   s     r*   r<   zTextItem.setFontz   s$     	t$r+   c                 6    || _         | j                  d       y)a  
        Set the angle of the text in degrees.

        This sets the rotation angle of the text as a whole, measured
        counter-clockwise from the x axis of the parent. Note that this rotation
        angle does not depend on horizontal/vertical scaling of the parent.
        T)forceN)r(   updateTransform)r$   r(   s     r*   r#   zTextItem.setAngle   s     
4(r+   c                 D    t        |      | _        | j                          y r2   )r   r   r0   )r$   r   s     r*   	setAnchorzTextItem.setAnchor   s    Fmr+   c                     t        j                  |      | _        | j                  j	                  | j                         y)zr
        Set the color for this text.
        
        See QtWidgets.QGraphicsItem.setDefaultTextColor().
        N)r   mkColorr&   r   setDefaultTextColor)r$   r&   s     r*   r   zTextItem.setColor   s*     ZZ&
))$**5r+   c                 8   | j                   j                         }| j                   j                  |j                               }| j                   j                  |j	                               }||z
  | j
                  z  }| j                   j                  |        y r2   )r   boundingRectmapToParenttopLeftbottomRightr   setPos)r$   rtlbroffsets        r*   r0   zTextItem.updateTextPos   sn    MM&&(]]&&qyy{3]]&&q}}7r'T[[(fW%r+   c                     |r+|d   |d   }}|| j                   |   cxk  r|k  s	ddgS  ddgS | j                   |   | j                   |   gS )z
        Returns only the anchor point for when calulating view ranges.
        
        Sacrifices some visual polish for fixing issue #2642.
        r   r   N)r   )r$   axfrac
orthoRange	range_min	range_maxs         r*   r   zTextItem.dataBounds   sa     #-a=*Q-yIB<9<d|# =d|#BR11r+   c                 h    | j                   j                  | j                   j                               S r2   )r   mapRectToParentrF   r3   s    r*   rF   zTextItem.boundingRect   s$    }},,T]]-G-G-IJJr+   c                 $    | j                          y r2   )r?   r3   s    r*   viewTransformChangedzTextItem.viewTransformChanged   s     	r+   c                    | j                         }| j                  }||ur|%|j                  j                  | j                         || _        |%|j                  j                  | j                         | j	                          |j                  | j                                | j                  j                         t        j                  j                  j                  k7  s?| j                  j                         t        j                  j                  j                   k7  r|j#                  | j                         |j%                  | j                         |j'                  |j(                  j*                  d       |j-                  | j.                  j1                  | j.                  j3                                      y y )NT)scener   sigPrepareForPaint
disconnectr?   connectsetTransformsceneTransformr"   styler   QtPenStyleNoPenr    
BrushStyleNoBrushsetPensetBrushsetRenderHint
RenderHintAntialiasingdrawPolygonr   rG   rF   )r$   pr:   slss        r*   paintzTextItem.paint   s5    JJL__B;~%%001E1EFDO}$$,,T-A-AB  "NN4..01;;&))"4"4":"::diioo>OSYS\S\SgSgSoSo>oHHT[[!JJtyy!OOALL55t<MM$--33DMM4N4N4PQR	 ?pr+   c                 V    t        j                  | |       |r| j                          y y r2   )r   
setVisibler?   )r$   vs     r*   rq   zTextItem.setVisible   s&    !!$*  " r+   c                 V   | j                         sy | j                         }|t        j                         }n|j	                         }|s|| j
                  k(  ry t        j                  |      }|j                  |j                         |j                         |j                         |j                         |j                         |j                         dd|j                         	       | j                    }| j"                  m|j%                  | j"                        |j%                  t'        dd            z
  }t)        t+        |j-                         |j/                                     }||z  }|j1                  |       | j3                  |       || _        | j5                          y )Nr   )	isVisible
parentItemr	   
QTransformr_   r   r   invertQTransform	setMatrixm11m12m13m21m22m23m33r(   r   mapr   r   r   yxrotater^   r0   )r$   r>   rl   pttr(   das           r*   r?   zTextItem.updateTransform   s;   ~~ OO9!!#B!!#Bt222#	AEEGQUUWaeegquuw!QPQPUPUPWX ??&t'"&&q!*==AacceQSSU+,AQJE	! r+   )	 )   r   r   N)r   r   NNr   NFr2   )g      ?N)F)__name__
__module____qualname____doc__r   r   r-   r/   r   r5   r8   r<   r#   rA   r   r0   r   rF   rX   ro   rq   r?    r+   r*   r   r   
   sn     HMRW:x !+!&
	)6&2K
S(#
r+   N)mathr   r   r   r   r   r   ra   r   r	   r
   r   __all__r   r   r+   r*   <module>r      s,       ) ) *,f~ fr+   