代码拉取完成,页面将自动刷新
#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;
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。