WebBrowser/WebBrowserView.py

branch
QtWebEngine
changeset 4727
62b50a24fb59
parent 4726
c26e2a2dc0cb
child 4728
0367675d783d
--- a/WebBrowser/WebBrowserView.py	Sun Feb 07 18:08:48 2016 +0100
+++ b/WebBrowser/WebBrowserView.py	Sun Feb 07 19:36:07 2016 +0100
@@ -385,6 +385,36 @@
         """
         self.triggerPageAction(QWebEnginePage.Copy)
     
+    def cut(self):
+        """
+        Public slot to cut the selected text.
+        """
+        self.triggerPageAction(QWebEnginePage.Cut)
+    
+    def paste(self):
+        """
+        Public slot to paste text from the clipboard.
+        """
+        self.triggerPageAction(QWebEnginePage.Paste)
+    
+    def undo(self):
+        """
+        Public slot to undo the last edit action.
+        """
+        self.triggerPageAction(QWebEnginePage.Undo)
+    
+    def redo(self):
+        """
+        Public slot to redo the last edit action.
+        """
+        self.triggerPageAction(QWebEnginePage.Redo)
+    
+    def selectAll(self):
+        """
+        Public slot to select all text.
+        """
+        self.triggerPageAction(QWebEnginePage.SelectAll)
+    
     def isForwardAvailable(self):
         """
         Public method to determine, if a forward move in history is possible.
@@ -556,7 +586,8 @@
 ##            menu.addSeparator()
 ##            menu.addAction(
 ##                UI.PixmapCache.getIcon("editCopy.png"),
-##                self.tr("Copy Link to Clipboard"), self.__copyLink)
+##                self.tr("Copy Link to Clipboard"), self.__copyLink)\
+##                .setData(hit.linkUrl())
 ##            menu.addAction(
 ##                UI.PixmapCache.getIcon("mailSend.png"),
 ##                self.tr("Send Link"),
@@ -584,7 +615,7 @@
 ##            menu.addAction(
 ##                UI.PixmapCache.getIcon("editCopy.png"),
 ##                self.tr("Copy Image Location to Clipboard"),
-##                self.__copyLocation).setData(hit.imageUrl().toString())
+##                self.__copyLink).setData(hit.imageUrl())
 ##            menu.addAction(
 ##                UI.PixmapCache.getIcon("mailSend.png"),
 ##                self.tr("Send Image Link"),
@@ -633,7 +664,7 @@
 ##                menu.addAction(
 ##                    UI.PixmapCache.getIcon("editCopy.png"),
 ##                    self.tr("Copy Media Address to Clipboard"),
-##                    self.__copyLocation).setData(videoUrl.toString())
+##                    self.__copyLink).setData(videoUrl)
 ##                menu.addAction(
 ##                    UI.PixmapCache.getIcon("mailSend.png"),
 ##                    self.tr("Send Media Address"), self.__sendLink)\
@@ -725,6 +756,9 @@
 ##            UI.PixmapCache.getIcon("bookmark22.png"),
 ##            self.tr("Bookmark this Page"), self.addBookmark)
         menu.addAction(
+            UI.PixmapCache.getIcon("editCopy.png"),
+            self.tr("Copy Page Link"), self.__copyLink).setData(self.url())
+        menu.addAction(
             UI.PixmapCache.getIcon("mailSend.png"),
             self.tr("Send Page Link"), self.__sendLink).setData(self.url())
         menu.addSeparator()
@@ -741,8 +775,16 @@
         menu.addAction(self.__mw.zoomResetAct)
         menu.addAction(self.__mw.zoomOutAct)
         menu.addSeparator()
+        # TODO: edit actions only for forms
+        menu.addAction(self.__mw.undoAct)
+        menu.addAction(self.__mw.redoAct)
+        menu.addSeparator()
         if self.selectedText():
             menu.addAction(self.__mw.copyAct)
+            menu.addAction(self.__mw.cutAct)
+        menu.addAction(self.__mw.pasteAct)
+        menu.addAction(self.__mw.selectAllAct)
+        if self.selectedText():
             menu.addAction(
                 UI.PixmapCache.getIcon("mailSend.png"),
                 self.tr("Send Text"),
@@ -805,7 +847,7 @@
 ##                           self.__addSearchEngine).setData(element)
 ##            menu.addSeparator()
         
-        # TODO: Web Inspector
+        # TODO: WebInspector
 ##        menu.addAction(
 ##            UI.PixmapCache.getIcon("webInspector.png"),
 ##            self.tr("Web Inspector..."), self.__webInspector)
@@ -867,18 +909,25 @@
             data = data.toString()
         QDesktopServices.openUrl(QUrl("mailto:?body=" + data))
     
+    def __copyLink(self):
+        """
+        Private slot to copy a link to the clipboard.
+        """
+        act = self.sender()
+        data = act.data()
+        if isinstance(data, QUrl) and data.isEmpty():
+            return
+        
+        if isinstance(data, QUrl):
+            data = data.toString()
+        QApplication.clipboard().setText(data)
+    
 ##    def __downloadLink(self):
 ##        """
 ##        Private slot to download a link and save it to disk.
 ##        """
 ##        self.pageAction(QWebPage.DownloadLinkToDisk).trigger()
 ##    
-##    def __copyLink(self):
-##        """
-##        Private slot to copy a link to the clipboard.
-##        """
-##        self.pageAction(QWebPage.CopyLinkToClipboard).trigger()
-##    
 ##    def __downloadImage(self):
 ##        """
 ##        Private slot to download an image and save it to disk.
@@ -891,14 +940,6 @@
 ##        """
 ##        self.pageAction(QWebPage.CopyImageToClipboard).trigger()
     
-    def __copyLocation(self):
-        """
-        Private slot to copy an image or media location to the clipboard.
-        """
-        act = self.sender()
-        url = act.data()
-        QApplication.clipboard().setText(url)
-    
     # TODO: AdBlock
 ##    def __blockImage(self):
 ##        """

eric ide

mercurial