00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "GraphPropertiesWidget.h"
00022 #include "model_GraphProperties.h"
00023 #include <KDebug>
00024 #include <QGraphicsItem>
00025 #include "graph.h"
00026 #include "graphDocument.h"
00027 #include "node.h"
00028 #include "edge.h"
00029 #include "MainWindow.h"
00030 #include "NodeItem.h"
00031 #include "OrientedEdgeItem.h"
00032 #include "GraphScene.h"
00033 #include <KLocale>
00034 #include <QRadioButton>
00035
00036
00037 GraphPropertiesWidget::GraphPropertiesWidget( Graph* g, QWidget* parent )
00038 : KButtonGroup( parent )
00039 {
00040 setupUi( this );
00041 _mainWindow = ( MainWindow* ) parent;
00043
00044 _graph = g;
00045 _graphName->setText( _graph->name() );
00046 _graphEdgeColor->setColor( _graph->edgeDefaultColor() );
00047 _graphNodeColor->setColor( _graph->nodeDefaultColor() );
00048 _graphAutomate->setChecked( _graph->automate() );
00049 _graphOriented->setChecked( _graph->directed() );
00050 _graphVisible->setChecked( ! _graph->readOnly() );
00051 _activateGraph->setChecked( true );
00052 _showEdgeNames->setChecked( _graph->edgeNameVisibility() );
00053 _showEdgeValues->setChecked( _graph->edgeValueVisibility() );
00054 _showNodeNames->setChecked( _graph->nodeNameVisibility() );
00055 _showNodeValues->setChecked( _graph->nodeValueVisibility() );
00056
00057 _editWidget->setVisible( _activateGraph->isChecked() );
00058
00059 GraphDocument* gDocument = qobject_cast<GraphDocument*>( g->parent() );
00060 connect( this, SIGNAL( addGraph( QString ) ), gDocument, SLOT( addGraph( QString ) ) );
00061 connect( this, SIGNAL( removeGraph() ), g, SLOT( remove() ) );
00062
00063 connect( _graphEdgeColor, SIGNAL( activated( QColor ) ), this, SLOT( setEdgeDefaultColor( QColor ) ) );
00064 connect( _graphNodeColor, SIGNAL( activated( QColor ) ), this, SLOT( setNodeDefaultColor( QColor ) ) );
00065
00066 connect( this, SIGNAL( edgeColorsChanged( QString ) ), g, SLOT( setEdgesColor( QString ) ) );
00067 connect( this, SIGNAL( nodeColorsChanged( QString ) ), g, SLOT( setNodesColor( QString ) ) );
00068 connect( this, SIGNAL( edgeDefaultColorSetted( QString ) ), g, SLOT( setEdgeDefaultColor( QString ) ) );
00069 connect( this, SIGNAL( nodeDefaultColorSetted( QString ) ), g, SLOT( setNodeDefaultColor( QString ) ) );
00070
00071
00072 connect( _showEdgeNames, SIGNAL( toggled( bool ) ), g, SLOT( setEdgeNameVisibility( bool ) ) );
00073 connect( _showEdgeValues, SIGNAL( toggled( bool ) ), g, SLOT( setEdgeValueVisibility( bool ) ) );
00074 connect( _showNodeNames, SIGNAL( toggled( bool ) ), g, SLOT( setNodeNameVisibility( bool ) ) );
00075 connect( _showNodeValues, SIGNAL( toggled( bool ) ), g, SLOT( setNodeValueVisibility( bool ) ) );
00076
00077 connect( _graphName, SIGNAL( textChanged( QString ) ), g, SLOT( setName( QString ) ) );
00078
00079 connect( _graphOriented, SIGNAL( toggled( bool ) ), g, SLOT( setDirected( bool ) ) );
00080 connect( _graphAutomate, SIGNAL( toggled( bool ) ), g, SLOT( setAutomate( bool ) ) );
00081
00082 }
00083
00084 void GraphPropertiesWidget::setEdgeDefaultColor( QColor c )
00085 {
00086 emit edgeDefaultColorSetted( c.name() );
00087 }
00088 void GraphPropertiesWidget::setNodeDefaultColor( QColor c )
00089 {
00090 emit nodeDefaultColorSetted( c.name() );
00091 }
00092 void GraphPropertiesWidget::on__graphEdgeColorApplyNow_clicked()
00093 {
00094 emit edgeColorsChanged( _graphEdgeColor->color().name() );
00095 }
00096 void GraphPropertiesWidget::on__graphNodeColorApplyNow_clicked()
00097 {
00098 emit nodeColorsChanged( _graphNodeColor->color().name() );
00099 }
00100
00101 void GraphPropertiesWidget::on__graphVisible_toggled( bool b )
00102 {
00103 _graph->readOnly( !b );
00104 _mainWindow->scene()->hideGraph( _graph, b );
00105 }
00106
00107 QRadioButton* GraphPropertiesWidget::radio()const
00108 {
00109 return _activateGraph;
00110 }
00111
00112 void GraphPropertiesWidget::on__activateGraph_toggled( bool b )
00113 {
00114 _editWidget->setVisible( b );
00115 if( b )
00116 {
00117 _mainWindow->setActiveGraph( _graph );
00118 }
00119 }
00120
00121 void GraphPropertiesWidget::on__graphDelete_clicked()
00122 {
00123 bool createNewGraph = false;
00124 bool isActive = false;
00125
00126 if( _graph == _mainWindow->graph() )
00127 {
00128 isActive = true;
00129 }
00130
00131 GraphDocument* gd = qobject_cast<GraphDocument*>( _graph->parent() );
00132
00133 if( gd->size() == 1 )
00134 {
00135 createNewGraph = true;
00136 }
00137
00138
00139 if( isActive ) emit updateNeeded();
00140 radio()->group()->removeButton( radio() );
00141
00142
00144 emit removeGraph();
00145
00146 if( createNewGraph )
00147 {
00148 emit addGraph( i18n( "Untitled0" ) );
00149 }
00150
00151 deleteLater();
00152 }
00153
00154 void GraphPropertiesWidget::on__graphName_textChanged( const QString& s )
00155 {
00156 _activateGraph->setText( s );
00157 }
00158