0.3.1
[qanava.git] / tests / customnodes / canMainWindow.h
blob58af3eca9c13dfe3af943ef1ba4a1e80466f11f7
1 //-----------------------------------------------------------------------------
2 // This file is a part of the Qanava software.
3 //
4 // \file canMainWindow.h
5 // \author Benoit Autheman (benoit@libqanava.org)
6 // \date 2005 November 11
7 //-----------------------------------------------------------------------------
10 #ifndef canMainWindow_h
11 #define canMainWindow_h
14 // Qanava headers
15 #include "./qanGraph.h"
16 #include "../../src/qanGraphView.h"
17 #include "../../src/qanNodeItem.h"
18 #include "../../src/qanStyle.h"
20 #include "ui_canMainWindow.h"
23 // QT headers
24 #include <QMainWindow>
25 #include <QComboBox>
26 #include <QGraphicsItem>
27 #include <QTimer>
30 //-----------------------------------------------------------------------------
31 class MyNode : public qan::AbstractNodeItem, public QGraphicsItem
33 Q_OBJECT
35 public:
37 MyNode( qan::Node& node, qan::Style::Manager& styleManager, qan::Style& style,
38 QGraphicsItem* parent, QGraphicsScene* scene,
39 QPoint origin, const QString& label ) :
40 AbstractNodeItem( node, styleManager, &style ),
41 QGraphicsItem( parent, scene )
43 setFlag( QGraphicsItem::ItemIsMovable );
44 setZValue( 1.5 );
47 virtual ~MyNode( ) { }
49 virtual QGraphicsItem* getGraphicsItem( ) { return static_cast< QGraphicsItem* >( this ); }
51 QRectF boundingRect( ) const
53 qreal adjust = 2;
54 return QRectF(-10 - adjust, -10 - adjust, 23 + adjust, 23 + adjust);
57 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
59 painter->setPen(Qt::NoPen);
60 painter->setBrush(Qt::darkGray);
61 painter->drawEllipse(-7, -7, 20, 20);
63 QRadialGradient gradient(-3, -3, 10);
64 if ( option->state & QStyle::State_Sunken ) {
65 gradient.setCenter(3, 3);
66 gradient.setFocalPoint(3, 3);
67 gradient.setColorAt(1, QColor(Qt::yellow).light(120));
68 gradient.setColorAt(0, QColor(Qt::darkYellow).light(120));
69 } else {
70 gradient.setColorAt(0, Qt::yellow);
71 gradient.setColorAt(1, Qt::darkYellow);
73 painter->setBrush(gradient);
74 painter->setPen(QPen(Qt::black, 0));
75 painter->drawEllipse(-10, -10, 20, 20);
78 QVariant itemChange( GraphicsItemChange change, const QVariant& value );
80 public slots:
82 virtual void updateNode( )
87 public:
89 struct Factory : public qan::AbstractNodeItem::Factory< MyNode >
91 Factory( qan::Style::Manager& styleManager ) :
92 qan::AbstractNodeItem::Factory< MyNode >( 2, styleManager, false ) { } // Factory for node of type '2', no default
97 //!
98 /*!
99 \nosubgrouping
101 class MainWindow : public QMainWindow, public Ui::MainWindow
103 Q_OBJECT
105 public:
107 MainWindow( QWidget* parent = 0 );
109 virtual ~MainWindow( ) { }
111 private:
113 MainWindow( const MainWindow& );
115 MainWindow& operator=( const MainWindow& );
117 QComboBox* _cbGridType;
119 qan::GraphView* _graphView;
121 protected slots:
123 void selectNode( qan::Node* node, QPoint p );
125 void layoutGraph( );
127 protected:
129 QTimer* _timer;
131 qan::UndirectedGraph* _layout;
133 //-----------------------------------------------------------------------------
136 #endif //