##// END OF EJS Templates
Merge pull request #2233 from bfroehle/drag_n_drop...
Bussonnier Matthias -
r8684:97d40224 merge
parent child Browse files
Show More
@@ -268,7 +268,6 b' class ConsoleWidget(LoggingConfigurable, QtGui.QWidget):'
268 self._continuation_prompt = '> '
268 self._continuation_prompt = '> '
269 self._continuation_prompt_html = None
269 self._continuation_prompt_html = None
270 self._executing = False
270 self._executing = False
271 self._filter_drag = False
272 self._filter_resize = False
271 self._filter_resize = False
273 self._html_exporter = HtmlExporter(self._control)
272 self._html_exporter = HtmlExporter(self._control)
274 self._input_buffer_executing = ''
273 self._input_buffer_executing = ''
@@ -343,7 +342,51 b' class ConsoleWidget(LoggingConfigurable, QtGui.QWidget):'
343 triggered=self.reset_font)
342 triggered=self.reset_font)
344 self.addAction(self.reset_font_size)
343 self.addAction(self.reset_font_size)
345
344
345 # Accept drag and drop events here. Drops were already turned off
346 # in self._control when that widget was created.
347 self.setAcceptDrops(True)
346
348
349 #---------------------------------------------------------------------------
350 # Drag and drop support
351 #---------------------------------------------------------------------------
352
353 def dragEnterEvent(self, e):
354 if e.mimeData().hasUrls():
355 # The link action should indicate to that the drop will insert
356 # the file anme.
357 e.setDropAction(QtCore.Qt.LinkAction)
358 e.accept()
359 elif e.mimeData().hasText():
360 # By changing the action to copy we don't need to worry about
361 # the user accidentally moving text around in the widget.
362 e.setDropAction(QtCore.Qt.CopyAction)
363 e.accept()
364
365 def dragMoveEvent(self, e):
366 if e.mimeData().hasUrls():
367 pass
368 elif e.mimeData().hasText():
369 cursor = self._control.cursorForPosition(e.pos())
370 if self._in_buffer(cursor.position()):
371 e.setDropAction(QtCore.Qt.CopyAction)
372 self._control.setTextCursor(cursor)
373 else:
374 e.setDropAction(QtCore.Qt.IgnoreAction)
375 e.accept()
376
377 def dropEvent(self, e):
378 if e.mimeData().hasUrls():
379 self._keep_cursor_in_buffer()
380 cursor = self._control.textCursor()
381 filenames = [url.toLocalFile() for url in e.mimeData().urls()]
382 text = ', '.join("'" + f.replace("'", "'\"'\"'") + "'"
383 for f in filenames)
384 self._insert_plain_text_into_buffer(cursor, text)
385 elif e.mimeData().hasText():
386 cursor = self._control.cursorForPosition(e.pos())
387 if self._in_buffer(cursor.position()):
388 text = e.mimeData().text()
389 self._insert_plain_text_into_buffer(cursor, text)
347
390
348 def eventFilter(self, obj, event):
391 def eventFilter(self, obj, event):
349 """ Reimplemented to ensure a console-like behavior in the underlying
392 """ Reimplemented to ensure a console-like behavior in the underlying
@@ -392,39 +435,6 b' class ConsoleWidget(LoggingConfigurable, QtGui.QWidget):'
392 event.key() in self._shortcuts:
435 event.key() in self._shortcuts:
393 event.accept()
436 event.accept()
394
437
395 # Ensure that drags are safe. The problem is that the drag starting
396 # logic, which determines whether the drag is a Copy or Move, is locked
397 # down in QTextControl. If the widget is editable, which it must be if
398 # we're not executing, the drag will be a Move. The following hack
399 # prevents QTextControl from deleting the text by clearing the selection
400 # when a drag leave event originating from this widget is dispatched.
401 # The fact that we have to clear the user's selection is unfortunate,
402 # but the alternative--trying to prevent Qt from using its hardwired
403 # drag logic and writing our own--is worse.
404 elif etype == QtCore.QEvent.DragEnter and \
405 obj == self._control.viewport() and \
406 event.source() == self._control.viewport():
407 self._filter_drag = True
408 elif etype == QtCore.QEvent.DragLeave and \
409 obj == self._control.viewport() and \
410 self._filter_drag:
411 cursor = self._control.textCursor()
412 cursor.clearSelection()
413 self._control.setTextCursor(cursor)
414 self._filter_drag = False
415
416 # Ensure that drops are safe.
417 elif etype == QtCore.QEvent.Drop and obj == self._control.viewport():
418 cursor = self._control.cursorForPosition(event.pos())
419 if self._in_buffer(cursor.position()):
420 text = event.mimeData().text()
421 self._insert_plain_text_into_buffer(cursor, text)
422
423 # Qt is expecting to get something here--drag and drop occurs in its
424 # own event loop. Send a DragLeave event to end it.
425 QtGui.qApp.sendEvent(obj, QtGui.QDragLeaveEvent())
426 return True
427
428 # Handle scrolling of the vsplit pager. This hack attempts to solve
438 # Handle scrolling of the vsplit pager. This hack attempts to solve
429 # problems with tearing of the help text inside the pager window. This
439 # problems with tearing of the help text inside the pager window. This
430 # happens only on Mac OS X with both PySide and PyQt. This fix isn't
440 # happens only on Mac OS X with both PySide and PyQt. This fix isn't
@@ -1035,8 +1045,12 b' class ConsoleWidget(LoggingConfigurable, QtGui.QWidget):'
1035 control.setAcceptRichText(False)
1045 control.setAcceptRichText(False)
1036 control.setMouseTracking(True)
1046 control.setMouseTracking(True)
1037
1047
1048 # Prevent the widget from handling drops, as we already provide
1049 # the logic in this class.
1050 control.setAcceptDrops(False)
1051
1038 # Install event filters. The filter on the viewport is needed for
1052 # Install event filters. The filter on the viewport is needed for
1039 # mouse events and drag events.
1053 # mouse events.
1040 control.installEventFilter(self)
1054 control.installEventFilter(self)
1041 control.viewport().installEventFilter(self)
1055 control.viewport().installEventFilter(self)
1042
1056
General Comments 0
You need to be logged in to leave comments. Login now