代码拉取完成,页面将自动刷新
#include "riggerview.h"
#include <QDebug>
#include <QScrollBar>
#include <QWheelEvent>
#include <QEvent>
#include <QPointF>
RiggerView::RiggerView(QWidget* parent)
: QGraphicsView(parent)
{
// p_RightBtnMenu = new QMenu(this);
// m_MenuActionList.append(p_RightBtnMenu->addAction(QIcon(":/icons/zoom_out.png"), QString("放大"), this, &RiggerView::viewZoomOut));
// m_MenuActionList.append(p_RightBtnMenu->addAction(QIcon(":/icons/zoom_in.png"), QString("缩小"), this, &RiggerView::viewZoomIn));
// m_MenuActionList.append(p_RightBtnMenu->addAction(QString("重置"), this, &RiggerView::viewZoomReset));
}
//bool RiggerView::eventFilter(QObject *obj, QEvent *event)
//{
// QGraphicsView::eventFilter(obj, event);
//}
void RiggerView::wheelEvent(QWheelEvent* event)
{
if (event->modifiers() == Qt::ControlModifier)
{
QPointF cursorPos = event->position();//event->pos();
QPointF scenePos = mapFromScene(event->position());
QPoint angle = event->angleDelta() / 8;
int numDegrees = angle.y();
if (numDegrees > 0)
{
viewZoomOut();
}
else if (numDegrees < 0)
{
viewZoomIn();
}
QPointF viewPoint = m_Transform.map(scenePos);
if (horizontalScrollBar()->isVisible())
{
horizontalScrollBar()->setValue(int(viewPoint.x() - cursorPos.x()));
}
if (verticalScrollBar()->isVisible())
{
verticalScrollBar()->setValue(int(viewPoint.y() - cursorPos.y()));
}
}
}
void RiggerView::mousePressEvent(QMouseEvent* event)
{
if (event->button() == Qt::RightButton)
{
}
QGraphicsView::mousePressEvent(event);
}
void RiggerView::keyPressEvent(QKeyEvent* event)
{
QGraphicsView::keyPressEvent(event);
}
//void RiggerView::contextMenuEvent(QContextMenuEvent *event)
//{
// p_RightBtnMenu->exec(QCursor::pos());
// QGraphicsView::contextMenuEvent(event);
//}
void RiggerView::viewZoomOut()
{
if (m_Transform.m11() * 1.1 > 2.0)
return;
m_Transform.scale(1.1, 1.1);
setTransform(m_Transform);
// qDebug()<<"zoom in"<<m_Transform.m11();
}
void RiggerView::viewZoomIn()
{
if (m_Transform.m11() / 1.1 < 0.5)
return;
m_Transform.scale(1 / 1.1, 1 / 1.1);
setTransform(m_Transform);
// qDebug()<<"zoom out"<<m_Transform.m11();
}
void RiggerView::viewZoomReset()
{
m_Transform.reset();
setTransform(m_Transform);
// qDebug()<<"zoom reset"<<m_Transform.m11();
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。