1 Star 0 Fork 0

yuwei/expandImage

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
ExpendedImage.cpp 2.83 KB
一键复制 编辑 原始数据 按行查看 历史
yuwei 提交于 2024-07-22 00:58 . 整理代码
#include "ExpendedImage.h"
#include <QGraphicsItem>
#include <QDebug>
#include <QMenu>
#include <QScrollBar>
#include <qpushbutton.h>
#include <qradiobutton.h>
ExpendedImage::ExpendedImage(QWidget* parent)
: QWidget(parent)
, ui(new Ui::ExpendedImageClass())
{
ui->setupUi(this);
ItemType = ELLIPSE_ITEM;
p_RiggerScene = new RiggerScene(ui->graphicsView->size(), ItemType);
ui->graphicsView->setScene(p_RiggerScene);
ui->graphicsView->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
}
ExpendedImage::~ExpendedImage()
{
delete ui;
}
void ExpendedImage::mousePressEvent(QMouseEvent* event)
{
QPoint pos = event->pos();
QWidget::mousePressEvent(event);
}
void ExpendedImage::resizeEvent(QResizeEvent* event)
{
QWidget::resizeEvent(event);
}
void ExpendedImage::showEvent(QShowEvent* event)
{
static bool firstflag = true;
if (firstflag)
{
p_RiggerScene->resizeScene(QRectF(QPoint(0, 0), ui->graphicsView->size()));
firstflag = false;
}
}
void ExpendedImage::on_graphicsView_customContextMenuRequested(const QPoint& pos)
{
QMenu menu;
QAction* action = menu.addAction(QIcon(":/icons/add_plus.png"), QString("添加图形"));
if (menu.exec(QCursor::pos()) == action)
{
QPen pen(Qt::red, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
switch (ItemType) {
case ELLIPSE_ITEM:
{
QGraphicsEllipseItem* ellipse = new QGraphicsEllipseItem(QRect(pos, QSize(200, 200)));
ellipse->setAcceptHoverEvents(true);
ellipse->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
pen.setWidth(1);
ellipse->setPen(pen);
ellipse->setBrush(QBrush(Qt::red));
ellipse->setOpacity(0.8);
p_RiggerScene->addItem(ellipse);
}
break;
case LINE_ITEM:
{
QGraphicsLineItem* line = new QGraphicsLineItem(QLine(pos, pos + QPoint(100, 50)));
line->setAcceptHoverEvents(true);
line->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
pen.setWidth(3);
line->setPen(pen);
line->setOpacity(0.8);
p_RiggerScene->addItem(line);
}
break;
case RECT_ITEM:
{
QGraphicsRectItem* rect = new QGraphicsRectItem(QRect(pos, QSize(200, 150)));
rect->setAcceptHoverEvents(true);
rect->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
pen.setWidth(1);
rect->setPen(pen);
rect->setBrush(QBrush(Qt::red));
rect->setOpacity(0.8);
p_RiggerScene->addItem(rect);
}
break;
case IMAGE_ITEM:
{
QGraphicsPixmapItem* pixmap = new QGraphicsPixmapItem(QPixmap(":/icons/circle_green.png"));
pixmap->setAcceptHoverEvents(true);
pixmap->setOffset(pos);
pixmap->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
p_RiggerScene->addItem(pixmap);
}
break;
case ANCHOR_ITEM:
{
AnchorItem* item = new AnchorItem(QRect(pos, QSize(200, 200)));
p_RiggerScene->addItem(item);
}
break;
default:
break;
}
}
}
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

搜索帮助