コード例 #1
0
ファイル: text.py プロジェクト: pombreda/calibre-1
    def font(self, text_style):
        device_font = text_style.fontfacename in LIBERATION_FONT_MAP
        try:
            if device_font:
                face = self.font_map[text_style.fontfacename]
            else:
                face = self.face_map[text_style.fontfacename]
        except KeyError:  # Bad fontfacename field in LRF
            face = self.font_map['Dutch801 Rm BT Roman']

        sz = text_style.fontsize
        wt = text_style.fontweight
        style = text_style.fontstyle
        font = (
            face,
            wt,
            style,
            sz,
        )
        if font in self.cache:
            rfont = self.cache[font]
        else:
            italic = font[2] == QFont.StyleItalic
            rfont = QFont(font[0], font[3], font[1], italic)
            rfont.setPixelSize(font[3])
            rfont.setBold(wt >= 69)
            self.cache[font] = rfont
        qfont = rfont
        if text_style.emplinetype != 'none':
            qfont = QFont(rfont)
            qfont.setOverline(text_style.emplineposition == 'before')
            qfont.setUnderline(text_style.emplineposition == 'after')
        return qfont
コード例 #2
0
ファイル: text.py プロジェクト: Farb/calibre
    def font(self, text_style):
        device_font = text_style.fontfacename in LIBERATION_FONT_MAP
        try:
            if device_font:
                face = self.font_map[text_style.fontfacename]
            else:
                face = self.face_map[text_style.fontfacename]
        except KeyError:  # Bad fontfacename field in LRF
            face = self.font_map['Dutch801 Rm BT Roman']

        sz = text_style.fontsize
        wt = text_style.fontweight
        style = text_style.fontstyle
        font = (face, wt, style, sz,)
        if font in self.cache:
            rfont = self.cache[font]
        else:
            italic = font[2] == QFont.StyleItalic
            rfont = QFont(font[0], font[3], font[1], italic)
            rfont.setPixelSize(font[3])
            rfont.setBold(wt>=69)
            self.cache[font] = rfont
        qfont = rfont
        if text_style.emplinetype != 'none':
            qfont = QFont(rfont)
            qfont.setOverline(text_style.emplineposition == 'before')
            qfont.setUnderline(text_style.emplineposition == 'after')
        return qfont
コード例 #3
0
    def add_button(self,
                   text='',
                   action=lambda: None,
                   menu=None,
                   tooltip='',
                   bold=False,
                   underline=False,
                   autoraise=False,
                   text_color: str = None):
        button = QToolButton(self)
        if text_color is not None:
            button.setStyleSheet('QToolButton {color: ' + text_color + ';}')
        button.setText(text)
        font = QFont()
        font.setBold(bold)
        font.setUnderline(underline)
        button.setFont(font)
        button.setAutoRaise(autoraise)
        button.clicked.connect(action)
        button.setFixedHeight(self.hight)
        button.setToolTip(tooltip)

        if menu is not None:
            button.setMenu(menu)
            button.setPopupMode(QToolButton.MenuButtonPopup)

        self.buttons.append(button)
        self._place()
        self.show()
コード例 #4
0
    def set_button_style(self, attr_value_dict: dict):
        """
        :param attr_value_dict:
                Available styles:
                    'color' - text color
                    'background'
                    'font' - font family
                    'font_size'
                    'bold'
                    'italic'
                    'underline'
                    'autoraise' - autoraise button
                    'on_remove' - handler of remove function, None if no need

            Example: button.set_button_style({'color':'magenta' , 'font_size': 18})
        """
        if not attr_value_dict:
            return
        style = ''
        if 'color' in attr_value_dict and attr_value_dict['color']:
            style += 'color: ' + attr_value_dict['color'] + ';'
        if 'background' in attr_value_dict:
            style += 'background-color: ' + attr_value_dict['background'] + ';'

        if style is not '':
            self.setStyleSheet('QToolButton {' + style + '}')

        font = QFont()
        if 'font' in attr_value_dict:
            font.setFamily(attr_value_dict['font'])
        if 'font_size' in attr_value_dict:
            font.setPointSize(attr_value_dict['font_size'])
        font.setBold(attr_value_dict.get('bold', False))
        font.setItalic(attr_value_dict.get('italic', False))
        font.setUnderline(attr_value_dict.get('underline', False))
        self.setFont(font)

        self.setAutoRaise(attr_value_dict.get('autoraise', True))
        self.remove = attr_value_dict.get('on_remove', None)
        if self.remove:
            # set button context menu policy
            self.setContextMenuPolicy(Qt.CustomContextMenu)
            self.customContextMenuRequested.connect(self.on_context_menu)

            # create context menu
            self.popMenu = QMenu(self)
            menu_action = QAction('Remove', self, triggered=self.remove)
            self.popMenu.addAction(menu_action)
コード例 #5
0
 def getFont(self):
     font = QFont()
     font.setBold(True)
     font.setUnderline(True)
     return font