43 |
43 |
44 #include "mainwindow.h" |
44 #include "mainwindow.h" |
45 #include "diagramitem.h" |
45 #include "diagramitem.h" |
46 #include "diagramscene.h" |
46 #include "diagramscene.h" |
47 #include "diagramtextitem.h" |
47 #include "diagramtextitem.h" |
|
48 #include "arrow.h" |
48 |
49 |
49 const int InsertTextButton = 10; |
50 const int InsertTextButton = 10; |
50 |
51 |
51 //! [0] |
52 //! [0] |
52 MainWindow::MainWindow() |
53 MainWindow::MainWindow() |
53 { |
54 { |
54 createActions(); |
55 createActions(); |
55 createToolBox(); |
56 createToolBox(); |
56 createMenus(); |
57 createMenus(); |
57 |
58 |
58 scene = new DiagramScene(itemMenu); |
59 scene = new DiagramScene(itemMenu, this); |
59 scene->setSceneRect(QRectF(0, 0, 5000, 5000)); |
60 scene->setSceneRect(QRectF(0, 0, 5000, 5000)); |
60 connect(scene, SIGNAL(itemInserted(DiagramItem*)), |
61 connect(scene, SIGNAL(itemInserted(DiagramItem*)), |
61 this, SLOT(itemInserted(DiagramItem*))); |
62 this, SLOT(itemInserted(DiagramItem*))); |
62 connect(scene, SIGNAL(textInserted(QGraphicsTextItem*)), |
63 connect(scene, SIGNAL(textInserted(QGraphicsTextItem*)), |
63 this, SLOT(textInserted(QGraphicsTextItem*))); |
64 this, SLOT(textInserted(QGraphicsTextItem*))); |
121 |
122 |
122 //! [3] |
123 //! [3] |
123 void MainWindow::deleteItem() |
124 void MainWindow::deleteItem() |
124 { |
125 { |
125 foreach (QGraphicsItem *item, scene->selectedItems()) { |
126 foreach (QGraphicsItem *item, scene->selectedItems()) { |
126 if (item->type() == DiagramItem::Type) { |
127 if (item->type() == Arrow::Type) { |
127 qgraphicsitem_cast<DiagramItem *>(item)->removeArrows(); |
128 scene->removeItem(item); |
|
129 Arrow *arrow = qgraphicsitem_cast<Arrow *>(item); |
|
130 arrow->startItem()->removeArrow(arrow); |
|
131 arrow->endItem()->removeArrow(arrow); |
|
132 delete item; |
128 } |
133 } |
129 scene->removeItem(item); |
|
130 } |
134 } |
|
135 |
|
136 foreach (QGraphicsItem *item, scene->selectedItems()) { |
|
137 if (item->type() == DiagramItem::Type) { |
|
138 qgraphicsitem_cast<DiagramItem *>(item)->removeArrows(); |
|
139 } |
|
140 scene->removeItem(item); |
|
141 delete item; |
|
142 } |
131 } |
143 } |
132 //! [3] |
144 //! [3] |
133 |
145 |
134 //! [4] |
146 //! [4] |
135 void MainWindow::pointerGroupClicked(int) |
147 void MainWindow::pointerGroupClicked(int) |
311 //! [20] |
323 //! [20] |
312 |
324 |
313 //! [21] |
325 //! [21] |
314 void MainWindow::createToolBox() |
326 void MainWindow::createToolBox() |
315 { |
327 { |
316 buttonGroup = new QButtonGroup; |
328 buttonGroup = new QButtonGroup(this); |
317 buttonGroup->setExclusive(false); |
329 buttonGroup->setExclusive(false); |
318 connect(buttonGroup, SIGNAL(buttonClicked(int)), |
330 connect(buttonGroup, SIGNAL(buttonClicked(int)), |
319 this, SLOT(buttonGroupClicked(int))); |
331 this, SLOT(buttonGroupClicked(int))); |
320 QGridLayout *layout = new QGridLayout; |
332 QGridLayout *layout = new QGridLayout; |
321 layout->addWidget(createCellWidget(tr("Conditional"), |
333 layout->addWidget(createCellWidget(tr("Conditional"), |
343 layout->setColumnStretch(2, 10); |
355 layout->setColumnStretch(2, 10); |
344 |
356 |
345 QWidget *itemWidget = new QWidget; |
357 QWidget *itemWidget = new QWidget; |
346 itemWidget->setLayout(layout); |
358 itemWidget->setLayout(layout); |
347 |
359 |
348 backgroundButtonGroup = new QButtonGroup; |
360 backgroundButtonGroup = new QButtonGroup(this); |
349 connect(backgroundButtonGroup, SIGNAL(buttonClicked(QAbstractButton*)), |
361 connect(backgroundButtonGroup, SIGNAL(buttonClicked(QAbstractButton*)), |
350 this, SLOT(backgroundButtonGroupClicked(QAbstractButton*))); |
362 this, SLOT(backgroundButtonGroupClicked(QAbstractButton*))); |
351 |
363 |
352 QGridLayout *backgroundLayout = new QGridLayout; |
364 QGridLayout *backgroundLayout = new QGridLayout; |
353 backgroundLayout->addWidget(createBackgroundCellWidget(tr("Blue Grid"), |
365 backgroundLayout->addWidget(createBackgroundCellWidget(tr("Blue Grid"), |
458 editToolBar->addAction(deleteAction); |
470 editToolBar->addAction(deleteAction); |
459 editToolBar->addAction(toFrontAction); |
471 editToolBar->addAction(toFrontAction); |
460 editToolBar->addAction(sendBackAction); |
472 editToolBar->addAction(sendBackAction); |
461 |
473 |
462 fontCombo = new QFontComboBox(); |
474 fontCombo = new QFontComboBox(); |
463 fontSizeCombo = new QComboBox(); |
|
464 connect(fontCombo, SIGNAL(currentFontChanged(QFont)), |
475 connect(fontCombo, SIGNAL(currentFontChanged(QFont)), |
465 this, SLOT(currentFontChanged(QFont))); |
476 this, SLOT(currentFontChanged(QFont))); |
466 |
477 |
467 fontSizeCombo = new QComboBox; |
478 fontSizeCombo = new QComboBox; |
468 fontSizeCombo->setEditable(true); |
479 fontSizeCombo->setEditable(true); |
524 pointerButton->setIcon(QIcon(":/images/pointer.png")); |
535 pointerButton->setIcon(QIcon(":/images/pointer.png")); |
525 QToolButton *linePointerButton = new QToolButton; |
536 QToolButton *linePointerButton = new QToolButton; |
526 linePointerButton->setCheckable(true); |
537 linePointerButton->setCheckable(true); |
527 linePointerButton->setIcon(QIcon(":/images/linepointer.png")); |
538 linePointerButton->setIcon(QIcon(":/images/linepointer.png")); |
528 |
539 |
529 pointerTypeGroup = new QButtonGroup; |
540 pointerTypeGroup = new QButtonGroup(this); |
530 pointerTypeGroup->addButton(pointerButton, int(DiagramScene::MoveItem)); |
541 pointerTypeGroup->addButton(pointerButton, int(DiagramScene::MoveItem)); |
531 pointerTypeGroup->addButton(linePointerButton, |
542 pointerTypeGroup->addButton(linePointerButton, |
532 int(DiagramScene::InsertLine)); |
543 int(DiagramScene::InsertLine)); |
533 connect(pointerTypeGroup, SIGNAL(buttonClicked(int)), |
544 connect(pointerTypeGroup, SIGNAL(buttonClicked(int)), |
534 this, SLOT(pointerGroupClicked(int))); |
545 this, SLOT(pointerGroupClicked(int))); |
603 colors << Qt::black << Qt::white << Qt::red << Qt::blue << Qt::yellow; |
614 colors << Qt::black << Qt::white << Qt::red << Qt::blue << Qt::yellow; |
604 QStringList names; |
615 QStringList names; |
605 names << tr("black") << tr("white") << tr("red") << tr("blue") |
616 names << tr("black") << tr("white") << tr("red") << tr("blue") |
606 << tr("yellow"); |
617 << tr("yellow"); |
607 |
618 |
608 QMenu *colorMenu = new QMenu; |
619 QMenu *colorMenu = new QMenu(this); |
609 for (int i = 0; i < colors.count(); ++i) { |
620 for (int i = 0; i < colors.count(); ++i) { |
610 QAction *action = new QAction(names.at(i), this); |
621 QAction *action = new QAction(names.at(i), this); |
611 action->setData(colors.at(i)); |
622 action->setData(colors.at(i)); |
612 action->setIcon(createColorIcon(colors.at(i))); |
623 action->setIcon(createColorIcon(colors.at(i))); |
613 connect(action, SIGNAL(triggered()), |
624 connect(action, SIGNAL(triggered()), |