1 #include <cpExtensions/QT/PropertyWidget.h>
3 #ifdef cpExtensions_QT4
5 #include <QColorDialog>
9 #include <vtkProperty.h>
10 #include <vtkRenderWindow.h>
12 #include <cpExtensions/ui_PropertyWidget.h>
14 // -------------------------------------------------------------------------
15 cpExtensions::QT::PropertyWidget::
16 PropertyWidget( QWidget* parent )
18 m_UI( new Ui::PropertyWidget ),
22 this->m_UI->setupUi( this );
24 this->m_UI->m_Color, SIGNAL( clicked( ) ),
25 this, SLOT( _Color( ) )
28 this->m_UI->m_Opacity, SIGNAL( valueChanged( int ) ),
29 this, SLOT( _Opacity( int ) )
32 this->m_UI->m_LineWidth, SIGNAL( valueChanged( double ) ),
33 this, SLOT( _LineWidth( double ) )
36 this->m_UI->m_PointSize, SIGNAL( valueChanged( double ) ),
37 this, SLOT( _PointSize( double ) )
41 // -------------------------------------------------------------------------
42 cpExtensions::QT::PropertyWidget::
48 // -------------------------------------------------------------------------
49 vtkProp* cpExtensions::QT::PropertyWidget::
52 return( this->m_Prop );
55 // -------------------------------------------------------------------------
56 vtkRenderWindow* cpExtensions::QT::PropertyWidget::
59 return( this->m_Window );
62 // -------------------------------------------------------------------------
63 void cpExtensions::QT::PropertyWidget::
67 if( this->m_Prop == NULL )
70 auto actor = dynamic_cast< vtkActor* >( this->m_Prop );
74 double opacity = actor->GetProperty( )->GetOpacity( );
75 double lw = actor->GetProperty( )->GetLineWidth( );
76 double ps = actor->GetProperty( )->GetPointSize( );
77 opacity *= this->m_UI->m_Opacity->maximum( );
79 this->m_UI->m_Opacity->setValue( opacity );
80 this->m_UI->m_LineWidth->setValue( lw );
81 this->m_UI->m_PointSize->setValue( ps );
84 // -------------------------------------------------------------------------
85 void cpExtensions::QT::PropertyWidget::
86 SetRenderWindow( vtkRenderWindow* w )
91 // -------------------------------------------------------------------------
92 void cpExtensions::QT::PropertyWidget::
95 if( this->m_Prop == NULL )
98 auto actor = dynamic_cast< vtkActor* >( this->m_Prop );
103 actor->GetProperty( )->GetColor( rgb );
105 QColorDialog::getColor(
106 QColor( rgb[ 0 ] * 255, rgb[ 1 ] * 255, rgb[ 2 ] * 255 ),
109 QColorDialog::DontUseNativeDialog
111 if( color.isValid( ) )
113 rgb[ 0 ] = double( color.red( ) ) / double( 255 );
114 rgb[ 1 ] = double( color.green( ) ) / double( 255 );
115 rgb[ 2 ] = double( color.blue( ) ) / double( 255 );
116 actor->GetMapper( )->ScalarVisibilityOff( );
117 actor->GetProperty( )->SetColor( rgb );
119 if( this->m_Window != NULL )
120 this->m_Window->Render( );
125 // -------------------------------------------------------------------------
126 void cpExtensions::QT::PropertyWidget::
129 if( this->m_Prop == NULL )
132 auto actor = dynamic_cast< vtkActor* >( this->m_Prop );
135 double v = double( o ) / double( this->m_UI->m_Opacity->maximum( ) );
136 actor->GetProperty( )->SetOpacity( v );
138 if( this->m_Window != NULL )
139 this->m_Window->Render( );
142 // -------------------------------------------------------------------------
143 void cpExtensions::QT::PropertyWidget::
144 _LineWidth( double lw )
146 if( this->m_Prop == NULL )
149 auto actor = dynamic_cast< vtkActor* >( this->m_Prop );
152 actor->GetProperty( )->SetLineWidth( lw );
154 if( this->m_Window != NULL )
155 this->m_Window->Render( );
158 // -------------------------------------------------------------------------
159 void cpExtensions::QT::PropertyWidget::
160 _PointSize( double ps )
162 if( this->m_Prop == NULL )
165 auto actor = dynamic_cast< vtkActor* >( this->m_Prop );
168 actor->GetProperty( )->SetPointSize( ps );
170 if( this->m_Window != NULL )
171 this->m_Window->Render( );
174 #endif // cpExtensions_QT4