-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #581 from Yutsuten/crop
Add crop feature fixes #8
- Loading branch information
Showing
17 changed files
with
572 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
Feature: Crop an image. | ||
|
||
Background: | ||
Given I open any image of size 300x200 | ||
|
||
Scenario: Enter crop widget | ||
When I run crop | ||
Then there should be 1 crop widget | ||
And the center status should include crop: | ||
|
||
Scenario: Enter crop widget with fixed aspectratio | ||
When I run crop --aspectratio=1:1 | ||
Then there should be 1 crop widget | ||
And the center status should include crop: | ||
|
||
Scenario: Leave crop widget without changes | ||
When I run crop | ||
And I press '<escape>' in the crop widget | ||
Then there should be 0 crop widgets | ||
And the image size should be 300x200 | ||
|
||
Scenario: Leave crop widget accepting changes | ||
When I run crop | ||
And I press '<return>' in the crop widget | ||
Then there should be 0 crop widgets | ||
And the image size should be 150x100 | ||
|
||
Scenario Outline: Drag crop widget with the mouse | ||
When I run crop | ||
And I drag the crop widget by <dx>+<dy> | ||
Then the crop rectangle should be <geometry> | ||
|
||
Examples: | ||
| dx | dy | geometry | | ||
| 0 | 0 | 150x100+75+50 | | ||
# small dx dy | ||
| 30 | -20 | 150x100+105+30 | | ||
# dx only as far as the image allows | ||
| 125 | 0 | 150x100+150+50 | | ||
# dy only as far as the image allows | ||
| 10 | -100 | 150x100+85+0 | | ||
# Ignored as dx/dy are outside of the image | ||
| 1000 | 1000 | 150x100+75+50 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# vim: ft=python fileencoding=utf-8 sw=4 et sts=4 | ||
|
||
# This file is part of vimiv. | ||
# Copyright 2017-2023 Christian Karl (karlch) <karlch at protonmail dot com> | ||
# License: GNU GPL v3, see the "LICENSE" and "AUTHORS" files for details. | ||
|
||
import re | ||
|
||
from PyQt5.QtCore import Qt, QPoint | ||
from PyQt5.QtWidgets import QApplication | ||
|
||
import pytest | ||
import pytest_bdd as bdd | ||
|
||
import vimiv.gui.crop_widget | ||
|
||
|
||
bdd.scenarios("crop.feature") | ||
|
||
|
||
def find_crop_widgets(image): | ||
return image.findChildren(vimiv.gui.crop_widget.CropWidget) | ||
|
||
|
||
@pytest.fixture() | ||
def crop(image): | ||
"""Fixture to retrieve the current instance of the crop widget.""" | ||
widgets = find_crop_widgets(image) | ||
assert len(widgets) == 1, "Wrong number of crop wigets found" | ||
return widgets[0] | ||
|
||
|
||
@pytest.fixture() | ||
def ensure_moving(): | ||
QApplication.setOverrideCursor(Qt.ClosedHandCursor) | ||
yield | ||
QApplication.restoreOverrideCursor() | ||
|
||
|
||
@bdd.when(bdd.parsers.parse("I press '{keys}' in the crop widget")) | ||
def press_key_crop(keypress, crop, keys): | ||
keypress(crop, keys) | ||
|
||
|
||
@bdd.then(bdd.parsers.parse("there should be {number:d} crop widgets")) | ||
@bdd.then(bdd.parsers.parse("there should be {number:d} crop widget")) | ||
def check_number_of_crop_widgets(qtbot, image, number): | ||
def check(): | ||
assert len(find_crop_widgets(image)) == number | ||
|
||
qtbot.waitUntil(check) | ||
|
||
|
||
@bdd.when(bdd.parsers.parse("I drag the crop widget by {dx:d}+{dy:d}")) | ||
@bdd.when("I drag the crop widget by <dx>+<dy>") | ||
def drag_crop_widget(qtbot, mousedrag, crop, dx, dy): | ||
dx = int(int(dx) * crop.image.zoom_level) | ||
dy = int(int(dy) * crop.image.zoom_level) | ||
|
||
start = QPoint(crop.width() // 2, crop.height() // 2) | ||
mousedrag(crop, start=start, diff=QPoint(dx, dy)) | ||
|
||
|
||
@bdd.then(bdd.parsers.parse("the crop rectangle should be {geometry}")) | ||
@bdd.then("the crop rectangle should be <geometry>") | ||
def check_crop_rectangle(crop, geometry): | ||
match = re.match(r"(\d+)x(\d+)\+(\d+)\+(\d+)", geometry) | ||
assert match is not None, "Invalid geometry passed" | ||
width, height, x, y = match.groups() | ||
rect = crop.crop_rect() | ||
assert int(width) == pytest.approx(rect.width(), abs=1) | ||
assert int(height) == pytest.approx(rect.height(), abs=1) | ||
assert int(x) == pytest.approx(rect.x(), abs=1) | ||
assert int(y) == pytest.approx(rect.y(), abs=1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.