9 |
9 |
10 from PyQt4.QtCore import pyqtSignal, Qt, QEvent, qVersion |
10 from PyQt4.QtCore import pyqtSignal, Qt, QEvent, qVersion |
11 from PyQt4.QtGui import QLineEdit, QStyle, QPainter, QPalette, QStyleOptionFrameV2, \ |
11 from PyQt4.QtGui import QLineEdit, QStyle, QPainter, QPalette, QStyleOptionFrameV2, \ |
12 QWidget, QHBoxLayout, QBoxLayout, QLayout, QApplication, QSpacerItem, QSizePolicy |
12 QWidget, QHBoxLayout, QBoxLayout, QLayout, QApplication, QSpacerItem, QSizePolicy |
13 |
13 |
14 |
14 from E5Gui.E5LineEditButton import E5LineEditButton |
15 class SideWidget(QWidget): |
15 |
|
16 import UI.PixmapCache |
|
17 |
|
18 |
|
19 class E5LineEditSideWidget(QWidget): |
16 """ |
20 """ |
17 Class implementing the side widgets for the line edit class. |
21 Class implementing the side widgets for the line edit class. |
18 """ |
22 """ |
19 sizeHintChanged = pyqtSignal() |
23 sizeHintChanged = pyqtSignal() |
20 |
24 |
59 if qVersion() < "4.7.0": |
63 if qVersion() < "4.7.0": |
60 self.__inactiveText = inactiveText |
64 self.__inactiveText = inactiveText |
61 else: |
65 else: |
62 self.setPlaceholderText(inactiveText) |
66 self.setPlaceholderText(inactiveText) |
63 |
67 |
64 self.__leftWidget = SideWidget(self) |
68 self.__leftWidget = E5LineEditSideWidget(self) |
65 self.__leftWidget.resize(0, 0) |
69 self.__leftWidget.resize(0, 0) |
66 self.__leftLayout = QHBoxLayout(self.__leftWidget) |
70 self.__leftLayout = QHBoxLayout(self.__leftWidget) |
67 self.__leftLayout.setContentsMargins(0, 0, 0, 0) |
71 self.__leftLayout.setContentsMargins(0, 0, 0, 0) |
68 if QApplication.isRightToLeft(): |
72 if QApplication.isRightToLeft(): |
69 self.__leftLayout.setDirection(QBoxLayout.RightToLeft) |
73 self.__leftLayout.setDirection(QBoxLayout.RightToLeft) |
70 else: |
74 else: |
71 self.__leftLayout.setDirection(QBoxLayout.LeftToRight) |
75 self.__leftLayout.setDirection(QBoxLayout.LeftToRight) |
72 self.__leftLayout.setSizeConstraint(QLayout.SetFixedSize) |
76 self.__leftLayout.setSizeConstraint(QLayout.SetFixedSize) |
73 |
77 |
74 self.__rightWidget = SideWidget(self) |
78 self.__rightWidget = E5LineEditSideWidget(self) |
75 self.__rightWidget.resize(0, 0) |
79 self.__rightWidget.resize(0, 0) |
76 self.__rightLayout = QHBoxLayout(self.__rightWidget) |
80 self.__rightLayout = QHBoxLayout(self.__rightWidget) |
77 self.__rightLayout.setContentsMargins(0, 0, 0, 0) |
81 self.__rightLayout.setContentsMargins(0, 0, 0, 0) |
78 if self.isRightToLeft(): |
82 if self.isRightToLeft(): |
79 self.__rightLayout.setDirection(QBoxLayout.RightToLeft) |
83 self.__rightLayout.setDirection(QBoxLayout.RightToLeft) |
259 if qVersion() < "4.7.0": |
263 if qVersion() < "4.7.0": |
260 self.__inactiveText = inactiveText |
264 self.__inactiveText = inactiveText |
261 self.update() |
265 self.update() |
262 else: |
266 else: |
263 self.setPlaceholderText(inactiveText) |
267 self.setPlaceholderText(inactiveText) |
|
268 |
|
269 |
|
270 class E5ClearableLineEdit(E5LineEdit): |
|
271 """ |
|
272 Class implementing a line edit widget showing some inactive text and a clear button, |
|
273 if it has some contents. |
|
274 """ |
|
275 def __init__(self, parent=None, inactiveText="", side=E5LineEdit.RightSide): |
|
276 """ |
|
277 Constructor |
|
278 |
|
279 @param parent reference to the parent widget (QWidget) |
|
280 @keyparam inactiveText text to be shown on inactivity (string) |
|
281 @keyparam side side the clear button should be shown at (E5LineEdit.RightSide, |
|
282 E5LineEdit.LeftSide) |
|
283 """ |
|
284 assert side in [E5LineEdit.RightSide, E5LineEdit.LeftSide] |
|
285 |
|
286 super().__init__(parent, inactiveText) |
|
287 |
|
288 self.__clearButton = E5LineEditButton(self) |
|
289 self.__clearButton.setIcon(UI.PixmapCache.getIcon("clearLeft.png")) |
|
290 self.addWidget(self.__clearButton, side) |
|
291 self.__clearButton.setVisible(False) |
|
292 |
|
293 self.__clearButton.clicked[()].connect(self.clear) |
|
294 self.textChanged.connect(self.__textChanged) |
|
295 |
|
296 def __textChanged(self, txt): |
|
297 """ |
|
298 Private slot to handle changes of the text. |
|
299 |
|
300 @param txt text (string) |
|
301 """ |
|
302 self.__clearButton.setVisible(txt != "") |