5 |
5 |
6 """ |
6 """ |
7 Module implementing a horizontal search widget for QTextEdit. |
7 Module implementing a horizontal search widget for QTextEdit. |
8 """ |
8 """ |
9 |
9 |
10 from __future__ import unicode_literals |
|
11 |
10 |
12 from PyQt5.QtCore import pyqtSlot, Qt, QMetaObject, QSize |
11 from PyQt5.QtCore import pyqtSlot, Qt, QMetaObject, QSize |
13 from PyQt5.QtGui import QPalette, QBrush, QColor, QTextDocument, QTextCursor |
12 from PyQt5.QtGui import QPalette, QBrush, QColor, QTextDocument, QTextCursor |
14 from PyQt5.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLabel, \ |
13 from PyQt5.QtWidgets import ( |
15 QComboBox, QCheckBox, QToolButton, QSizePolicy |
14 QWidget, QVBoxLayout, QHBoxLayout, QLabel, QComboBox, QCheckBox, |
|
15 QToolButton, QSizePolicy |
|
16 ) |
16 |
17 |
17 from E5Gui.E5ComboBox import E5ClearableComboBox |
18 from E5Gui.E5ComboBox import E5ClearableComboBox |
18 |
19 |
19 import UI.PixmapCache |
20 import UI.PixmapCache |
20 |
21 |
39 |
40 |
40 self.__textedit = None |
41 self.__textedit = None |
41 self.__texteditType = "" |
42 self.__texteditType = "" |
42 self.__findBackwards = True |
43 self.__findBackwards = True |
43 |
44 |
44 self.__defaultBaseColor = \ |
45 self.__defaultBaseColor = ( |
45 self.findtextCombo.lineEdit().palette().color(QPalette.Base) |
46 self.findtextCombo.lineEdit().palette().color(QPalette.Base) |
46 self.__defaultTextColor = \ |
47 ) |
|
48 self.__defaultTextColor = ( |
47 self.findtextCombo.lineEdit().palette().color(QPalette.Text) |
49 self.findtextCombo.lineEdit().palette().color(QPalette.Text) |
|
50 ) |
48 |
51 |
49 self.findHistory = [] |
52 self.findHistory = [] |
50 |
53 |
51 self.findtextCombo.setCompleter(None) |
54 self.findtextCombo.setCompleter(None) |
52 self.findtextCombo.lineEdit().returnPressed.connect( |
55 self.findtextCombo.lineEdit().returnPressed.connect( |
271 if self.__texteditType == "QTextEdit": |
274 if self.__texteditType == "QTextEdit": |
272 ok = self.__findPrevNextQTextEdit(backwards) |
275 ok = self.__findPrevNextQTextEdit(backwards) |
273 self.__findNextPrevCallback(ok) |
276 self.__findNextPrevCallback(ok) |
274 elif self.__texteditType == "QWebEngineView": |
277 elif self.__texteditType == "QWebEngineView": |
275 self.__findPrevNextQWebEngineView(backwards) |
278 self.__findPrevNextQWebEngineView(backwards) |
276 elif self.__texteditType == "QWebView": |
|
277 ok = self.__findPrevNextQWebView(backwards) |
|
278 self.__findNextPrevCallback(ok) |
|
279 |
279 |
280 def __findPrevNextQTextEdit(self, backwards): |
280 def __findPrevNextQTextEdit(self, backwards): |
281 """ |
281 """ |
282 Private method to to search the associated edit widget of |
282 Private method to to search the associated edit widget of |
283 type QTextEdit. |
283 type QTextEdit. |
308 self.__textedit.setTextCursor(cursor) |
308 self.__textedit.setTextCursor(cursor) |
309 ok = self.__textedit.find(self.findtextCombo.currentText(), flags) |
309 ok = self.__textedit.find(self.findtextCombo.currentText(), flags) |
310 |
310 |
311 return ok |
311 return ok |
312 |
312 |
313 def __findPrevNextQWebView(self, backwards): |
|
314 """ |
|
315 Private method to to search the associated edit widget of |
|
316 type QWebView. |
|
317 |
|
318 @param backwards flag indicating a backwards search |
|
319 @type bool |
|
320 @return flag indicating the search result |
|
321 @rtype bool |
|
322 """ |
|
323 from PyQt5.QtWebKitWidgets import QWebPage |
|
324 |
|
325 findFlags = QWebPage.FindFlags(QWebPage.FindWrapsAroundDocument) |
|
326 if self.caseCheckBox.isChecked(): |
|
327 findFlags |= QWebPage.FindCaseSensitively |
|
328 if backwards: |
|
329 findFlags |= QWebPage.FindBackward |
|
330 |
|
331 return self.__textedit.findText(self.findtextCombo.currentText(), |
|
332 findFlags) |
|
333 |
|
334 def __findPrevNextQWebEngineView(self, backwards): |
313 def __findPrevNextQWebEngineView(self, backwards): |
335 """ |
314 """ |
336 Private method to to search the associated edit widget of |
315 Private method to to search the associated edit widget of |
337 type QWebEngineView. |
316 type QWebEngineView. |
338 |
317 |