Add url handling in editor and viewer
This commit is contained in:
@@ -38,12 +38,13 @@ from enum import Enum
|
||||
from time import time
|
||||
|
||||
from PyQt5.QtCore import (
|
||||
QObject, QPoint, QRegularExpression, QRunnable, Qt, QTimer, pyqtSignal,
|
||||
pyqtSlot
|
||||
QObject, QPoint, QRegularExpression, QRunnable, Qt, QTimer, QUrl,
|
||||
pyqtSignal, pyqtSlot
|
||||
)
|
||||
from PyQt5.QtGui import (
|
||||
QColor, QCursor, QKeyEvent, QKeySequence, QMouseEvent, QPalette, QPixmap,
|
||||
QResizeEvent, QTextBlock, QTextCursor, QTextDocument, QTextOption
|
||||
QColor, QCursor, QDesktopServices, QKeyEvent, QKeySequence, QMouseEvent,
|
||||
QPalette, QPixmap, QResizeEvent, QTextBlock, QTextCursor, QTextDocument,
|
||||
QTextOption
|
||||
)
|
||||
from PyQt5.QtWidgets import (
|
||||
QAction, QApplication, QFrame, QGridLayout, QHBoxLayout, QLabel, QLineEdit,
|
||||
@@ -985,7 +986,12 @@ class GuiDocEditor(QPlainTextEdit):
|
||||
follow tag function.
|
||||
"""
|
||||
if QApplication.keyboardModifiers() == QtModCtrl:
|
||||
self._processTag(self.cursorForPosition(event.pos()))
|
||||
cursor = self.cursorForPosition(event.pos())
|
||||
mData, mType = self._qDocument.metaDataAtPos(cursor.position())
|
||||
if mData and mType == "url":
|
||||
self._openWebsite(mData)
|
||||
else:
|
||||
self._processTag(cursor)
|
||||
super().mouseReleaseEvent(event)
|
||||
return
|
||||
|
||||
@@ -1116,6 +1122,13 @@ class GuiDocEditor(QPlainTextEdit):
|
||||
action = ctxMenu.addAction(self.tr("Set as Document Name"))
|
||||
action.triggered.connect(lambda: self._emitRenameItem(pBlock))
|
||||
|
||||
# URL
|
||||
(mData, mType) = self._qDocument.metaDataAtPos(pCursor.position())
|
||||
if mData and mType == "url":
|
||||
action = ctxMenu.addAction(self.tr("Open URL"))
|
||||
action.triggered.connect(lambda: self._openWebsite(mData))
|
||||
ctxMenu.addSeparator()
|
||||
|
||||
# Follow
|
||||
status = self._processTag(cursor=pCursor, follow=False)
|
||||
if status == nwTrinary.POSITIVE:
|
||||
@@ -1183,6 +1196,12 @@ class GuiDocEditor(QPlainTextEdit):
|
||||
|
||||
return
|
||||
|
||||
@pyqtSlot(str)
|
||||
def _openWebsite(self, url: str) -> None:
|
||||
"""Open a URL in the system's default browser."""
|
||||
QDesktopServices.openUrl(QUrl(url))
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def _runDocumentTasks(self) -> None:
|
||||
"""Run timer document tasks."""
|
||||
|
||||
Reference in New Issue
Block a user