1 // SALOME SALOMEGUI : implementation of desktop and GUI kernel
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : QAD_HelpWindow.cxx
25 // Author : Nicolas REJNERI
31 \class QAD_HelpWindow QAD_HelpWindow.h
32 \brief Html browser for help.
35 #include "QAD_HelpWindow.h"
36 #include "QAD_ResourceMgr.h"
37 #include "QAD_Desktop.h"
38 #include "QAD_Application.h"
39 #include "QAD_Tools.h"
42 #include <qapplication.h>
46 #include <qtoolbutton.h>
47 #include <qcombobox.h>
48 #include <qfileinfo.h>
53 QAD_HelpWindow::QAD_HelpWindow()
54 : QMainWindow( 0, "SALOME Professional Help", WStyle_Customize | WType_TopLevel | WDestructiveClose ),
55 pathCombo( 0 ), selectedURL()
57 QAD_ResourceMgr* rmgr = QAD_Desktop::getResourceManager();
59 // alternative palette
60 setPalette( QAD_Application::getPalette(true) );
62 setCaption( tr("SALOMEGUI_HELP_TITLE") );
64 QPixmap icon ( rmgr->loadPixmap( "CLIENT", tr("ICON_DESK_DEFAULTICON") ) );
65 if ( !icon.isNull() ) setIcon( icon );
68 browser = new QTextBrowser( this );
69 browser->setFrameStyle( QFrame::Panel | QFrame::Sunken );
70 connect( browser, SIGNAL( textChanged() ), this, SLOT( textChanged() ) );
71 setCentralWidget( browser );
73 // menu/toolbar actions
74 menuBar()->setItemEnabled( forwardId, FALSE);
75 menuBar()->setItemEnabled( backwardId, FALSE);
76 connect( browser, SIGNAL( backwardAvailable( bool ) ),
77 this, SLOT( setBackwardAvailable( bool ) ) );
78 connect( browser, SIGNAL( forwardAvailable( bool ) ),
79 this, SLOT( setForwardAvailable( bool ) ) );
81 QIconSet icon_back( QPixmap(rmgr->loadPixmap("QAD", tr("ICON_APP_HELP_BACK")) ));
82 QIconSet icon_forward( QPixmap(rmgr->loadPixmap("QAD", tr("ICON_APP_HELP_FORWARD")) ));
83 QIconSet icon_home( QPixmap(rmgr->loadPixmap("QAD", tr("ICON_APP_HELP_HOME")) ));
85 QToolBar* toolbar = new QToolBar( this );
86 addToolBar( toolbar, "Toolbar");
89 button = new QToolButton( icon_back, tr("TOT_HELPWINDOW_BACKWARD"), "", browser, SLOT(backward()), toolbar );
90 connect( browser, SIGNAL( backwardAvailable(bool) ), button, SLOT( setEnabled(bool) ) );
91 button->setEnabled( FALSE );
92 button = new QToolButton( icon_forward, tr("TOT_HELPWINDOW_FORWARD"), "", browser, SLOT(forward()), toolbar );
93 connect( browser, SIGNAL( forwardAvailable(bool) ), button, SLOT( setEnabled(bool) ) );
94 button->setEnabled( FALSE );
95 button = new QToolButton( icon_home, tr("TOT_HELPWINDOW_HOME"), "", browser, SLOT(home()), toolbar );
97 toolbar->addSeparator();
99 pathCombo = new QComboBox( TRUE, toolbar );
100 pathCombo->setInsertionPolicy(QComboBox::NoInsertion);
101 pathCombo->setDuplicatesEnabled(false);
102 connect( pathCombo, SIGNAL( activated( const QString & ) ),
103 this, SLOT( pathSelected( const QString & ) ) );
104 toolbar->setStretchableWidget( pathCombo );
105 setRightJustification( TRUE );
106 setDockEnabled( Left, FALSE );
107 setDockEnabled( Right, FALSE );
108 setDockEnabled( Bottom, FALSE );
109 setDockEnabled( TornOff, FALSE );
110 setDockMenuEnabled( false );
113 // look for index.html and set homeDir
114 // 1. $(SALOME_ROOT_DIR)/doc/index.html
115 // 2. $(SALOME_ROOT_DIR)/doc/html/index.html
116 // 3. $(SALOME_ROOT_DIR)/doc/html/html/index.html
117 // 4. /usr/local/doc/html/index.html
121 if ( (dir = getenv("KERNEL_ROOT_DIR")) ) {
122 root = QAD_Tools::addSlash( QAD_Tools::addSlash(dir) + QAD_Tools::addSlash("share") + QAD_Tools::addSlash("salome") + "doc" );
123 if ( QFileInfo( root + "index.html" ).exists() ) {
127 root = QAD_Tools::addSlash( root + "html" );
128 if ( QFileInfo( root + "index.html" ).exists() ) {
132 root = QAD_Tools::addSlash( root + "html" );
133 if ( QFileInfo( root + "index.html" ).exists() ) {
139 if ( root.isEmpty() ) {
140 if ( QFileInfo( "/usr/local/doc/html/index.html" ).exists() ) {
141 homeDir = "/usr/local/doc/html/";
144 if ( root.isEmpty() )
147 browser->setSource( QFileInfo( homeDir + "index.html" ).absFilePath() );
151 QSize dSize = QApplication::desktop()->size();
152 int x = ( dSize.width() - 750 ) / 2;
153 int y = ( dSize.height() - 680 ) / 2;
154 setGeometry( x, y, 750, 680 );
160 QAD_HelpWindow::~QAD_HelpWindow()
162 emit(helpWindowClosed());
166 enables/disables <Backward> button
168 void QAD_HelpWindow::setBackwardAvailable( bool b)
170 menuBar()->setItemEnabled( backwardId, b);
174 enables/disables <Forward> button
176 void QAD_HelpWindow::setForwardAvailable( bool b)
178 menuBar()->setItemEnabled( forwardId, b);
182 called when new document is loaded into browser
184 void QAD_HelpWindow::textChanged()
186 if ( browser->documentTitle().isNull() && browser->context().isNull() && browser->source().isNull() )
188 selectedURL = browser->source(); //caption();
189 if ( !selectedURL.isEmpty() && pathCombo ) {
192 for ( i = 0; i < pathCombo->count(); ++i ) {
193 if ( pathCombo->text( i ) == selectedURL ) {
199 pathCombo->insertItem( selectedURL, 0 );
200 pathCombo->setCurrentItem( 0 );
202 pathCombo->setCurrentItem( i );
204 selectedURL = QString::null;
209 called when users selectes dosument from the combo box
211 void QAD_HelpWindow::pathSelected( const QString& _path )
213 browser->setSource( _path );
217 goes back to the contents
219 void QAD_HelpWindow::contents()
225 opens new document in browser window and makes context search
226 <_source> is a filename, can be relative, if empty, index.html name is used
227 <_context> is a context, e.g. link in the file
229 void QAD_HelpWindow::context( const QString& _source, const QString& _context)
232 if ( _source.isEmpty() ) {
233 src = homeDir + "index.html";
236 QFileInfo fi( _source );
237 if ( fi.isRelative() )
238 src = homeDir + _source;
242 if ( !_context.isEmpty() )
243 src += "#" + _context;
244 browser->setSource( src );