]> SALOME platform Git repositories - modules/gui.git/blob - src/OCCViewer/OCCViewer_ToolTip.cxx
Salome HOME
3efef8d2ba67123aabd2ec73c7c3a8d81fc1253b
[modules/gui.git] / src / OCCViewer / OCCViewer_ToolTip.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File:      OCCViewer_ToolTip.cxx
23 // Author:    Alexandre SOLOVYOV
24 //
25 #include "OCCViewer_ToolTip.h"
26 #include "OCCViewer_ViewWindow.h"
27 #include "OCCViewer_ViewPort3d.h"
28 #include "OCCViewer_ViewModel.h"
29
30 #include <SUIT_ViewManager.h>
31
32 #include <SelectMgr_EntityOwner.hxx>
33
34 /*!
35   Constructor
36
37   \param wnd - window where the tooltip should be assigned
38 */
39 OCCViewer_ToolTip::OCCViewer_ToolTip( OCCViewer_ViewWindow* wnd )
40 : QtxToolTip( wnd->getViewPort() ),
41   myWnd( wnd )
42 {
43   connect( this, SIGNAL( maybeTip( QPoint, QString&, QFont&, QRect&, QRect& ) ),
44            this, SLOT( onToolTip( QPoint, QString&, QFont&, QRect&, QRect& ) ) );
45 }
46
47 /*!
48   Destructor
49  */
50 OCCViewer_ToolTip::~OCCViewer_ToolTip()
51 {
52 }
53
54 /*!
55   \return font of the tooltip
56  */
57 QFont OCCViewer_ToolTip::font() const
58 {
59   return myFont;
60 }
61
62 /*!
63   Change font of the tooltip
64
65   \param f - new font
66  */
67 void OCCViewer_ToolTip::setFont( const QFont& f )
68 {
69   myFont = f;
70 }
71
72 /*!
73   Tooltip handler
74
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
80  */
81 void OCCViewer_ToolTip::onToolTip( QPoint p, QString& str, QFont& f, QRect& txtRect, QRect& rect )
82 {
83   OCCViewer_Viewer* v = dynamic_cast<OCCViewer_Viewer*>( myWnd->getViewManager()->getViewModel() );
84   Handle( AIS_InteractiveContext ) aCont = v->getAISContext();
85   if( aCont.IsNull() )
86     return;
87
88   QString txt;
89   Handle( SelectMgr_EntityOwner ) owner = aCont->DetectedOwner();
90   if( !owner.IsNull() )
91     emit toolTipFor( owner, txt );
92
93   Handle_AIS_InteractiveObject obj = aCont->DetectedInteractive();
94   if( txt.isEmpty() && !obj.IsNull() )
95     emit toolTipFor( obj, txt );
96
97   if( txt.isEmpty() )
98     return;
99
100   str = txt;
101   QFontMetrics m( myFont );
102   int w = m.width( str ), h = m.height();
103
104   txtRect = QRect( p.x()+4, p.y()-h, w, h );
105   rect = txtRect;
106 }