#include "ImageWidget_nodrag.h"
#include "ui_ImageWidget_nodrag.h"
#include <QPainter>

ImageWidget_nodrag::ImageWidget_nodrag(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::ImageWidget_nodrag),
    imageOffset(0, 0)
{
    ui->setupUi(this);
}

ImageWidget_nodrag::~ImageWidget_nodrag()
{
    delete ui;
}

void ImageWidget_nodrag::setPixmap(const QPixmap& newPixmap) {
    this->pixmap = newPixmap;
    imageOffset = QPoint(0, 0);
    update();
}

void ImageWidget_nodrag::paintEvent(QPaintEvent *event) {
    QPainter painter(this);
    if (!pixmap.isNull()) {
        int centerX = width() / 2;
        int centerY = height() / 2;
        int pixmapCenterX = pixmap.width() / 2;
        int pixmapCenterY = pixmap.height() / 2;
        int x = centerX - pixmapCenterX + imageOffset.x();
        int y = centerY - pixmapCenterY + imageOffset.y();
        painter.drawPixmap(x, y, pixmap);
    }
}
