1 //-----------------------------------------------------------------------------
2 // This file is a part of the Qanava software.
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
15 #include "./qanGraph.h"
16 #include "../../src/qanGraphView.h"
17 #include "../../src/qanNodeItem.h"
18 #include "../../src/qanStyle.h"
20 #include "ui_canMainWindow.h"
24 #include <QMainWindow>
26 #include <QGraphicsItem>
30 //-----------------------------------------------------------------------------
31 class MyNode
: public qan::AbstractNodeItem
, public QGraphicsItem
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
);
47 virtual ~MyNode( ) { }
49 virtual QGraphicsItem
* getGraphicsItem( ) { return static_cast< QGraphicsItem
* >( this ); }
51 QRectF
boundingRect( ) const
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));
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
);
82 virtual void updateNode( )
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
101 class MainWindow
: public QMainWindow
, public Ui::MainWindow
107 MainWindow( QWidget
* parent
= 0 );
109 virtual ~MainWindow( ) { }
113 MainWindow( const MainWindow
& );
115 MainWindow
& operator=( const MainWindow
& );
117 QComboBox
* _cbGridType
;
119 qan::GraphView
* _graphView
;
123 void selectNode( qan::Node
* node
, QPoint p
);
131 qan::UndirectedGraph
* _layout
;
133 //-----------------------------------------------------------------------------