Beispiel #1
0
 def do_insert_link(self, *args):
     link, name, is_image = self.ask_link()
     if not link:
         return
     url = self.parse_link(link)
     if url.isValid():
         url = unicode_type(url.toString(NO_URL_FORMATTING))
         self.focus_self()
         with self.editing_cursor() as c:
             if is_image:
                 c.insertImage(url)
             else:
                 name = name or url
                 fmt = QTextCharFormat()
                 fmt.setAnchor(True)
                 fmt.setAnchorHref(url)
                 fmt.setFontUnderline(True)
                 fmt.setForeground(QBrush(QColor('blue')))
                 prev_fmt = c.charFormat()
                 c.mergeCharFormat(fmt)
                 c.insertText(url)
                 c.setCharFormat(prev_fmt)
     else:
         error_dialog(self, _('Invalid URL'),
                      _('The url %r is invalid') % link, show=True)
 def do_underline(self):
     with self.editing_cursor() as c:
         fmt = QTextCharFormat()
         fmt.setFontUnderline(not c.charFormat().fontUnderline())
         c.mergeCharFormat(fmt)