Skip to content

Commit

Permalink
keep pos consistent in auto_zoom mode
Browse files Browse the repository at this point in the history
  • Loading branch information
xinntao committed Jul 21, 2022
1 parent 7bf1b6f commit 9104b54
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
12 changes: 8 additions & 4 deletions handyview/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def compare_folders(self, step):
def show_image(self, init=False):
interval_mode = (self.db.get_folder_len() == 1)
for idx, qscene in enumerate(self.qscenes):
qview = self.qviews[idx]
if interval_mode:
pidx = self.db.pidx + idx
img_path = self.db.get_path(pidx=pidx)[0]
Expand Down Expand Up @@ -249,7 +250,7 @@ def show_image(self, init=False):

# --------------- auto zoom scale ratio -------------------
if self.target_zoom_width > 0:
self.qviews[idx].set_zoom(self.target_zoom_width / qimg.width())
qview.set_zoom(self.target_zoom_width / qimg.width())
# --------------- end of auto zoom scale ratio -------------------

# shown text
Expand Down Expand Up @@ -285,12 +286,12 @@ def get_parent_dir(path, levels=1):
shown_text.append(f'md5: {md5}')
shown_text.append(f'phash: {phash}')

if self.qviews[idx].hasFocus():
if qview.hasFocus():
color = 'red'
else:
color = 'green'
self.qviews[idx].set_shown_text(shown_text, color)
# self.qviews[idx].viewport().update()
qview.set_shown_text(shown_text, color)
# qview.viewport().update()
qpixmap = QPixmap.fromImage(qimg)

# draw border
Expand All @@ -307,6 +308,9 @@ def get_parent_dir(path, levels=1):
qscene.set_width_height(width, height)
# put image always in the center of a QGraphicsView
qscene.setSceneRect(0, 0, width, height)
# set the scroll bar position, so that it can keep the same position in auto_zoom
qview.verticalScrollBar().setSliderPosition(qview.vertical_scroll_value)
qview.horizontalScrollBar().setSliderPosition(qview.horizontal_scroll_value)

# set include and exclude name info
if self.num_view == 1:
Expand Down
6 changes: 5 additions & 1 deletion handyview/db.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import hashlib
import imagehash
import os
from PIL import Image
from PIL import Image, ImageFile

from handyview.utils import FORMATS, ROOT_DIR, get_img_list, scandir, sizeof_fmt
from handyview.widgets import show_msg

# for loading large image file
ImageFile.LOAD_TRUNCATED_IMAGES = True
Image.MAX_IMAGE_PIXELS = None


class HVDB():
"""HandyView database.
Expand Down
2 changes: 1 addition & 1 deletion handyview/handyviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def open_history(self):
# slots: refresh and index
# ---------------------------------------
def refresh_img_list(self):
# should be used in Main Cavans
# should be used in Main Canvas
if self.canvas_type != 'main':
self.switch_main_canvas()

Expand Down
5 changes: 5 additions & 0 deletions handyview/view_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ def __init__(self, scene, parent=None, show_info=True):
self.rotate = 0
self.shown_text = None

self.vertical_scroll_value = 0
self.horizontal_scroll_value = 0

self.font = QFont('times', 15)
font_metrics = QFontMetrics(self.font)
self.text_height = font_metrics.height()
Expand Down Expand Up @@ -116,6 +119,8 @@ def mouseReleaseEvent(self, event):
self.rubber_band_changable = False
else:
QGraphicsView.mouseReleaseEvent(self, event)
self.vertical_scroll_value = self.verticalScrollBar().value()
self.horizontal_scroll_value = self.horizontalScrollBar().value()

def wheelEvent(self, event):
mouse = event.angleDelta().y() / 120
Expand Down

0 comments on commit 9104b54

Please sign in to comment.