1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File: OCCViewer_ToolTip.cxx
23 // Author: Alexandre SOLOVYOV
25 #include "OCCViewer_ToolTip.h"
26 #include "OCCViewer_ViewWindow.h"
27 #include "OCCViewer_ViewPort3d.h"
28 #include "OCCViewer_ViewModel.h"
30 #include <SUIT_ViewManager.h>
32 #include <SelectMgr_EntityOwner.hxx>
37 \param wnd - window where the tooltip should be assigned
39 OCCViewer_ToolTip::OCCViewer_ToolTip( OCCViewer_ViewWindow* wnd )
40 : QtxToolTip( wnd->getViewPort() ),
43 connect( this, SIGNAL( maybeTip( QPoint, QString&, QFont&, QRect&, QRect& ) ),
44 this, SLOT( onToolTip( QPoint, QString&, QFont&, QRect&, QRect& ) ) );
50 OCCViewer_ToolTip::~OCCViewer_ToolTip()
55 \return font of the tooltip
57 QFont OCCViewer_ToolTip::font() const
63 Change font of the tooltip
67 void OCCViewer_ToolTip::setFont( const QFont& f )
75 \param p - current point
76 \param str - returned tooltip text
77 \param f - returned tooltip font
78 \param txtRect - returned tooltip text rectangle
79 \param rect - returned tooltip rectangle
81 void OCCViewer_ToolTip::onToolTip( QPoint p, QString& str, QFont& f, QRect& txtRect, QRect& rect )
83 OCCViewer_Viewer* v = dynamic_cast<OCCViewer_Viewer*>( myWnd->getViewManager()->getViewModel() );
84 Handle( AIS_InteractiveContext ) aCont = v->getAISContext();
89 Handle( SelectMgr_EntityOwner ) owner = aCont->DetectedOwner();
91 emit toolTipFor( owner, txt );
93 Handle_AIS_InteractiveObject obj = aCont->DetectedInteractive();
94 if( txt.isEmpty() && !obj.IsNull() )
95 emit toolTipFor( obj, txt );
101 QFontMetrics m( myFont );
102 int w = m.width( str ), h = m.height();
104 txtRect = QRect( p.x()+4, p.y()-h, w, h );