0.3.1
[qanava.git] / tests / styles / canMainWindow.cpp
blob58432ac827ebccf2fb4f42abd33528c0e3ead954
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 "./qanRepository.h"
12 #include "../../src/qanGraphView.h"
13 #include "../../src/qanGraphScene.h"
14 #include "../../src/qanGrid.h"
15 #include "../../src/ui/uiStyleView.h"
16 #include "canMainWindow.h"
19 // QT headers
20 #include <QToolBar>
21 #include <QAction>
22 #include <QMessageBox>
23 #include <QTableView>
24 #include <QHeaderView>
25 #include <QTimer>
28 using namespace qan;
31 //-----------------------------------------------------------------------------
32 MainWindow::MainWindow( QWidget* parent ) :
33 QMainWindow( parent )
35 setupUi( this );
37 QHBoxLayout *hbox = new QHBoxLayout( _frame );
38 hbox->setMargin( 0 );
39 hbox->setSpacing( 2 );
41 // Setup zoom and navigation toolbars
42 QToolBar* zoomBar = addToolBar( "Zooming" );
43 QSlider* sldZoom = new QSlider( Qt::Horizontal, zoomBar );
44 sldZoom->setMinimum( 1 );
45 sldZoom->setMaximum( 99 );
46 sldZoom->setPageStep( 10 );
47 sldZoom->setSliderPosition( 50 );
48 sldZoom->setMinimumWidth( 190 );
49 zoomBar->addWidget( sldZoom );
51 QToolBar* navigationBar = addToolBar( "Navigation" );
52 navigationBar->setIconSize( QSize( 16, 16 ) );
54 // Generate a simple graph
55 Graph* graph = new Graph( );
56 qan::Repository* gmlRepository = new qan::GMLRepository( "styles_data.xml" );
57 gmlRepository->load( graph );
58 graph->generateRootNodes( );
60 /* Graph* graph = new Graph( );
61 Node& na = *graph->addNode( "Node A<br> <b>Multi line</b> and rich-<br> text <i>HTML</i> label test.", 2 );
62 Node& nb = *graph->addNode( "Node B", 1 );
63 graph->addEdge( na, nb );
65 Node& nc = *graph->addNode( "Node C<br>With an <b>icon</b>!", 1 );
66 Node& nd = *graph->addNode( "<b>Node D</b><br>With a too long description.", 1 );*/
69 // Setup item views
70 _graphView = new qan::GraphView( _frame, QColor( 170, 171, 205 ) );
71 GridItem* grid = new GridCheckBoardItem( _graphView, QColor( 255, 255, 255 ), QColor( 238, 230, 230 ) );
72 hbox->addWidget( _graphView );
75 // Configure node selection and tooltip popup rendering
76 //connect( _graphView->getTooltipModifier( ), SIGNAL( nodeTipped(qan::Node*, QPoint) ), SLOT( showNodeTooltip(qan::Node*, QPoint) ) );
77 //connect( _graphView->getSelectionModifier( ), SIGNAL( nodeSelected(qan::Node*, QPoint) ), SLOT( selectNode(qan::Node*, QPoint) ) );
80 // Add canvas pan and zoom action to the navigation tobar
81 _cbGridType = new QComboBox( navigationBar );
82 _cbGridType->addItem( QIcon(), "<< Grid Type >>" );
83 _cbGridType->addItem( QIcon(), "Regular" );
84 _cbGridType->addItem( QIcon(), "Check Board" );
85 connect( _cbGridType, SIGNAL(activated(int)), this, SLOT(gridChanged(int)));
86 navigationBar->addWidget( _cbGridType );
88 connect( sldZoom, SIGNAL( valueChanged(int) ), _graphView, SLOT( setZoomPercent(int) ) );
89 navigationBar->setIconSize( QSize( 16, 16 ) );
90 if ( _graphView->getAction( "zoom_in" ) != 0 )
91 navigationBar->addAction( _graphView->getAction( "zoom_in" ) );
92 if ( _graphView->getAction( "zoom_out" ) != 0 )
93 navigationBar->addAction( _graphView->getAction( "zoom_out" ) );
94 navigationBar->addSeparator( );
95 if ( _graphView->getAction( "pan_controller" ) != 0 )
96 navigationBar->addAction( _graphView->getAction( "pan_controller" ) );
97 if ( _graphView->getAction( "zoom_window_controller" ) != 0 )
98 navigationBar->addAction( _graphView->getAction( "zoom_window_controller" ) );
101 /* Style* blueNode = new Style( "bluenode" );
102 blueNode->addImageName( "backimage", "images/gradblue.png" );
103 blueNode->addColor( "bordercolor", 0, 0, 0 );
104 graph->getM( ).applyStyle( &na, blueNode );
106 Style* greenNode = new Style( "greennode" );
107 greenNode->addImageName( "backimage", "images/gradgreen.png" );
108 greenNode->addColor( "bordercolor", 50, 100, 200 );
109 greenNode->addT< int >( "fontsize", 14 );
110 graph->getM( ).applyStyle( &nb, greenNode );
112 Style* iconNode = new Style( "iconnode" );
113 iconNode->addImageName( "backimage", "images/gradblue.png" );
114 iconNode->addImageName( "icon", "images/icon.png" );
115 iconNode->addColor( "bordercolor", 0, 255, 0 );
116 graph->getM( ).applyStyle( &nc, iconNode );
118 Style* orangeNode = new Style( "orangenode" );
119 orangeNode->addImageName( "backimage", "images/gradorange.png" );
120 orangeNode->addColor( "bordercolor", 50, 100, 200 );
121 orangeNode->addT< int >( "maximumwidth", 125 );
122 orangeNode->addT< int >( "maximumheight", 25 );
123 orangeNode->addT< bool >( "hasshadow", true );
124 orangeNode->addColor( "shadowcolor", 150, 150, 150 );
125 greenNode->addT< int >( "shadowoffset", 6 );
126 graph->getM( ).applyStyle( &nd, orangeNode );*/
128 //treeView->setModel( graphModel );
129 qan::Style* style = 0;
130 if ( graph->getNodes( ).size( ) > 0 )
132 qan::Node* node = graph->getNodes( ).at( 0 );
133 style = graph->getM( ).getStyleManager( ).getStyle( node );
136 if ( style != 0 )
138 qan::StyleEditor* styleEditor = new qan::StyleEditor( this, style );
139 styleEditor->setMaximumWidth( 200 );
140 hbox->addWidget( styleEditor );
143 //styleView->setModel( orangeNode );
144 /*show( );
145 resize( 400, 200 );
146 updateGeometry( );
147 _graphView->getGraphicsView( )->resize( 300, 300 );*/
149 _graphView->setGraph( *graph );
150 QTimer::singleShot( 0, this, SLOT( layoutGraph( ) ) );
153 void MainWindow::gridChanged( int index )
155 /* GridItem* grid = 0;
156 if ( index == 1 )
157 grid = new GridItemRegularItem( 0, QColor( 170, 171, 205 ) );
158 else if ( index == 2 )
159 grid = new GridCheckBoardItem( 0, QColor( 255, 255, 255 ), QColor( 238, 230, 230 ) );
160 if ( grid != 0 && _graphView != 0 && _graphView->getCanvas( ) != 0 )
161 _graphView->getCanvas( )->setGrid( grid );*/
164 void MainWindow::selectNode( qan::Node * node, QPoint p )
166 /* if ( node != 0 )
168 std::string msg( "Node \"" );
169 msg += node->getLabel( );
170 msg += "\" selected.";
171 QMessageBox::information( this, "Qanava Basic Test", msg.c_str( ) );
175 void MainWindow::showNodeTooltip( qan::Node* node, QPoint p )
177 /* NodeItemInfoPopup* popup = new NodeItemInfoPopup( this );
178 popup->popup( QString( node->getLabel( ).c_str( ) ), p );*/
181 void MainWindow::layoutGraph( )
183 _graphView->layoutGraph( );
185 //-----------------------------------------------------------------------------