Adding svn:eol-style=LF property
[occt.git] / samples / qt / Graphic3dDemo / src / ViewDlg.cxx
1 // ViewDlg.cpp: implementation of the ViewDlg class.
2 //
3 //////////////////////////////////////////////////////////////////////
4
5 #include <qlayout.h>
6 #include <qpushbutton.h>
7 #include <qframe.h>
8 #include <qcheckbox.h>
9 #include <qlabel.h>
10 #include <qcombobox.h>
11
12 #include <V3d_TypeOfVisualization.hxx>
13
14 #include "Application.h"
15 #include "ViewDlg.h"
16 #include "global.h"
17
18 //////////////////////////////////////////////////////////////////////
19 // Construction/Destruction
20 //////////////////////////////////////////////////////////////////////
21
22 ViewDlg::ViewDlg( QWidget* parent/*, Handle(V3d_View)& view*/ )
23 :QDialog( parent ),
24   myAutoApply( true ), /*myView( view ),*/ myApplyAllViews(false)
25 {
26     setModal( false );
27     setWindowTitle( tr( "TITLE_VIEW_DLG" ) );
28
29     QVBoxLayout* topLayout = new QVBoxLayout( this );
30     topLayout->setMargin( 5 );
31
32     QFrame* mainFrame = new QFrame( this );
33     mainFrame->setFrameStyle( QFrame::Box | QFrame::Sunken );
34     topLayout->addWidget( mainFrame );
35     topLayout->addSpacing( 10 );
36
37     // view properties
38     QGridLayout* pLayout = new QGridLayout( mainFrame );
39     pLayout->setMargin( 5 );
40     myZBufferBox = new QCheckBox( mainFrame );;
41     myZBufferBox->setText( tr( "BTN_ZBUFFER" ) );
42     verify( connect( myZBufferBox, SIGNAL( toggled( bool ) ), SLOT( onZBuffer( bool ) ) ) );
43
44     myAnimBox = new QCheckBox( mainFrame );
45     myAnimBox->setText( tr( "BTN_ANIMATION" ) );
46     verify( connect( myAnimBox, SIGNAL( toggled( bool ) ), SLOT( onAnimation( bool ) ) ) );
47
48     myDegBox = new QCheckBox( mainFrame );
49     myDegBox->setText( tr( "BTN_DEGENERATION" ) );
50     verify( connect( myDegBox, SIGNAL( toggled( bool ) ), SLOT( onDegeneration( bool ) ) ) );
51
52     pLayout->addWidget( myZBufferBox, 0, 0 );
53     pLayout->addWidget( myAnimBox, 1, 0 );
54     pLayout->addWidget( myDegBox, 2, 0 );
55     pLayout->setRowStretch( 3, 10 );
56     pLayout->setColumnStretch( 1, 10 );
57
58     // apply controls
59     QCheckBox *autoApply, *applyAllViews;
60     autoApply = new QCheckBox( this );
61     autoApply->setText( tr( "BTN_AUTOAPPLY" ) );
62     autoApply->setChecked( true );
63     verify( connect( autoApply, SIGNAL( toggled( bool ) ), SLOT( onAutoApply( bool ) ) ) );
64     applyAllViews = new QCheckBox( this );
65     applyAllViews->setText( tr( "BTN_APPLYALLVIEWS" ) );
66     verify( connect( applyAllViews, SIGNAL( toggled( bool ) ), 
67                                     SLOT( onApplyAllViews( bool ) ) ) );
68
69     QHBoxLayout* applyLayout = new QHBoxLayout();
70     applyLayout->addWidget( autoApply );
71     applyLayout->addStretch( 10 );
72     applyLayout->addWidget( applyAllViews );
73     topLayout->addLayout( applyLayout );
74     topLayout->addSpacing( 10 );
75
76     // control buttons
77     QPushButton *bOk, *bCancel/*, *bHelp*/;
78         
79     bOk     = new QPushButton( tr( "BTN_OK" ), this );
80     verify( connect( bOk, SIGNAL( clicked() ), SLOT( onOk() ) ) );
81         bOk->setDefault(true); 
82     bCancel = new QPushButton( tr( "BTN_CANCEL" ), this );
83     verify( connect( bCancel, SIGNAL( clicked() ), SLOT( onCancel() ) ) );
84
85
86 //    bHelp   = new QPushButton( tr( "BTN_HELP" ), this );
87 //    verify( connect( bHelp, SIGNAL( clicked() ), SLOT( onHelp() ) ) );
88
89     QHBoxLayout* btnLayout = new QHBoxLayout();
90     btnLayout->setSpacing( 5 );
91     btnLayout->addStretch( 10 );
92     btnLayout->addWidget( bOk );
93     btnLayout->addWidget( bCancel );
94     btnLayout->addStretch( 10 );
95 //    btnLayout->addWidget( bHelp );
96     topLayout->addLayout( btnLayout );
97
98     QSize s = topLayout->totalMinimumSize();
99     s.setWidth( s.width() + topLayout->margin() + 10 );
100     s.setHeight( s.height() + topLayout->margin() + 10 );
101     setFixedSize( s );
102
103         Handle(V3d_View) aView = Application::getApplication()->getActiveMDI()->getView();
104         myIsAnim = aView->AnimationMode(myIsDeg);
105 }
106
107 ViewDlg::~ViewDlg()
108 {
109 }
110
111 void ViewDlg::showEvent ( QShowEvent* e )
112 {
113         Update();
114         QWidget::showEvent( e );
115 }   
116
117 void ViewDlg::onOk()
118 {
119     hide();
120         bool Auto = myAutoApply;
121
122         myAutoApply = true;
123         onZBuffer(myZBufferBox->isChecked());
124         onAnimation(myAnimBox->isChecked());
125         onDegeneration(myDegBox->isChecked());
126         myAutoApply = Auto;
127 }
128  
129 void ViewDlg::onCancel()
130 {
131     hide();
132 }
133
134 void ViewDlg::onHelp()
135 {
136 }
137
138 void ViewDlg::onZBuffer( bool on )
139 {
140         QWidgetList aWidgetList;
141         Handle(V3d_View) aView;
142         QWidget* aWidget;
143
144         if (!myApplyAllViews)
145                 aWidgetList.append(Application::getApplication()->getActiveMDI());
146         else
147                 aWidgetList = Application::getWorkspace()->windowList();
148
149         if ( myAutoApply ){
150                 foreach(aWidget, aWidgetList){
151       if ( !aWidget ) continue;
152                         MDIWindow* aMDIWindow = (MDIWindow*)aWidget;
153                         aView = aMDIWindow->getView();
154                         if ( on )
155                                 aView->SetVisualization( V3d_ZBUFFER );
156                         else
157                                 aView->SetVisualization( V3d_WIREFRAME );
158                 }
159         }
160 }
161
162 void ViewDlg::onAnimation( bool on )
163 {
164         QWidgetList aWidgetList;
165         Handle(V3d_View) aView;
166
167         myIsAnim = on;
168     myDegBox->setEnabled( myIsAnim );
169         if (!myIsAnim) myDegBox->setChecked(false);
170
171         if (!myApplyAllViews)
172                 aWidgetList.append(Application::getApplication()->getActiveMDI());
173         else
174                 aWidgetList = Application::getWorkspace()->windowList();
175         
176         if ( myAutoApply ){
177                 QWidget* aWidget;
178                 foreach(aWidget, aWidgetList){
179       if ( !aWidget ) continue;
180                         MDIWindow* aMDIWindow = (MDIWindow*)aWidget;
181                         aView = aMDIWindow->getView();
182                         aView->SetAnimationMode( myIsAnim, myIsDeg );
183                         aView->Redraw();
184                         aView->SetImmediateUpdate(true);
185                         aView->Update();
186                 }
187         }       
188 }
189
190 void ViewDlg::onDegeneration( bool on )
191 {
192         QWidgetList aWidgetList;
193         Handle(V3d_View) aView;
194         QWidget* aWidget;
195
196         if (!myApplyAllViews)
197                 aWidgetList.append(Application::getApplication()->getActiveMDI());
198         else
199                 aWidgetList = Application::getWorkspace()->windowList();
200
201
202     myIsDeg = on;
203     if ( myAutoApply ){
204                 foreach(aWidget, aWidgetList){
205       if ( !aWidget ) continue;
206                         MDIWindow* aMDIWindow = (MDIWindow*)aWidget;
207                         aView = aMDIWindow->getView();
208             aView->SetAnimationMode( myIsAnim, myIsDeg );
209                 }
210         }
211 }
212
213 void ViewDlg::onAutoApply( bool on )
214 {
215   myAutoApply = on;
216 }
217
218 void ViewDlg::onApplyAllViews( bool on )
219 {
220         myApplyAllViews = on;
221 }
222
223 void ViewDlg::Update()
224 {
225         MDIWindow* anActiveMDIWindow = Application::getApplication()->getActiveMDI();
226         if (anActiveMDIWindow){
227                 Handle(V3d_View) aView = anActiveMDIWindow->getView();
228                 if(!aView.IsNull()){
229                 
230                 myIsAnim = aView->AnimationMode( myIsDeg );
231                 myAnimBox->blockSignals( true );
232                 myDegBox->blockSignals( true );
233                 myAnimBox->setChecked( myIsAnim );
234                 myDegBox->setChecked( myIsDeg );
235                 myDegBox->setEnabled( myIsAnim );
236                 myAnimBox->blockSignals( false );
237                 myDegBox->blockSignals( false );
238
239                 myZBufferBox->blockSignals(true);
240                 V3d_TypeOfVisualization aVisuType = aView->Visualization();
241                 if(aVisuType == V3d_WIREFRAME)
242                         myZBufferBox -> setChecked(false);
243                 else
244                         myZBufferBox -> setChecked(true);
245                 myZBufferBox->blockSignals(false);
246                 }
247         }
248 }