1 Star 0 Fork 0

yuwei/expandImage

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
riggerview.cpp 2.29 KB
一键复制 编辑 原始数据 按行查看 历史
yuwei 提交于 2024-07-22 00:58 . 整理代码
#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();
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yuwei_2_838529949/expand-image.git
[email protected]:yuwei_2_838529949/expand-image.git
yuwei_2_838529949
expand-image
expandImage
master

搜索帮助