代码拉取完成,页面将自动刷新
#include "qenhancedgraphicsview.h"
#include <QDebug>
QEnhancedGraphicsView::QEnhancedGraphicsView(QWidget *parent)
: QGraphicsView(parent)
{
setMouseTracking(true);
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
setResizeAnchor(QGraphicsView::AnchorUnderMouse);
}
void QEnhancedGraphicsView::wheelEvent(QWheelEvent *event)
{
if (event->orientation() == Qt::Vertical)
{
double angleDeltaY = event->angleDelta().y();
double zoomFactor = qPow(1.0015, angleDeltaY);
scale(zoomFactor, zoomFactor);
emit sendZoomFactor(zoomFactor,sceneMousePos);
this->viewport()->update();
event->accept();
}
else
{
event->ignore();
}
}
void QEnhancedGraphicsView::mousePressEvent(QMouseEvent *event)
{
if(event->button() == Qt::RightButton)
{
QMenu menu;
QAction *clearAllAction = menu.addAction("Clear All");
connect(clearAllAction,
SIGNAL(triggered(bool)),
this,
SLOT(clearAll(bool)));
QAction *clearSelectedAction = menu.addAction("Clear Selected");
connect(clearSelectedAction,
SIGNAL(triggered(bool)),
this,
SLOT(clearSelected(bool)));
QAction *noEffectAction = menu.addAction("No Effect");
connect(noEffectAction,
SIGNAL(triggered(bool)),
this,
SLOT(noEffect(bool)));
QAction *blurEffectAction = menu.addAction("Blur Effect");
connect(blurEffectAction,
SIGNAL(triggered(bool)),
this,
SLOT(blurEffect(bool)));
QAction *dropShadEffectAction = menu.addAction("Drop Shadow Effect");
connect(dropShadEffectAction,
SIGNAL(triggered(bool)),
this,
SLOT(dropShadowEffect(bool)));
QAction *colorizeEffectAction = menu.addAction("Colorize Effect");
connect(colorizeEffectAction,
SIGNAL(triggered(bool)),
this,
SLOT(colorizeEffect(bool)));
QAction *customEffectAction = menu.addAction("Custom Effect");
connect(customEffectAction,
SIGNAL(triggered(bool)),
this,
SLOT(customEffect(bool)));
menu.exec(event->globalPos());
event->accept();
}
else
{
QGraphicsView::mousePressEvent(event);
qDebug()<<event->pos();
}
}
void QEnhancedGraphicsView::clearAll(bool)
{
scene()->clear();
}
void QEnhancedGraphicsView::clearSelected(bool)
{
while(scene()->selectedItems().count() > 0)
{
delete scene()->selectedItems().at(0);
scene()->selectedItems().removeAt(0);
}
}
void QEnhancedGraphicsView::noEffect(bool)
{
foreach(QGraphicsItem *item, scene()->selectedItems())
{
item->setGraphicsEffect(Q_NULLPTR);
}
}
void QEnhancedGraphicsView::blurEffect(bool)
{
foreach(QGraphicsItem *item, scene()->selectedItems())
{
item->setGraphicsEffect(new QGraphicsBlurEffect(this));
}
}
void QEnhancedGraphicsView::dropShadowEffect(bool)
{
foreach(QGraphicsItem *item, scene()->selectedItems())
{
item->setGraphicsEffect(new QGraphicsDropShadowEffect(this));
}
}
void QEnhancedGraphicsView::colorizeEffect(bool)
{
foreach(QGraphicsItem *item, scene()->selectedItems())
{
item->setGraphicsEffect(new QGraphicsColorizeEffect(this));
}
}
void QEnhancedGraphicsView::customEffect(bool)
{
foreach(QGraphicsItem *item, scene()->selectedItems())
{
item->setGraphicsEffect(new QCustomGraphicsEffect(this));
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。