def keyPressEvent(self, evt): """ Protected method to handle key presses. @param evt reference to the key press event (QKeyEvent) """ if evt.key() == Qt.Key_Escape and self.__browser is not None: self.setText( str(self.__browser.url().toEncoded(), encoding="utf-8")) self.selectAll() return currentText = self.text().strip() if evt.key() in [Qt.Key_Enter, Qt.Key_Return] and \ not currentText.lower().startswith("http://"): append = "" if evt.modifiers() == Qt.KeyboardModifiers(Qt.ControlModifier): append = ".com" elif evt.modifiers() == Qt.KeyboardModifiers(Qt.ControlModifier | Qt.ShiftModifier): append = ".org" elif evt.modifiers() == Qt.KeyboardModifiers(Qt.ShiftModifier): append = ".net" if append != "": url = QUrl("http://www." + currentText) host = url.host() if not host.lower().endswith(append): host += append url.setHost(host) self.setText(url.toString()) E5LineEdit.keyPressEvent(self, evt)
def keyPressEvent(self, evt): """ Protected method to handle key presses. @param evt reference to the key press event (QKeyEvent) """ if evt.key() == Qt.Key_Escape and self.__browser is not None: self.setText( str(self.__browser.url().toEncoded(), encoding="utf-8")) self.selectAll() return currentText = self.text().strip() if evt.key() in [Qt.Key_Enter, Qt.Key_Return] and \ not currentText.lower().startswith("http://"): append = "" if evt.modifiers() == Qt.KeyboardModifiers(Qt.ControlModifier): append = ".com" elif evt.modifiers() == Qt.KeyboardModifiers( Qt.ControlModifier | Qt.ShiftModifier): append = ".org" elif evt.modifiers() == Qt.KeyboardModifiers(Qt.ShiftModifier): append = ".net" if append != "": url = QUrl("http://www." + currentText) host = url.host() if not host.lower().endswith(append): host += append url.setHost(host) self.setText(url.toString()) E5LineEdit.keyPressEvent(self, evt)
def paintEvent(self, evt): """ Protected method handling a paint event. @param evt reference to the paint event (QPaintEvent) """ if self.__privateMode: backgroundColor = QColor(220, 220, 220) # light gray foregroundColor = Qt.black else: backgroundColor = QApplication.palette().color(QPalette.Base) foregroundColor = QApplication.palette().color(QPalette.Text) if self.__browser is not None: p = self.palette() progress = self.__browser.progress() if progress == 0 or progress == 100: if self.__browser.url().scheme() == "https": if QSslCertificate is not None: if self.__browser.page().hasValidSslInfo(): backgroundColor = Preferences.getHelp( "SaveUrlColor") else: backgroundColor = Preferences.getHelp("SaveUrlColor") p.setBrush(QPalette.Base, backgroundColor) p.setBrush(QPalette.Text, foregroundColor) else: if self.__browser.url().scheme() == "https": if QSslCertificate is not None: if self.__browser.page().hasValidSslInfo(): backgroundColor = Preferences.getHelp( "SaveUrlColor") else: backgroundColor = Preferences.getHelp("SaveUrlColor") highlight = QApplication.palette().color(QPalette.Highlight) r = (highlight.red() + 2 * backgroundColor.red()) // 3 g = (highlight.green() + 2 * backgroundColor.green()) // 3 b = (highlight.blue() + 2 * backgroundColor.blue()) // 3 loadingColor = QColor(r, g, b) if abs(loadingColor.lightness() - backgroundColor.lightness()) < 20: # special handling for special color schemes (e.g Gaia) r = (2 * highlight.red() + backgroundColor.red()) // 3 g = (2 * highlight.green() + backgroundColor.green()) // 3 b = (2 * highlight.blue() + backgroundColor.blue()) // 3 loadingColor = QColor(r, g, b) gradient = QLinearGradient( QPointF(0, 0), QPointF(self.width(), 0)) gradient.setColorAt(0, loadingColor) gradient.setColorAt(progress / 100.0 - 0.000001, loadingColor) gradient.setColorAt(progress / 100.0, backgroundColor) p.setBrush(QPalette.Base, gradient) self.setPalette(p) E5LineEdit.paintEvent(self, evt)
def paintEvent(self, evt): """ Protected method handling a paint event. @param evt reference to the paint event (QPaintEvent) """ if self.__privateMode: backgroundColor = QColor(220, 220, 220) # light gray foregroundColor = Qt.black else: backgroundColor = QApplication.palette().color(QPalette.Base) foregroundColor = QApplication.palette().color(QPalette.Text) if self.__browser is not None: p = self.palette() progress = self.__browser.progress() if progress == 0 or progress == 100: if self.__browser.url().scheme() == "https": if QSslCertificate is not None: if self.__browser.page().hasValidSslInfo(): backgroundColor = Preferences.getHelp( "SaveUrlColor") else: backgroundColor = Preferences.getHelp("SaveUrlColor") p.setBrush(QPalette.Base, backgroundColor) p.setBrush(QPalette.Text, foregroundColor) else: if self.__browser.url().scheme() == "https": if QSslCertificate is not None: if self.__browser.page().hasValidSslInfo(): backgroundColor = Preferences.getHelp( "SaveUrlColor") else: backgroundColor = Preferences.getHelp("SaveUrlColor") highlight = QApplication.palette().color(QPalette.Highlight) r = (highlight.red() + 2 * backgroundColor.red()) // 3 g = (highlight.green() + 2 * backgroundColor.green()) // 3 b = (highlight.blue() + 2 * backgroundColor.blue()) // 3 loadingColor = QColor(r, g, b) if abs(loadingColor.lightness() - backgroundColor.lightness()) < 20: # special handling for special color schemes (e.g Gaia) r = (2 * highlight.red() + backgroundColor.red()) // 3 g = (2 * highlight.green() + backgroundColor.green()) // 3 b = (2 * highlight.blue() + backgroundColor.blue()) // 3 loadingColor = QColor(r, g, b) gradient = QLinearGradient(QPointF(0, 0), QPointF(self.width(), 0)) gradient.setColorAt(0, loadingColor) gradient.setColorAt(progress / 100.0 - 0.000001, loadingColor) gradient.setColorAt(progress / 100.0, backgroundColor) p.setBrush(QPalette.Base, gradient) self.setPalette(p) E5LineEdit.paintEvent(self, evt)
def focusOutEvent(self, evt): """ Protected method to handle focus out event. @param evt reference to the focus event (QFocusEvent) """ if self.text() == "" and self.__browser is not None: self.__browserUrlChanged(self.__browser.url()) E5LineEdit.focusOutEvent(self, evt)
def mouseDoubleClickEvent(self, evt): """ Protected method to handle mouse double click events. @param evt reference to the mouse event (QMouseEvent) """ if evt.button() == Qt.LeftButton: self.selectAll() else: E5LineEdit.mouseDoubleClickEvent(self, evt)
def dragEnterEvent(self, evt): """ Protected method to handle drag enter events. @param evt reference to the drag enter event (QDragEnterEvent) """ mimeData = evt.mimeData() if mimeData.hasUrls() or mimeData.hasText(): evt.acceptProposedAction() E5LineEdit.dragEnterEvent(self, evt)
def __init__(self, mainWindow, parent=None): """ Constructor @param mainWindow reference to the main window (WebBrowserWindow) @param parent reference to the parent widget (WebBrowserView) """ E5LineEdit.__init__(self, parent) self.setInactiveText(self.tr("Enter the URL here.")) self.setWhatsThis(self.tr("Enter the URL here.")) self.__mw = mainWindow self.__browser = None self.__privateMode = WebBrowserWindow.isPrivate() self.__bmActiveIcon = UI.PixmapCache.getIcon("bookmark16.png") self.__bmInactiveIcon = QIcon( self.__bmActiveIcon.pixmap(16, 16, QIcon.Disabled)) self.__safeBrowsingLabel = SafeBrowsingLabel(self) self.addWidget(self.__safeBrowsingLabel, E5LineEdit.LeftSide) self.__safeBrowsingLabel.setVisible(False) self.__favicon = FavIconLabel(self) self.addWidget(self.__favicon, E5LineEdit.LeftSide) self.__rssButton = E5LineEditButton(self) self.__rssButton.setIcon(UI.PixmapCache.getIcon("rss16.png")) self.addWidget(self.__rssButton, E5LineEdit.RightSide) self.__rssButton.setVisible(False) self.__bookmarkButton = E5LineEditButton(self) self.addWidget(self.__bookmarkButton, E5LineEdit.RightSide) self.__bookmarkButton.setVisible(False) self.__clearButton = E5LineEditButton(self) self.__clearButton.setIcon(UI.PixmapCache.getIcon("clearLeft.png")) self.addWidget(self.__clearButton, E5LineEdit.RightSide) self.__clearButton.setVisible(False) self.__safeBrowsingLabel.clicked.connect(self.__showThreatInfo) self.__bookmarkButton.clicked.connect(self.__showBookmarkInfo) self.__rssButton.clicked.connect(self.__rssClicked) self.__clearButton.clicked.connect(self.clear) self.textChanged.connect(self.__textChanged) self.__mw.bookmarksManager().entryChanged.connect( self.__bookmarkChanged) self.__mw.bookmarksManager().entryAdded.connect(self.__bookmarkChanged) self.__mw.bookmarksManager().entryRemoved.connect( self.__bookmarkChanged) self.__mw.speedDial().pagesChanged.connect(self.__bookmarkChanged)
def setupUi(self, AddBookmarkDialog): AddBookmarkDialog.setObjectName("AddBookmarkDialog") AddBookmarkDialog.resize(500, 230) AddBookmarkDialog.setMinimumSize(QtCore.QSize(500, 0)) AddBookmarkDialog.setMaximumSize(QtCore.QSize(500, 250)) AddBookmarkDialog.setSizeGripEnabled(True) self.gridLayout = QtWidgets.QGridLayout(AddBookmarkDialog) self.gridLayout.setObjectName("gridLayout") self.label_2 = QtWidgets.QLabel(AddBookmarkDialog) self.label_2.setObjectName("label_2") self.gridLayout.addWidget(self.label_2, 0, 0, 1, 1) self.nameEdit = E5LineEdit(AddBookmarkDialog) self.nameEdit.setObjectName("nameEdit") self.gridLayout.addWidget(self.nameEdit, 0, 1, 1, 1) self.label_3 = QtWidgets.QLabel(AddBookmarkDialog) self.label_3.setObjectName("label_3") self.gridLayout.addWidget(self.label_3, 1, 0, 1, 1) self.addressEdit = E5LineEdit(AddBookmarkDialog) self.addressEdit.setObjectName("addressEdit") self.gridLayout.addWidget(self.addressEdit, 1, 1, 1, 1) self.label = QtWidgets.QLabel(AddBookmarkDialog) self.label.setAlignment(QtCore.Qt.AlignLeading | QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop) self.label.setObjectName("label") self.gridLayout.addWidget(self.label, 2, 0, 1, 1) self.descriptionEdit = QtWidgets.QPlainTextEdit(AddBookmarkDialog) self.descriptionEdit.setObjectName("descriptionEdit") self.gridLayout.addWidget(self.descriptionEdit, 2, 1, 1, 1) self.label_4 = QtWidgets.QLabel(AddBookmarkDialog) self.label_4.setObjectName("label_4") self.gridLayout.addWidget(self.label_4, 3, 0, 1, 1) self.locationCombo = QtWidgets.QComboBox(AddBookmarkDialog) self.locationCombo.setObjectName("locationCombo") self.gridLayout.addWidget(self.locationCombo, 3, 1, 1, 1) self.buttonBox = QtWidgets.QDialogButtonBox(AddBookmarkDialog) self.buttonBox.setOrientation(QtCore.Qt.Horizontal) self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel | QtWidgets.QDialogButtonBox.Ok) self.buttonBox.setObjectName("buttonBox") self.gridLayout.addWidget(self.buttonBox, 4, 0, 1, 2) self.retranslateUi(AddBookmarkDialog) self.buttonBox.accepted.connect(AddBookmarkDialog.accept) self.buttonBox.rejected.connect(AddBookmarkDialog.reject) QtCore.QMetaObject.connectSlotsByName(AddBookmarkDialog) AddBookmarkDialog.setTabOrder(self.nameEdit, self.addressEdit) AddBookmarkDialog.setTabOrder(self.addressEdit, self.descriptionEdit) AddBookmarkDialog.setTabOrder(self.descriptionEdit, self.locationCombo) AddBookmarkDialog.setTabOrder(self.locationCombo, self.buttonBox)
def setupUi(self, BookmarkPropertiesDialog): BookmarkPropertiesDialog.setObjectName("BookmarkPropertiesDialog") BookmarkPropertiesDialog.resize(500, 221) BookmarkPropertiesDialog.setMinimumSize(QtCore.QSize(500, 0)) BookmarkPropertiesDialog.setMaximumSize(QtCore.QSize(500, 250)) BookmarkPropertiesDialog.setSizeGripEnabled(True) self.gridLayout = QtWidgets.QGridLayout(BookmarkPropertiesDialog) self.gridLayout.setObjectName("gridLayout") self.label_2 = QtWidgets.QLabel(BookmarkPropertiesDialog) self.label_2.setObjectName("label_2") self.gridLayout.addWidget(self.label_2, 0, 0, 1, 1) self.nameEdit = E5LineEdit(BookmarkPropertiesDialog) self.nameEdit.setObjectName("nameEdit") self.gridLayout.addWidget(self.nameEdit, 0, 1, 1, 1) self.addressLabel = QtWidgets.QLabel(BookmarkPropertiesDialog) self.addressLabel.setObjectName("addressLabel") self.gridLayout.addWidget(self.addressLabel, 1, 0, 1, 1) self.addressEdit = E5LineEdit(BookmarkPropertiesDialog) self.addressEdit.setObjectName("addressEdit") self.gridLayout.addWidget(self.addressEdit, 1, 1, 1, 1) self.label = QtWidgets.QLabel(BookmarkPropertiesDialog) self.label.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop) self.label.setObjectName("label") self.gridLayout.addWidget(self.label, 2, 0, 1, 1) self.descriptionEdit = QtWidgets.QPlainTextEdit(BookmarkPropertiesDialog) self.descriptionEdit.setObjectName("descriptionEdit") self.gridLayout.addWidget(self.descriptionEdit, 2, 1, 1, 1) self.buttonBox = QtWidgets.QDialogButtonBox(BookmarkPropertiesDialog) self.buttonBox.setOrientation(QtCore.Qt.Horizontal) self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok) self.buttonBox.setObjectName("buttonBox") self.gridLayout.addWidget(self.buttonBox, 3, 0, 1, 2) self.retranslateUi(BookmarkPropertiesDialog) self.buttonBox.accepted.connect(BookmarkPropertiesDialog.accept) self.buttonBox.rejected.connect(BookmarkPropertiesDialog.reject) QtCore.QMetaObject.connectSlotsByName(BookmarkPropertiesDialog) BookmarkPropertiesDialog.setTabOrder(self.nameEdit, self.addressEdit) BookmarkPropertiesDialog.setTabOrder(self.addressEdit, self.descriptionEdit) BookmarkPropertiesDialog.setTabOrder(self.descriptionEdit, self.buttonBox)
def dropEvent(self, evt): """ Protected method to handle drop events. @param evt reference to the drop event (QDropEvent) """ mimeData = evt.mimeData() url = QUrl() if mimeData.hasUrls(): url = mimeData.urls()[0] elif mimeData.hasText(): url = QUrl.fromEncoded(mimeData.text().encode(), QUrl.TolerantMode) if url.isEmpty() or not url.isValid(): E5LineEdit.dropEvent(self, evt) return self.setText(str(url.toEncoded(), encoding="utf-8")) self.selectAll() evt.acceptProposedAction()
def dropEvent(self, evt): """ Protected method to handle drop events. @param evt reference to the drop event (QDropEvent) """ mimeData = evt.mimeData() url = QUrl() if mimeData.hasUrls(): url = mimeData.urls()[0] elif mimeData.hasText(): url = QUrl.fromEncoded(mimeData.text().encode("utf-8"), QUrl.TolerantMode) if url.isEmpty() or not url.isValid(): E5LineEdit.dropEvent(self, evt) return self.setText(str(url.toEncoded(), encoding="utf-8")) self.selectAll() evt.acceptProposedAction()
def __init__(self, mainWindow, parent=None): """ Constructor @param mainWindow reference to the main window (HelpWindow) @param parent reference to the parent widget (HelpBrowser) """ E5LineEdit.__init__(self, parent) self.setInactiveText(self.tr("Enter the URL here.")) self.setWhatsThis(self.tr("Enter the URL here.")) self.__mw = mainWindow self.__browser = None self.__privateMode = QWebSettings.globalSettings().testAttribute( QWebSettings.PrivateBrowsingEnabled) self.__bmActiveIcon = UI.PixmapCache.getIcon("bookmark16.png") self.__bmInactiveIcon = QIcon( self.__bmActiveIcon.pixmap(16, 16, QIcon.Disabled)) self.__favicon = FavIconLabel(self) self.addWidget(self.__favicon, E5LineEdit.LeftSide) self.__sslLabel = SslLabel(self) self.addWidget(self.__sslLabel, E5LineEdit.LeftSide) self.__sslLabel.setVisible(False) self.__privacyButton = E5LineEditButton(self) self.__privacyButton.setIcon( UI.PixmapCache.getIcon("privateBrowsing.png")) self.addWidget(self.__privacyButton, E5LineEdit.RightSide) self.__privacyButton.setVisible(self.__privateMode) self.__rssButton = E5LineEditButton(self) self.__rssButton.setIcon(UI.PixmapCache.getIcon("rss16.png")) self.addWidget(self.__rssButton, E5LineEdit.RightSide) self.__rssButton.setVisible(False) self.__bookmarkButton = E5LineEditButton(self) self.addWidget(self.__bookmarkButton, E5LineEdit.RightSide) self.__bookmarkButton.setVisible(False) self.__clearButton = E5LineEditButton(self) self.__clearButton.setIcon(UI.PixmapCache.getIcon("clearLeft.png")) self.addWidget(self.__clearButton, E5LineEdit.RightSide) self.__clearButton.setVisible(False) self.__bookmarkButton.clicked.connect(self.__showBookmarkInfo) self.__privacyButton.clicked.connect(self.__privacyClicked) self.__rssButton.clicked.connect(self.__rssClicked) self.__clearButton.clicked.connect(self.clear) self.__mw.privacyChanged.connect(self.__privacyButton.setVisible) self.textChanged.connect(self.__textChanged) Helpviewer.HelpWindow.HelpWindow.bookmarksManager()\ .entryChanged.connect(self.__bookmarkChanged) Helpviewer.HelpWindow.HelpWindow.bookmarksManager()\ .entryAdded.connect(self.__bookmarkChanged) Helpviewer.HelpWindow.HelpWindow.bookmarksManager()\ .entryRemoved.connect(self.__bookmarkChanged) Helpviewer.HelpWindow.HelpWindow.speedDial().pagesChanged.connect( self.__bookmarkChanged)