문제

I am writing a GUI application that works on Mac and Win and there is one little problem, which i do not know how to solve. In my application I have a small (250 x 250 px) preview window (let' call it SW) in which placed the image. Image can be much bigger, than SW. Somewhere I have a slider which implements zoom function of image inside SW. My main problem is implement zoom function on this image.

On enter I have:

  • source image and it's width and height;
  • view image - it is zoomed copy of source image;
  • position of zoomed image
  • size of viewport is 250 x 250 px

It should works like zoom in image processing programs. When we changing our zoom value image becomes smaller or bigger relative to viewport center and position of image inside it. We can move image inside of viewport. For correct implementation of that problem we need to calculate images size and position inside our view. I'm already wrote some "algo" that implements image size modification. It is looks like:

float one = (source_original_size - thumbnail_size) / 100;
int bigger_side_size = qRound((100-value) * one) + thumbnail_size;

But I can not imagine how I can calculate position on scene of that zoomed image.

Can anybody help me with ideas?

If it is important I am using Qt framework and QGraphicsView, QGraphicsScene and QGraphicsPixmapItem.

올바른 솔루션이 없습니다

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top