1 //-----------------------------------------------------------------------------
2 // This file is a part of the Qanava software.
4 // \file canMainWindow.cpp
5 // \author Benoit Autheman (benoit@libqanava.org)
6 // \date 2005 November 11
7 //-----------------------------------------------------------------------------
11 #include "../../src/can/canGraphItemModel.h"
12 #include "../../src/can/canGraphicsView.h"
13 #include "../../src/can/canGraphItemView.h"
14 #include "../../src/can/canGrid.h"
15 #include "./canMainWindow.h"
16 #include "./uiProgressQt.h"
22 #include <QMessageBox>
29 void generateBranch( la::Graph
& _graph
, la::Node
& superNode
, int depth
)
34 int subNodeCount
= 5 + ( rand( ) % 5 );
35 for ( int n
= 0; n
< subNodeCount
; n
++ )
39 label
+= QString::number( _graph
.getNodeCount( ) );
40 la::Node
* node
= _graph
.insertNode( label
.toStdString( ) );
41 _graph
.createEdge( superNode
, *node
);
42 generateBranch( _graph
, *node
, depth
);
46 void generateTree( la::Graph
& _graph
, int depth
= 5 )
48 la::Node
* root
= _graph
.insertNode( "Root" );
50 generateBranch( _graph
, *root
, depth
);
51 _graph
.generateRootNodes( );
54 //-----------------------------------------------------------------------------
55 MainWindow::MainWindow( QApplication
* application
, QWidget
* parent
) :
56 QMainWindow( parent
),
57 _application( application
)
61 QHBoxLayout
*hbox
= new QHBoxLayout( _frame
);
63 hbox
->setSpacing( 2 );
65 // Setup zoom and navigation toolbars
66 QToolBar
* zoomBar
= addToolBar( "Zooming" );
67 QSlider
* sldZoom
= new QSlider( Qt::Horizontal
, zoomBar
);
68 sldZoom
->setMinimum( 1 );
69 sldZoom
->setMaximum( 99 );
70 sldZoom
->setPageStep( 10 );
71 sldZoom
->setSliderPosition( 50 );
72 sldZoom
->setMinimumWidth( 190 );
73 zoomBar
->addWidget( sldZoom
);
75 QToolBar
* navigationBar
= addToolBar( "Navigation" );
76 navigationBar
->setIconSize( QSize( 16, 16 ) );
78 // Generate a simple _graph
79 _graph
= new la::Graph( );
82 _graphItemView
= new can::GraphItemView( _frame
, _graph
, QColor( 170, 171, 205 ) );
83 can::Grid
* grid
= new can::GridCheckBoard( _graphItemView
->getGraphicsView( ), QColor( 255, 255, 255 ), QColor( 238, 230, 230 ) );
84 hbox
->addWidget( _graphItemView
);
86 // Add canvas pan and zoom action to the navigation tobar
87 _cbGridType
= new QComboBox( navigationBar
);
88 _cbGridType
->addItem( QIcon(), "<< Grid Type >>" );
89 _cbGridType
->addItem( QIcon(), "Regular" );
90 _cbGridType
->addItem( QIcon(), "Check Board" );
91 connect( _cbGridType
, SIGNAL(activated(int)), this, SLOT(gridChanged(int)));
92 navigationBar
->addWidget( _cbGridType
);
94 can::GraphicsView
* graphicsView
= _graphItemView
->getGraphicsView( );
95 connect( sldZoom
, SIGNAL( valueChanged(int) ), graphicsView
, SLOT( setZoomPercent(int) ) );
96 navigationBar
->setIconSize( QSize( 16, 16 ) );
98 if ( graphicsView
->getAction( "zoom_in" ) != 0 )
99 navigationBar
->addAction( graphicsView
->getAction( "zoom_in" ) );
100 if ( graphicsView
->getAction( "zoom_out" ) != 0 )
101 navigationBar
->addAction( graphicsView
->getAction( "zoom_out" ) );
102 navigationBar
->addSeparator( );
103 if ( graphicsView
->getAction( "pan_controller" ) != 0 )
104 navigationBar
->addAction( graphicsView
->getAction( "pan_controller" ) );
105 if ( graphicsView
->getAction( "zoom_window_controller" ) != 0 )
106 navigationBar
->addAction( graphicsView
->getAction( "zoom_window_controller" ) );
109 QTimer::singleShot( 0, this, SLOT( loadGraph( ) ) );
112 void MainWindow::loadGraph( )
114 generateTree( *_graph
, 5 );
116 can::GraphItemModel
* graphModel
= new can::GraphItemModel( *_graph
);
117 _graphItemView
->setModel( graphModel
);
118 //qan::utl::ProgressVoid progress;
119 qan::ui::ProgressQt
* progress
= new qan::ui::ProgressQt( _application
, this );
121 qan::la::VectorF
origin( 2 ); origin( 0 ) = 10.f
; origin( 1 ) = 10.f
;
122 qan::la::VectorF
spacing( 2 ); spacing( 0 ) = 120.f
; spacing( 1 ) = 55.f
;
123 //_graphItemView->setGraphLayout( new qan::la::DirectedTree( origin, spacing, qan::la::DirectedTree::HORIZONTAL ), progress );
124 //_graphItemView->setGraphLayout( new qan::la::UndirectedGraph( ), progress );
125 _graphItemView
->setGraphLayout( new qan::la::Concentric( 20., 60. ), *progress
);
126 _graphItemView
->layoutGraph( *progress
);
128 //-----------------------------------------------------------------------------