-
大小: 993KB文件类型: .zip金币: 1下载: 0 次发布日期: 2021-05-20
- 语言: 其他
- 标签: graphicItem 各种变化
资源简介
主要是演示QT GraphicView中GraphicItem的各种变化(eg.缩放、变形等等)
代码片段和文件信息
#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
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-01-28 15:05 qdraw-master\
文件 242 2017-01-28 15:05 qdraw-master\.gitignore
文件 8 2017-01-28 15:05 qdraw-master\README.md
目录 0 2017-01-28 15:05 qdraw-master\app\
文件 813 2017-01-28 15:05 qdraw-master\app\app.pro
文件 1427 2017-01-28 15:05 qdraw-master\app\app.qrc
文件 10349 2017-01-28 15:05 qdraw-master\app\commands.cpp
文件 3645 2017-01-28 15:05 qdraw-master\app\commands.h
文件 17161 2017-01-28 15:05 qdraw-master\app\customproperty.cpp
文件 3143 2017-01-28 15:05 qdraw-master\app\customproperty.h
文件 50 2017-01-28 15:05 qdraw-master\app\document.cpp
文件 108 2017-01-28 15:05 qdraw-master\app\document.h
文件 41867 2017-01-28 15:05 qdraw-master\app\drawobj.cpp
文件 12333 2017-01-28 15:05 qdraw-master\app\drawobj.h
文件 11388 2017-01-28 15:05 qdraw-master\app\drawscene.cpp
文件 2313 2017-01-28 15:05 qdraw-master\app\drawscene.h
文件 16877 2017-01-28 15:05 qdraw-master\app\drawtool.cpp
文件 2995 2017-01-28 15:05 qdraw-master\app\drawtool.h
文件 9292 2017-01-28 15:05 qdraw-master\app\drawview.cpp
文件 1338 2017-01-28 15:05 qdraw-master\app\drawview.h
目录 0 2017-01-28 15:05 qdraw-master\app\icons\
文件 2951 2017-01-28 15:05 qdraw-master\app\icons\align_all.png
文件 1009 2017-01-28 15:05 qdraw-master\app\icons\align_bottom.png
文件 1229 2017-01-28 15:05 qdraw-master\app\icons\align_hcenter.png
文件 2256 2017-01-28 15:05 qdraw-master\app\icons\align_height.png
文件 1505 2017-01-28 15:05 qdraw-master\app\icons\align_height.svg
文件 355 2017-01-28 15:05 qdraw-master\app\icons\align_horzeven.png
文件 1192 2017-01-28 15:05 qdraw-master\app\icons\align_left.png
文件 1141 2017-01-28 15:05 qdraw-master\app\icons\align_right.png
文件 1199 2017-01-28 15:05 qdraw-master\app\icons\align_top.png
文件 1223 2017-01-28 15:05 qdraw-master\app\icons\align_vcenter.png
............此处省略321个文件信息
评论
共有 条评论