nodeeditor_doxy
src/ExampleApp/mainwindow.h
Go to the documentation of this file.
00001 #ifndef MAINWINDOW_H
00002 #define MAINWINDOW_H
00003 
00004 #include <QMainWindow>
00005 
00006 #include "diagramscene.h"
00007 #include "NodeItem.h"
00008 
00009 class DiagramScene;
00010 
00011 QT_BEGIN_NAMESPACE
00012 class QAction;
00013 class QToolBox;
00014 class QFrame;
00015 class QSpinBox;
00016 class QComboBox;
00017 class QFontComboBox;
00018 class QButtonGroup;
00019 class QLineEdit;
00020 class QGraphicsTextItem;
00021 class QFont;
00022 class QToolButton;
00023 class QAbstractButton;
00024 class QGraphicsView;
00025 //class QGraphicsItem;
00026 QT_END_NAMESPACE
00027 
00028 class ExampleDiagramScene;
00029 
00031 class MainWindow : public QMainWindow
00032 {
00033     Q_OBJECT
00034 
00035 public:
00036    MainWindow();
00037 
00038 private slots:
00039     void backgroundButtonGroupClicked(QAbstractButton *button);
00040     void buttonGroupClicked(int id);
00041     void deleteItem();
00042     void pointerGroupClicked(int id);
00043     void bringToFront();
00044     void sendToBack();
00045     void sceneScaleChanged(const QString &scale);
00046     void lineColorChanged();
00047     void lineButtonTriggered();
00048     //void itemSelected(QGraphicsItem *item);
00049         void itemInserted(NodeItem* item);
00050     void about();
00051 
00052         void fileNew();
00053         void fileSave();
00054         void fileOpen();
00055 
00056 public slots:
00057         void setNodeItemsStyle(const QString &styleName);
00058         void setNodeItemsStylesheet(const QString &stylesheetName);
00059         void setNoteItemsWindowFlags(Qt::WindowFlags flags);
00060 
00061 private:
00062     void createToolBox();
00063     void createActions();
00064     void createMenus();
00065     void createToolbars();
00066     QWidget *createBackgroundCellWidget(const QString &text,
00067                                         const QString &image);
00068     //QWidget *createCellWidget(const QString &text,
00069     //                         DiagramItem::DiagramType type);
00070     QMenu *createColorMenu(const char *slot, QColor defaultColor);
00071     QIcon createColorToolButtonIcon(const QString &image, QColor color);
00072     QIcon createColorIcon(QColor color);
00073 
00074     ExampleDiagramScene *scene;
00075     QGraphicsView *view;
00076 
00077     QAction *exitAction;
00078     QAction *addAction;
00079     QAction *deleteAction;
00080 
00081         //dw new5
00082         QAction *fileNewAction;
00083         QAction *fileSaveAction;
00084         QAction *fileOpenAction;
00085 
00086     QAction *toFrontAction;
00087     QAction *sendBackAction;
00088     QAction *aboutAction;
00089 
00090     QMenu *fileMenu;
00091     QMenu *itemMenu;
00092     QMenu *aboutMenu;
00093 
00094     QToolBar *editToolBar;
00095     QToolBar *colorToolBar;
00096     QToolBar *pointerToolbar;
00097 
00098         //dw new
00099         QCheckBox* debugDrawCheckbox;
00100 
00101     QComboBox *sceneScaleCombo;
00102 
00103     //QToolBox *toolBox;
00104         //QFrame *toolBox;
00105         QScrollArea *toolBox;
00106 
00107     QButtonGroup *buttonGroup;
00108     QButtonGroup *pointerTypeGroup;
00109     QButtonGroup *backgroundButtonGroup;
00110     QToolButton *lineColorToolButton;
00111     QAction *lineAction;
00112 
00113         QString currentStylesheet;
00114         Qt::WindowFlags currentWindowFlags;
00115 };
00117 
00118 class ExampleBaseNode : public NodeItem {
00119 public:
00120         QGridLayout  *innerGridLayout;
00121         QHBoxLayout *topLayout;
00122         QVBoxLayout *leftLayout;
00123         QVBoxLayout *rightLayout;
00124         QHBoxLayout *bottomLayout;
00125 
00126 
00127         void ExampleBaseNode::setWidget(QWidget *widget) {
00128                 //does this work for all possible wiget types
00129 //dw: need other base class!!!          NodeItem::setWidget(widget);
00130                 widget->setObjectName("ExampleBaseNode");
00131         }
00132  
00133 
00134         ExampleBaseNode(QMenu *contextMenu, QGraphicsItem *parent = 0, QGraphicsScene *scene = 0, Qt::WindowFlags wFlags = 0) : NodeItem(contextMenu, parent, scene, wFlags) {
00135                                 //dw new
00136                 QFrame *outterFrame = new QFrame;
00137                 //QWidget *outterFrame = new QWidget;
00138                 outterFrame->setObjectName("outterFrame");
00139                 //QFormLayout *formlayout = new QFormLayout;
00140 
00141                 QVBoxLayout* outterLayout = new QVBoxLayout;
00142                 outterLayout->setMargin(0);
00143 
00144 
00145                 //QGroupBox *innerFrame = new QGroupBox(outterFrame/*"Contact Details"*/);
00146                 //QFrame *innerFrame = new QFrame(outterFrame/*"Contact Details"*/);
00147                 //QFrame *innerFrame = new QFrame(outterFrame);
00148                 //QWidget *innerFrame = new QWidget(outterFrame);
00149                 QFrame *innerFrame = new QFrame();
00150                 innerFrame->setObjectName("innerFrame");
00151 
00152                 //QLineEdit *numberEdit = new QLineEdit;
00153                 //QFormLayout *layout = new QFormLayout;
00154                 //QGridLayout  *innerGridLayout = new QGridLayout;
00155                 innerGridLayout = new QGridLayout;
00156                 topLayout = new QHBoxLayout();
00157                 //innerGridLayout->addLayout(topLayout, 0, 0, 1, 2/*, Qt::AlignCenter*/);
00158                 QFrame *topFrame = new QFrame;
00159                 topFrame->setLayout(topLayout);
00160                 innerGridLayout->addWidget(topFrame, 0, 0, 1, 2/*, Qt::AlignCenter*/);
00161                 leftLayout = new QVBoxLayout();
00162                 //innerGridLayout->addLayout(leftLayout, 1, 0, 1, 1/*, Qt::AlignLeft*/);
00163                 QFrame *leftFrame = new QFrame;
00164                 leftFrame->setLayout(leftLayout);
00165                 innerGridLayout->addWidget(leftFrame, 1, 0, 1, 1/*, Qt::AlignLeft*/);
00166                 rightLayout = new QVBoxLayout();
00167                 //innerGridLayout->addLayout(rightLayout, 1, 1, 1, 1/*, Qt::AlignRight*/);
00168                 QFrame *rightFrame = new QFrame;
00169                 rightFrame->setLayout(rightLayout);
00170                 innerGridLayout->addWidget(rightFrame, 1, 1, 1, 1/*, Qt::AlignRight*/);
00171                 bottomLayout = new QHBoxLayout();
00172                 //innerGridLayout->addLayout(bottomLayout, 2, 0, 1, 2/*, Qt::AlignCenter*/);
00173                 QFrame *bottomFrame = new QFrame;
00174                 bottomFrame->setLayout(bottomLayout);
00175                 innerGridLayout->addWidget(bottomFrame, 2, 0, 1, 2/*, Qt::AlignCenter*/);
00176 
00177                 topLayout->setMargin(0);
00178                 leftLayout->setMargin(0);
00179                 rightLayout->setMargin(0);
00180                 bottomLayout->setMargin(0);
00181 
00182 
00183                 //dw newwww
00184                 innerGridLayout->setMargin(0);
00185                 /*
00186                 innerGridLayout->addItem(new QSpacerItem(0,0),0,0);
00187                 innerGridLayout->addItem(new QSpacerItem(0,0),0,1);
00188                 innerGridLayout->addItem(new QSpacerItem(0,0),1,0);
00189                 innerGridLayout->addItem(new QSpacerItem(0,0),1,1);
00190                 */
00191 
00192 
00193                 /*
00194                 addConnectorAndLabel("b1", NodeConnector::InOut, NodeConnector::Bottom);
00195                 addConnectorAndLabel("righttest1", NodeConnector::InOut, NodeConnector::Right);
00196                 addConnectorAndLabel("righttest2", NodeConnector::InOut, NodeConnector::Right);
00197                 addConnectorAndLabel("b2", NodeConnector::InOut, NodeConnector::Bottom);
00198                 addConnectorAndLabel("righttest3", NodeConnector::InOut, NodeConnector::Right);
00199                 addConnectorAndLabel("lefttest1", NodeConnector::InOut, NodeConnector::Left);
00200                 addConnectorAndLabel("lefttest2", NodeConnector::InOut, NodeConnector::Left);
00201                 addConnectorAndLabel("lefttest3", NodeConnector::InOut, NodeConnector::Left);
00202                 addConnectorAndLabel("b3", NodeConnector::InOut, NodeConnector::Bottom);
00203                 addConnectorAndLabel("t1", NodeConnector::InOut, NodeConnector::Top);
00204                 addConnectorAndLabel("t2", NodeConnector::InOut, NodeConnector::Top);
00205                 addConnectorAndLabel("lefttest4", NodeConnector::InOut, NodeConnector::Left);
00206                 addConnectorAndLabel("b4", NodeConnector::InOut, NodeConnector::Bottom);
00207                 */
00208 
00209 
00210                 //formlayout->addWidget(innerFrame);
00211                 //setWidget(innerFrame);
00212                 //outterLayout->addWidget(innerFrame);
00213 
00214                 //outterLayout->addLayout(innerGridLayout);
00215                 innerFrame->setLayout(innerGridLayout);
00216                 outterLayout->addWidget(innerFrame);
00217 
00218                 //innerFrame->setLayout(innerGridLayout);
00219                 outterFrame->setLayout(outterLayout);
00220                 setWidget(outterFrame);
00221 
00222 
00223                 outterFrame->setObjectName("ExampleBaseNode");
00224         }
00225 
00226 
00227 
00228         virtual void addConnectorAndLabel(QString name, NodeConnector::ConnectorType t, NodeConnector::ConnectorAlignment align) {
00229                 int cols = innerGridLayout->columnCount();
00230                 int rows = innerGridLayout->rowCount();
00231 
00232                 QLabel* l = new QLabel(name);
00233                 if (align == NodeConnector::Left) {
00234                         l->setObjectName("leftLabel");
00235                         l->setAlignment(Qt::AlignLeft);
00236                         if (leftLayout->count() < 1) leftLayout->addStretch();
00237                         leftLayout->addWidget(l);
00238                         leftLayout->addStretch();
00239                 }
00240                 else if (align == NodeConnector::Right) {
00241                         l->setObjectName("rightLabel");
00242                         l->setAlignment(Qt::AlignRight);
00243                         if (rightLayout->count() < 1) rightLayout->addStretch();
00244                         rightLayout->addWidget(l);
00245                         rightLayout->addStretch();
00246                 }
00247                 else if (align == NodeConnector::Top) {
00248                         l->setObjectName("topLabel");
00249                         l->setAlignment(Qt::AlignCenter);
00250                         if (topLayout->count() < 1) topLayout->addStretch();
00251                         topLayout->addWidget(l);
00252                         topLayout->addStretch();
00253                 } else if (align == NodeConnector::Bottom) {
00254                         l->setObjectName("bottomLabel");
00255                         l->setAlignment(Qt::AlignCenter);
00256                         if (bottomLayout->count() < 1) bottomLayout->addStretch();
00257                         bottomLayout->addWidget(l);
00258                         bottomLayout->addStretch();
00259                 }
00260 
00261                 //innerGridLayout->upd
00262 
00263                 addConnector(new NodeConnector(this, scene(), l, t, align, false));
00264         }
00265 
00266 
00267         virtual void serialize(QTextStream& out) {
00268                 //QString res;
00269                 //node
00270                 out << "typeId=" << QString::number(getId()) << "\n";
00271                 out << "uid=" << QString::number((size_t) this) << ", x=" << QString::number(pos().x()) << ", y=" << QString::number(pos().y()) << "\n";
00272                 //connections that start on this node
00273                 foreach(NodeConnector* con, connectors) {
00274                         foreach(NodeConnection* c, con->arrows) {
00275                                 NodeConnector* oc = NULL;
00276                                 if (c->startConnector() == con) {
00277                                         oc = c->endConnector();
00278                                 }
00279                                 else {
00280                                         oc = c->startConnector();
00281                                 }
00282                                 ExampleBaseNode* oi = static_cast<ExampleBaseNode*>(oc->parentItem());
00283                                 //otherwise self-connections on this node (but not when on same connector) would be written twice, so do nothing in one of the two cases
00284                                 if (this == oi && this->connectors.indexOf(con) < oi->connectors.indexOf(oc)) {
00285                                         continue;
00286                                 }
00287                                 if (c->startConnector() == con) {
00288                                         out << "startNodeConnector=" << QString::number(this->connectors.indexOf(con));
00289                                         out << ", endNodeUid=" << QString::number((size_t) oi);
00290                                         out << ", endNodeConnector=" << QString::number(oi->connectors.indexOf(oc));
00291                                 }
00292                                 else {
00293                                         out << "endNodeConnector=" << QString::number(this->connectors.indexOf(con));
00294                                         out << ", startNodeUid=" << QString::number((size_t) oi);
00295                                         out << ", startNodeConnector=" << QString::number(oi->connectors.indexOf(oc));
00296                                 }
00297                                 out << "\n";
00298                         }
00299                 }
00300                 out << "\n";
00301         }
00302 
00303         virtual void deserialize(QTextStream& out, QMap<int, ExampleBaseNode*>& map) {
00304                 //typeId is read by caller
00305                 QString  l;
00306                 if ((l=out.readLine()) != "") {
00307                         QStringList list = l.split(",");
00308                         int id = list[0].split("=")[1].toInt();
00309                         int x = list[1].split("=")[1].toInt();
00310                         int y = list[2].split("=")[1].toInt();
00311                         this->setPos(x, y);
00312                         map[id] = this;
00313                 }
00314                 while ((l=out.readLine()) != "") {
00315                         bool isStart = l.startsWith("startNodeConnector=");
00316                         QStringList list = l.split(",");
00317                         int c = list[0].split("=")[1].toInt();
00318                         int oid = list[1].split("=")[1].toInt();
00319                         int oc = list[2].split("=")[1].toInt();
00320                         //only the second node creates the connection
00321                         if (map.contains(oid)) {
00322                                 NodeItem* other = map[oid];
00323                                 NodeConnector* thisCon = this->connectors[c];
00324                                 NodeConnector* oCon = other->connectors[oc];
00325                                 NodeConnection* newCon = NULL;
00326                                 if (isStart) {
00327                                         newCon = new NodeConnection(thisCon, oCon, NULL, this->scene());
00328                                 }
00329                                 else {
00330                                         newCon = new NodeConnection(oCon, thisCon, NULL, this->scene());
00331                                 }
00332                                 //FIXME: should not be job of user
00333                                 thisCon->addConnection(newCon);
00334                                 oCon->addConnection(newCon);
00335                                 newCon->setZValue(-1000.0);
00336                         }
00337                 }
00338         }
00339 
00340         virtual int getId() = 0;
00341 };
00342 
00343 //"ExampleNode1: dialog, single in, only one connection"
00344 class ExampleNode1 : public ExampleBaseNode {
00345 public:
00346         ExampleNode1(QMenu *contextMenu, QGraphicsItem *parent = 0, QGraphicsScene *scene = 0) : ExampleBaseNode(contextMenu, parent, scene) {
00347                 /*
00348                 QLabel* in0 = new QLabel("in0");
00349                 this->innerGridLayout->addWidget(in0);
00350                 
00351                 //dialog->setAttribute(Qt::WA_DeleteOnClose);
00352                 //this->setWidget(dialog);
00353 
00354                 addConnector(new NodeConnector(this, scene, in0, NodeConnector::In, NodeConnector::Left, true));
00355                 */
00356                 //FIXME:
00357                 addConnectorAndLabel("in0", NodeConnector::In, NodeConnector::Left);
00358         }
00359         int getId() { return 1; }
00360 };
00361 
00362 //"ExampleNode2: groupBox, single in, multi connection"
00363 class ExampleNode2 : public ExampleBaseNode {
00364 public:
00365         ExampleNode2(QMenu *contextMenu, QGraphicsItem *parent = 0, QGraphicsScene *scene = 0) : ExampleBaseNode(contextMenu, parent, scene) {
00366                 /*
00367                 QLabel* in0 = new QLabel("in0");
00368 
00369                 innerGridLayout->addWidget(in0);
00370                 
00371                 //QGroupBox *dialog = new QGroupBox();
00372                 //dialog->setLayout(layout);
00373 
00374                 //dw668 was active: dialog->setAttribute(Qt::WA_DeleteOnClose);
00375 
00376                 //this->setWidget(dialog);
00377 
00378                 addConnector(new NodeConnector(this, scene, in0, NodeConnector::In, NodeConnector::Left, false));
00379                 */
00380                 //FIXME:
00381                 addConnectorAndLabel("in0", NodeConnector::In, NodeConnector::Left);
00382         }
00383         int getId() { return 2; }
00384 };
00385 
00386 //"ExampleNode5: dialog, single in, only one connection"
00387 class ExampleNode5 : public ExampleBaseNode {
00388 public:
00389         ExampleNode5(QMenu *contextMenu, QGraphicsItem *parent = 0, QGraphicsScene *scene = 0) : ExampleBaseNode(contextMenu, parent, scene) {
00390                 //QFormLayout *layout2 = new QFormLayout;
00391                 /*
00392                 QLabel* out0 = new QLabel("out0");
00393                 out0->setAlignment(Qt::AlignRight);
00394                 QLabel* in0 = new QLabel("in0");
00395                 
00396                 innerGridLayout->addWidget(in0,0,0);
00397                 innerGridLayout->addWidget(out0,0,1);
00398                 QLabel* in1 = new QLabel("in1");
00399                 innerGridLayout->addWidget(in1,1,0,1,2);
00400                 QLabel* in2 = new QLabel("in2");
00401                 innerGridLayout->addWidget(in2,2,0,1,2);
00402                 QLabel* inout0 = new QLabel("inOut0");
00403                 inout0->setAlignment(Qt::AlignRight);
00404                 innerGridLayout->addWidget(inout0,3,0,1,2);
00405 
00406                 QSpinBox* spinBox = new QSpinBox();
00407                 spinBox->setMinimum(0);
00408                 spinBox->setMaximum(9);
00409                 innerGridLayout->addWidget(spinBox,4,0,1,2);
00410                 */
00411 
00412                 addConnectorAndLabel("in0", NodeConnector::In, NodeConnector::Left);
00413                 addConnectorAndLabel("out0", NodeConnector::Out, NodeConnector::Right);
00414                 addConnectorAndLabel("in1", NodeConnector::In, NodeConnector::Left);
00415                 addConnectorAndLabel("in2", NodeConnector::In, NodeConnector::Left);
00416                 addConnectorAndLabel("inOut0", NodeConnector::InOut, NodeConnector::Right);
00417                 QSpinBox* spinBox = new QSpinBox();
00418                 spinBox->setMinimum(0);
00419                 spinBox->setMaximum(9);
00420                 leftLayout->addWidget(spinBox);
00421                 addConnector(new NodeConnector(this, scene, spinBox, NodeConnector::InOut));
00422 
00423 
00424                 //QDialog *dialog1 = new QDialog();
00425                 //dw from: http://lists.trolltech.com/qt-interest/2002-05/thread00837-0.html
00426                 //MyDialog::MyDialog(QWidget* parent, const char* name) : QDialog(parent, name, true, WStyle_Customize | WStyle_DialogBorder | WStyle_Title | WStyle_SysMenu)
00427 
00428                 /*
00429                 QDialog *dialog1 = new QDialog(NULL, Qt::WindowType::FramelessWindowHint);
00430                 dialog1->setLayout(layout2);
00431                 */
00432 
00433                 //dialog1->setAttribute(Qt::WA_DeleteOnClose);
00434 
00435                 //dw new3
00436                 //dialog1->setStyle(new QStyle::());
00437 
00438                 //dialog1->setSizeGripEnabled(false);
00439 
00440                 //dialog1->setFixedSize(dialog1->size());
00441                 //dialog1->setSizePolicy(QSizePolicy::Fixed);
00442                 //layout2->setSizeConstraint(QLayout::SetFixedSize);
00443 
00444                 //dialog1->layout()->setSizeConstraint( QLayout::SetFixedSize ) ;
00445                 //dialog1->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
00446                 
00447 
00448                 /*
00449                 this->setWidget(dialog1);
00450                 setWindowFlags(dialog1->windowFlags() | Qt::Tool);
00451                 */
00452                 /*
00453                 addConnector(new NodeConnector(this, scene, out0, NodeConnector::Out, NodeConnector::Right));
00454                 addConnector(new NodeConnector(this, scene, in0, NodeConnector::In));
00455                 addConnector(new NodeConnector(this, scene, in1, NodeConnector::In));
00456                 addConnector(new NodeConnector(this, scene, in2, NodeConnector::In));
00457                 addConnector(new NodeConnector(this, scene, inout0, NodeConnector::InOut, NodeConnector::Right));
00458                 addConnector(new NodeConnector(this, scene, spinBox, NodeConnector::InOut));
00459                 */
00460         }
00461         int getId() { return 5; }
00462 };
00463 
00464 //"ExampleNode6: groupBox, 2x inout, multi connection"
00465 class ExampleNode6 : public ExampleBaseNode {
00466 public:
00467         ExampleNode6(QMenu *contextMenu, QGraphicsItem *parent = 0, QGraphicsScene *scene = 0) : ExampleBaseNode(contextMenu, parent, scene) {
00468 
00469                 addConnectorAndLabel("inout0", NodeConnector::InOut, NodeConnector::Left);
00470                 addConnectorAndLabel("inout1", NodeConnector::InOut, NodeConnector::Right);
00471 
00472                 /*
00473                 //QFormLayout *layout = new QFormLayout;
00474                 QLabel* inout0 = new QLabel("inout0");
00475                 QLabel* inout1 = new QLabel("inout1");
00476                 inout1->setAlignment(Qt::AlignRight);
00477                 //layout->addRow(inout0, inout1);
00478                 //QGroupBox *dialog = new QGroupBox();
00479                 //dialog->setLayout(layout);
00480 
00481                 innerGridLayout->addWidget(inout0,0,0);
00482                 innerGridLayout->addWidget(inout1,0,1);
00483                 */
00484 
00485                 /*
00486                 dialog->setAttribute(Qt::WA_DeleteOnClose);
00487                 this->setWidget(dialog);
00488                 //dw with Qt:Tool they seem to be movable by click!!! but bar has same size on windows vista
00489                 setWindowFlags(dialog->windowFlags() | Qt::Tool | Qt::WindowType::FramelessWindowHint);
00490                 */
00491 
00492                 /*
00493                 addConnector(new NodeConnector(this, scene, inout0, NodeConnector::InOut, NodeConnector::Left, false));
00494                 addConnector(new NodeConnector(this, scene, inout1, NodeConnector::InOut, NodeConnector::Right, false));
00495                 */
00496         }
00497         int getId() { return 6; }
00498 };
00499 
00500 //"ExampleNode7: frame with title, 1 x out, multi connection"
00501 class ExampleNode7 : public ExampleBaseNode {
00502 public:
00503         ExampleNode7(QMenu *contextMenu, QGraphicsItem *parent = 0, QGraphicsScene *scene = 0) : ExampleBaseNode(contextMenu, parent, scene, Qt::WindowType::Dialog | Qt::CustomizeWindowHint | Qt::WindowType::MSWindowsFixedSizeDialogHint | Qt::WindowType::WindowTitleHint | Qt::Tool) {
00504                 addConnectorAndLabel("out0", NodeConnector::Out, NodeConnector::Right);
00505 
00506                 /*
00507                 //QFormLayout *layout = new QFormLayout;
00508                 QLabel* out0 = new QLabel("out0");
00509                 out0->setAlignment(Qt::AlignRight);
00510                 */
00511                 /*
00512                 layout->addRow(out0);
00513                 QDialog *dialog = new QDialog(NULL);
00514                 dialog->setWindowTitle("ExampleNode7: frame with title, 1 x out, multi connection");
00515                 //QToolBox *dialog = new QToolBox();
00516                 dialog->setWindowTitle("xxx7");
00517                 dialog->setLayout(layout);
00518                 //dialog->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
00519                 //dialog->setFixedSize(dialog->sizeHint());
00520                 //layout->setSizeConstraint(QLayout::SetFixedSize);
00521                 this->mNoResize = false;
00522                 */
00523 
00524                 //dialog->setAttribute(Qt::WA_DeleteOnClose);
00525                 //this->setWidget(dialog);
00526 
00527                 /*
00528                 innerGridLayout->addWidget(out0);
00529                 addConnector(new NodeConnector(this, scene, out0, NodeConnector::Out, NodeConnector::Right, false));
00530                 */
00531         }
00532         int getId() { return 7; }
00533 };
00534 
00535 //"ExampleNode8: only groupBox"
00536 class ExampleNode8 : public ExampleBaseNode {
00537 public:
00538         ExampleNode8(QMenu *contextMenu, QGraphicsItem *parent = 0, QGraphicsScene *scene = 0) : ExampleBaseNode(contextMenu, parent, scene) {
00539 
00540                 addConnectorAndLabel("t0", NodeConnector::InOut, NodeConnector::Top);
00541                 addConnectorAndLabel("t1", NodeConnector::InOut, NodeConnector::Top);
00542                 addConnectorAndLabel("t2", NodeConnector::InOut, NodeConnector::Top);
00543 
00544                 addConnectorAndLabel("l0", NodeConnector::InOut, NodeConnector::Left);
00545                 addConnectorAndLabel("l1", NodeConnector::InOut, NodeConnector::Left);
00546                 addConnectorAndLabel("l2", NodeConnector::InOut, NodeConnector::Left);
00547 
00548                 addConnectorAndLabel("r0", NodeConnector::InOut, NodeConnector::Right);
00549                 addConnectorAndLabel("r1", NodeConnector::InOut, NodeConnector::Right);
00550                 addConnectorAndLabel("r2", NodeConnector::InOut, NodeConnector::Right);
00551 
00552                 addConnectorAndLabel("b0", NodeConnector::InOut, NodeConnector::Bottom);
00553                 addConnectorAndLabel("b1", NodeConnector::InOut, NodeConnector::Bottom);
00554                 addConnectorAndLabel("b2", NodeConnector::InOut, NodeConnector::Bottom);
00555 
00556 
00557 
00558         }
00559         int getId() { return 8; }
00560 };
00561 
00562 class ExampleDiagramScene : public DiagramScene {
00563 public:
00564         int mode;
00565         ExampleDiagramScene(QMenu *itemMenu, QObject* parent = 0) : DiagramScene(itemMenu, parent ), mode(0) {
00566         }
00567         void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) {
00568                 if (mode == 0) {
00569                         DiagramScene::mousePressEvent(mouseEvent);
00570                 }
00571                 else {
00572                         NodeItem *node2 = createNode(mode);
00573                         //this->addItem(node2);
00574                         node2->setPos(mouseEvent->scenePos());
00575                         mode = 0;
00576                 }
00577         }
00578         ExampleBaseNode* createNode(int type) {
00579                 ExampleBaseNode *node2 = NULL;
00580                 switch (type) {
00581                         case 1:
00582                                 node2 = new ExampleNode1(mItemMenu,NULL,this);
00583                                 break;
00584                         case 2:
00585                                 node2 = new ExampleNode2(mItemMenu,NULL,this);
00586                                 break;
00587                         case 5:
00588                                 node2 = new ExampleNode5(mItemMenu,NULL,this);
00589                                 break;
00590                         case 6:
00591                                 node2 = new ExampleNode6(mItemMenu,NULL,this);
00592                                 break;
00593                         case 7:
00594                                 node2 = new ExampleNode7(mItemMenu,NULL,this);
00595                                 break;
00596                         case 8:
00597                                 node2 = new ExampleNode8(mItemMenu,NULL,this);
00598                                 break;
00599                 }
00600                 emit nodeItemInserted(node2);
00601                 return node2;
00602         }
00603 };
00604 
00605 
00606 
00607 
00608 class MyFasterGraphicView : public QGraphicsView
00609 {
00610 Q_OBJECT
00611 public:
00612         MyFasterGraphicView(QGraphicsScene* scene): QGraphicsView(scene) {}
00613 protected:
00614         void paintEvent ( QPaintEvent * event) {
00615                 QPaintEvent *newEvent=new QPaintEvent(event->region().boundingRect());
00616                 QGraphicsView::paintEvent(newEvent);
00617                 delete newEvent;
00618         }
00619 };
00620 
00621 
00622 #endif