ImageView big images property

This commit is contained in:
2023-01-23 11:22:46 +03:00
parent a0363ba99d
commit 7d7ec8976d
2 changed files with 27 additions and 14 deletions

View File

@@ -24,8 +24,8 @@ ImageView::ImageView(QWidget * parent): QGraphicsView(parent), item(new QGraphic
scene()->addItem(item);
viewport()->setAutoFillBackground(false);
viewport()->installEventFilter(this);
autofit_ = true;
interactive_ = false;
autofit_ = smooth_big = true;
interactive_ = false;
}
@@ -87,6 +87,12 @@ void ImageView::clear() {
}
void ImageView::setSmoothBigImages(bool yes) {
smooth_big = yes;
adjustView();
}
void ImageView::mouseDoubleClickEvent(QMouseEvent *) {
autofit();
}
@@ -133,18 +139,21 @@ bool ImageView::eventFilter(QObject * o, QEvent * e) {
void ImageView::adjustView() {
QSize ws = size();
#if QT_VERSION_MAJOR >= 5
ws *= devicePixelRatio();
#endif
int nw = map.size().width();
item->setScale(1.);
if (nw > 0) {
qreal mp = map.width() / nw;
if (mp > 1.) {
QSize ss = map.size();
item->setPixmap(map.scaled(map.size() / mp, Qt::KeepAspectRatio, Qt::SmoothTransformation));
item->setScale(double(ss.width()) / item->pixmap().width());
if (smooth_big) {
QSize ws = size();
#if QT_VERSION_MAJOR >= 5
ws *= devicePixelRatio();
#endif
int nw = map.size().boundedTo(ws).width();
if (nw > 0) {
qreal mp = map.width() / nw;
if (mp > 1.) {
QSize ss = map.size();
item->setPixmap(map.scaled(map.size() / mp, Qt::KeepAspectRatio, Qt::SmoothTransformation));
item->setScale(double(ss.width()) / item->pixmap().width());
} else
item->setPixmap(map);
} else
item->setPixmap(map);
} else