]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/ActorAxesProperties.cxx
9de508191cbdef36843f776fb9961edaf8547bcd
[cpPlugins.git] / lib / cpPlugins / ActorAxesProperties.cxx
1 #include <cpPlugins/ActorAxesProperties.h>
2
3 #ifdef cpPlugins_QT4
4
5 #include <cpPlugins/ui_ActorAxesProperties.h>
6
7 #include <QColorDialog>
8 #include <vtkAxesActor.h>
9 #include <vtkCaptionActor2D.h>
10 #include <vtkProperty2D.h>
11
12 // -------------------------------------------------------------------------
13 cpPlugins::ActorAxesProperties::
14 ActorAxesProperties( QWidget* parent )
15   : cpPlugins::ActorProperties( parent ),
16     m_UI( new Ui::ActorAxesProperties )
17 {
18   this->m_UI->setupUi( this );
19 }
20
21 // -------------------------------------------------------------------------
22 cpPlugins::ActorAxesProperties::
23 ~ActorAxesProperties( )
24 {
25   delete this->m_UI;
26 }
27
28 // -------------------------------------------------------------------------
29 bool cpPlugins::ActorAxesProperties::
30 addActor( vtkProp* obj )
31 {
32   auto actor = dynamic_cast< vtkAxesActor* >( obj );
33   if( actor != NULL )
34   {
35     this->m_Actors.insert( obj );
36     if( this->m_Actors.size( ) == 1 )
37       this->_updateWidgets( );
38     return( true );
39   }
40   else
41     return( false );
42 }
43
44 // -------------------------------------------------------------------------
45 void cpPlugins::ActorAxesProperties::
46 _updateWidgets( )
47 {
48   auto actor =
49     dynamic_cast< vtkAxesActor* >( this->m_Actors.begin( )->GetPointer( ) );
50   if( actor == NULL )
51     return;
52
53   // Get properties
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( );
59   double rgb[ 3 ];
60   prop->GetColor( rgb );
61   rgb[ 0 ] *= double( 255 );
62   rgb[ 1 ] *= double( 255 );
63   rgb[ 2 ] *= double( 255 );
64
65   // Set widget values
66   auto palette = this->m_UI->TextColor->palette( );
67   palette.setColor(
68     QPalette::Button, QColor( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ] )
69     );
70   this->m_UI->TextColor->setAutoFillBackground( true );
71   this->m_UI->TextColor->setPalette( palette );
72
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 );
77
78   // Connect stuff
79   this->connect(
80     this->m_UI->Scale, SIGNAL( valueChanged( double ) ),
81     this, SLOT( _Scale( double ) )
82     );
83   this->connect(
84     this->m_UI->XText, SIGNAL( textChanged( const QString& ) ),
85     this, SLOT( _TextChanged( const QString& ) )
86     );
87   this->connect(
88     this->m_UI->YText, SIGNAL( textChanged( const QString& ) ),
89     this, SLOT( _TextChanged( const QString& ) )
90     );
91   this->connect(
92     this->m_UI->ZText, SIGNAL( textChanged( const QString& ) ),
93     this, SLOT( _TextChanged( const QString& ) )
94     );
95   this->connect(
96     this->m_UI->TextColor, SIGNAL( clicked( ) ),
97     this, SLOT( _TextColor( ) )
98     );
99 }
100
101 // -------------------------------------------------------------------------
102 void cpPlugins::ActorAxesProperties::
103 _Scale( double v )
104 {
105   auto aIt = this->m_Actors.begin( );
106   for( ; aIt != this->m_Actors.end( ); ++aIt )
107   {
108     auto ma = dynamic_cast< vtkAxesActor* >( aIt->GetPointer( ) );
109     ma->SetScale( v );
110     ma->Modified( );
111
112   } // rof
113   this->_render( );
114 }
115
116 // -------------------------------------------------------------------------
117 void cpPlugins::ActorAxesProperties::
118 _TextChanged( const QString& text )
119 {
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 )
124   {
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( ) );
132     ma->Modified( );
133
134   } // rof
135   this->_render( );
136 }
137
138 // -------------------------------------------------------------------------
139 void cpPlugins::ActorAxesProperties::
140 _TextColor( )
141 {
142   if( this->m_Actors.size( ) == 0 )
143     return;
144   QPalette pal = this->m_UI->TextColor->palette( );
145   QColor color =
146     QColorDialog::getColor(
147       pal.color( QPalette::Button ),
148       this,
149       "Select Color",
150       QColorDialog::DontUseNativeDialog
151       );
152   if( color.isValid( ) )
153   {
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( );
158
159     double rgb[ 3 ];
160     rgb[ 0 ] = double( color.red( ) ) / double( 255 );
161     rgb[ 1 ] = double( color.green( ) ) / double( 255 );
162     rgb[ 2 ] = double( color.blue( ) ) / double( 255 );
163
164     auto aIt = this->m_Actors.begin( );
165     for( ; aIt != this->m_Actors.end( ); ++aIt )
166     {
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 );
171       ma->Modified( );
172
173     } // rof
174     this->_render( );
175
176   } // fi
177 }
178
179 #endif // cpPlugins_QT4
180
181 // eof - $RCSfile$