mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#4158 Implement info box for grid cross plots and improve plot overlay legends
This commit is contained in:
@@ -24,12 +24,22 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiuWidgetDragger::RiuWidgetDragger(QWidget* widgetToMove)
|
||||
RiuWidgetDragger::RiuWidgetDragger(QWidget* widgetToMove, QWidget* widgetToSnapTo /*= nullptr*/, int snapMargins /*= 5*/)
|
||||
: QObject(widgetToMove)
|
||||
, m_widgetToMove(widgetToMove)
|
||||
, m_widgetToSnapTo(widgetToSnapTo)
|
||||
, m_snapMargins(snapMargins)
|
||||
, m_startPos(0,0)
|
||||
{
|
||||
m_widgetToMove->installEventFilter(this);
|
||||
addWidget(m_widgetToMove);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuWidgetDragger::addWidget(QWidget* widget)
|
||||
{
|
||||
widget->installEventFilter(this);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -42,13 +52,75 @@ bool RiuWidgetDragger::eventFilter(QObject * watched, QEvent * event)
|
||||
QMouseEvent* mMoveEv = static_cast<QMouseEvent*>(event);
|
||||
if (mMoveEv->buttons() & Qt::LeftButton)
|
||||
{
|
||||
m_widgetToMove->move( m_widgetToMove->mapToParent(mMoveEv->pos() - m_startPos));
|
||||
QPoint relativeMove = mMoveEv->pos() - m_startPos;
|
||||
QRect newFrameRect = m_widgetToMove->frameGeometry().translated(relativeMove);
|
||||
|
||||
if (m_widgetToSnapTo)
|
||||
{
|
||||
QRect snapToRect = m_widgetToSnapTo->frameGeometry();
|
||||
{
|
||||
QPoint snapToTopLeft = snapToRect.topLeft();
|
||||
QPoint widgetTopLeft = newFrameRect.topLeft();
|
||||
QPoint diff = snapToTopLeft - widgetTopLeft;
|
||||
if (std::abs(diff.x()) < 4 * m_snapMargins)
|
||||
{
|
||||
newFrameRect.moveLeft(snapToTopLeft.x() + m_snapMargins);
|
||||
}
|
||||
if (std::abs(diff.y()) < 4 * m_snapMargins)
|
||||
{
|
||||
newFrameRect.moveTop(snapToTopLeft.y() + m_snapMargins);
|
||||
}
|
||||
}
|
||||
{
|
||||
QPoint snapToBottomLeft = snapToRect.bottomLeft();
|
||||
QPoint widgetBottomLeft = newFrameRect.bottomLeft();
|
||||
QPoint diff = snapToBottomLeft - widgetBottomLeft;
|
||||
if (std::abs(diff.x()) < 4 * m_snapMargins)
|
||||
{
|
||||
newFrameRect.moveLeft(snapToBottomLeft.x() + m_snapMargins);
|
||||
}
|
||||
if (std::abs(diff.y()) < 4 * m_snapMargins)
|
||||
{
|
||||
newFrameRect.moveBottom(snapToBottomLeft.y() - m_snapMargins);
|
||||
}
|
||||
}
|
||||
{
|
||||
QPoint snapToTopRight = snapToRect.topRight();
|
||||
QPoint widgetTopRight = newFrameRect.topRight();
|
||||
QPoint diff = snapToTopRight - widgetTopRight;
|
||||
if (std::abs(diff.x()) < 4 * m_snapMargins)
|
||||
{
|
||||
newFrameRect.moveRight(snapToTopRight.x() - m_snapMargins);
|
||||
}
|
||||
if (std::abs(diff.y()) < 4 * m_snapMargins)
|
||||
{
|
||||
newFrameRect.moveTop(snapToTopRight.y() + m_snapMargins);
|
||||
}
|
||||
}
|
||||
{
|
||||
QPoint snapToBottomRight = snapToRect.bottomRight();
|
||||
QPoint widgetBottomRight = newFrameRect.bottomRight();
|
||||
QPoint diff = snapToBottomRight - widgetBottomRight;
|
||||
if (std::abs(diff.x()) < 4 * m_snapMargins)
|
||||
{
|
||||
newFrameRect.moveRight(snapToBottomRight.x() - m_snapMargins);
|
||||
}
|
||||
if (std::abs(diff.y()) < 4 * m_snapMargins)
|
||||
{
|
||||
newFrameRect.moveBottom(snapToBottomRight.y() - m_snapMargins);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
m_widgetToMove->move(newFrameRect.topLeft());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (event->type() == QEvent::MouseButtonPress)
|
||||
{
|
||||
QMouseEvent* mEv = static_cast<QMouseEvent*>(event);
|
||||
m_startPos = mEv->pos();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user