9
use QtCore4::isa qw( Qt::MainWindow );
11
itemMoved => ['QGraphicsPolygonItem *', 'const QPointF &'],
16
itemMenuAboutToShow => [],
17
itemMenuAboutToHide => [];
28
return this->{deleteAction};
32
return this->{addBoxAction};
35
sub addTriangleAction() {
36
return this->{addTriangleAction};
40
return this->{undoAction};
44
return this->{redoAction};
48
return this->{exitAction};
52
return this->{aboutAction};
56
return this->{fileMenu};
60
return this->{editMenu};
64
return this->{itemMenu};
68
return this->{helpMenu};
72
return this->{diagramScene};
76
return this->{undoStack};
80
return this->{undoView};
84
return this->{rootUndoCommand};
92
this->{undoStack} = Qt::UndoStack();
93
this->{rootUndoCommand} = Qt::UndoCommand();
100
this->{diagramScene} = DiagramScene();
101
my $pixmapBrush = Qt::Brush(Qt::Pixmap(':/images/cross.png')->scaled(30, 30));
102
diagramScene->setBackgroundBrush($pixmapBrush);
103
diagramScene->setSceneRect(Qt::RectF(0, 0, 500, 500));
105
this->connect(diagramScene, SIGNAL 'itemMoved(QGraphicsPolygonItem*,QPointF)',
106
this, SLOT 'itemMoved(QGraphicsPolygonItem*,QPointF)');
108
setWindowTitle('Undo Framework');
109
my $view = Qt::GraphicsView(diagramScene);
110
setCentralWidget($view);
118
this->{undoView} = Qt::UndoView(undoStack);
119
undoView->setWindowTitle(this->tr('Command List'));
121
undoView->setAttribute(Qt::WA_QuitOnClose(), 0);
128
this->{deleteAction} = Qt::Action(this->tr('&Delete Item'), this);
129
deleteAction->setShortcut(Qt::KeySequence(this->tr('Del')));
130
this->connect(deleteAction, SIGNAL 'triggered()', this, SLOT 'deleteItem()');
134
this->{addBoxAction} = Qt::Action(this->tr('Add &Box'), this);
136
addBoxAction->setShortcut(Qt::KeySequence(this->tr('Ctrl+O')));
137
this->connect(addBoxAction, SIGNAL 'triggered()', this, SLOT 'addBox()');
139
this->{addTriangleAction} = Qt::Action(this->tr('Add &Triangle'), this);
140
addTriangleAction->setShortcut(Qt::KeySequence(this->tr('Ctrl+T')));
141
this->connect(addTriangleAction, SIGNAL 'triggered()', this, SLOT 'addTriangle()');
144
this->{undoAction} = undoStack->createUndoAction(this, this->tr('&Undo'));
145
undoAction->setShortcut(Qt::KeySequence(Qt::KeySequence::Undo()));
147
this->{redoAction} = undoStack->createRedoAction(this, this->tr('&Redo'));
148
redoAction->setShortcut(Qt::KeySequence(Qt::KeySequence::Redo()));
151
this->{exitAction} = Qt::Action(this->tr('E&xit'), this);
152
exitAction->setShortcut(Qt::KeySequence(Qt::KeySequence::Quit()));
153
this->connect(exitAction, SIGNAL 'triggered()', this, SLOT 'close()');
155
this->{aboutAction} = Qt::Action(this->tr('&About'), this);
156
my @aboutShortcuts = (
157
Qt::KeySequence( this->tr('Ctrl+A') ),
158
Qt::KeySequence( this->tr('Ctrl+B') )
160
aboutAction->setShortcuts(\@aboutShortcuts);
161
this->connect(aboutAction, SIGNAL 'triggered()', this, SLOT 'about()');
168
this->{fileMenu} = menuBar()->addMenu(this->tr('&File'));
169
fileMenu->addAction(exitAction);
172
this->{editMenu} = menuBar()->addMenu(this->tr('&Edit'));
173
editMenu->addAction(undoAction);
174
editMenu->addAction(redoAction);
175
editMenu->addSeparator();
176
editMenu->addAction(deleteAction);
177
this->connect(editMenu, SIGNAL 'aboutToShow()',
178
this, SLOT 'itemMenuAboutToShow()');
179
this->connect(editMenu, SIGNAL 'aboutToHide()',
180
this, SLOT 'itemMenuAboutToHide()');
183
this->{itemMenu} = menuBar()->addMenu(this->tr('&Item'));
184
itemMenu->addAction(addBoxAction);
185
itemMenu->addAction(addTriangleAction);
187
this->{helpMenu} = menuBar()->addMenu(this->tr('&About'));
188
helpMenu->addAction(aboutAction);
196
my ($movedItem, $oldPosition) = @_;
197
undoStack->push(MoveCommand($movedItem, $oldPosition, rootUndoCommand));
204
if (!scalar @{diagramScene->selectedItems()}) {
208
my $deleteCommand = DeleteCommand(diagramScene, rootUndoCommand);
209
undoStack->push($deleteCommand);
214
sub itemMenuAboutToHide
216
deleteAction->setEnabled(1);
221
sub itemMenuAboutToShow
223
deleteAction->setEnabled(scalar @{diagramScene->selectedItems()} > 0);
230
my $addCommand = AddCommand(DiagramItem::Box, diagramScene, rootUndoCommand);
231
undoStack->push($addCommand);
238
my $addCommand = AddCommand(DiagramItem::Triangle, diagramScene, rootUndoCommand);
239
undoStack->push($addCommand);
246
Qt::MessageBox::about(this, this->tr('About Undo'),
247
this->tr('The <b>Undo</b> example demonstrates how to ' .
248
'use Qt\'s undo framework.'));