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/qanGraphView.h"
12 #include "../../src/qanGraphScene.h"
13 #include "../../src/qanGrid.h"
14 #include "./canMainWindow.h"
21 #include <QMessageBox>
27 //-----------------------------------------------------------------------------
28 MainWindow::MainWindow( QWidget
* parent
) :
33 QHBoxLayout
*hbox
= new QHBoxLayout( _frame
);
35 hbox
->setSpacing( 2 );
37 // Setup zoom and navigation toolbars
38 QToolBar
* zoomBar
= addToolBar( "Zooming" );
39 QSlider
* sldZoom
= new QSlider( Qt::Horizontal
, zoomBar
);
40 sldZoom
->setMinimum( 1 );
41 sldZoom
->setMaximum( 99 );
42 sldZoom
->setPageStep( 10 );
43 sldZoom
->setSliderPosition( 50 );
44 sldZoom
->setMinimumWidth( 190 );
45 zoomBar
->addWidget( sldZoom
);
47 QToolBar
* navigationBar
= addToolBar( "Navigation" );
48 navigationBar
->setIconSize( QSize( 16, 16 ) );
50 // Generate a simple graph
51 Graph
* graph
= new Graph( );
52 Node
& na
= *graph
->addNode( "Node A<br> <b>Multi line</b> and rich-<br> text <i>HTML</i> label test.", 2 );
53 Node
& nb
= *graph
->addNode( "Node B", 1 );
54 graph
->addEdge( na
, nb
);
56 Node
& nc
= *graph
->addNode( "Node C<br>With an <b>icon</b>!", 1 );
58 Node
& nd
= *graph
->addNode( "<b>Node D</b><br>With a too long description.", 1 );
62 _graphView
= new qan::GraphView( _frame
, QColor( 170, 171, 205 ) );
63 GridItem
* grid
= new GridCheckBoardItem( _graphView
, QColor( 255, 255, 255 ), QColor( 238, 230, 230 ) );
64 hbox
->addWidget( _graphView
);
66 // Configure node selection and tooltip popup rendering
67 // connect( _graphView->getTooltipController( ), SIGNAL( nodeTipped(qan::Node*, QPoint) ), SLOT( showNodeTooltip(qan::Node*, QPoint) ) );
68 // connect( _graphView->getSelectionController( ), SIGNAL( nodeSelected(qan::Node*, QPoint) ), SLOT( selectNode(qan::Node*, QPoint) ) );
71 // Add canvas pan and zoom action to the navigation tobar
72 _cbGridType
= new QComboBox( navigationBar
);
73 _cbGridType
->addItem( QIcon(), "<< Grid Type >>" );
74 _cbGridType
->addItem( QIcon(), "Regular" );
75 _cbGridType
->addItem( QIcon(), "Check Board" );
76 connect( _cbGridType
, SIGNAL(activated(int)), this, SLOT(gridChanged(int)));
77 navigationBar
->addWidget( _cbGridType
);
79 qan::GraphView
* GraphView
= _graphView
;/*->getGraphView( );*/
80 connect( sldZoom
, SIGNAL( valueChanged(int) ), GraphView
, SLOT( setZoomPercent(int) ) );
81 navigationBar
->setIconSize( QSize( 16, 16 ) );
83 if ( GraphView
->getAction( "zoom_in" ) != 0 )
84 navigationBar
->addAction( GraphView
->getAction( "zoom_in" ) );
85 if ( GraphView
->getAction( "zoom_out" ) != 0 )
86 navigationBar
->addAction( GraphView
->getAction( "zoom_out" ) );
87 navigationBar
->addSeparator( );
88 if ( GraphView
->getAction( "pan_controller" ) != 0 )
89 navigationBar
->addAction( GraphView
->getAction( "pan_controller" ) );
90 if ( GraphView
->getAction( "zoom_window_controller" ) != 0 )
91 navigationBar
->addAction( GraphView
->getAction( "zoom_window_controller" ) );
93 QTreeView
* treeView
= new QTreeView( _frame
);
94 treeView
->setAlternatingRowColors( true );
95 treeView
->setMaximumWidth( 100 );
96 treeView
->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOn
);
97 hbox
->addWidget( treeView
);
99 Style
* blueNode
= new Style( "bluenode" );
100 blueNode
->addImageName( "backimage", "images/gradblue.png" );
101 blueNode
->addColor( "bordercolor", 0, 0, 0 );
102 graph
->getM( ).applyStyle( &na
, blueNode
);
104 Style
* greenNode
= new Style( "greennode" );
105 greenNode
->addImageName( "backimage", "images/gradgreen.png" );
106 greenNode
->addColor( "bordercolor", 50, 100, 200 );
107 greenNode
->addT
< int >( "fontsize", 14 );
108 graph
->getM( ).applyStyle( &nb
, greenNode
);
110 Style
* iconNode
= new Style( "iconnode" );
111 iconNode
->addImageName( "backimage", "images/gradblue.png" );
112 iconNode
->addImageName( "icon", "images/icon.png" );
113 iconNode
->addColor( "bordercolor", 0, 255, 0 );
114 graph
->getM( ).applyStyle( &nc
, iconNode
);
116 Style
* orangeNode
= new Style( "orangenode" );
117 orangeNode
->addImageName( "backimage", "images/gradorange.png" );
118 orangeNode
->addColor( "bordercolor", 50, 100, 200 );
119 orangeNode
->addT
< int >( "maximumwidth", 125 );
120 orangeNode
->addT
< int >( "maximumheight", 25 );
121 graph
->getM( ).applyStyle( &nd
, orangeNode
);
123 _graphView
->setGraph( *graph
);
124 _graphView
->layoutGraph( );
125 graph
->updateModels( );
126 treeView
->setModel( &graph
->getO( ) );
129 void MainWindow::gridChanged( int index
)
134 void MainWindow::selectNode( qan::Node
* node
, QPoint p
)
138 QString
msg( "Node \"" );
139 msg
+= node
->getLabel( );
140 msg
+= "\" selected.";
141 QMessageBox::information( this, "Qanava Basic Test", msg
);
144 //-----------------------------------------------------------------------------