7fd59977 |
1 | #include "MDIWindow.h" |
2 | |
3 | #include "View.h" |
4 | #include "DocumentCommon.h" |
5 | #include "ApplicationCommon.h" |
6 | |
7 | #include <QFrame> |
8 | #include <QToolBar> |
9 | #include <QFileDialog> |
10 | #include <QMessageBox> |
11 | #include <QApplication> |
12 | #include <QDir> |
13 | #include <QFile> |
14 | #include <QFileInfo> |
15 | #include <QMainWindow> |
16 | #include <QVBoxLayout> |
17 | |
18 | MDIWindow::MDIWindow(View* aView, |
19 | DocumentCommon* aDocument, |
20 | QWidget* parent, |
21 | Qt::WindowFlags wflags ) |
22 | : QMainWindow( parent, wflags ) |
23 | { |
24 | |
25 | myView = aView; |
26 | myDocument = aDocument; |
e276548b |
27 | |
28 | #ifdef HAVE_OPENCL |
29 | |
30 | myShadowsEnabled = true; |
31 | myReflectionsEnabled = true; |
32 | myAntialiasingEnabled = false; |
33 | |
34 | #endif |
7fd59977 |
35 | } |
36 | |
e276548b |
37 | MDIWindow::MDIWindow( DocumentCommon* aDocument, QWidget* parent, Qt::WindowFlags wflags, bool theRT ) |
7fd59977 |
38 | : QMainWindow( parent, wflags ) |
39 | { |
40 | QFrame *vb = new QFrame( this ); |
41 | |
42 | QVBoxLayout *layout = new QVBoxLayout( vb ); |
43 | layout->setMargin( 0 ); |
44 | |
45 | vb->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken ); |
46 | |
47 | setCentralWidget( vb ); |
48 | |
49 | myDocument = aDocument; |
e276548b |
50 | myView = new View( myDocument->getContext(), vb, theRT ); |
7fd59977 |
51 | layout->addWidget( myView ); |
52 | |
53 | connect( myView, SIGNAL( selectionChanged() ), |
54 | this, SIGNAL( selectionChanged() ) ); |
55 | createViewActions(); |
56 | |
57 | resize( sizeHint() ); |
58 | |
59 | setFocusPolicy( Qt::StrongFocus ); |
e276548b |
60 | |
61 | #ifdef HAVE_OPENCL |
62 | |
63 | myShadowsEnabled = true; |
64 | myReflectionsEnabled = true; |
65 | myAntialiasingEnabled = false; |
66 | |
67 | #endif |
7fd59977 |
68 | } |
69 | |
70 | MDIWindow::~MDIWindow() |
71 | { |
72 | } |
73 | |
74 | DocumentCommon* MDIWindow::getDocument() |
75 | { |
76 | return myDocument; |
77 | } |
78 | |
de75ed09 |
79 | void MDIWindow::closeEvent(QCloseEvent* ) |
7fd59977 |
80 | { |
81 | emit sendCloseView(this); |
82 | } |
83 | |
84 | void MDIWindow::fitAll() |
85 | { |
86 | myView->fitAll(); |
87 | } |
88 | |
89 | void MDIWindow::createViewActions() |
90 | { |
91 | // populate a tool bar with some actions |
92 | QToolBar* aToolBar = addToolBar( tr( "View Operations" ) ); |
93 | |
94 | QList<QAction*>* aList = myView->getViewActions(); |
95 | aToolBar->addActions( *aList ); |
96 | |
97 | aToolBar->toggleViewAction()->setVisible(false); |
98 | aList->at(View::ViewHlrOffId)->setChecked( true ); |
99 | } |
100 | |
101 | void MDIWindow::onWindowActivated () |
102 | { |
103 | getDocument()->getApplication()->onSelectionChanged(); |
104 | } |
105 | |
106 | |
107 | void MDIWindow::dump() |
108 | { |
109 | |
110 | QString datadir = (QString(getenv("CASROOT")) + "/../data/images"); |
111 | static QString filter; |
1d8ec4db |
112 | filter = "Images Files (*.bmp *.ppm *.png *.jpg *.tiff *.tga *.gif *.exr *.ps *.eps *.tex *.pdf *.svg *.pgf)"; |
7fd59977 |
113 | QFileDialog fd ( 0 ); |
114 | fd.setModal( true ); |
115 | fd.setFilter( filter ); |
116 | fd.setWindowTitle( QObject::tr("INF_APP_EXPORT") ); |
117 | fd.setFileMode( QFileDialog::AnyFile ); |
118 | int ret = fd.exec(); |
119 | |
120 | /* update the desktop after the dialog is closed */ |
121 | qApp->processEvents(); |
122 | |
123 | QStringList fileNames; |
124 | fileNames = fd.selectedFiles(); |
125 | |
126 | QString file ( (ret == QDialog::Accepted && !fileNames.isEmpty() )? fileNames[0] : QString::null); |
127 | if ( !file.isNull() ) |
128 | { |
129 | QApplication::setOverrideCursor( Qt::WaitCursor ); |
130 | if ( !QFileInfo( file ).completeSuffix().length() ) |
131 | file += QString( ".bmp" ); |
132 | bool res = myView->dump( (Standard_CString)file.toLatin1().constData() ); |
133 | QApplication::restoreOverrideCursor(); |
134 | if ( !res ) |
135 | { |
136 | QWidgetList list = qApp->allWidgets(); |
137 | QWidget* mainWidget; |
138 | for( int i = 0; i < list.size(); ++i ) |
139 | { |
140 | if( qobject_cast<ApplicationCommonWindow*>( list.at( i ) ) ) |
141 | mainWidget = qobject_cast<ApplicationCommonWindow*>( list.at( i ) ); |
142 | } |
143 | |
144 | QMessageBox::information ( mainWidget, QObject::tr("TIT_ERROR"), QObject::tr("INF_ERROR"), QObject::tr("BTN_OK"), |
145 | QString::null, QString::null, 0, 0 ); |
146 | qApp->processEvents(); |
147 | } |
148 | } |
149 | } |
150 | |
151 | QSize MDIWindow::sizeHint() const |
152 | { |
153 | return QSize( 450, 300 ); |
154 | } |
155 | |
e276548b |
156 | #ifdef HAVE_OPENCL |
157 | |
158 | void MDIWindow::setRaytracedShadows( int state ) |
159 | { |
160 | myView->setRaytracedShadows( state ); |
161 | myShadowsEnabled = state; |
162 | } |
163 | |
164 | void MDIWindow::setRaytracedReflections( int state ) |
165 | { |
166 | myView->setRaytracedReflections( state ); |
167 | myReflectionsEnabled = state; |
168 | } |
169 | |
170 | void MDIWindow::setRaytracedAntialiasing( int state ) |
171 | { |
172 | myView->setRaytracedAntialiasing( state ); |
173 | myAntialiasingEnabled = state; |
174 | } |
175 | |
176 | #endif |
177 | |
7fd59977 |
178 | |