#include #include #include #include #include #include #include #include #include "imageredactor.h" ImageRedactor::ImageRedactor(QWidget *parent) : QGraphicsView(parent) { scene = new QGraphicsScene(this); setScene(scene); // Load the image QPixmap pixmap("image.jpg"); item = new QGraphicsPixmapItem(pixmap); scene->addItem(item); // Set the initial zoom level setTransformationAnchor(QGraphicsView::AnchorUnderMouse); } void ImageRedactor::wheelEvent(QWheelEvent *event) { // Zoom in/out setTransformationAnchor(QGraphicsView::AnchorUnderMouse); double angle = event->angleDelta().y(); double factor = qPow(1.2, angle / 240.0); scale(factor, factor); } void ImageRedactor::mousePressEvent(QMouseEvent *event) { // Pan the image if (event->button() == Qt::LeftButton) { setDragMode(QGraphicsView::ScrollHandDrag); } } void ImageRedactor::mouseReleaseEvent(QMouseEvent *event) { // Reset the drag mode if (event->button() == Qt::LeftButton) { setDragMode(QGraphicsView::NoDrag); } }