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