1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File: OCCViewer_ToolTip.cxx
21 // Author: Alexandre SOLOVYOV
23 #include "OCCViewer_ToolTip.h"
24 #include "OCCViewer_ViewWindow.h"
25 #include "OCCViewer_ViewPort3d.h"
26 #include "OCCViewer_ViewModel.h"
28 #include <SUIT_ViewManager.h>
30 #include <SelectMgr_EntityOwner.hxx>
35 \param wnd - window where the tooltip should be assigned
37 OCCViewer_ToolTip::OCCViewer_ToolTip( OCCViewer_ViewWindow* wnd )
38 : QtxToolTip( wnd->getViewPort() ),
41 connect( this, SIGNAL( maybeTip( QPoint, QString&, QFont&, QRect&, QRect& ) ),
42 this, SLOT( onToolTip( QPoint, QString&, QFont&, QRect&, QRect& ) ) );
48 OCCViewer_ToolTip::~OCCViewer_ToolTip()
53 \return font of the tooltip
55 QFont OCCViewer_ToolTip::font() const
61 Change font of the tooltip
65 void OCCViewer_ToolTip::setFont( const QFont& f )
73 \param p - current point
74 \param str - returned tooltip text
75 \param f - returned tooltip font
76 \param txtRect - returned tooltip text rectangle
77 \param rect - returned tooltip rectangle
79 void OCCViewer_ToolTip::onToolTip( QPoint p, QString& str, QFont& f, QRect& txtRect, QRect& rect )
81 OCCViewer_Viewer* v = dynamic_cast<OCCViewer_Viewer*>( myWnd->getViewManager()->getViewModel() );
82 Handle( AIS_InteractiveContext ) aCont = v->getAISContext();
87 Handle( SelectMgr_EntityOwner ) owner = aCont->DetectedOwner();
89 emit toolTipFor( owner, txt );
91 Handle_AIS_InteractiveObject obj = aCont->DetectedInteractive();
92 if( txt.isEmpty() && !obj.IsNull() )
93 emit toolTipFor( obj, txt );
99 QFontMetrics m( myFont );
100 int w = m.width( str ), h = m.height();
102 txtRect = QRect( p.x()+4, p.y()-h, w, h );