mirror of
https://github.com/rbreu/beeref.git
synced 2026-03-11 08:54:28 +00:00
Normalize actions scale around image centers
This commit is contained in:
parent
5fd18253e1
commit
b7a9ab01ba
3 changed files with 25 additions and 11 deletions
|
|
@ -13,7 +13,7 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with BeeRef. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from PyQt6 import QtGui
|
||||
from PyQt6 import QtCore, QtGui
|
||||
|
||||
|
||||
class InsertItems(QtGui.QUndoCommand):
|
||||
|
|
@ -132,8 +132,10 @@ class NormalizeItems(QtGui.QUndoCommand):
|
|||
self.old_scale_factors = []
|
||||
for item, factor in zip(self.items, self.scale_factors):
|
||||
self.old_scale_factors.append(item.scale())
|
||||
item.setScale(factor)
|
||||
item.setScale(factor,
|
||||
QtCore.QPointF(item.width, item.height) / 2)
|
||||
|
||||
def undo(self):
|
||||
for item, factor in zip(self.items, self.old_scale_factors):
|
||||
item.setScale(factor)
|
||||
item.setScale(factor,
|
||||
QtCore.QPointF(item.width, item.height) / 2)
|
||||
|
|
|
|||
|
|
@ -247,6 +247,7 @@ class BeeGraphicsView(QtWidgets.QGraphicsView):
|
|||
parent=self)
|
||||
fileio.load(filename, self.scene, progress)
|
||||
self.filename = filename
|
||||
progress.close()
|
||||
except fileio.BeeFileIOError:
|
||||
QtWidgets.QMessageBox.warning(
|
||||
self,
|
||||
|
|
@ -278,6 +279,7 @@ class BeeGraphicsView(QtWidgets.QGraphicsView):
|
|||
fileio.save(filename, self.scene, create_new=True,
|
||||
progress=progress)
|
||||
self.filename = filename
|
||||
progress.close()
|
||||
except fileio.BeeFileIOError:
|
||||
QtWidgets.QMessageBox.warning(
|
||||
self,
|
||||
|
|
@ -294,6 +296,7 @@ class BeeGraphicsView(QtWidgets.QGraphicsView):
|
|||
parent=self)
|
||||
fileio.save(self.filename, self.scene, create_new=False,
|
||||
progress=progress)
|
||||
progress.close()
|
||||
|
||||
def on_action_quit(self):
|
||||
logger.info('User quit. Exiting...')
|
||||
|
|
@ -328,6 +331,7 @@ class BeeGraphicsView(QtWidgets.QGraphicsView):
|
|||
pos.setX(pos.x() + 50)
|
||||
pos.setY(pos.y() + 50)
|
||||
|
||||
progress.close()
|
||||
self.undo_stack.push(commands.InsertItems(self.scene, items))
|
||||
|
||||
if errors:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from unittest.mock import MagicMock, patch
|
||||
from unittest.mock import MagicMock, patch, PropertyMock
|
||||
|
||||
from PyQt6 import QtCore, QtGui
|
||||
|
||||
|
|
@ -199,10 +199,18 @@ class NormalizeItemsTestCase(BeeTestCase):
|
|||
item1.setScale(1)
|
||||
item2 = BeePixmapItem(QtGui.QImage())
|
||||
item2.setScale(3)
|
||||
command = commands.NormalizeItems([item1, item2], [2, 0.5])
|
||||
command.redo()
|
||||
assert item1.scale() == 2
|
||||
assert item2.scale() == 0.5
|
||||
command.undo()
|
||||
assert item1.scale() == 1
|
||||
assert item2.scale() == 3
|
||||
with patch('beeref.items.BeePixmapItem.width',
|
||||
new_callable=PropertyMock, return_value=100):
|
||||
with patch('beeref.items.BeePixmapItem.height',
|
||||
new_callable=PropertyMock, return_value=80):
|
||||
command = commands.NormalizeItems([item1, item2], [2, 0.5])
|
||||
command.redo()
|
||||
assert item1.scale() == 2
|
||||
assert item1.pos() == QtCore.QPointF(-50, -40)
|
||||
assert item2.scale() == 0.5
|
||||
assert item2.pos() == QtCore.QPointF(125, 100)
|
||||
command.undo()
|
||||
assert item1.scale() == 1
|
||||
assert item1.pos() == QtCore.QPointF(0, 0)
|
||||
assert item2.scale() == 3
|
||||
assert item2.pos() == QtCore.QPointF(0, 0)
|
||||
|
|
|
|||
Loading…
Reference in a new issue