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 |
10 from __future__ import unicode_literals |
11 |
11 |
12 from PyQt5.QtCore import pyqtSlot, Qt |
12 from PyQt5.QtCore import pyqtSlot, Qt, QMetaObject, QSize |
13 from PyQt5.QtGui import QPalette, QBrush, QColor, QTextDocument, QTextCursor |
13 from PyQt5.QtGui import QPalette, QBrush, QColor, QTextDocument, QTextCursor |
14 from PyQt5.QtWidgets import QWidget |
14 from PyQt5.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLabel, \ |
15 |
15 QComboBox, QCheckBox, QToolButton, QSizePolicy |
16 from .Ui_E5TextEditSearchWidget import Ui_E5TextEditSearchWidget |
16 |
|
17 from E5Gui.E5ComboBox import E5ClearableComboBox |
17 |
18 |
18 import UI.PixmapCache |
19 import UI.PixmapCache |
19 |
20 |
20 |
21 |
21 class E5TextEditSearchWidget(QWidget, Ui_E5TextEditSearchWidget): |
22 class E5TextEditSearchWidget(QWidget): |
22 """ |
23 """ |
23 Class implementing a horizontal search widget for QTextEdit. |
24 Class implementing a horizontal search widget for QTextEdit. |
24 """ |
25 """ |
25 def __init__(self, parent=None): |
26 def __init__(self, parent=None, widthForHeight=True): |
26 """ |
27 """ |
27 Constructor |
28 Constructor |
28 |
29 |
29 @param parent reference to the parent widget (QWidget) |
30 @param parent reference to the parent widget |
|
31 @type QWidget |
|
32 @param widthForHeight flag indicating to prefer width for height. |
|
33 If this parameter is False, some widgets are shown in a third |
|
34 line. |
|
35 @type bool |
30 """ |
36 """ |
31 super(E5TextEditSearchWidget, self).__init__(parent) |
37 super(E5TextEditSearchWidget, self).__init__(parent) |
32 self.setupUi(self) |
38 self.__setupUi(widthForHeight) |
33 |
39 |
34 self.__textedit = None |
40 self.__textedit = None |
35 self.__texteditType = "" |
41 self.__texteditType = "" |
36 self.__findBackwards = True |
42 self.__findBackwards = True |
37 |
|
38 self.findPrevButton.setIcon(UI.PixmapCache.getIcon("1leftarrow.png")) |
|
39 self.findNextButton.setIcon(UI.PixmapCache.getIcon("1rightarrow.png")) |
|
40 |
43 |
41 self.__defaultBaseColor = \ |
44 self.__defaultBaseColor = \ |
42 self.findtextCombo.lineEdit().palette().color(QPalette.Base) |
45 self.findtextCombo.lineEdit().palette().color(QPalette.Base) |
43 self.__defaultTextColor = \ |
46 self.__defaultTextColor = \ |
44 self.findtextCombo.lineEdit().palette().color(QPalette.Text) |
47 self.findtextCombo.lineEdit().palette().color(QPalette.Text) |
51 |
54 |
52 self.__setSearchButtons(False) |
55 self.__setSearchButtons(False) |
53 self.infoLabel.hide() |
56 self.infoLabel.hide() |
54 |
57 |
55 self.setFocusProxy(self.findtextCombo) |
58 self.setFocusProxy(self.findtextCombo) |
|
59 |
|
60 def __setupUi(self, widthForHeight): |
|
61 """ |
|
62 Private method to generate the UI. |
|
63 |
|
64 @param widthForHeight flag indicating to prefer width for height |
|
65 @type bool |
|
66 """ |
|
67 self.setObjectName("E5TextEditSearchWidget") |
|
68 |
|
69 self.verticalLayout = QVBoxLayout(self) |
|
70 self.verticalLayout.setObjectName("verticalLayout") |
|
71 self.verticalLayout.setContentsMargins(0, 0, 0, 0) |
|
72 |
|
73 # row 1 of widgets |
|
74 self.horizontalLayout1 = QHBoxLayout() |
|
75 self.horizontalLayout1.setObjectName("horizontalLayout1") |
|
76 |
|
77 self.label = QLabel(self) |
|
78 self.label.setObjectName("label") |
|
79 self.label.setText(self.tr("Find:")) |
|
80 self.horizontalLayout1.addWidget(self.label) |
|
81 |
|
82 self.findtextCombo = E5ClearableComboBox(self) |
|
83 sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) |
|
84 sizePolicy.setHorizontalStretch(0) |
|
85 sizePolicy.setVerticalStretch(0) |
|
86 sizePolicy.setHeightForWidth( |
|
87 self.findtextCombo.sizePolicy().hasHeightForWidth()) |
|
88 self.findtextCombo.setSizePolicy(sizePolicy) |
|
89 self.findtextCombo.setMinimumSize(QSize(200, 0)) |
|
90 self.findtextCombo.setEditable(True) |
|
91 self.findtextCombo.setInsertPolicy(QComboBox.InsertAtTop) |
|
92 self.findtextCombo.setDuplicatesEnabled(False) |
|
93 self.findtextCombo.setObjectName("findtextCombo") |
|
94 self.horizontalLayout1.addWidget(self.findtextCombo) |
|
95 |
|
96 # row 2 (maybe) of widgets |
|
97 self.horizontalLayout2 = QHBoxLayout() |
|
98 self.horizontalLayout2.setObjectName("horizontalLayout2") |
|
99 |
|
100 self.caseCheckBox = QCheckBox(self) |
|
101 self.caseCheckBox.setObjectName("caseCheckBox") |
|
102 self.caseCheckBox.setText(self.tr("Match case")) |
|
103 self.horizontalLayout2.addWidget(self.caseCheckBox) |
|
104 |
|
105 self.wordCheckBox = QCheckBox(self) |
|
106 self.wordCheckBox.setObjectName("wordCheckBox") |
|
107 self.wordCheckBox.setText(self.tr("Whole word")) |
|
108 self.horizontalLayout2.addWidget(self.wordCheckBox) |
|
109 |
|
110 # layout for the navigation buttons |
|
111 self.horizontalLayout3 = QHBoxLayout() |
|
112 self.horizontalLayout3.setSpacing(0) |
|
113 self.horizontalLayout3.setObjectName("horizontalLayout3") |
|
114 |
|
115 self.findPrevButton = QToolButton(self) |
|
116 self.findPrevButton.setObjectName("findPrevButton") |
|
117 self.findPrevButton.setToolTip(self.tr( |
|
118 "Press to find the previous occurrence")) |
|
119 self.findPrevButton.setIcon(UI.PixmapCache.getIcon("1leftarrow.png")) |
|
120 self.horizontalLayout3.addWidget(self.findPrevButton) |
|
121 |
|
122 self.findNextButton = QToolButton(self) |
|
123 self.findNextButton.setObjectName("findNextButton") |
|
124 self.findNextButton.setToolTip(self.tr( |
|
125 "Press to find the next occurrence")) |
|
126 self.findNextButton.setIcon(UI.PixmapCache.getIcon("1rightarrow.png")) |
|
127 self.horizontalLayout3.addWidget(self.findNextButton) |
|
128 |
|
129 self.horizontalLayout2.addLayout(self.horizontalLayout3) |
|
130 |
|
131 # info label (in row 2 or 3) |
|
132 self.infoLabel = QLabel(self) |
|
133 self.infoLabel.setText("") |
|
134 self.infoLabel.setObjectName("infoLabel") |
|
135 |
|
136 # place everything together |
|
137 self.verticalLayout.addLayout(self.horizontalLayout1) |
|
138 if widthForHeight: |
|
139 self.horizontalLayout1.addLayout(self.horizontalLayout2) |
|
140 else: |
|
141 self.verticalLayout.addLayout(self.horizontalLayout2) |
|
142 self.verticalLayout.addWidget(self.infoLabel) |
|
143 |
|
144 QMetaObject.connectSlotsByName(self) |
|
145 |
|
146 self.setTabOrder(self.findtextCombo, self.caseCheckBox) |
|
147 self.setTabOrder(self.caseCheckBox, self.wordCheckBox) |
|
148 self.setTabOrder(self.wordCheckBox, self.findPrevButton) |
|
149 self.setTabOrder(self.findPrevButton, self.findNextButton) |
56 |
150 |
57 def attachTextEdit(self, textedit, editType="QTextEdit"): |
151 def attachTextEdit(self, textedit, editType="QTextEdit"): |
58 """ |
152 """ |
59 Public method to attach a QTextEdit widget. |
153 Public method to attach a QTextEdit widget. |
60 |
154 |