71 lines
1.7 KiB
C++
71 lines
1.7 KiB
C++
#include "MyCustomGraphicsItem.h"
|
|
#include <QDebug>
|
|
#include <QMessageBox>
|
|
|
|
|
|
CMyCustomGraphicsItem::CMyCustomGraphicsItem(QObject *parent) : QObject(parent)
|
|
{
|
|
|
|
}
|
|
|
|
void CMyCustomGraphicsItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
|
|
{
|
|
QGraphicsItem::mouseDoubleClickEvent(event);
|
|
qDebug() << "mouseDoubleClickEvent" << event->scenePos() <<endl;
|
|
//QGraphicsItem *item = scene.itemAt(mapToScene(event->pos()), QTransform());
|
|
|
|
// QMessageBox msgBox; // 生成对象
|
|
// msgBox.setText("This is Rect."); // 设置文本
|
|
// int ret = msgBox.exec(); // 执行
|
|
|
|
// emit doubleclick(event);
|
|
}
|
|
|
|
void CMyCustomGraphicsItem::wheelEvent(QGraphicsSceneWheelEvent *event)
|
|
{
|
|
// if(event->delta() > 0){
|
|
|
|
// }
|
|
}
|
|
//显示范围
|
|
float LineItem::maxX()
|
|
{
|
|
return m_maxX;
|
|
}
|
|
void LineItem::setMaxX(float value)
|
|
{
|
|
if (m_maxX == value) {
|
|
return;
|
|
}
|
|
//通知Scene边界范围发生了变化,如果不调用的话
|
|
//缓存的边界范围不会发生变化
|
|
prepareGeometryChange();
|
|
m_maxX = value;
|
|
}
|
|
|
|
void LineItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
{
|
|
if (event->button() & Qt::LeftButton)
|
|
{
|
|
// float x = event->pos().x();
|
|
// QPointF point(x, 5*sin(x));
|
|
// static const float r = 0.3;
|
|
// QGraphicsEllipseItem *ellipse = new QGraphicsEllipseItem(-r, -r, 2 * r, 2 * r, this);
|
|
// ellipse->setPen(Qt::NoPen);
|
|
// ellipse->setBrush(QBrush(Qt::red));
|
|
// ellipse->setPos(point);
|
|
// event->accept();
|
|
}
|
|
//右键刷新显示范围
|
|
else if(event->button() & Qt::RightButton)
|
|
{
|
|
int value = m_maxX + 5;
|
|
setMaxX(value);
|
|
event->accept();
|
|
}
|
|
else
|
|
{
|
|
event->ignore();
|
|
}
|
|
}
|