piqt importand fix with qmap serialization

ImageView now supprt view interaction
BlockView update background when EnabledChange
This commit is contained in:
2021-08-05 00:41:52 +03:00
parent a9203554c5
commit 1ab677774b
4 changed files with 46 additions and 22 deletions

View File

@@ -4,6 +4,7 @@
#include <QEvent>
#include <QMouseEvent>
#include <QWheelEvent>
#include <QScrollBar>
#include <QDebug>
#include <qmath.h>
@@ -22,6 +23,7 @@ ImageView::ImageView(QWidget * parent): QGraphicsView(parent) {
viewport()->setAutoFillBackground(false);
viewport()->installEventFilter(this);
autofit_ = true;
interactive_ = false;
}
@@ -40,6 +42,11 @@ void ImageView::setPixmap(QPixmap pixmap) {
}
void ImageView::setViewInteractive(bool yes) {
interactive_ = yes;
}
void ImageView::setImage(const QImage & i, bool save) {
im_data.clear();
if (i.isNull()) {
@@ -87,20 +94,14 @@ void ImageView::mousePressEvent(QMouseEvent * e) {
}
void ImageView::mouseMoveEvent(QMouseEvent * e) {
//if (e->buttons().testFlag(Qt::RightButton) && !autofit_ && isInteractive()) return;;
QGraphicsView::mouseMoveEvent(e);
void ImageView::wheelEvent(QWheelEvent * e) {
if (!e->modifiers().testFlag(Qt::ControlModifier) || !viewInteractive()) return;
double scl = 1. + e->angleDelta().y() / 500.;
autofit_ = false;
scale(scl, scl);
}
//void ImageView::wheelEvent(QWheelEvent * e) {
// if (!e->modifiers().testFlag(Qt::ControlModifier) || !isInteractive()) return;
// double scl = 1. + e->delta() / 500.;
// //autofit_ = false;
// //scale(scl, scl);
//}
bool ImageView::eventFilter(QObject * o, QEvent * e) {
QMouseEvent * me = (QMouseEvent *)e;
switch (e->type()) {
@@ -108,16 +109,20 @@ bool ImageView::eventFilter(QObject * o, QEvent * e) {
adjustView();
break;
case QEvent::MouseButtonPress:
prev_pos = me->pos();
if (me->buttons().testFlag(Qt::RightButton) && !autofit_ && viewInteractive())
viewport()->setCursor(Qt::ClosedHandCursor);
break;
case QEvent::MouseButtonRelease:
viewport()->unsetCursor();
prev_pos = me->pos();
break;
case QEvent::MouseMove:
if (!me->buttons().testFlag(Qt::RightButton) || autofit_ || !isInteractive()) break;
{
//double scl = 1. / qSqrt(transform().determinant());
//QPointF dp = QPointF(me->pos() - prev_pos) * scl;
//qDebug() << dp;
//translate(0.00001, 0);
prev_pos = me->pos();
if (me->buttons().testFlag(Qt::RightButton) && !autofit_ && viewInteractive()) {
QPointF dp = QPointF(me->pos() - prev_pos);
horizontalScrollBar()->setValue(horizontalScrollBar()->value() - dp.x());
verticalScrollBar()->setValue(verticalScrollBar()->value() - dp.y());
prev_pos = me->pos();
}
break;
default: break;