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