Merge branch 'master' of https://git.shs.tools/SHS/qad
This commit is contained in:
@@ -24,8 +24,8 @@ ImageView::ImageView(QWidget * parent): QGraphicsView(parent), item(new QGraphic
|
|||||||
scene()->addItem(item);
|
scene()->addItem(item);
|
||||||
viewport()->setAutoFillBackground(false);
|
viewport()->setAutoFillBackground(false);
|
||||||
viewport()->installEventFilter(this);
|
viewport()->installEventFilter(this);
|
||||||
autofit_ = true;
|
autofit_ = smooth_big = true;
|
||||||
interactive_ = false;
|
interactive_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -87,6 +87,12 @@ void ImageView::clear() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ImageView::setSmoothBigImages(bool yes) {
|
||||||
|
smooth_big = yes;
|
||||||
|
adjustView();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ImageView::mouseDoubleClickEvent(QMouseEvent *) {
|
void ImageView::mouseDoubleClickEvent(QMouseEvent *) {
|
||||||
autofit();
|
autofit();
|
||||||
}
|
}
|
||||||
@@ -133,18 +139,21 @@ bool ImageView::eventFilter(QObject * o, QEvent * e) {
|
|||||||
|
|
||||||
|
|
||||||
void ImageView::adjustView() {
|
void ImageView::adjustView() {
|
||||||
QSize ws = size();
|
|
||||||
#if QT_VERSION_MAJOR >= 5
|
|
||||||
ws *= devicePixelRatio();
|
|
||||||
#endif
|
|
||||||
int nw = map.size().boundedTo(ws).width();
|
|
||||||
item->setScale(1.);
|
item->setScale(1.);
|
||||||
if (nw > 0) {
|
if (smooth_big) {
|
||||||
qreal mp = map.width() / nw;
|
QSize ws = size();
|
||||||
if (mp > 1.) {
|
#if QT_VERSION_MAJOR >= 5
|
||||||
QSize ss = map.size();
|
ws *= devicePixelRatio();
|
||||||
item->setPixmap(map.scaled(map.size() / mp, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
#endif
|
||||||
item->setScale(double(ss.width()) / item->pixmap().width());
|
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
|
} else
|
||||||
item->setPixmap(map);
|
item->setPixmap(map);
|
||||||
} else
|
} else
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ class QAD_WIDGETS_EXPORT ImageView: public QGraphicsView {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap)
|
Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap)
|
||||||
Q_PROPERTY(bool viewInteractive READ viewInteractive WRITE setViewInteractive)
|
Q_PROPERTY(bool viewInteractive READ viewInteractive WRITE setViewInteractive)
|
||||||
|
Q_PROPERTY(bool smoothBigImages READ isSmoothBigImages WRITE setSmoothBigImages)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ImageView(QWidget * parent = nullptr);
|
ImageView(QWidget * parent = nullptr);
|
||||||
@@ -44,6 +45,9 @@ public:
|
|||||||
bool viewInteractive() const { return interactive_; }
|
bool viewInteractive() const { return interactive_; }
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
|
bool isSmoothBigImages() const { return smooth_big; }
|
||||||
|
void setSmoothBigImages(bool yes);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void autofit();
|
void autofit();
|
||||||
void setPixmap(QPixmap pixmap);
|
void setPixmap(QPixmap pixmap);
|
||||||
@@ -62,7 +66,7 @@ private:
|
|||||||
QGraphicsPixmapItem * item;
|
QGraphicsPixmapItem * item;
|
||||||
QByteArray im_data;
|
QByteArray im_data;
|
||||||
QPoint prev_pos;
|
QPoint prev_pos;
|
||||||
bool autofit_, interactive_;
|
bool autofit_, interactive_, smooth_big;
|
||||||
QPixmap map;
|
QPixmap map;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user