improve ImageView quality
This commit is contained in:
2
pip
2
pip
Submodule pip updated: 31f0d88157...9834ac177b
@@ -28,6 +28,9 @@
|
||||
</color>
|
||||
</brush>
|
||||
</property>
|
||||
<property name="renderHints">
|
||||
<set>QPainter::SmoothPixmapTransform|QPainter::TextAntialiasing</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
|
||||
@@ -14,6 +14,8 @@ ImageView::ImageView(QWidget * parent): QGraphicsView(parent) {
|
||||
setDragMode(QGraphicsView::NoDrag);
|
||||
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
|
||||
setScene(new QGraphicsScene());
|
||||
setRenderHint(QPainter::Antialiasing, true);
|
||||
setRenderHint(QPainter::SmoothPixmapTransform, true);
|
||||
item.setTransformationMode(Qt::SmoothTransformation);
|
||||
item.setFlags(0);
|
||||
scene()->addItem(&item);
|
||||
@@ -28,12 +30,12 @@ ImageView::~ImageView() {
|
||||
|
||||
|
||||
QPixmap ImageView::pixmap() const {
|
||||
return item.pixmap();
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
void ImageView::setPixmap(QPixmap pixmap) {
|
||||
item.setPixmap(pixmap);
|
||||
map = pixmap;
|
||||
adjustView();
|
||||
}
|
||||
|
||||
@@ -42,12 +44,13 @@ void ImageView::setImage(const QImage & i) {
|
||||
im_data.clear();
|
||||
if (i.isNull()) {
|
||||
item.setPixmap(QPixmap());
|
||||
map = QPixmap();
|
||||
return;
|
||||
}
|
||||
QBuffer b(&im_data); b.open(QIODevice::ReadWrite);
|
||||
i.save(&b, "png");
|
||||
b.close();
|
||||
item.setPixmap(QPixmap::fromImage(i));
|
||||
map = QPixmap::fromImage(i);
|
||||
adjustView();
|
||||
}
|
||||
|
||||
@@ -56,17 +59,18 @@ void ImageView::setImage(const QByteArray & i) {
|
||||
im_data = i;
|
||||
if (i.isEmpty()) {
|
||||
item.setPixmap(QPixmap());
|
||||
map = QPixmap();
|
||||
return;
|
||||
}
|
||||
item.setPixmap(QPixmap::fromImage(QImage::fromData(i)));
|
||||
map = QPixmap::fromImage(QImage::fromData(i));
|
||||
adjustView();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ImageView::clear() {
|
||||
im_data.clear();
|
||||
item.setPixmap(QPixmap());
|
||||
map = QPixmap();
|
||||
}
|
||||
|
||||
|
||||
@@ -121,10 +125,17 @@ bool ImageView::eventFilter(QObject * o, QEvent * e) {
|
||||
|
||||
|
||||
void ImageView::adjustView() {
|
||||
qreal mp = map.width() / map.size().boundedTo(size()).width();
|
||||
if (mp > 2) {
|
||||
item.setPixmap(map.scaled(map.size()/mp, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||
} else {
|
||||
item.setPixmap(map);
|
||||
}
|
||||
if (!autofit_) return;
|
||||
setSceneRect(item.boundingRect());
|
||||
fitInView(&item, Qt::KeepAspectRatio);
|
||||
centerOn(&item);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ private:
|
||||
QByteArray im_data;
|
||||
QPoint prev_pos;
|
||||
bool autofit_;
|
||||
QPixmap map;
|
||||
|
||||
|
||||
public slots:
|
||||
|
||||
Reference in New Issue
Block a user