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/qanGraphItemModel.h"
12 #include "../../src/qanGraphItemView.h"
13 #include "../../src/qanGrid.h"
14 #include "./canMainWindow.h"
24 //-----------------------------------------------------------------------------
25 MainWindow::MainWindow( QApplication
* application
, QWidget
* parent
) :
26 QMainWindow( parent
),
27 _application( application
)
31 QHBoxLayout
* hbox
= new QHBoxLayout( _frame
);
34 // Setup zoom and navigation toolbars
35 QToolBar
* zoomBar
= addToolBar( "Zooming" );
36 QSlider
* sldZoom
= new QSlider( Qt::Horizontal
, zoomBar
);
37 sldZoom
->setMinimum( 1 );
38 sldZoom
->setMaximum( 99 );
39 sldZoom
->setPageStep( 10 );
40 sldZoom
->setSliderPosition( 50 );
41 sldZoom
->setMinimumWidth( 190 );
42 zoomBar
->addWidget( sldZoom
);
44 QToolBar
* navigationBar
= addToolBar( "Navigation" );
45 navigationBar
->setIconSize( QSize( 16, 16 ) );
46 QAction
* layoutGraph
= navigationBar
->addAction( QIcon( ), "Layout" );
47 connect( layoutGraph
, SIGNAL( triggered( ) ), this, SLOT( layoutGraph( ) ) );
48 navigationBar
->addSeparator( );
50 QSplitter
* splitter
= new QSplitter( Qt::Horizontal
, this );
51 hbox
->addWidget( splitter
);
53 // Create a directory model ("culled" to a leaf directory for efficiency)
54 QDirModel
* dirModel
= new QDirModel( QStringList( ), QDir::AllDirs
| QDir::Files
, QDir::Name
, _frame
);
56 // Display the dir model in a standard qt tree view
57 QTreeView
* dirTreeView
= new QTreeView( _frame
);
58 dirTreeView
->setAlternatingRowColors( true );
59 dirTreeView
->setMaximumWidth( 200 );
60 dirTreeView
->setModel( dirModel
);
61 splitter
->addWidget( dirTreeView
);
63 // Create a grah item view and display the dir model
64 _dirItemView
= new qan::GraphItemView( _frame
, 0, QColor( 170, 171, 205 ), QSize( 300, 150 ), false );
65 qan::GridItem
* grid
= new qan::GridCheckBoardItem( _dirItemView
->getGraphicsView( ), palette( ).color( QPalette::Base
), palette( ).color( QPalette::AlternateBase
) );
66 _dirItemView
->setModel( dirModel
);
67 _dirItemView
->setGraphLayout( new qan::UndirectedGraph( ) );
68 _dirItemView
->layoutGraph( );
69 connect( _dirItemView
, SIGNAL( nodeDoubleClicked(qan::Node
*) ), this, SLOT( expandNode(qan::Node
*) ) );
70 splitter
->addWidget( _dirItemView
);
72 // Add canvas pan and zoom action to the navigation tobar
73 qan::GraphicsView
* graphicsView
= _dirItemView
->getGraphicsView( );
74 connect( sldZoom
, SIGNAL( valueChanged(int) ), graphicsView
, SLOT( setZoomPercent(int) ) );
75 navigationBar
->setIconSize( QSize( 16, 16 ) );
77 if ( graphicsView
->getAction( "zoom_in" ) != 0 )
78 navigationBar
->addAction( graphicsView
->getAction( "zoom_in" ) );
79 if ( graphicsView
->getAction( "zoom_out" ) != 0 )
80 navigationBar
->addAction( graphicsView
->getAction( "zoom_out" ) );
81 navigationBar
->addSeparator( );
82 if ( graphicsView
->getAction( "pan_controller" ) != 0 )
83 navigationBar
->addAction( graphicsView
->getAction( "pan_controller" ) );
84 if ( graphicsView
->getAction( "zoom_window_controller" ) != 0 )
85 navigationBar
->addAction( graphicsView
->getAction( "zoom_window_controller" ) );
88 void MainWindow::layoutGraph( )
90 _dirItemView
->layoutGraph( new QProgressDialog( "Laying out...", "Cancel", 1, 100, this ) );
93 void MainWindow::expandNode( qan::Node
* node
)
95 _dirItemView
->expand( node
);
98 //-----------------------------------------------------------------------------