1 Star 0 Fork 1

家有一亩三分地/ImageShow

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
qenhancedgraphicsview.cpp 3.63 KB
一键复制 编辑 原始数据 按行查看 历史
家有一亩三分地 提交于 2021-11-07 21:14 . add websocketwnd
#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));
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/JiaYouYiMuSanFenDi/image-show.git
git@gitee.com:JiaYouYiMuSanFenDi/image-show.git
JiaYouYiMuSanFenDi
image-show
ImageShow
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385