checks-parser/imageview/imageview.cpp

52 lines
1.8 KiB
C++

#include <QWheelEvent>
#include "imageview.h"
#include <iostream>
ImageView::ImageView(QWidget *parent) :
QLabel(parent) {
// std::cout << this->geometry().height() << " " << this->geometry().width() << std::endl;
}
// ImageView::ImageView(QWidget *parent, std::string path):
// QLabel(parent) {
// this->setPixmap(QPixmap(QString::fromStdString(path)));
// }
void ImageView::wheelEvent(QWheelEvent *event) {
QPointF shift = event->position();
QRegion r = QRegion();
// this->pixmap(Qt::ReturnByValueConstant::ReturnByValue).scroll(10, 10, this->rect(), &r);
this->scroll(shift.x(), shift.y(), this->rect());
// this->setPixmap(QPixmap());
// pm.scroll(shift.x(), shift.y(), this->rect());
// pm.scroll();
// this->setPixmap(pm);
//this->pixmap(Qt::ReturnByValueConstant::ReturnByValue).scroll(shift.x(), shift.y(), this->pixmap()->rect());
QPoint numDegrees = event->angleDelta() / 8;
std::cout << numDegrees.x() << std::endl;
event->accept();
}
void ImageView::setImage(std::string image){
//Commented is a way of scaling that is, as I understand, is lossless. If there'll be problems with current method's losses, I'll return to commented method
maxHeight = this->height();
maxWidth = this->width();
QPixmap pixmap = QPixmap(QString::fromStdString(image));
// double scaleFactor = pixmap.height() > pixmap.width()? static_cast<double>(maxHeight) / pixmap.height() : static_cast<double>(maxWidth) / pixmap.width();
pixmap = pixmap.scaled(maxWidth, maxHeight, Qt::AspectRatioMode::KeepAspectRatio);
this->setPixmap(pixmap);
// this->setGeometry(this->geometry().x(), this->geometry().y(), pixmap.width() * scaleFactor, pixmap.height() * scaleFactor);
// this->setScaledContents(true);
}