Esempio n. 1
0
 def minimumLabelHeight(self):
     """
     Returns the minimum height that will be required based on this font size
     and labels list.
     """
     metrics = QFontMetrics(self.labelFont())
     return max(self._minimumLabelHeight,
                metrics.height() + self.verticalLabelPadding())
Esempio n. 2
0
    def paintEvent(self, event):
        """
        Overloads the paint event to paint additional \
        hint information if no text is set on the \
        editor.
        
        :param      event      | <QPaintEvent>
        """
        super(XLineEdit, self).paintEvent(event)

        # paint the hint text if not text is set
        if self.text() and not (self.icon() and not self.icon().isNull()):
            return

        # paint the hint text
        with XPainter(self) as painter:
            painter.setPen(self.hintColor())

            icon = self.icon()
            left, top, right, bottom = self.getTextMargins()

            w = self.width()
            h = self.height() - 2

            w -= (right + left)
            h -= (bottom + top)

            if icon and not icon.isNull():
                size = icon.actualSize(self.iconSize())
                x = self.cornerRadius() + 2
                y = (self.height() - size.height()) / 2.0

                painter.drawPixmap(x, y,
                                   icon.pixmap(size.width(), size.height()))

                w -= size.width() - 2
            else:
                x = 6 + left

            w -= self._buttonWidth
            y = 2 + top

            # create the elided hint
            if not self.text() and self.hint():
                rect = self.cursorRect()
                metrics = QFontMetrics(self.font())
                hint = metrics.elidedText(self.hint(), Qt.ElideRight, w)
                align = self.alignment()

                if align & Qt.AlignHCenter:
                    x = 0
                else:
                    x = rect.center().x()

                painter.drawText(x, y, w, h, align, hint)
Esempio n. 3
0
 def paintEvent(self, event):
     """
     Overloads the paint event to paint additional \
     hint information if no text is set on the \
     editor.
     
     :param      event      | <QPaintEvent>
     """
     super(XLineEdit, self).paintEvent(event)
     
     # paint the hint text if not text is set
     if self.text() and not (self.icon() and not self.icon().isNull()):
         return
     
     # paint the hint text
     with XPainter(self) as painter:
         painter.setPen(self.hintColor())
         
         icon = self.icon()
         left, top, right, bottom = self.getTextMargins()
         
         w = self.width()
         h = self.height() - 2
         
         w -= (right + left)
         h -= (bottom + top)
         
         if icon and not icon.isNull():
             size = icon.actualSize(self.iconSize())
             x    = self.cornerRadius() + 2
             y    = (self.height() - size.height()) / 2.0
             
             painter.drawPixmap(x, y, icon.pixmap(size.width(), size.height()))
             
             w -= size.width() - 2
         else:
             x = 6 + left
         
         w -= self._buttonWidth
         y = 2 + top
         
         # create the elided hint
         if not self.text() and self.hint():
             rect    = self.cursorRect()
             metrics = QFontMetrics(self.font())
             hint    = metrics.elidedText(self.hint(), Qt.ElideRight, w)
             align   = self.alignment()
             
             if align & Qt.AlignHCenter:
                 x = 0
             else:
                 x = rect.center().x()
             
             painter.drawText(x, y, w, h, align, hint)
Esempio n. 4
0
 def minimumLabelWidth(self):
     """
     Returns the minimum label width required on this renderers font size.
     
     :param      labels | [<str>, ..]
     """
     min_w = 0
     metrics = QFontMetrics(self.labelFont())
     for label in self.labels():
         min_w = max(min_w, metrics.width(label))
     
     return max(self._minimumLabelWidth,
                min_w + self.horizontalLabelPadding())
Esempio n. 5
0
 def setText( self, text ):
     """
     Sets the text for this item and resizes it to fit the text and the
     remove button.
     
     :param      text | <str>
     """
     super(XMultiTagItem, self).setText(text)
     
     metrics = QFontMetrics(self.font())
     
     hint = QSize(metrics.width(text) + 24, 18)
     self.setSizeHint(hint)
Esempio n. 6
0
    def setText(self, text):
        """
        Sets the text for this item and resizes it to fit the text and the
        remove button.
        
        :param      text | <str>
        """
        super(XMultiTagItem, self).setText(text)

        metrics = QFontMetrics(self.font())

        hint = QSize(metrics.width(text) + 24, 18)
        self.setSizeHint(hint)
Esempio n. 7
0
 def adjustMinimumWidth( self ):
     """
     Updates the minimum width for this menu based on the font metrics \
     for its title (if its shown).  This method is called automatically \
     when the menu is shown.
     """
     if not self.showTitle():
         return
     
     metrics = QFontMetrics(self.font())
     width   = metrics.width(self.title()) + 20
     
     if self.minimumWidth() < width:
         self.setMinimumWidth(width)
Esempio n. 8
0
    def adjustMinimumWidth(self):
        """
        Updates the minimum width for this menu based on the font metrics \
        for its title (if its shown).  This method is called automatically \
        when the menu is shown.
        """
        if not self.showTitle():
            return

        metrics = QFontMetrics(self.font())
        width = metrics.width(self.title()) + 20

        if self.minimumWidth() < width:
            self.setMinimumWidth(width)
Esempio n. 9
0
    def updateEditorGeometry(self, editor, option, index):
        super(ColumnDelegate, self).updateEditorGeometry(editor, option, index)

        keys = map(lambda x: nativestring(editor.itemText(x)),
                   range(editor.count()))
        longest = max(map(lambda x: (len(x), x), keys))[1]

        metrics = QFontMetrics(editor.font())
        width = metrics.width(longest) + 30
        tree = self.parent()
        item = tree.itemFromIndex(index)
        rect = tree.visualItemRect(item)

        if (index.column() == 0):
            width += rect.x()

        editor.resize(width, rect.height())
Esempio n. 10
0
 def updateEditorGeometry( self, editor, option, index ):
     super(ColumnDelegate, self).updateEditorGeometry(editor, 
                                                        option, 
                                                        index)
     
     keys = map(lambda x: nativestring(editor.itemText(x)), range(editor.count()))
     longest = max(map(lambda x: (len(x), x), keys))[1]
     
     metrics = QFontMetrics(editor.font())
     width   = metrics.width(longest) + 30
     tree    = self.parent()
     item    = tree.itemFromIndex(index)
     rect    = tree.visualItemRect(item)
     
     if ( index.column() == 0 ):
         width += rect.x()
     
     editor.resize(width, rect.height())
Esempio n. 11
0
 def maxNotchSize( self, orientation ):
     """
     Returns the maximum size for this ruler based on its notches and the
     given orientation.
     
     :param      orientation | <Qt.Orientation>
     
     :return     <int>
     """
     metrics = QFontMetrics(QApplication.font())
     
     if orientation == Qt.Vertical:
         notch = ''
         for n in self.notches():
             if len(nativestring(n)) > len(nativestring(notch)):
                 notch = nativestring(n)
         
         return metrics.width(notch)
     else:
         return metrics.height()
Esempio n. 12
0
    def maxNotchSize(self, orientation):
        """
        Returns the maximum size for this ruler based on its notches and the
        given orientation.
        
        :param      orientation | <Qt.Orientation>
        
        :return     <int>
        """
        metrics = QFontMetrics(QApplication.font())

        if orientation == Qt.Vertical:
            notch = ''
            for n in self.notches():
                if len(nativestring(n)) > len(nativestring(notch)):
                    notch = nativestring(n)

            return metrics.width(notch)
        else:
            return metrics.height()
Esempio n. 13
0
    def initOptions(self, options):
        """
        Initializes the edit with the inputed options data set.
        
        :param      options | <XScintillaEditOptions>
        """
        self.setAutoIndent(options.value('autoIndent'))
        self.setIndentationsUseTabs(options.value('indentationsUseTabs'))
        self.setTabIndents(options.value('tabIndents'))
        self.setTabWidth(options.value('tabWidth'))

        self.setCaretLineVisible(options.value('showCaretLine'))
        self.setShowWhitespaces(options.value('showWhitespaces'))
        self.setMarginLineNumbers(0, options.value('showLineNumbers'))
        self.setIndentationGuides(options.value('showIndentations'))
        self.setEolVisibility(options.value('showEndlines'))

        if options.value('showLimitColumn'):
            self.setEdgeMode(self.EdgeLine)
            self.setEdgeColumn(options.value('limitColumn'))
        else:
            self.setEdgeMode(self.EdgeNone)

        if options.value('showLineWrap'):
            self.setWrapMode(self.WrapWord)
        else:
            self.setWrapMode(self.WrapNone)

        # set the autocompletion source
        if options.value('autoComplete'):
            self.setAutoCompletionSource(QsciScintilla.AcsAll)
        else:
            self.setAutoCompletionSource(QsciScintilla.AcsNone)

        self.setAutoCompletionThreshold(options.value('autoCompleteThreshold'))

        # update the font information
        font = options.value('documentFont')
        font.setPointSize(options.value('documentFontSize'))
        self.setFont(font)

        # udpate the lexer
        lexer = self.lexer()
        if lexer:
            lexer.setFont(font)

        # create the margin font option
        mfont = options.value('documentMarginFont')
        mfont.setPointSize(font.pointSize() - 2)
        self.setMarginsFont(mfont)
        self.setMarginWidth(0, QFontMetrics(mfont).width('0000000') + 5)