资源简介
基于QT QGraphicsView Framework的绘图软件,可以绘制常见的直线、矩形、圆、椭圆等图形,可以实现图形的交互如碰撞检测、控制手柄拖动缩放、撤销重做等。还有属性树的用法
代码片段和文件信息
#include “commands.h“
#include
MoveShapeCommand::MoveShapeCommand(QGraphicsScene *graphicsScene const QPointF &delta QUndoCommand *parent)
: QUndoCommand(parent)
{
myItem = 0;
myItems = graphicsScene->selectedItems();
myGraphicsScene = graphicsScene;
myDelta = delta;
bMoved = true;
}
MoveShapeCommand::MoveShapeCommand(QGraphicsItem * item const QPointF &delta QUndoCommand *parent)
: QUndoCommand(parent)
{
myGraphicsScene = 0;
myItem = item;
myDelta = delta;
bMoved = true;
}
//! [2]
void MoveShapeCommand::undo()
{
if ( myItem )
myItem->moveBy(-myDelta.x()-myDelta.y());
else if( myItems.count() > 0 ){
foreach (QGraphicsItem *item myItems) {
item->moveBy(-myDelta.x()-myDelta.y());
}
}
setText(Qobject::tr(“Undo Move %1%2“)
.arg(-myDelta.x()).arg(-myDelta.y()));
bMoved = false;
}
//! [2]
//! [3]
void MoveShapeCommand::redo()
{
if ( !bMoved ){
if ( myItem ){
myItem->moveBy(myDelta.x()myDelta.y());
myItem->scene()->update();
}else if( myItems.count() > 0 ){
foreach (QGraphicsItem *item myItems) {
item->moveBy(myDelta.x()myDelta.y());
}
myGraphicsScene->update();
}
}
setText(Qobject::tr(“Redo Move %1%2“)
.arg(myDelta.x()).arg(myDelta.y()));
}
//! [3]
//! [4]
RemoveShapeCommand::RemoveShapeCommand(QGraphicsScene *scene QUndoCommand *parent)
: QUndoCommand(parent)
{
myGraphicsScene = scene;
items = myGraphicsScene->selectedItems();
}
RemoveShapeCommand::~RemoveShapeCommand()
{
}
//! [4]
//! [5]
void RemoveShapeCommand::undo()
{
foreach (QGraphicsItem *item items) {
QGraphicsItemGroup *g = dynamic_cast(item->parentItem());
if ( !g )
myGraphicsScene->addItem(item);
}
myGraphicsScene->update();
setText(Qobject::tr(“Undo Delete %1“).arg(items.count()));
}
//! [5]
//! [6]
void RemoveShapeCommand::redo()
{
foreach (QGraphicsItem *item items) {
QGraphicsItemGroup *g = dynamic_cast(item->parentItem());
if ( !g )
myGraphicsScene->removeItem(item);
}
setText(Qobject::tr(“Redo Delete %1“).arg(items.count()));
}
//! [6]
//! [7]
AddShapeCommand::AddShapeCommand(QGraphicsItem *item
QGraphicsScene *scene QUndoCommand *parent)
: QUndoCommand(parent)
{
static int itemCount = 0;
myGraphicsScene = scene;
myDiagramItem = item;
initialPosition = item->pos();
++itemCount;
}
//! [7]
AddShapeCommand::~AddShapeCommand()
{
if (!myDiagramItem->scene())
delete myDiagramItem;
}
//! [8]
void AddShapeCommand::undo()
{
myGraphicsScene->removeItem(myDiagramItem);
myGraphicsScene->update();
setText(Qobject::tr(“Undo Add %1“)
.arg(createCommandString(myDiagramItem initialPosition)));
}
//! [8]
//! [9]
void AddSha
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
....... 242 2017-01-28 23:05 qdraw-master\.gitignore
....... 813 2017-01-28 23:05 qdraw-master\app\app.pro
....... 1427 2017-01-28 23:05 qdraw-master\app\app.qrc
....... 10349 2017-01-28 23:05 qdraw-master\app\commands.cpp
....... 3645 2017-01-28 23:05 qdraw-master\app\commands.h
....... 17161 2017-01-28 23:05 qdraw-master\app\customproperty.cpp
....... 3143 2017-01-28 23:05 qdraw-master\app\customproperty.h
....... 50 2017-01-28 23:05 qdraw-master\app\document.cpp
....... 108 2017-01-28 23:05 qdraw-master\app\document.h
....... 41867 2017-01-28 23:05 qdraw-master\app\drawobj.cpp
....... 12333 2017-01-28 23:05 qdraw-master\app\drawobj.h
....... 11388 2017-01-28 23:05 qdraw-master\app\drawscene.cpp
....... 2313 2017-01-28 23:05 qdraw-master\app\drawscene.h
....... 16877 2017-01-28 23:05 qdraw-master\app\drawtool.cpp
....... 2995 2017-01-28 23:05 qdraw-master\app\drawtool.h
....... 9292 2017-01-28 23:05 qdraw-master\app\drawview.cpp
....... 1338 2017-01-28 23:05 qdraw-master\app\drawview.h
....... 2951 2017-01-28 23:05 qdraw-master\app\icons\align_all.png
....... 1009 2017-01-28 23:05 qdraw-master\app\icons\align_bottom.png
....... 1229 2017-01-28 23:05 qdraw-master\app\icons\align_hcenter.png
....... 2256 2017-01-28 23:05 qdraw-master\app\icons\align_height.png
....... 1505 2017-01-28 23:05 qdraw-master\app\icons\align_height.svg
....... 355 2017-01-28 23:05 qdraw-master\app\icons\align_horzeven.png
....... 1192 2017-01-28 23:05 qdraw-master\app\icons\align_left.png
....... 1141 2017-01-28 23:05 qdraw-master\app\icons\align_right.png
....... 1199 2017-01-28 23:05 qdraw-master\app\icons\align_top.png
....... 1223 2017-01-28 23:05 qdraw-master\app\icons\align_vcenter.png
....... 344 2017-01-28 23:05 qdraw-master\app\icons\align_verteven.png
....... 2001 2017-01-28 23:05 qdraw-master\app\icons\align_width.png
....... 1777 2017-01-28 23:05 qdraw-master\app\icons\align_width.svg
............此处省略325个文件信息
相关资源
- QT-玛丽奥医生的源代码
- QT画坐标系折线图
- MainWindow和Dialog通过信号和槽通信
- 在QGraphicsScene上画矩形
- Qt下使用GLSL的-变色的小球
- Qt 推箱子游戏及最短路径 源码
- Qt简易浏览器(类似微信)无边框阴影
- Qt状态灯红绿灯实现
- QT:学生信息管理系统
- ModbusTCPMQTT
- qt UDP聊天
- QT自定义 换肤界面
- qt天气预报
- qt聊天室程序
- Qt绘制sin函数静态波形
- Qt异或实现文件加解密.rar
- EncryptQtDemo.rar
- QT等待对话框
- QT5串口上位机源代码
- qml 用item自定义dialog 对话框
- PyQt入门指南
- 汽车仪表盘
- qt做的小程序-鼠标事件
-
Qt Remote ob
ject(QtRO)进程间通信De - 基于QT扫雷游戏开发
- 解决QTextEdit右键菜单为英文的问题
- Qt QRCode生成二维码,完整代码可运行
- mqtt前端调用
- Ubuntu系统:为Qt配置ROS开发环境
- QT4编写的简单计算器
评论
共有 条评论