Show More
@@ -157,17 +157,49 class CallTipWidget(QtGui.QLabel): | |||||
157 | self.resize(self.sizeHint()) |
|
157 | self.resize(self.sizeHint()) | |
158 |
|
158 | |||
159 | # Locate and show the widget. Place the tip below the current line |
|
159 | # Locate and show the widget. Place the tip below the current line | |
160 |
# unless it would be off the screen. In that case, |
|
160 | # unless it would be off the screen. In that case, decide the best | |
161 | # the current line. |
|
161 | # location based trying to minimize the area that goes off-screen. | |
162 | padding = 3 # Distance in pixels between cursor bounds and tip box. |
|
162 | padding = 3 # Distance in pixels between cursor bounds and tip box. | |
163 | cursor_rect = text_edit.cursorRect(cursor) |
|
163 | cursor_rect = text_edit.cursorRect(cursor) | |
164 | screen_rect = QtGui.qApp.desktop().screenGeometry(text_edit) |
|
164 | screen_rect = QtGui.qApp.desktop().screenGeometry(text_edit) | |
165 | point = text_edit.mapToGlobal(cursor_rect.bottomRight()) |
|
165 | point = text_edit.mapToGlobal(cursor_rect.bottomRight()) | |
166 | point.setY(point.y() + padding) |
|
166 | point.setY(point.y() + padding) | |
167 | tip_height = self.size().height() |
|
167 | tip_height = self.size().height() | |
|
168 | tip_width = self.size().width() | |||
|
169 | ||||
|
170 | vertical = 'bottom' | |||
|
171 | horizontal = 'Right' | |||
168 | if point.y() + tip_height > screen_rect.height(): |
|
172 | if point.y() + tip_height > screen_rect.height(): | |
169 | point = text_edit.mapToGlobal(cursor_rect.topRight()) |
|
173 | point_ = text_edit.mapToGlobal(cursor_rect.topRight()) | |
|
174 | # If tip is still off screen, check if point is in top or bottom | |||
|
175 | # half of screen. | |||
|
176 | if point_.y() - tip_height < padding: | |||
|
177 | # If point is in upper half of screen, show tip below it. | |||
|
178 | # otherwise above it. | |||
|
179 | if 2*point.y() < screen_rect.height(): | |||
|
180 | vertical = 'bottom' | |||
|
181 | else: | |||
|
182 | vertical = 'top' | |||
|
183 | else: | |||
|
184 | vertical = 'top' | |||
|
185 | if point.x() + tip_width > screen_rect.width(): | |||
|
186 | point_ = text_edit.mapToGlobal(cursor_rect.topRight()) | |||
|
187 | # If tip is still off-screen, check if point is in the right or | |||
|
188 | # left half of the screen. | |||
|
189 | if point_.x() - tip_width < padding: | |||
|
190 | if 2*point.x() < screen_rect.width(): | |||
|
191 | horizontal = 'Right' | |||
|
192 | else: | |||
|
193 | horizontal = 'Left' | |||
|
194 | else: | |||
|
195 | horizontal = 'Left' | |||
|
196 | pos = getattr(cursor_rect, '%s%s' %(vertical, horizontal)) | |||
|
197 | point = text_edit.mapToGlobal(pos()) | |||
|
198 | if vertical == 'top': | |||
170 | point.setY(point.y() - tip_height - padding) |
|
199 | point.setY(point.y() - tip_height - padding) | |
|
200 | if horizontal == 'Left': | |||
|
201 | point.setX(point.x() - tip_width - padding) | |||
|
202 | ||||
171 | self.move(point) |
|
203 | self.move(point) | |
172 | self.show() |
|
204 | self.show() | |
173 | return True |
|
205 | return True |
General Comments 0
You need to be logged in to leave comments.
Login now