Import doxygen generated api doc
[qanava.git] / tests / large / canMainWindow.cpp
blobae73f2e571f6f5b618b331063c3b76719fa177f9
1 //-----------------------------------------------------------------------------
2 // This file is a part of the Qanava software.
3 //
4 // \file canMainWindow.cpp
5 // \author Benoit Autheman (benoit@libqanava.org)
6 // \date 2005 November 11
7 //-----------------------------------------------------------------------------
10 // Qanava headers
11 #include "../../src/qanGraphItemModel.h"
12 #include "../../src/qanGraphicsView.h"
13 #include "../../src/qanGraphItemView.h"
14 #include "../../src/qanGrid.h"
15 #include "./canMainWindow.h"
18 // QT headers
19 #include <QToolBar>
20 #include <QAction>
21 #include <QMessageBox>
22 #include <QTimer>
25 using namespace qan;
28 void generateBranch( Graph& _graph, Node& superNode, int depth, QProgressDialog* progress, QApplication* app, bool root = false )
30 if ( --depth < 1 )
31 return;
33 int subNodeCount = 5 + ( rand( ) % 5 );
34 app->processEvents( );
35 if ( root )
36 progress->setMaximum( subNodeCount );
38 for ( int n = 0; n < subNodeCount; n++ )
40 if ( root )
42 app->processEvents( );
43 progress->setValue( n );
44 if ( progress->wasCanceled( ) )
45 break;
48 QString label;
49 label = "Node ";
50 label += QString::number( _graph.getNodeCount( ) );
51 Node* node = _graph.addNode( label );
52 _graph.addEdge( superNode, *node );
53 generateBranch( _graph, *node, depth, progress, app );
57 void generateTree( Graph& _graph, QProgressDialog* progress, QApplication* app, int depth = 5 )
59 Node* root = _graph.addNode( "Root" );
60 if ( root != 0 )
61 generateBranch( _graph, *root, depth, progress, app, true );
64 //-----------------------------------------------------------------------------
65 MainWindow::MainWindow( QApplication* application, QWidget* parent ) :
66 QMainWindow( parent ),
67 _application( application )
69 setupUi( this );
71 QHBoxLayout *hbox = new QHBoxLayout( _frame );
72 hbox->setMargin( 0 );
73 hbox->setSpacing( 2 );
75 // Setup zoom and navigation toolbars
76 QToolBar* zoomBar = addToolBar( "Zooming" );
77 QSlider* sldZoom = new QSlider( Qt::Horizontal, zoomBar );
78 sldZoom->setMinimum( 1 );
79 sldZoom->setMaximum( 99 );
80 sldZoom->setPageStep( 10 );
81 sldZoom->setSliderPosition( 50 );
82 sldZoom->setMinimumWidth( 190 );
83 zoomBar->addWidget( sldZoom );
85 QToolBar* navigationBar = addToolBar( "Navigation" );
86 navigationBar->setIconSize( QSize( 16, 16 ) );
88 // Generate a simple _graph
89 _graph = new Graph( );
91 // Setup item views
92 _graphItemView = new qan::GraphItemView( _frame, _graph, QColor( 170, 171, 205 ) );
93 GridItem* grid = new GridCheckBoardItem( _graphItemView->getGraphicsView( ), QColor( 255, 255, 255 ), QColor( 238, 230, 230 ) );
94 hbox->addWidget( _graphItemView );
96 // Add canvas pan and zoom action to the navigation tobar
97 _cbGridType = new QComboBox( navigationBar );
98 _cbGridType->addItem( QIcon(), "<< Grid Type >>" );
99 _cbGridType->addItem( QIcon(), "Regular" );
100 _cbGridType->addItem( QIcon(), "Check Board" );
101 connect( _cbGridType, SIGNAL(activated(int)), this, SLOT(gridChanged(int)));
102 navigationBar->addWidget( _cbGridType );
104 qan::GraphicsView* graphicsView = _graphItemView->getGraphicsView( );
105 connect( sldZoom, SIGNAL( valueChanged(int) ), graphicsView, SLOT( setZoomPercent(int) ) );
106 navigationBar->setIconSize( QSize( 16, 16 ) );
108 if ( graphicsView->getAction( "zoom_in" ) != 0 )
109 navigationBar->addAction( graphicsView->getAction( "zoom_in" ) );
110 if ( graphicsView->getAction( "zoom_out" ) != 0 )
111 navigationBar->addAction( graphicsView->getAction( "zoom_out" ) );
112 navigationBar->addSeparator( );
113 if ( graphicsView->getAction( "pan_controller" ) != 0 )
114 navigationBar->addAction( graphicsView->getAction( "pan_controller" ) );
115 if ( graphicsView->getAction( "zoom_window_controller" ) != 0 )
116 navigationBar->addAction( graphicsView->getAction( "zoom_window_controller" ) );
119 QTimer::singleShot( 0, this, SLOT( loadGraph( ) ) );
122 void MainWindow::loadGraph( )
124 QProgressDialog* progress = new QProgressDialog( "Generating graph...", "Cancel", 0, 100, this );
125 progress->setWindowModality( Qt::WindowModal );
126 progress->show( );
127 generateTree( *_graph, progress, _application, 5 );
128 progress->close( );
130 _graphItemView->setModel( _graph );
132 qan::VectorF origin( 2 ); origin( 0 ) = 10.f; origin( 1 ) = 10.f;
133 qan::VectorF spacing( 2 ); spacing( 0 ) = 120.f; spacing( 1 ) = 55.f;
134 _graphItemView->setGraphLayout( new qan::Concentric( 20., 60. ) );
135 _graphItemView->layoutGraph( new QProgressDialog( "Laying out...", "Cancel", 1, 100, this ) );
137 //-----------------------------------------------------------------------------