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