1 #include <cpPlugins/ActorAxesProperties.h>
5 #include <cpPlugins/ui_ActorAxesProperties.h>
7 #include <QColorDialog>
8 #include <vtkAxesActor.h>
9 #include <vtkCaptionActor2D.h>
10 #include <vtkProperty2D.h>
12 // -------------------------------------------------------------------------
13 cpPlugins::ActorAxesProperties::
14 ActorAxesProperties( QWidget* parent )
15 : cpPlugins::ActorProperties( parent ),
16 m_UI( new Ui::ActorAxesProperties )
18 this->m_UI->setupUi( this );
21 // -------------------------------------------------------------------------
22 cpPlugins::ActorAxesProperties::
23 ~ActorAxesProperties( )
28 // -------------------------------------------------------------------------
29 bool cpPlugins::ActorAxesProperties::
30 addActor( vtkProp* obj )
32 auto actor = dynamic_cast< vtkAxesActor* >( obj );
35 this->m_Actors.insert( obj );
36 if( this->m_Actors.size( ) == 1 )
37 this->_updateWidgets( );
44 // -------------------------------------------------------------------------
45 void cpPlugins::ActorAxesProperties::
49 dynamic_cast< vtkAxesActor* >( this->m_Actors.begin( )->GetPointer( ) );
54 std::string xtext( actor->GetXAxisLabelText( ) );
55 std::string ytext( actor->GetYAxisLabelText( ) );
56 std::string ztext( actor->GetZAxisLabelText( ) );
57 double scale = actor->GetScale( )[ 0 ];
58 auto prop = actor->GetXAxisCaptionActor2D( )->GetProperty( );
60 prop->GetColor( rgb );
61 rgb[ 0 ] *= double( 255 );
62 rgb[ 1 ] *= double( 255 );
63 rgb[ 2 ] *= double( 255 );
66 auto palette = this->m_UI->TextColor->palette( );
68 QPalette::Button, QColor( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ] )
70 this->m_UI->TextColor->setAutoFillBackground( true );
71 this->m_UI->TextColor->setPalette( palette );
73 this->m_UI->XText->setText( xtext.c_str( ) );
74 this->m_UI->YText->setText( ytext.c_str( ) );
75 this->m_UI->ZText->setText( ztext.c_str( ) );
76 this->m_UI->Scale->setValue( scale );
80 this->m_UI->Scale, SIGNAL( valueChanged( double ) ),
81 this, SLOT( _Scale( double ) )
84 this->m_UI->XText, SIGNAL( textChanged( const QString& ) ),
85 this, SLOT( _TextChanged( const QString& ) )
88 this->m_UI->YText, SIGNAL( textChanged( const QString& ) ),
89 this, SLOT( _TextChanged( const QString& ) )
92 this->m_UI->ZText, SIGNAL( textChanged( const QString& ) ),
93 this, SLOT( _TextChanged( const QString& ) )
96 this->m_UI->TextColor, SIGNAL( clicked( ) ),
97 this, SLOT( _TextColor( ) )
101 // -------------------------------------------------------------------------
102 void cpPlugins::ActorAxesProperties::
105 auto aIt = this->m_Actors.begin( );
106 for( ; aIt != this->m_Actors.end( ); ++aIt )
108 auto ma = dynamic_cast< vtkAxesActor* >( aIt->GetPointer( ) );
116 // -------------------------------------------------------------------------
117 void cpPlugins::ActorAxesProperties::
118 _TextChanged( const QString& text )
120 auto obj = this->sender( );
121 auto aIt = this->m_Actors.begin( );
122 auto str = text.toStdString( );
123 for( ; aIt != this->m_Actors.end( ); ++aIt )
125 auto ma = dynamic_cast< vtkAxesActor* >( aIt->GetPointer( ) );
126 if( obj == this->m_UI->XText )
127 ma->SetXAxisLabelText( str.c_str( ) );
128 else if( obj == this->m_UI->YText )
129 ma->SetYAxisLabelText( str.c_str( ) );
130 else if( obj == this->m_UI->ZText )
131 ma->SetZAxisLabelText( str.c_str( ) );
138 // -------------------------------------------------------------------------
139 void cpPlugins::ActorAxesProperties::
142 if( this->m_Actors.size( ) == 0 )
144 QPalette pal = this->m_UI->TextColor->palette( );
146 QColorDialog::getColor(
147 pal.color( QPalette::Button ),
150 QColorDialog::DontUseNativeDialog
152 if( color.isValid( ) )
154 pal.setColor( QPalette::Button, color );
155 this->m_UI->TextColor->setAutoFillBackground( true );
156 this->m_UI->TextColor->setPalette( pal );
157 this->m_UI->TextColor->update( );
160 rgb[ 0 ] = double( color.red( ) ) / double( 255 );
161 rgb[ 1 ] = double( color.green( ) ) / double( 255 );
162 rgb[ 2 ] = double( color.blue( ) ) / double( 255 );
164 auto aIt = this->m_Actors.begin( );
165 for( ; aIt != this->m_Actors.end( ); ++aIt )
167 auto ma = dynamic_cast< vtkAxesActor* >( aIt->GetPointer( ) );
168 ma->GetXAxisCaptionActor2D( )->GetProperty( )->SetColor( rgb );
169 ma->GetYAxisCaptionActor2D( )->GetProperty( )->SetColor( rgb );
170 ma->GetZAxisCaptionActor2D( )->GetProperty( )->SetColor( rgb );
179 #endif // cpPlugins_QT4