first commit

This commit is contained in:
2026-02-21 17:11:31 +09:00
commit 18b4338361
4001 changed files with 365464 additions and 0 deletions

View File

@@ -0,0 +1,230 @@
#include "fm_drag_zoom_widget.h"
#if (USE_DRAG_ZOOM)
#include <QPainter>
#include <QMouseEvent>
#include <QDebug>
#include <QTimer>
#include "../core/rm_math.h"
#include "../rm_include.h"
//#include "rm_controlwidget.h"
//#include "rm_constants.h"
FMDragZoomWidget::FMDragZoomWidget(QWidget *parent) : QWidget(parent)
{
#if (DRAG_ZOOM_BY_RATIO)
ratio = QSize(160000,90000);
#endif //
_mousePressed = false;
_drawStarted = false;
_ROIEnabled = false;
#if (USE_DRAG_ZOOM)
_disabled = false;
_block = false;
#endif
QPixmap pixmap;
pixmap.load(":/image/cursor_magnify.png");
_magnify = new QCursor(pixmap);
}
QPoint FMDragZoomWidget::filterPoint(QPoint point)
{
#if (DRAG_ZOOM_BY_RATIO)
QRectF bound = QRectAspectFitRect(ratio,QRect(0,0,this->size().width(),this->size().height()));
#else // DRAG_ZOOM_BY_RATIO
#if (TOP_DOWN_360)
QRectF bound = QRectAspectFitRect(QSize(1,1),QRect(0,0,this->size().width(),this->size().height()));
#else
QRectF bound = QRectAspectFitRect(QSize(160000,90000),QRect(0,0,this->size().width(),this->size().height()));
#endif
#endif // DRAG_ZOOM_BY_RATIO
if(bound.contains(point) == false)
{
double xmin = qMin(bound.left(), bound.right());
double xmax = qMax(bound.left(), bound.right());
double ymax = qMax(bound.top(), bound.bottom());
double ymin = qMin(bound.top(), bound.bottom());
return QPoint((int)qMax(qMin(point.x(),(int)xmax),(int)xmin),(int)qMax(qMin(point.y(),(int)ymax),(int)ymin));
}
return point;
}
void FMDragZoomWidget::sendSelectedSignal()
{
_rect = _rect.normalized();
// 영역이 너무 작을 경우 취소
if(_rect.width() < 5 || _rect.height() < 5)
{
return;
}
// 후방도 16:9로 고정되어 있어 문제가 안됨. ???
#if (DRAG_ZOOM_BY_RATIO)
QRectF bound = QRectAspectFitRect(ratio,QRect(0,0,this->size().width(),this->size().height()));
#else // DRAG_ZOOM_BY_RATIO
#if (TOP_DOWN_360)
QRectF bound = QRectAspectFitRect(QSize(1,1),QRect(0,0,this->size().width(),this->size().height()));
#else // TOP_DOWN_360
QRectF bound = QRectAspectFitRect(QSize(160000,90000),QRect(0,0,this->size().width(),this->size().height()));
#endif // TOP_DOWN_360
#endif // DRAG_ZOOM_BY_RATIO
// 크기는 확인
//qInfo() << "AREA" << this->size() << "BOUND" << bound << "RECT" << _rect << __FUNCTION__;
double xmin = qMin(_rect.left(), _rect.right());
double ymin = qMin(_rect.top(), _rect.bottom());
double x = (xmin - bound.left()) / bound.width();
double y = (ymin - bound.top()) / bound.height();
double width = ((double)_rect.width()) / bound.width();
double height = ((double)_rect.height()) / bound.height();
//qInfo() << "RECT" << x << y << width << height << __FUNCTION__;
#if (FISH_EYE_CLIP)
// 실제 사용자가 화면에서 선택한 영역은 원본 데이터의 85% CLIP 영역
qInfo() << "XYWH:" << x << y << width << height << __FUNCTION__;
// (버릴 영역의 크기: 15% / 2 = 7.5%)
x = (x * 0.85) + 0.075;
y = (y * 0.85) + 0.075;
width *= 0.85;
height *= 0.85;
//qInfo() << "XYWH2:" << x << y << width << height << __FUNCTION__;
#endif
emit ROISelected(x,y,width,height);
}
void FMDragZoomWidget::ROIReset()
{
_mousePressed = false;
_ROIEnabled = true;
//update();
}
void FMDragZoomWidget::setROIEnabled(bool enabled)
{
_ROIEnabled = enabled;
}
void FMDragZoomWidget::mousePressEvent(QMouseEvent *event)
{
//time.start(); // 확인
#if (USE_DRAG_ZOOM)
if(_disabled || _block) {
QWidget::mousePressEvent(event);
return;
}
#endif
if(_ROIEnabled == true && event->button() == Qt::LeftButton)
{
_mousePressed = true;
_rect.setTopLeft(filterPoint(event->pos()));
_rect.setBottomRight(filterPoint(event->pos()));
}
QWidget::mousePressEvent(event);
}
void FMDragZoomWidget::mouseMoveEvent(QMouseEvent *event)
{
//qInfo() << _ROIEnabled << __FUNCTION__;
if(_ROIEnabled == true && _mousePressed == true)
{
_rect.setBottomRight(filterPoint(event->pos()));
if(fabs((float)_rect.width()) > 5.0f && fabs((float)_rect.height()) > 5.0f)
{
setCursor(*_magnify); // 클릭시 커서를 변경하면 보기 싫다.
}
update();
}
QWidget::mouseMoveEvent(event);
}
void FMDragZoomWidget::mouseReleaseEvent(QMouseEvent *event)
{
Q_UNUSED(event);
#if (USE_DRAG_ZOOM)
if(_disabled || _block) {
QWidget::mouseReleaseEvent(event);
return;
}
#endif
//qInfo() << "CLICKED _ROIEnabled:" << _ROIEnabled << "_mousePressed:" << _mousePressed << "_drawStarted:" << _drawStarted << __FUNCTION__;
bool ROI = false;
if(_ROIEnabled == true && _mousePressed == true)
{
#if (CLICK_PAUSE_PLAY)
if(_rect.width() < 5 && _rect.height() < 5) {
emit clicked();
}
#endif // CLICK_PAUSE_PLAY
if(_drawStarted == true)
{
sendSelectedSignal();
ROI = true;
_rect.setRect(0,0,0,0); // 삭제
update();
}
unsetCursor();
}
if(ROI == false)
{
emit ROICleared();
}
_mousePressed = false;
QWidget::mouseReleaseEvent(event);
}
void FMDragZoomWidget::onReleaseDisabled()
{
_block = false;
}
void FMDragZoomWidget::mouseDoubleClickEvent(QMouseEvent *e)
{
_block = true;
QTimer::singleShot(100,Qt::PreciseTimer,this,SLOT(onReleaseDisabled()));
QWidget::mouseDoubleClickEvent(e);
}
void FMDragZoomWidget::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
_painter.begin(this);
QPen pen(Qt::red);
_painter.setPen(pen);
_painter.setRenderHint(QPainter::Antialiasing, false);
QRect nrect = _rect;
nrect = nrect.normalized();
if(_mousePressed)
{
_painter.drawPixmap(0,0,_pixmap);
if(nrect.width() > 5 && nrect.height() > 5) {
_painter.drawRect(nrect);
}
_drawStarted = true;
}
else if (_drawStarted && !_pixmap.isNull())
{
QPainter tempPainter(&_pixmap);
tempPainter.setRenderHint(QPainter::Antialiasing, false);
tempPainter.setPen(pen);
if(nrect.width() > 5 && nrect.height() > 5) {
tempPainter.drawRect(nrect);
}
_painter.drawPixmap(0,0,_pixmap);
}
_painter.end();
}
#endif // USE_DRAG_ZOOM