Example #1
0
    def doTextEdit(self, url, setCursor=False):
        """Process a textedit link and either highlight
           the corresponding source code or set the 
           cursor to it.
        """
        t = textedit.link(url)
        # Only process textedit links
        if not t:
            return False
        filename = util.normpath(t.filename)
        doc = self.document(filename, setCursor)
        if doc:
            cursor = QTextCursor(doc)
            b = doc.findBlockByNumber(t.line - 1)
            p = b.position() + t.column
            cursor.setPosition(p)
            cursors = pointandclick.positions(cursor)
            # Do highlighting if the document is active
            if cursors and doc == self.mainwindow().currentDocument():
                import viewhighlighter

                view = self.mainwindow().currentView()
                viewhighlighter.highlighter(view).highlight(self._highlightFormat, cursors, 2, 0)
            # set the cursor and bring the document to front
            if setCursor:
                mainwindow = self.mainwindow()
                mainwindow.setTextCursor(cursor)
                import widgets.blink

                widgets.blink.Blinker.blink_cursor(mainwindow.currentView())
                self.mainwindow().setCurrentDocument(doc)
                mainwindow.activateWindow()
                mainwindow.currentView().setFocus()
        return True
Example #2
0
 def doTextEdit(self, url, setCursor=False):
     """Process a textedit link and either highlight
        the corresponding source code or set the 
        cursor to it.
     """
     t = textedit.link(url)
     # Only process textedit links
     if not t:
         return False
     doc = self.document(t.filename, setCursor)
     if doc:
         cursor = QtGui.QTextCursor(doc)
         b = doc.findBlockByNumber(t.line - 1)
         p = b.position() + t.column
         cursor.setPosition(p)
         cursors = pointandclick.positions(cursor)
         # Do highlighting if the document is active
         if cursors and doc == self.mainwindow().currentDocument():
             import viewhighlighter
             view = self.mainwindow().currentView()
             viewhighlighter.highlighter(view).highlight(
                 self._highlightFormat, cursors, 2, 0)
         # set the cursor and bring the document to front
         if setCursor:
             mainwindow = self.mainwindow()
             mainwindow.setTextCursor(cursor)
             import widgets.blink
             widgets.blink.Blinker.blink_cursor(mainwindow.currentView())
             self.mainwindow().setCurrentDocument(doc)
             mainwindow.activateWindow()
             mainwindow.currentView().setFocus()
     return True
Example #3
0
 def dragElement(self, url):
     t = textedit.link(url)
     # Only process textedit links
     if not t:
         return False
     doc = self.document(t.filename, True)
     if doc:
         cursor = QtGui.QTextCursor(doc)
         b = doc.findBlockByNumber(t.line - 1)
         p = b.position() + t.column
         cursor.setPosition(p)
     self.emitCursor(cursor)
Example #4
0
 def dragElement(self, url):
     t = textedit.link(url)
     # Only process textedit links
     if not t:
         return False
     filename = util.normpath(t.filename)
     doc = self.document(filename, True)
     if doc:
         cursor = QTextCursor(doc)
         b = doc.findBlockByNumber(t.line - 1)
         p = b.position() + t.column
         cursor.setPosition(p)
     self.emitCursor(cursor)
 def cursor(self, link, load=False):
     """Returns the destination of a link as a QTextCursor of the destination document.
     
     If load (defaulting to False) is True, the document is loaded if it is not yet loaded.
     Returns None if the url was not valid or the document could not be loaded.
     
     """
     import popplerqt4
     if not isinstance(link, popplerqt4.Poppler.LinkBrowse) or not link.url():
         return
     t = textedit.link(link.url())
     if t:
         return super(Links, self).cursor(t.filename, t.line, t.column, load)
Example #6
0
 def slotLinkHelpRequested(self, pos, page, link):
     """Called when a ToolTip wants to appear above the hovered link."""
     if isinstance(link, popplerqt5.Poppler.LinkBrowse):
         cursor = self._links.cursor(link)
         if cursor:
             import documenttooltip
             text = documenttooltip.text(cursor)
         elif link.url():
             l = textedit.link(link.url())
             if l:
                 text = "{0} ({1}:{2})".format(os.path.basename(l.filename), l.line, l.column)
             else:
                 text = link.url()
         QToolTip.showText(pos, text, self.view.surface(), page.linkRect(link.linkArea()))
Example #7
0
    def cursor(self, link, load=False):
        """Returns the destination of a link as a QTextCursor of the destination document.

        If load (defaulting to False) is True, the document is loaded if it is not yet loaded.
        Returns None if the url was not valid or the document could not be loaded.

        """
        import qpageview.link
        if not isinstance(link, qpageview.link.Link) or not link.url:
            return
        t = textedit.link(link.url)
        if t:
            filename = util.normpath(t.filename)
            return super(Links, self).cursor(filename, t.line, t.column, load)
Example #8
0
 def slotLinkHelpRequested(self, pos, page, link):
     """Called when a ToolTip wants to appear above the hovered link."""
     if isinstance(link, popplerqt5.Poppler.LinkBrowse):
         cursor = self._links.cursor(link)
         if cursor:
             import documenttooltip
             text = documenttooltip.text(cursor)
         elif link.url():
             l = textedit.link(link.url())
             if l:
                 text = "{0} ({1}:{2})".format(os.path.basename(l.filename), l.line, l.column)
             else:
                 text = link.url()
         QToolTip.showText(pos, text, self.view.surface(), page.linkRect(link.linkArea()))
Example #9
0
 def hover(self, url):
     """actions when user set mouse over link"""
     t = textedit.link(url)
     if t:
         doc = self.document(t.filename)
         if doc and doc == self.mainwindow().currentDocument():
             cursor = QtGui.QTextCursor(doc)
             b = doc.findBlockByNumber(t.line - 1)
             p = b.position() + t.column
             cursor.setPosition(p)
             cursors = pointandclick.positions(cursor)
             if cursors:
                 import viewhighlighter
                 view = self.mainwindow().currentView()
                 viewhighlighter.highlighter(view).highlight(self._highlightFormat, cursors, 2, 5000)
Example #10
0
def links(document):
    try:
        return _cache[document]
    except KeyError:
        l = _cache[document] = Links()
        with l:
            import popplerqt4
            with qpopplerview.lock(document):
                for num in range(document.numPages()):
                    page = document.page(num)
                    for link in page.links():
                        if isinstance(link, popplerqt4.Poppler.LinkBrowse):
                            t = textedit.link(link.url())
                            if t:
                                l.add_link(t.filename, t.line, t.column, (num, link.linkArea()))
        return l
Example #11
0
def links(document):
    try:
        return _cache[document]
    except KeyError:
        l = _cache[document] = Links()
        with l:
            import popplerqt5
            with qpageview.locking.lock(document):
                for num in range(document.numPages()):
                    page = document.page(num)
                    for link in page.links():
                        if isinstance(link, popplerqt5.Poppler.LinkBrowse):
                            t = textedit.link(link.url())
                            if t:
                                filename = util.normpath(t.filename)
                                l.add_link(filename, t.line, t.column, (num, link.linkArea()))
        return l
Example #12
0
 def setCursor(self, url):
     """set cursor in source by clicked textedit link""" 
     t = textedit.link(url)
     if t:
         doc = self.document(t.filename, True)
         cursor = QtGui.QTextCursor(doc)
         b = doc.findBlockByNumber(t.line - 1)
         p = b.position() + t.column
         cursor.setPosition(p)
         mainwindow = self.mainwindow()
         mainwindow.setTextCursor(cursor)
         import widgets.blink
         widgets.blink.Blinker.blink_cursor(mainwindow.currentView())
         mainwindow.activateWindow()
         mainwindow.currentView().setFocus()
     else:
         import helpers
         helpers.openUrl(QtCore.QUrl(url))
Example #13
0
 def slotLinkHelpRequested(self, pos, page, link):
     """Called when a ToolTip wants to appear above the hovered link."""
     if isinstance(link, popplerqt4.Poppler.LinkBrowse):
         cursor = self._links.cursor(link)
         if cursor:
             from . import tooltip
             text = tooltip.text(cursor)
         elif link.url():
             l = textedit.link(link.url())
             if l:
                 text = "{0} ({1}:{2})".format(os.path.basename(l.filename), l.line, l.column)
             else:
                 text = link.url()
     elif isinstance(link, popplerqt4.Poppler.LinkGoto):
         text = _("Page {num}").format(num=link.destination().pageNumber())
         if link.isExternal():
             text = link.fileName() + "\n" + text
     else:
         return
     QToolTip.showText(pos, text, self.view.surface(), page.linkRect(link.linkArea()))
Example #14
0
 def slotLinkHelpRequested(self, ev, page, link):
     """Called when a ToolTip wants to appear above the hovered link."""
     pos = self.view.viewport().mapToGlobal(ev.pos())
     if link.url:
         cursor = self._links.cursor(link)
         if cursor:
             import documenttooltip
             text = documenttooltip.text(cursor)
         else:
             l = textedit.link(link.url)
             if l:
                 text = "{0} ({1}:{2})".format(os.path.basename(l.filename), l.line, l.column)
             else:
                 text = link.url
     elif hasattr(link, "linkobj") and isinstance(link.linkobj, popplerqt5.Poppler.LinkGoto):
         text = _("Page {num}").format(num=link.linkobj.destination().pageNumber())
         if link.linkobj.isExternal():
             text = link.linkobj.fileName() + "\n" + text
     else:
         return
     QToolTip.showText(pos, text, self.view, page.linkRect(link))