mirror of
https://github.com/rbreu/beeref.git
synced 2026-03-11 08:54:28 +00:00
Fix copying text items
This commit is contained in:
parent
f08ac4cfe2
commit
7f9fc8944c
6 changed files with 40 additions and 4 deletions
|
|
@ -7,6 +7,8 @@ Added
|
|||
-----
|
||||
|
||||
* You can now add plain text notes and paste text from the clipboard
|
||||
* You can now open bee files from finder on MacOS (by Davin Andrs)
|
||||
|
||||
|
||||
Changed
|
||||
-------
|
||||
|
|
|
|||
|
|
@ -136,6 +136,9 @@ class BeePixmapItem(BeeItemMixin, QtWidgets.QGraphicsPixmapItem):
|
|||
item.do_flip()
|
||||
return item
|
||||
|
||||
def copy_to_clipboard(self, clipboard):
|
||||
clipboard.setPixmap(self.pixmap())
|
||||
|
||||
|
||||
@register_item
|
||||
class BeeTextItem(BeeItemMixin, QtWidgets.QGraphicsTextItem):
|
||||
|
|
@ -219,3 +222,6 @@ class BeeTextItem(BeeItemMixin, QtWidgets.QGraphicsTextItem):
|
|||
event.accept()
|
||||
return
|
||||
super().keyPressEvent(event)
|
||||
|
||||
def copy_to_clipboard(self, clipboard):
|
||||
clipboard.setText(self.toPlainText())
|
||||
|
|
|
|||
|
|
@ -438,7 +438,7 @@ class BeeGraphicsView(QtWidgets.QGraphicsView, ActionsMixin):
|
|||
# At the moment, we can only copy one image to the global
|
||||
# clipboard. (Later, we might create an image of the whole
|
||||
# selection for external copying.)
|
||||
clipboard.setPixmap(items[0].pixmap())
|
||||
items[0].copy_to_clipboard(clipboard)
|
||||
|
||||
# However, we can copy all items to the internal clipboard:
|
||||
self.scene.copy_selection_to_internal_clipboard()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from unittest.mock import patch, MagicMock, PropertyMock
|
||||
|
||||
from PyQt6 import QtCore, QtGui
|
||||
from PyQt6 import QtCore, QtGui, QtWidgets
|
||||
|
||||
from beeref.items import BeePixmapItem, item_registry
|
||||
|
||||
|
|
@ -174,3 +174,10 @@ def test_create_copy(qapp, imgfilename3x3):
|
|||
assert item.flip() == -1
|
||||
assert item.zValue() == 0.5
|
||||
assert item.scale() == 2.2
|
||||
|
||||
|
||||
def test_item_to_clipboard(qapp, imgfilename3x3):
|
||||
clipboard = QtWidgets.QApplication.clipboard()
|
||||
item = BeePixmapItem(QtGui.QImage(imgfilename3x3), 'foo.png')
|
||||
item.copy_to_clipboard(clipboard)
|
||||
assert clipboard.pixmap().size() == item.pixmap().size()
|
||||
|
|
|
|||
|
|
@ -299,3 +299,10 @@ def test_key_press_event_enter(exit_mock, key_press_mock, view):
|
|||
key_press_mock.assert_not_called()
|
||||
exit_mock.assert_called_once_with()
|
||||
assert view.scene.edit_item is None
|
||||
|
||||
|
||||
def test_item_to_clipboard(qapp):
|
||||
clipboard = QtWidgets.QApplication.clipboard()
|
||||
item = BeeTextItem('foo bar')
|
||||
item.copy_to_clipboard(clipboard)
|
||||
assert clipboard.text() == 'foo bar'
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ from PyQt6 import QtCore, QtGui, QtWidgets
|
|||
from PyQt6.QtCore import Qt
|
||||
|
||||
from beeref.config import logfile_name
|
||||
from beeref.items import BeePixmapItem
|
||||
from beeref.items import BeePixmapItem, BeeTextItem
|
||||
from beeref.view import BeeGraphicsView
|
||||
|
||||
|
||||
|
|
@ -333,7 +333,7 @@ def test_on_action_insert_text(clear_mock, view):
|
|||
|
||||
|
||||
@patch('PyQt6.QtWidgets.QApplication.clipboard')
|
||||
def test_on_action_copy(clipboard_mock, view, imgfilename3x3):
|
||||
def test_on_action_copy_image(clipboard_mock, view, imgfilename3x3):
|
||||
item = BeePixmapItem(QtGui.QImage(imgfilename3x3))
|
||||
view.scene.addItem(item)
|
||||
item.setSelected(True)
|
||||
|
|
@ -346,6 +346,20 @@ def test_on_action_copy(clipboard_mock, view, imgfilename3x3):
|
|||
assert mimedata.data('beeref/items') == b'1'
|
||||
|
||||
|
||||
@patch('PyQt6.QtWidgets.QApplication.clipboard')
|
||||
def test_on_action_copy_text(clipboard_mock, view, imgfilename3x3):
|
||||
item = BeeTextItem('foo bar')
|
||||
view.scene.addItem(item)
|
||||
item.setSelected(True)
|
||||
mimedata = QtCore.QMimeData()
|
||||
clipboard_mock.return_value.mimeData.return_value = mimedata
|
||||
view.on_action_copy()
|
||||
|
||||
clipboard_mock.return_value.setText.assert_called_once_with('foo bar')
|
||||
view.scene.internal_clipboard == [item]
|
||||
assert mimedata.data('beeref/items') == b'1'
|
||||
|
||||
|
||||
@patch('beeref.scene.BeeGraphicsScene.clearSelection')
|
||||
@patch('PyQt6.QtGui.QClipboard.image')
|
||||
def test_on_action_paste_external(
|
||||
|
|
|
|||
Loading…
Reference in a new issue