18 """ |
18 """ |
19 Class implementing a specialized line edit for entering IRC messages. |
19 Class implementing a specialized line edit for entering IRC messages. |
20 """ |
20 """ |
21 MaxHistory = 100 |
21 MaxHistory = 100 |
22 |
22 |
23 def __init__(self, parent=None, inactiveText="", side=E5LineEdit.RightSide): |
23 def __init__(self, parent=None, inactiveText="", |
|
24 side=E5LineEdit.RightSide): |
24 """ |
25 """ |
25 Constructor |
26 Constructor |
26 |
27 |
27 @param parent reference to the parent widget (QWidget) |
28 @param parent reference to the parent widget (QWidget) |
28 @keyparam inactiveText text to be shown on inactivity (string) |
29 @keyparam inactiveText text to be shown on inactivity (string) |
29 @keyparam side side the clear button should be shown at (E5LineEdit.RightSide, |
30 @keyparam side side the clear button should be shown at |
30 E5LineEdit.LeftSide) |
31 (E5LineEdit.RightSide, E5LineEdit.LeftSide) |
31 """ |
32 """ |
32 super(IrcMessageEdit, self).__init__(parent, inactiveText, side) |
33 super(IrcMessageEdit, self).__init__(parent, inactiveText, side) |
33 |
34 |
34 self.__historyList = [""] # initialize with one empty line |
35 self.__historyList = [""] # initialize with one empty line |
35 self.__historyLine = 0 |
36 self.__historyLine = 0 |
36 |
37 |
37 def setText(self, text): |
38 def setText(self, text): |
38 """ |
39 """ |
39 Public method to set the text. |
40 Public method to set the text. |
40 |
41 |
41 Note: This reimplementation ensures, that the cursor is at the end of the text. |
42 Note: This reimplementation ensures, that the cursor is at the end of |
|
43 the text. |
42 |
44 |
43 @param text text to be set (string) |
45 @param text text to be set (string) |
44 """ |
46 """ |
45 super(IrcMessageEdit, self).setText(text) |
47 super(IrcMessageEdit, self).setText(text) |
46 self.setCursorPosition(len(text)) |
48 self.setCursorPosition(len(text)) |
69 |
71 |
70 def wheelEvent(self, evt): |
72 def wheelEvent(self, evt): |
71 """ |
73 """ |
72 Protected slot to support wheel events. |
74 Protected slot to support wheel events. |
73 |
75 |
74 @param reference to the wheel event (QWheelEvent) |
76 @param evt reference to the wheel event (QWheelEvent) |
75 """ |
77 """ |
76 if evt.delta() > 0: |
78 if evt.delta() > 0: |
77 self.__getHistory(True) |
79 self.__getHistory(True) |
78 elif evt.delta() < 0: |
80 elif evt.delta() < 0: |
79 self.__getHistory(False) |
81 self.__getHistory(False) |
107 if self.text(): |
109 if self.text(): |
108 self.__historyList[self.__historyLine] = self.text() |
110 self.__historyList[self.__historyLine] = self.text() |
109 |
111 |
110 if up: |
112 if up: |
111 self.__historyLine += 1 |
113 self.__historyLine += 1 |
112 # If the position was moved past the end of the history, go to the last entry |
114 # If the position was moved past the end of the history, |
|
115 # go to the last entry |
113 if self.__historyLine == len(self.__historyList): |
116 if self.__historyLine == len(self.__historyList): |
114 self.__historyLine -= 1 |
117 self.__historyLine -= 1 |
115 return |
118 return |
116 else: |
119 else: |
117 # If the position is at the top of the history, arrow-down shall add the text |
120 # If the position is at the top of the history, arrow-down shall |
118 # to the history and clear the line edit for new input |
121 # add the text to the history and clear the line edit for new input |
119 if self.__historyLine == 0: |
122 if self.__historyLine == 0: |
120 if self.text(): |
123 if self.text(): |
121 self.__addHistory(self.text()) |
124 self.__addHistory(self.text()) |
122 self.setText("") |
125 self.setText("") |
123 else: |
126 else: |
124 # If the position is not at the top of the history, decrement it |
127 # If the position is not at the top of the history, |
|
128 # decrement it |
125 self.__historyLine -= 1 |
129 self.__historyLine -= 1 |
126 |
130 |
127 # replace the text of the line edit with the selected history entry |
131 # replace the text of the line edit with the selected history entry |
128 self.setText(self.__historyList[self.__historyLine]) |
132 self.setText(self.__historyList[self.__historyLine]) |