2 // File : QAD_HelpWindow.cxx
3 // Created : Thu Jun 14 16:12:49 2001
4 // Author : Nicolas REJNERI
7 // Copyright : Open CASCADE
11 \class QAD_HelpWindow QAD_HelpWindow.h
12 \brief Html browser for help.
15 #include "QAD_HelpWindow.h"
16 #include "QAD_ResourceMgr.h"
17 #include "QAD_Desktop.h"
18 #include "QAD_Application.h"
19 #include "QAD_Tools.h"
22 #include <qapplication.h>
26 #include <qtoolbutton.h>
27 #include <qcombobox.h>
28 #include <qfileinfo.h>
33 QAD_HelpWindow::QAD_HelpWindow()
34 : QMainWindow( 0, "SALOME Professional Help", WStyle_Customize | WType_TopLevel | WDestructiveClose ),
35 pathCombo( 0 ), selectedURL()
37 QAD_ResourceMgr* rmgr = QAD_Desktop::getResourceManager();
39 // alternative palette
40 setPalette( QAD_Application::getPalette(true) );
42 setCaption( tr("SALOMEGUI_HELP_TITLE") );
44 QPixmap icon ( rmgr->loadPixmap( "CLIENT", tr("ICON_DESK_DEFAULTICON") ) );
45 if ( !icon.isNull() ) setIcon( icon );
48 browser = new QTextBrowser( this );
49 browser->setFrameStyle( QFrame::Panel | QFrame::Sunken );
50 connect( browser, SIGNAL( textChanged() ), this, SLOT( textChanged() ) );
51 setCentralWidget( browser );
53 // menu/toolbar actions
54 menuBar()->setItemEnabled( forwardId, FALSE);
55 menuBar()->setItemEnabled( backwardId, FALSE);
56 connect( browser, SIGNAL( backwardAvailable( bool ) ),
57 this, SLOT( setBackwardAvailable( bool ) ) );
58 connect( browser, SIGNAL( forwardAvailable( bool ) ),
59 this, SLOT( setForwardAvailable( bool ) ) );
61 QIconSet icon_back( QPixmap(rmgr->loadPixmap("QAD", tr("ICON_APP_HELP_BACK")) ));
62 QIconSet icon_forward( QPixmap(rmgr->loadPixmap("QAD", tr("ICON_APP_HELP_FORWARD")) ));
63 QIconSet icon_home( QPixmap(rmgr->loadPixmap("QAD", tr("ICON_APP_HELP_HOME")) ));
65 QToolBar* toolbar = new QToolBar( this );
66 addToolBar( toolbar, "Toolbar");
69 button = new QToolButton( icon_back, tr("TOT_HELPWINDOW_BACKWARD"), "", browser, SLOT(backward()), toolbar );
70 connect( browser, SIGNAL( backwardAvailable(bool) ), button, SLOT( setEnabled(bool) ) );
71 button->setEnabled( FALSE );
72 button = new QToolButton( icon_forward, tr("TOT_HELPWINDOW_FORWARD"), "", browser, SLOT(forward()), toolbar );
73 connect( browser, SIGNAL( forwardAvailable(bool) ), button, SLOT( setEnabled(bool) ) );
74 button->setEnabled( FALSE );
75 button = new QToolButton( icon_home, tr("TOT_HELPWINDOW_HOME"), "", browser, SLOT(home()), toolbar );
77 toolbar->addSeparator();
79 pathCombo = new QComboBox( TRUE, toolbar );
80 pathCombo->setInsertionPolicy(QComboBox::NoInsertion);
81 pathCombo->setDuplicatesEnabled(false);
82 connect( pathCombo, SIGNAL( activated( const QString & ) ),
83 this, SLOT( pathSelected( const QString & ) ) );
84 toolbar->setStretchableWidget( pathCombo );
85 setRightJustification( TRUE );
86 setDockEnabled( Left, FALSE );
87 setDockEnabled( Right, FALSE );
88 setDockEnabled( Bottom, FALSE );
89 setDockEnabled( TornOff, FALSE );
90 setDockMenuEnabled( false );
92 // look for index.html and set homeDir
93 // 1. $(SALOME_ROOT_DIR)/doc/index.html
94 // 2. $(SALOME_ROOT_DIR)/doc/html/index.html
95 // 3. $(SALOME_ROOT_DIR)/doc/html/html/index.html
96 // 4. /usr/local/doc/html/index.html
100 if ( (dir = getenv("SALOME_ROOT_DIR")) ) {
101 root = QAD_Tools::addSlash( QAD_Tools::addSlash(dir) + "doc" );
102 if ( QFileInfo( root + "index.html" ).exists() ) {
106 root = QAD_Tools::addSlash( root + "html" );
107 if ( QFileInfo( root + "index.html" ).exists() ) {
111 root = QAD_Tools::addSlash( root + "html" );
112 if ( QFileInfo( root + "index.html" ).exists() ) {
118 if ( root.isEmpty() ) {
119 if ( QFileInfo( "/usr/local/doc/html/index.html" ).exists() ) {
120 homeDir = "/usr/local/doc/html/";
123 if ( root.isEmpty() )
126 browser->setSource( QFileInfo( homeDir + "index.html" ).absFilePath() );
129 QSize dSize = QApplication::desktop()->size();
130 int x = ( dSize.width() - 750 ) / 2;
131 int y = ( dSize.height() - 680 ) / 2;
132 setGeometry( x, y, 750, 680 );
138 QAD_HelpWindow::~QAD_HelpWindow()
140 emit(helpWindowClosed());
144 enables/disables <Backward> button
146 void QAD_HelpWindow::setBackwardAvailable( bool b)
148 menuBar()->setItemEnabled( backwardId, b);
152 enables/disables <Forward> button
154 void QAD_HelpWindow::setForwardAvailable( bool b)
156 menuBar()->setItemEnabled( forwardId, b);
160 called when new document is loaded into browser
162 void QAD_HelpWindow::textChanged()
164 if ( browser->documentTitle().isNull() && browser->context().isNull() && browser->source().isNull() )
166 selectedURL = browser->source(); //caption();
167 if ( !selectedURL.isEmpty() && pathCombo ) {
170 for ( i = 0; i < pathCombo->count(); ++i ) {
171 if ( pathCombo->text( i ) == selectedURL ) {
177 pathCombo->insertItem( selectedURL, 0 );
178 pathCombo->setCurrentItem( 0 );
180 pathCombo->setCurrentItem( i );
182 selectedURL = QString::null;
187 called when users selectes dosument from the combo box
189 void QAD_HelpWindow::pathSelected( const QString& _path )
191 browser->setSource( _path );
195 goes back to the contents
197 void QAD_HelpWindow::contents()
203 opens new document in browser window and makes context search
204 <_source> is a filename, can be relative, if empty, index.html name is used
205 <_context> is a context, e.g. link in the file
207 void QAD_HelpWindow::context( const QString& _source, const QString& _context)
210 if ( _source.isEmpty() ) {
211 src = homeDir + "index.html";
214 QFileInfo fi( _source );
215 if ( fi.isRelative() )
216 src = homeDir + _source;
220 if ( !_context.isEmpty() )
221 src += "#" + _context;
222 browser->setSource( src );