refactoring qad widgets part 1

c++ cast, nullptr, forward declaration, agregate ui, connect to member functions, order and clear includes
This commit is contained in:
2022-12-11 16:27:04 +03:00
parent 5d9381dd37
commit 728c132f2b
22 changed files with 561 additions and 404 deletions

View File

@@ -1,4 +1,5 @@
#include "image_view.h"
#include <QGraphicsPixmapItem>
#include <QGraphicsScene>
#include <QBuffer>
#include <QEvent>
@@ -9,7 +10,7 @@
#include <qmath.h>
ImageView::ImageView(QWidget * parent): QGraphicsView(parent) {
ImageView::ImageView(QWidget * parent): QGraphicsView(parent), item(new QGraphicsPixmapItem) {
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setDragMode(QGraphicsView::NoDrag);
@@ -17,9 +18,9 @@ ImageView::ImageView(QWidget * parent): QGraphicsView(parent) {
setScene(new QGraphicsScene());
setRenderHint(QPainter::Antialiasing, true);
setRenderHint(QPainter::SmoothPixmapTransform, true);
item.setTransformationMode(Qt::SmoothTransformation);
item.setFlags(QGraphicsItem::GraphicsItemFlags());
scene()->addItem(&item);
item->setTransformationMode(Qt::SmoothTransformation);
item->setFlags(QGraphicsItem::GraphicsItemFlags());
scene()->addItem(item);
viewport()->setAutoFillBackground(false);
viewport()->installEventFilter(this);
autofit_ = true;
@@ -28,6 +29,7 @@ ImageView::ImageView(QWidget * parent): QGraphicsView(parent) {
ImageView::~ImageView() {
delete item;
}
@@ -50,7 +52,7 @@ void ImageView::setViewInteractive(bool yes) {
void ImageView::setImage(const QImage & i, bool save) {
im_data.clear();
if (i.isNull()) {
item.setPixmap(QPixmap());
item->setPixmap(QPixmap());
map = QPixmap();
return;
}
@@ -67,7 +69,7 @@ void ImageView::setImage(const QImage & i, bool save) {
void ImageView::setImage(const QByteArray & i) {
im_data = i;
if (i.isEmpty()) {
item.setPixmap(QPixmap());
item->setPixmap(QPixmap());
map = QPixmap();
return;
}
@@ -78,7 +80,7 @@ void ImageView::setImage(const QByteArray & i) {
void ImageView::clear() {
im_data.clear();
item.setPixmap(QPixmap());
item->setPixmap(QPixmap());
map = QPixmap();
}
@@ -103,7 +105,7 @@ void ImageView::wheelEvent(QWheelEvent * e) {
bool ImageView::eventFilter(QObject * o, QEvent * e) {
QMouseEvent * me = (QMouseEvent *)e;
QMouseEvent * me = reinterpret_cast<QMouseEvent *>(e);
switch (e->type()) {
case QEvent::Resize:
adjustView();
@@ -137,23 +139,22 @@ void ImageView::adjustView() {
ws *= devicePixelRatio();
#endif
int nw = map.size().boundedTo(ws).width();
item.setScale(1.);
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());
item->setPixmap(map.scaled(map.size() / mp, Qt::KeepAspectRatio, Qt::SmoothTransformation));
item->setScale(double(ss.width()) / item->pixmap().width());
} else
item.setPixmap(map);
item->setPixmap(map);
} else
item.setPixmap(map);
item->setPixmap(map);
if (!autofit_) return;
QRectF r = item.mapRectToScene(item.boundingRect());
QRectF r = item->mapRectToScene(item->boundingRect());
setSceneRect(r);
fitInView(r, Qt::KeepAspectRatio);
centerOn(r.center());
}