nodeeditor_doxy
|
00001 #include <QtGui> 00002 #include <QLabel> 00003 00004 #include "mainwindow.h" 00005 //dw 00006 //#include "diagramscene.h" 00007 //dw new 00008 #include "stylesheeteditor.h" 00009 #include "windowflagseditor.h" 00010 00011 00012 const int InsertTextButton = 10; 00013 //dw 00014 const int InsertNodeButton = 11; 00015 const int InsertNode2Button = 12; 00016 00018 MainWindow::MainWindow() 00019 { 00020 00021 //dw new: moved up 00022 //scene = new DiagramScene(itemMenu); 00023 scene = new ExampleDiagramScene(itemMenu); 00024 00025 createActions(); 00026 createToolBox(); 00027 createMenus(); 00028 00029 //dw ugly 00030 scene->mItemMenu = itemMenu; 00031 00032 00033 scene->setSceneRect(QRectF(0, 0, 5000, 5000)); 00034 //dw 00035 connect(scene, SIGNAL(nodeItemInserted(NodeItem *)), 00036 this, SLOT(itemInserted(NodeItem *))); 00037 00038 //connect(scene, SIGNAL(itemSelected(QGraphicsItem *)), 00039 // this, SLOT(itemSelected(QGraphicsItem *))); 00040 createToolbars(); 00041 00042 QHBoxLayout *layout = new QHBoxLayout; 00043 layout->addWidget(toolBox); 00044 00045 //dw new5 00046 view = new QGraphicsView(scene); 00047 //view = new MyFasterGraphicView(scene); 00048 view->setViewportUpdateMode(QGraphicsView::SmartViewportUpdate); 00049 00050 layout->addWidget(view); 00051 00052 QWidget *widget = new QWidget; 00053 widget->setLayout(layout); 00054 00055 setCentralWidget(widget); 00056 setWindowTitle(tr("NodeEditorScene")); 00057 00058 //FIXME: what is a good default 00059 //this->currentWindowFlags = Qt::CustomizeWindowHint | /*Qt::WindowType::MSWindowsFixedSizeDialogHint | Qt::WindowType::WindowTitleHint*/ Qt::WindowType::Tool; 00060 } 00062 00064 void MainWindow::backgroundButtonGroupClicked(QAbstractButton *button) 00065 { 00066 QList<QAbstractButton *> buttons = backgroundButtonGroup->buttons(); 00067 foreach (QAbstractButton *mButton, buttons) { 00068 if (mButton != button) 00069 button->setChecked(false); 00070 } 00071 QString text = button->text(); 00072 if (text == tr("Blue Grid")) 00073 scene->setBackgroundBrush(QPixmap(":/images/background1.png")); 00074 else if (text == tr("White Grid")) 00075 scene->setBackgroundBrush(QPixmap(":/images/background2.png")); 00076 else if (text == tr("Gray Grid")) 00077 scene->setBackgroundBrush(QPixmap(":/images/background3.png")); 00078 else 00079 scene->setBackgroundBrush(QPixmap(":/images/background4.png")); 00080 00081 scene->update(); 00082 view->update(); 00083 } 00085 00087 void MainWindow::buttonGroupClicked(int id) 00088 { 00089 QList<QAbstractButton *> buttons = buttonGroup->buttons(); 00090 foreach (QAbstractButton *button, buttons) { 00091 if (buttonGroup->button(id) != button) 00092 button->setChecked(false); 00093 } 00094 /* 00095 if (id == InsertTextButton) { 00096 scene->setMode(DiagramScene::InsertText); 00097 00098 //dw 00099 } 00100 else if (id == InsertNode2Button) { 00101 //scene->setItemType(DiagramItem::DiagramType::Node); 00102 scene->setMode(DiagramScene::InsertNode2); 00103 } 00104 00105 else { 00106 //scene->setItemType(DiagramItem::DiagramType(id)); 00107 //scene->setMode(DiagramScene::InsertItem); 00108 }*/ 00109 00110 this->scene->mode = id; 00111 } 00113 00115 void MainWindow::deleteItem() 00116 { 00117 if (scene->selectedItems().count()) { 00118 foreach (QGraphicsItem *item, scene->selectedItems()) { 00119 /*//now in dtor: 00120 if (item->type() == DiagramItem::Type) { 00121 qgraphicsitem_cast<DiagramItem *>(item)->removeArrows(); 00122 } 00123 00124 //dw isn't it better to delete stuff in destructors?? 00125 if (item->type() == NodeItem::Type) { 00126 qgraphicsitem_cast<NodeItem *>(item)->removeConnections(); 00127 } 00128 */ 00129 00130 //dw we are doing that now in removeConnections from idem dtor, is that good idea? 00131 //scene->removeItem(item); 00132 00133 //can we delete all item or better only ours, and why is it not deleted automatically on removal? what is the correct way? 00134 delete item; 00135 } 00136 scene->clearSelection(); 00137 scene->clearFocus(); 00138 } 00139 //maybe we are embedding a window so handle this too (TODO: is there a better way?) 00140 else if (this->scene->focusItem() && this->scene->focusItem()->type() == NodeItem::Type) { 00141 NodeItem* item = qgraphicsitem_cast<NodeItem *>(this->scene->focusItem()); 00142 //now in dtor: item->removeConnections(); 00143 00144 //dw we are doing that now in removeConnections from idem dtor, is that good idea? 00145 //scene->removeItem(item); 00146 delete item; 00147 scene->clearSelection(); 00148 scene->clearFocus(); 00149 } 00150 00151 } 00153 00155 void MainWindow::pointerGroupClicked(int) 00156 { 00157 scene->setMode(DiagramScene::Mode(pointerTypeGroup->checkedId())); 00158 } 00160 00162 void MainWindow::bringToFront() 00163 { 00164 if (scene->selectedItems().isEmpty()) 00165 return; 00166 00167 QGraphicsItem *selectedItem = scene->selectedItems().first(); 00168 QList<QGraphicsItem *> overlapItems = selectedItem->collidingItems(); 00169 00170 qreal zValue = 0; 00171 foreach (QGraphicsItem *item, overlapItems) { 00172 /*if (item->zValue() >= zValue && 00173 item->type() == DiagramItem::Type) 00174 zValue = item->zValue() + 0.1;*/ 00175 } 00176 selectedItem->setZValue(zValue); 00177 } 00179 00181 void MainWindow::sendToBack() 00182 { 00183 if (scene->selectedItems().isEmpty()) 00184 return; 00185 00186 QGraphicsItem *selectedItem = scene->selectedItems().first(); 00187 QList<QGraphicsItem *> overlapItems = selectedItem->collidingItems(); 00188 00189 qreal zValue = 0; 00190 foreach (QGraphicsItem *item, overlapItems) { 00191 /*if (item->zValue() <= zValue && 00192 item->type() == DiagramItem::Type) 00193 zValue = item->zValue() - 0.1;*/ 00194 } 00195 selectedItem->setZValue(zValue); 00196 } 00198 00199 00200 void MainWindow::itemInserted(NodeItem *item) { 00201 pointerTypeGroup->button(int(DiagramScene::MoveItem))->setChecked(true); 00202 scene->setMode(DiagramScene::Mode(pointerTypeGroup->checkedId())); 00203 //buttonGroup->button(int(item->diagramType()))->setChecked(false); 00204 00205 //caused crashes 00206 //buttonGroup->button(InsertNode2Button)->setChecked(false); 00207 00208 /*//dwFIXME:only proxified 00209 //note: can add widget later!! wrong location here 00210 if (item->widget() != NULL) { 00211 //FIXME: cleanup 00212 //QPointF p = item->pos(); 00213 item->setWindowFlags(currentWindowFlags); 00214 item->widget()->setStyleSheet(currentStylesheet); 00215 QPointF p2 = item->pos(); 00216 item->setVisible(true); 00217 //item->setPos(p); 00218 item->widget()->adjustSize(); 00219 item->widget()->updateGeometry(); 00220 } 00221 */ 00222 } 00223 00224 00225 00227 void MainWindow::sceneScaleChanged(const QString &scale) 00228 { 00229 double newScale = scale.left(scale.indexOf(tr("%"))).toDouble() / 100.0; 00230 QMatrix oldMatrix = view->matrix(); 00231 view->resetMatrix(); 00232 view->translate(oldMatrix.dx(), oldMatrix.dy()); 00233 view->scale(newScale, newScale); 00234 } 00236 00237 00238 00240 void MainWindow::lineColorChanged() 00241 { 00242 lineAction = qobject_cast<QAction *>(sender()); 00243 lineColorToolButton->setIcon(createColorToolButtonIcon( 00244 ":/images/linecolor.png", 00245 qVariantValue<QColor>(lineAction->data()))); 00246 lineButtonTriggered(); 00247 } 00249 00251 void MainWindow::lineButtonTriggered() 00252 { 00253 scene->setLineColor(qVariantValue<QColor>(lineAction->data())); 00254 } 00256 00258 void MainWindow::about() 00259 { 00260 QMessageBox::about(this, tr("About NodeEditor Scene"), 00261 tr("The <b>NodeEditor Scene</b> example shows " 00262 "use of the graphics framework.")); 00263 } 00265 00267 void MainWindow::createToolBox() 00268 { 00269 buttonGroup = new QButtonGroup; 00270 buttonGroup->setExclusive(false); 00271 connect(buttonGroup, SIGNAL(buttonClicked(int)), 00272 this, SLOT(buttonGroupClicked(int))); 00273 QGridLayout *layout = new QGridLayout; 00274 /* layout->addWidget(createCellWidget(tr("Conditional"), 00275 DiagramItem::Conditional), 0, 0); 00276 layout->addWidget(createCellWidget(tr("Process"), 00277 DiagramItem::Step),0, 1); 00278 layout->addWidget(createCellWidget(tr("Input/Output"), 00279 DiagramItem::Io), 1, 0); 00280 */ 00281 //dw 00282 //we are not a subtype of DiagramItem atm 00283 //layout->addWidget(createCellWidget(tr("Node"), 00284 //DiagramItem::Node), 2, 0); 00285 00286 //NodeItem item(NodeItem::Node, itemMenu); 00287 /* 00288 QToolButton *nodeButton = new QToolButton; 00289 nodeButton->setCheckable(true); 00290 buttonGroup->addButton(nodeButton, InsertNodeButton); 00291 nodeButton->setIcon(QIcon(QPixmap(":/images/createnode1.png") 00292 .scaled(30, 30))); 00293 nodeButton->setIconSize(QSize(50, 50)); 00294 QGridLayout *nodeLayout = new QGridLayout; 00295 nodeLayout->addWidget(nodeButton, 0, 0, Qt::AlignHCenter); 00296 nodeLayout->addWidget(new QLabel(tr("Node")), 1, 0, Qt::AlignCenter); 00297 QWidget *nodeWidget = new QWidget; 00298 nodeWidget->setLayout(nodeLayout); 00299 layout->addWidget(nodeWidget, 2, 0); 00300 */ 00301 00302 QToolButton *node1Button = new QToolButton; 00303 node1Button->setCheckable(true); 00304 buttonGroup->addButton(node1Button, 1); 00305 node1Button->setText(tr("ExampleNode1: dialog, single in, only one connection")); 00306 00307 QToolButton *node2Button = new QToolButton; 00308 node2Button->setCheckable(true); 00309 buttonGroup->addButton(node2Button, 2); 00310 node2Button->setText(tr("ExampleNode2: groupBox, single in, multi connection")); 00311 00312 QToolButton *node5Button = new QToolButton; 00313 node5Button->setCheckable(true); 00314 buttonGroup->addButton(node5Button, 5); 00315 node5Button->setText(tr("ExampleNode5: dialog, single in, only one connection")); 00316 00317 QToolButton *node6Button = new QToolButton; 00318 node6Button->setCheckable(true); 00319 buttonGroup->addButton(node6Button, 6); 00320 node6Button->setText(tr("ExampleNode6: groupBox, 2x inout, multi connection")); 00321 00322 QToolButton *node7Button = new QToolButton; 00323 node7Button->setCheckable(true); 00324 buttonGroup->addButton(node7Button, 7); 00325 node7Button->setText(tr("ExampleNode7: frame with title, 1 x out, multi connection")); 00326 00327 QToolButton *node8Button = new QToolButton; 00328 node8Button->setCheckable(true); 00329 buttonGroup->addButton(node8Button, 8); 00330 node8Button->setText(tr("ExampleNode8: only groupBox")); 00331 00332 layout->addWidget(node1Button); 00333 layout->addWidget(node2Button); 00334 layout->addWidget(node5Button); 00335 layout->addWidget(node6Button); 00336 layout->addWidget(node7Button); 00337 layout->addWidget(node8Button); 00338 00339 00340 /* 00341 QGridLayout *node2Layout = new QGridLayout; 00342 node2Layout->addWidget(node2Button, 0, 0, Qt::AlignHCenter); 00343 //node2Layout->addWidget(new QLabel(tr("Node2")), 1, 0, Qt::AlignCenter); 00344 QWidget *node2Widget = new QWidget; 00345 node2Widget->setLayout(node2Layout); 00346 layout->addWidget(node2Widget, 2, 1); 00347 */ 00348 00350 /* 00351 QToolButton *textButton = new QToolButton; 00352 textButton->setCheckable(true); 00353 buttonGroup->addButton(textButton, InsertTextButton); 00354 textButton->setIcon(QIcon(QPixmap(":/images/textpointer.png") 00355 .scaled(30, 30))); 00356 textButton->setIconSize(QSize(50, 50)); 00357 QGridLayout *textLayout = new QGridLayout; 00358 textLayout->addWidget(textButton, 0, 0, Qt::AlignHCenter); 00359 textLayout->addWidget(new QLabel(tr("Text")), 1, 0, Qt::AlignCenter); 00360 QWidget *textWidget = new QWidget; 00361 textWidget->setLayout(textLayout); 00362 layout->addWidget(textWidget, 1, 1); 00363 */ 00364 layout->setRowStretch(3, 10); 00365 layout->setColumnStretch(2, 10); 00366 00367 00368 00369 QWidget *itemWidget = new QWidget; 00370 itemWidget->setLayout(layout); 00371 00372 backgroundButtonGroup = new QButtonGroup; 00373 connect(backgroundButtonGroup, SIGNAL(buttonClicked(QAbstractButton *)), 00374 this, SLOT(backgroundButtonGroupClicked(QAbstractButton *))); 00375 00376 QGridLayout *backgroundLayout = new QGridLayout; 00377 backgroundLayout->addWidget(createBackgroundCellWidget(tr("Blue Grid"), 00378 ":/images/background1.png"), 0, 0); 00379 backgroundLayout->addWidget(createBackgroundCellWidget(tr("White Grid"), 00380 ":/images/background2.png"), 0, 1); 00381 backgroundLayout->addWidget(createBackgroundCellWidget(tr("Gray Grid"), 00382 ":/images/background3.png"), 0, 2); 00383 backgroundLayout->addWidget(createBackgroundCellWidget(tr("No Grid"), 00384 ":/images/background4.png"), 0, 3); 00385 00386 //backgroundLayout->setRowStretch(2, 10); 00387 //backgroundLayout->setColumnStretch(2, 10); 00388 00389 QWidget *backgroundWidget = new QWidget; 00390 backgroundWidget->setLayout(backgroundLayout); 00391 00392 00394 //toolBox = new QFrame; 00395 toolBox = new QScrollArea; 00396 QFrame* frame = new QFrame; 00397 toolBox->setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAsNeeded); 00398 //QScrollArea *scroll = new QScrollArea; 00399 QVBoxLayout* tbLayout = new QVBoxLayout; 00400 00401 00402 //toolBox->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred)); 00403 frame->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred)); 00404 toolBox->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred)); 00405 00406 QGroupBox* gBox = new QGroupBox(tr("Basic Flowchart Shapes")); 00407 QVBoxLayout* boxLayout = new QVBoxLayout; 00408 00409 boxLayout->addWidget(itemWidget); 00410 gBox->setLayout(boxLayout); 00411 tbLayout->addWidget(gBox/*, tr("Basic Flowchart Shapes")*/); 00412 00413 gBox = new QGroupBox(tr("Backgrounds")); 00414 boxLayout = new QVBoxLayout; 00415 boxLayout->addWidget(backgroundWidget); 00416 gBox->setLayout(boxLayout); 00417 tbLayout->addWidget(gBox/*, tr("Backgrounds")*/); 00418 00420 //FIXME: cleanup and release memory! 00421 StyleSheetEditor* styleSheetEditor = new StyleSheetEditor; 00422 /*QMenu* qssMenu = menuBar()->addMenu(tr("&Style")); 00423 QAction* styleAction = new QAction(QIcon(":/images/bringtofront.png"), 00424 tr("Edit &Style"), this); 00425 styleAction->setShortcut(tr("Ctrl+Y")); 00426 styleAction->setStatusTip(tr("Edit Style")); 00427 qssMenu->addAction(styleAction);*/ 00428 //connect(styleAction, SIGNAL(triggered()), 00429 // styleSheetEditor, SLOT(show())); 00430 connect(styleSheetEditor, SIGNAL(newStyle(const QString&)), 00431 this, SLOT(setNodeItemsStyle(const QString&))); 00432 connect(styleSheetEditor, SIGNAL(newStylesheet(const QString&)), 00433 this, SLOT(setNodeItemsStylesheet(const QString&))); 00434 //tbLayout->addWidget(styleSheetEditor/*, tr("Style/Stylesheet Editor")*/); 00435 00436 gBox = new QGroupBox(tr("Style/Stylesheet Editor")); 00437 boxLayout = new QVBoxLayout; 00438 boxLayout->addWidget(styleSheetEditor); 00439 gBox->setLayout(boxLayout); 00440 tbLayout->addWidget(gBox); 00441 00443 //FIXME: cleanup and release memory! 00444 WindowFlagsEditor* windowFlagsEditor = new WindowFlagsEditor; 00445 /*QMenu* flagsMenu = menuBar()->addMenu(tr("&WindowFlags")); 00446 QAction* flagsAction = new QAction(QIcon(":/images/bringtofront.png"), 00447 tr("Edit &Style"), this); 00448 flagsAction->setShortcut(tr("Ctrl+F")); 00449 flagsAction->setStatusTip(tr("Edit WindowFlags")); 00450 flagsMenu->addAction(flagsAction); 00451 connect(flagsAction, SIGNAL(triggered()), 00452 windowFlagsEditor, SLOT(show()));*/ 00453 connect(windowFlagsEditor, SIGNAL(newWindowFlags(Qt::WindowFlags)), 00454 this, SLOT(setNoteItemsWindowFlags(Qt::WindowFlags))); 00455 //tbLayout->addWidget(windowFlagsEditor/*, tr("WindowFlags Editor")*/); 00456 00457 gBox = new QGroupBox(tr("WindowFlags Editor")); 00458 boxLayout = new QVBoxLayout; 00459 boxLayout->addWidget(windowFlagsEditor); 00460 gBox->setLayout(boxLayout); 00461 tbLayout->addWidget(gBox); 00462 00463 //frame->setMinimumWidth(styleSheetEditor->sizeHint().width() + 40); 00464 //toolBox->setMinimumWidth(frame->sizeHint().width()); 00465 toolBox->setMinimumWidth(styleSheetEditor->sizeHint().width() + 40); 00466 00467 //toolBox->setLayout(tbLayout); 00468 frame->setLayout(tbLayout); 00469 tbLayout->setMargin(0); 00470 toolBox->setWidget(frame); 00471 } 00473 00475 void MainWindow::createActions() 00476 { 00477 toFrontAction = new QAction(QIcon(":/images/bringtofront.png"), 00478 tr("Bring to &Front"), this); 00479 toFrontAction->setShortcut(tr("Ctrl+F")); 00480 toFrontAction->setStatusTip(tr("Bring item to front")); 00481 connect(toFrontAction, SIGNAL(triggered()), 00482 this, SLOT(bringToFront())); 00484 00485 sendBackAction = new QAction(QIcon(":/images/sendtoback.png"), 00486 tr("Send to &Back"), this); 00487 sendBackAction->setShortcut(tr("Ctrl+B")); 00488 sendBackAction->setStatusTip(tr("Send item to back")); 00489 connect(sendBackAction, SIGNAL(triggered()), 00490 this, SLOT(sendToBack())); 00491 00492 deleteAction = new QAction(QIcon(":/images/delete.png"), 00493 tr("&Delete"), this); 00494 deleteAction->setShortcut(tr("Delete")); 00495 deleteAction->setStatusTip(tr("Delete item from diagram")); 00496 connect(deleteAction, SIGNAL(triggered()), 00497 this, SLOT(deleteItem())); 00498 00499 exitAction = new QAction(tr("E&xit"), this); 00500 exitAction->setShortcut(tr("Ctrl+X")); 00501 exitAction->setStatusTip(tr("Quit NodeEditor example")); 00502 connect(exitAction, SIGNAL(triggered()), this, SLOT(close())); 00503 00504 aboutAction = new QAction(tr("A&bout"), this); 00505 aboutAction->setShortcut(tr("Ctrl+B")); 00506 connect(aboutAction, SIGNAL(triggered()), 00507 this, SLOT(about())); 00508 00509 //dw new5 00510 fileNewAction = new QAction(tr("&New"), this); 00511 fileNewAction->setShortcut(tr("Ctrl+N")); 00512 connect(fileNewAction, SIGNAL(triggered()), 00513 this, SLOT(fileNew())); 00514 00515 fileSaveAction = new QAction(tr("&Save"), this); 00516 fileSaveAction->setShortcut(tr("Ctrl+S")); 00517 connect(fileSaveAction, SIGNAL(triggered()), 00518 this, SLOT(fileSave())); 00519 00520 fileOpenAction = new QAction(tr("&Open"), this); 00521 fileOpenAction->setShortcut(tr("Ctrl+O")); 00522 connect(fileOpenAction, SIGNAL(triggered()), 00523 this, SLOT(fileOpen())); 00524 } 00525 00526 void MainWindow::fileNew() { 00527 scene->clear(); 00528 } 00529 00530 void MainWindow::fileSave() { 00531 QString fileName = QFileDialog::getSaveFileName(this, 00532 tr("Save Node Diagram"), "./", tr("Diagram Files (*.diagram)")); 00533 00534 QFile f(fileName); 00535 if (!f.open(QIODevice::WriteOnly | QIODevice::Text)) 00536 return; 00537 00538 QTextStream out(&f); 00539 00540 foreach( QGraphicsItem* i, scene->items()) { 00541 //if (i->inherits("ExampleBaseNode")) { 00542 if (i->type() == NodeItem::Type) { 00543 ExampleBaseNode* n = static_cast<ExampleBaseNode*>(i); 00544 n->serialize(out); 00545 } 00546 } 00547 } 00548 00549 void MainWindow::fileOpen() { 00550 QString fileName = QFileDialog::getOpenFileName(this, 00551 tr("Open Node Diagram"), "./", tr("Diagram Files (*.diagram)")); 00552 00553 QFile f(fileName); 00554 if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) 00555 return; 00556 00557 //clear old scene 00558 scene->clear(); 00559 /*//this gives problems with connections, which are deleted by nodes! 00560 QList<QGraphicsItem *> list = scene->items(); 00561 QList<QGraphicsItem *>::Iterator it = list.begin(); 00562 for ( ; it != list.end(); ++it ) 00563 { 00564 QGraphicsItem* gi = (*it); 00565 if ( (*it) && (*it)->parentItem() == 0 && (*it)->type() == NodeItem::Type) 00566 { 00567 //NodeItem* node = static_cast<NodeItem*>(*it) 00568 scene->removeItem(*it); 00569 delete *it; 00570 } 00571 } 00572 */ 00573 00574 00575 QTextStream in(&f); 00576 QMap<int, ExampleBaseNode*> map ; 00577 00578 while (!in.atEnd()) { 00579 QString l = in.readLine(); 00580 int type = l.split("=")[1].toInt(); 00581 ExampleBaseNode* n = scene->createNode(type); 00582 n->deserialize(in, map); 00583 } 00584 } 00585 00587 void MainWindow::createMenus() 00588 { 00589 fileMenu = menuBar()->addMenu(tr("&File")); 00590 fileMenu->addAction(fileNewAction); 00591 fileMenu->addAction(fileOpenAction); 00592 fileMenu->addAction(fileSaveAction); 00593 fileMenu->addAction(exitAction); 00594 00595 itemMenu = menuBar()->addMenu(tr("&Item")); 00596 itemMenu->addAction(deleteAction); 00597 itemMenu->addSeparator(); 00598 itemMenu->addAction(toFrontAction); 00599 itemMenu->addAction(sendBackAction); 00600 00601 /* 00602 //FIXME: cleanup and release memory! 00603 StyleSheetEditor* styleSheetEditor = new StyleSheetEditor(this); 00604 QMenu* qssMenu = menuBar()->addMenu(tr("&Style")); 00605 QAction* styleAction = new QAction(QIcon(":/images/bringtofront.png"), 00606 tr("Edit &Style"), this); 00607 styleAction->setShortcut(tr("Ctrl+Y")); 00608 styleAction->setStatusTip(tr("Edit Style")); 00609 qssMenu->addAction(styleAction); 00610 connect(styleAction, SIGNAL(triggered()), 00611 styleSheetEditor, SLOT(show())); 00612 connect(styleSheetEditor, SIGNAL(newStyle(const QString&)), 00613 this, SLOT(setNodeItemsStyle(const QString&))); 00614 connect(styleSheetEditor, SIGNAL(newStylesheet(const QString&)), 00615 this, SLOT(setNodeItemsStylesheet(const QString&))); 00616 00617 //FIXME: cleanup and release memory! 00618 WindowFlagsEditor* windowFlagsEditor = new WindowFlagsEditor(this); 00619 QMenu* flagsMenu = menuBar()->addMenu(tr("&WindowFlags")); 00620 QAction* flagsAction = new QAction(QIcon(":/images/bringtofront.png"), 00621 tr("Edit &Style"), this); 00622 flagsAction->setShortcut(tr("Ctrl+F")); 00623 flagsAction->setStatusTip(tr("Edit WindowFlags")); 00624 flagsMenu->addAction(flagsAction); 00625 connect(flagsAction, SIGNAL(triggered()), 00626 windowFlagsEditor, SLOT(show())); 00627 connect(windowFlagsEditor, SIGNAL(newWindowFlags(Qt::WindowFlags)), 00628 this, SLOT(setNoteItemsWindowFlags(Qt::WindowFlags))); 00629 */ 00630 00631 00632 aboutMenu = menuBar()->addMenu(tr("&Help")); 00633 aboutMenu->addAction(aboutAction); 00634 } 00636 void MainWindow::setNodeItemsStyle(const QString &styleName) { 00637 /* 00638 foreach( QGraphicsItem* i, scene->items()) { 00639 //if (i->inherits("ExampleBaseNode")) { 00640 if (i->type() == NodeItem::Type) { 00641 ExampleBaseNode* n = static_cast<ExampleBaseNode*>(i); 00642 n->widget()->setStyle(styleName); 00643 } 00644 } 00645 */ 00646 qApp->setStyle(styleName); 00647 } 00648 00649 00650 /*//dw FIXME:only proxified 00651 void MainWindow::setNodeItemsStylesheet(const QString &stylesheetName) { 00652 currentStylesheet = stylesheetName; 00653 foreach( QGraphicsItem* i, scene->items()) { 00654 //if (i->inherits("ExampleBaseNode")) { 00655 if (i->type() == NodeItem::Type) { 00656 ExampleBaseNode* n = static_cast<ExampleBaseNode*>(i); 00657 n->widget()->setStyleSheet(stylesheetName); 00658 n->update(); 00659 } 00660 } 00661 } 00662 */ 00663 00664 /*//dw FIXME: only for proxified ones 00665 void MainWindow::setNoteItemsWindowFlags(Qt::WindowFlags flags) { 00666 currentWindowFlags = flags; 00667 foreach( QGraphicsItem* i, scene->items()) { 00668 if (i->type() == NodeItem::Type) { 00669 ExampleBaseNode* n = static_cast<ExampleBaseNode*>(i); 00670 /* 00671 If the widget had type Qt::Widget or Qt::SubWindow and becomes a window (Qt::Window, Qt::Dialog, etc.), 00672 it is put at position (0, 0) on the desktop. If the widget is a window and becomes a Qt::Widget or Qt::SubWindow, 00673 it is put at position (0, 0) relative to its parent widget. 00674 */ 00675 /* 00676 n->setWindowFlags(flags); 00677 n->setVisible(true); 00678 n->update(); 00679 n->widget()->adjustSize(); 00680 } 00681 } 00682 } 00683 */ 00684 00686 void MainWindow::createToolbars() 00687 { 00689 editToolBar = addToolBar(tr("Edit")); 00690 editToolBar->addAction(deleteAction); 00691 editToolBar->addAction(toFrontAction); 00692 editToolBar->addAction(sendBackAction); 00693 00694 /* 00695 fontCombo = new QFontComboBox(); 00696 fontSizeCombo = new QComboBox(); 00697 connect(fontCombo, SIGNAL(currentFontChanged(const QFont &)), 00698 this, SLOT(currentFontChanged(const QFont &))); 00699 00700 fontSizeCombo = new QComboBox; 00701 fontSizeCombo->setEditable(true); 00702 for (int i = 8; i < 30; i = i + 2) 00703 fontSizeCombo->addItem(QString().setNum(i)); 00704 QIntValidator *validator = new QIntValidator(2, 64, this); 00705 fontSizeCombo->setValidator(validator); 00706 connect(fontSizeCombo, SIGNAL(currentIndexChanged(const QString &)), 00707 this, SLOT(fontSizeChanged(const QString &))); 00708 00709 fontColorToolButton = new QToolButton; 00710 fontColorToolButton->setPopupMode(QToolButton::MenuButtonPopup); 00711 fontColorToolButton->setMenu(createColorMenu(SLOT(textColorChanged()), 00712 Qt::black)); 00713 textAction = fontColorToolButton->menu()->defaultAction(); 00714 fontColorToolButton->setIcon(createColorToolButtonIcon( 00715 ":/images/textpointer.png", Qt::black)); 00716 fontColorToolButton->setAutoFillBackground(true); 00717 connect(fontColorToolButton, SIGNAL(clicked()), 00718 this, SLOT(textButtonTriggered())); 00719 00721 fillColorToolButton = new QToolButton; 00722 fillColorToolButton->setPopupMode(QToolButton::MenuButtonPopup); 00723 fillColorToolButton->setMenu(createColorMenu(SLOT(itemColorChanged()), 00724 Qt::white)); 00725 fillAction = fillColorToolButton->menu()->defaultAction(); 00726 fillColorToolButton->setIcon(createColorToolButtonIcon( 00727 ":/images/floodfill.png", Qt::white)); 00728 connect(fillColorToolButton, SIGNAL(clicked()), 00729 this, SLOT(fillButtonTriggered())); 00731 */ 00732 00733 lineColorToolButton = new QToolButton; 00734 lineColorToolButton->setPopupMode(QToolButton::MenuButtonPopup); 00735 lineColorToolButton->setMenu(createColorMenu(SLOT(lineColorChanged()), 00736 Qt::black)); 00737 lineAction = lineColorToolButton->menu()->defaultAction(); 00738 lineColorToolButton->setIcon(createColorToolButtonIcon( 00739 ":/images/linecolor.png", Qt::black)); 00740 connect(lineColorToolButton, SIGNAL(clicked()), 00741 this, SLOT(lineButtonTriggered())); 00742 00743 /* 00744 textToolBar = addToolBar(tr("Font")); 00745 textToolBar->addWidget(fontCombo); 00746 textToolBar->addWidget(fontSizeCombo); 00747 textToolBar->addAction(boldAction); 00748 textToolBar->addAction(italicAction); 00749 textToolBar->addAction(underlineAction); 00750 */ 00751 00752 colorToolBar = addToolBar(tr("Color")); 00753 //colorToolBar->addWidget(fontColorToolButton); 00754 //colorToolBar->addWidget(fillColorToolButton); 00755 colorToolBar->addWidget(lineColorToolButton); 00756 00757 QToolButton *pointerButton = new QToolButton; 00758 pointerButton->setCheckable(true); 00759 pointerButton->setChecked(true); 00760 pointerButton->setIcon(QIcon(":/images/pointer.png")); 00761 QToolButton *linePointerButton = new QToolButton; 00762 linePointerButton->setCheckable(true); 00763 linePointerButton->setIcon(QIcon(":/images/linepointer.png")); 00764 00765 pointerTypeGroup = new QButtonGroup; 00766 pointerTypeGroup->addButton(pointerButton, int(DiagramScene::MoveItem)); 00767 pointerTypeGroup->addButton(linePointerButton, 00768 int(DiagramScene::InsertLine)); 00769 connect(pointerTypeGroup, SIGNAL(buttonClicked(int)), 00770 this, SLOT(pointerGroupClicked(int))); 00771 00772 sceneScaleCombo = new QComboBox; 00773 QStringList scales; 00774 scales << tr("50%") << tr("75%") << tr("100%") << tr("125%") << tr("150%"); 00775 sceneScaleCombo->addItems(scales); 00776 sceneScaleCombo->setCurrentIndex(2); 00777 connect(sceneScaleCombo, SIGNAL(currentIndexChanged(const QString &)), 00778 this, SLOT(sceneScaleChanged(const QString &))); 00779 00780 pointerToolbar = addToolBar(tr("Pointer type")); 00781 pointerToolbar->addWidget(pointerButton); 00782 pointerToolbar->addWidget(linePointerButton); 00783 pointerToolbar->addWidget(sceneScaleCombo); 00784 00785 00786 //dw debug draw switch 00787 debugDrawCheckbox = new QCheckBox("DebugDraw"); 00788 connect(debugDrawCheckbox, SIGNAL(clicked(bool)), 00789 static_cast<DiagramScene*>(scene), SLOT(setDebugDraw(bool))); 00790 00791 /*connect(debugDrawCheckbox, SIGNAL(stateChanged(int state)), 00792 static_cast<DiagramScene*>(scene), SLOT(setDebugDraw(bool enabled)));*/ 00793 00794 QToolBar* debugToolbar = addToolBar(tr("Debug Draw")); 00795 debugToolbar->addWidget(debugDrawCheckbox); 00796 00798 } 00800 00801 00803 QWidget *MainWindow::createBackgroundCellWidget(const QString &text, 00804 const QString &image) 00805 { 00806 QToolButton *button = new QToolButton; 00807 button->setText(text); 00808 button->setIcon(QIcon(image)); 00809 button->setIconSize(QSize(50, 50)); 00810 button->setCheckable(true); 00811 backgroundButtonGroup->addButton(button); 00812 00813 QGridLayout *layout = new QGridLayout; 00814 layout->addWidget(button, 0, 0, Qt::AlignHCenter); 00815 layout->addWidget(new QLabel(text), 1, 0, Qt::AlignCenter); 00816 00817 QWidget *widget = new QWidget; 00818 widget->setLayout(layout); 00819 00820 return widget; 00821 } 00823 00825 /* 00826 QWidget *MainWindow::createCellWidget(const QString &text, 00827 DiagramItem::DiagramType type) 00828 { 00829 00830 DiagramItem item(type, itemMenu); 00831 QIcon icon(item.image()); 00832 00833 QToolButton *button = new QToolButton; 00834 button->setIcon(icon); 00835 button->setIconSize(QSize(50, 50)); 00836 button->setCheckable(true); 00837 buttonGroup->addButton(button, int(type)); 00838 00839 QGridLayout *layout = new QGridLayout; 00840 layout->addWidget(button, 0, 0, Qt::AlignHCenter); 00841 layout->addWidget(new QLabel(text), 1, 0, Qt::AlignCenter); 00842 00843 QWidget *widget = new QWidget; 00844 widget->setLayout(layout); 00845 00846 return widget; 00847 } 00848 */ 00850 00852 QMenu *MainWindow::createColorMenu(const char *slot, QColor defaultColor) 00853 { 00854 QList<QColor> colors; 00855 colors << Qt::black << Qt::white << Qt::red << Qt::blue << Qt::yellow; 00856 QStringList names; 00857 names << tr("black") << tr("white") << tr("red") << tr("blue") 00858 << tr("yellow"); 00859 00860 QMenu *colorMenu = new QMenu; 00861 for (int i = 0; i < colors.count(); ++i) { 00862 QAction *action = new QAction(names.at(i), this); 00863 action->setData(colors.at(i)); 00864 action->setIcon(createColorIcon(colors.at(i))); 00865 connect(action, SIGNAL(triggered()), 00866 this, slot); 00867 colorMenu->addAction(action); 00868 if (colors.at(i) == defaultColor) { 00869 colorMenu->setDefaultAction(action); 00870 } 00871 } 00872 return colorMenu; 00873 } 00875 00877 QIcon MainWindow::createColorToolButtonIcon(const QString &imageFile, 00878 QColor color) 00879 { 00880 QPixmap pixmap(50, 80); 00881 pixmap.fill(Qt::transparent); 00882 QPainter painter(&pixmap); 00883 QPixmap image(imageFile); 00884 QRect target(0, 0, 50, 60); 00885 QRect source(0, 0, 42, 42); 00886 painter.fillRect(QRect(0, 60, 50, 80), color); 00887 painter.drawPixmap(target, image, source); 00888 00889 return QIcon(pixmap); 00890 } 00892 00894 QIcon MainWindow::createColorIcon(QColor color) 00895 { 00896 QPixmap pixmap(20, 20); 00897 QPainter painter(&pixmap); 00898 painter.setPen(Qt::NoPen); 00899 painter.fillRect(QRect(0, 0, 20, 20), color); 00900 00901 return QIcon(pixmap); 00902 }