5be0008f5c7fd5422b2b0fcb1ba4021063d54d4d
[occt.git] / samples / qt / Tutorial / src / ApplicationTut.cxx
1 #include "ApplicationTut.h"
2 #include "DocumentTut.h"
3
4 #include <OSD_Environment.hxx>
5
6 #include <QFileDialog>
7 #include <QStatusBar>
8 #include <QMdiSubWindow>
9
10 ApplicationTut::ApplicationTut()
11     : ApplicationCommonWindow( )
12 {
13   createMakeBottleOperation();
14 }
15
16 ApplicationTut::~ApplicationTut()
17 {
18 }
19
20 void ApplicationTut::createMakeBottleOperation(){
21         QPixmap MakeBottleIcon;
22         QString dir = getTutResourceDir() + QString( "/" );
23   MakeBottleIcon = QPixmap( dir+QObject::tr( "ICON_MAKE_BOTTLE" ) );
24         
25   QAction * MakeBottleAction = new QAction( MakeBottleIcon, QObject::tr("TBR_MAKEBOT"), this );
26   MakeBottleAction->setToolTip( QObject::tr( "TBR_MAKEBOT" ) );
27   MakeBottleAction->setStatusTip( QObject::tr("TBR_MAKEBOT") );
28   MakeBottleAction->setShortcut( QObject::tr( "CTRL+M" ) );
29         connect( MakeBottleAction, SIGNAL( triggered() ) , this, SLOT( onMakeBottleAction() ) );
30         
31         myMakeBottleBar = addToolBar( tr( "Make Bottle" ) );
32   insertToolBar( getCasCadeBar(), myMakeBottleBar );
33   myMakeBottleBar->addAction( MakeBottleAction );
34         myMakeBottleBar->hide();
35 }
36
37 void ApplicationTut::updateFileActions()
38 {
39   if ( getWorkspace()->subWindowList().isEmpty() )
40   {
41           if ( !isDocument() )
42                 {
43       myMakeBottleBar->show();
44     }
45     else
46     {
47       myMakeBottleBar->hide();
48     }
49   }
50   ApplicationCommonWindow::updateFileActions();
51 }
52
53 void ApplicationTut::onMakeBottleAction()
54 {
55         QMdiArea* ws = ApplicationCommonWindow::getWorkspace();
56   DocumentTut* doc = (DocumentTut*)( qobject_cast<MDIWindow*>( ws->activeSubWindow()->widget() )->getDocument() );
57         statusBar()->showMessage( QObject::tr("INF_MAKE_BOTTLE"), 5000 );
58         doc->onMakeBottle();
59         statusBar()->showMessage(QObject::tr("INF_DONE"));
60 }
61
62 QString ApplicationTut::getTutResourceDir()
63 {
64   static QString resDir (OSD_Environment ("CSF_TutorialResourcesDefaults").Value().ToCString());
65   if (resDir.isEmpty())
66     resDir = QString (OSD_Environment ("CSF_OCCTResourcePath").Value().ToCString()) + "/samples";
67   return resDir;
68 }