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 | { |
7fd59977 |
24 | myView = aView; |
2ad228f6 |
25 | myDocument = aDocument; |
26 | } |
27 | |
861a7b03 |
28 | MDIWindow::MDIWindow( DocumentCommon* aDocument, QWidget* parent, Qt::WindowFlags wflags) |
7fd59977 |
29 | : QMainWindow( parent, wflags ) |
30 | { |
2ad228f6 |
31 | QFrame *vb = new QFrame( this ); |
7fd59977 |
32 | |
2ad228f6 |
33 | QVBoxLayout *layout = new QVBoxLayout( vb ); |
34 | layout->setMargin( 0 ); |
7fd59977 |
35 | |
36 | vb->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken ); |
37 | |
2ad228f6 |
38 | setCentralWidget( vb ); |
7fd59977 |
39 | |
2ad228f6 |
40 | myDocument = aDocument; |
41 | myView = new View (myDocument->getContext(), vb); |
42 | layout->addWidget (myView); |
7fd59977 |
43 | |
44 | connect( myView, SIGNAL( selectionChanged() ), |
45 | this, SIGNAL( selectionChanged() ) ); |
2ad228f6 |
46 | |
861a7b03 |
47 | createViewActions(); |
48 | createRaytraceActions(); |
7fd59977 |
49 | |
50 | resize( sizeHint() ); |
51 | |
52 | setFocusPolicy( Qt::StrongFocus ); |
53 | } |
54 | |
55 | MDIWindow::~MDIWindow() |
56 | { |
57 | } |
58 | |
59 | DocumentCommon* MDIWindow::getDocument() |
60 | { |
2ad228f6 |
61 | return myDocument; |
7fd59977 |
62 | } |
63 | |
de75ed09 |
64 | void MDIWindow::closeEvent(QCloseEvent* ) |
7fd59977 |
65 | { |
2ad228f6 |
66 | emit sendCloseView(this); |
7fd59977 |
67 | } |
68 | |
69 | void MDIWindow::fitAll() |
70 | { |
2ad228f6 |
71 | myView->fitAll(); |
7fd59977 |
72 | } |
73 | |
74 | void MDIWindow::createViewActions() |
75 | { |
76 | // populate a tool bar with some actions |
2ad228f6 |
77 | QToolBar* aToolBar = addToolBar( tr( "View Operations" ) ); |
78 | |
7fd59977 |
79 | QList<QAction*>* aList = myView->getViewActions(); |
2ad228f6 |
80 | aToolBar->addActions( *aList ); |
7fd59977 |
81 | |
82 | aToolBar->toggleViewAction()->setVisible(false); |
83 | aList->at(View::ViewHlrOffId)->setChecked( true ); |
84 | } |
85 | |
861a7b03 |
86 | void MDIWindow::createRaytraceActions() |
87 | { |
88 | // populate a tool bar with some actions |
2ad228f6 |
89 | QToolBar* aToolBar = addToolBar( tr( "Ray-tracing Options" ) ); |
90 | |
861a7b03 |
91 | QList<QAction*>* aList = myView->getRaytraceActions(); |
2ad228f6 |
92 | aToolBar->addActions( *aList ); |
861a7b03 |
93 | |
94 | aToolBar->toggleViewAction()->setVisible (true); |
95 | aList->at (View::ToolRaytracingId)->setChecked (false); |
96 | aList->at (View::ToolShadowsId)->setChecked (true); |
2ad228f6 |
97 | aList->at (View::ToolReflectionsId)->setChecked (false); |
861a7b03 |
98 | aList->at (View::ToolAntialiasingId)->setChecked (false); |
99 | } |
100 | |
7fd59977 |
101 | void MDIWindow::onWindowActivated () |
102 | { |
103 | getDocument()->getApplication()->onSelectionChanged(); |
104 | } |
105 | |
7fd59977 |
106 | void MDIWindow::dump() |
107 | { |
4b3541c6 |
108 | QString datadir = (QString(qgetenv ("CSF_OCCTDataPath").constData()) + "/images"); |
2ad228f6 |
109 | static QString filter; |
1d8ec4db |
110 | filter = "Images Files (*.bmp *.ppm *.png *.jpg *.tiff *.tga *.gif *.exr *.ps *.eps *.tex *.pdf *.svg *.pgf)"; |
2ad228f6 |
111 | QFileDialog fd ( 0 ); |
112 | fd.setModal( true ); |
113 | fd.setNameFilter ( filter ); |
114 | fd.setWindowTitle( QObject::tr("INF_APP_EXPORT") ); |
115 | fd.setFileMode( QFileDialog::AnyFile ); |
116 | int ret = fd.exec(); |
7fd59977 |
117 | |
2ad228f6 |
118 | /* update the desktop after the dialog is closed */ |
119 | qApp->processEvents(); |
7fd59977 |
120 | |
2ad228f6 |
121 | QStringList fileNames; |
122 | fileNames = fd.selectedFiles(); |
7fd59977 |
123 | |
2ad228f6 |
124 | QString file ( (ret == QDialog::Accepted && !fileNames.isEmpty() )? fileNames[0] : QString::null); |
7fd59977 |
125 | if ( !file.isNull() ) |
126 | { |
2ad228f6 |
127 | QApplication::setOverrideCursor( Qt::WaitCursor ); |
128 | if ( !QFileInfo( file ).completeSuffix().length() ) |
7fd59977 |
129 | file += QString( ".bmp" ); |
861a7b03 |
130 | |
7fd59977 |
131 | bool res = myView->dump( (Standard_CString)file.toLatin1().constData() ); |
132 | QApplication::restoreOverrideCursor(); |
133 | if ( !res ) |
134 | { |
2ad228f6 |
135 | QWidgetList list = qApp->allWidgets(); |
136 | QWidget* mainWidget; |
7fd59977 |
137 | for( int i = 0; i < list.size(); ++i ) |
2ad228f6 |
138 | { |
139 | if( qobject_cast<ApplicationCommonWindow*>( list.at( i ) ) ) |
7fd59977 |
140 | mainWidget = qobject_cast<ApplicationCommonWindow*>( list.at( i ) ); |
2ad228f6 |
141 | } |
7fd59977 |
142 | |
2ad228f6 |
143 | QMessageBox::information ( mainWidget, QObject::tr("TIT_ERROR"), QObject::tr("INF_ERROR"), QObject::tr("BTN_OK"), |
144 | QString::null, QString::null, 0, 0 ); |
145 | qApp->processEvents(); |
7fd59977 |
146 | } |
2ad228f6 |
147 | } |
7fd59977 |
148 | } |
149 | |
150 | QSize MDIWindow::sizeHint() const |
151 | { |
2ad228f6 |
152 | return QSize( 450, 300 ); |
7fd59977 |
153 | } |