Back to index

salome-gui  6.5.0
OCCViewer_ToolTip.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 // File:      OCCViewer_ToolTip.cxx
00021 // Author:    Alexandre SOLOVYOV
00022 //
00023 #include "OCCViewer_ToolTip.h"
00024 #include "OCCViewer_ViewWindow.h"
00025 #include "OCCViewer_ViewPort3d.h"
00026 #include "OCCViewer_ViewModel.h"
00027 
00028 #include <SUIT_ViewManager.h>
00029 
00030 #include <SelectMgr_EntityOwner.hxx>
00031 
00037 OCCViewer_ToolTip::OCCViewer_ToolTip( OCCViewer_ViewWindow* wnd )
00038 : QtxToolTip( wnd->getViewPort() ),
00039   myWnd( wnd )
00040 {
00041   connect( this, SIGNAL( maybeTip( QPoint, QString&, QFont&, QRect&, QRect& ) ),
00042            this, SLOT( onToolTip( QPoint, QString&, QFont&, QRect&, QRect& ) ) );
00043 }
00044 
00048 OCCViewer_ToolTip::~OCCViewer_ToolTip()
00049 {
00050 }
00051 
00055 QFont OCCViewer_ToolTip::font() const
00056 {
00057   return myFont;
00058 }
00059 
00065 void OCCViewer_ToolTip::setFont( const QFont& f )
00066 {
00067   myFont = f;
00068 }
00069 
00079 void OCCViewer_ToolTip::onToolTip( QPoint p, QString& str, QFont& f, QRect& txtRect, QRect& rect )
00080 {
00081   OCCViewer_Viewer* v = dynamic_cast<OCCViewer_Viewer*>( myWnd->getViewManager()->getViewModel() );
00082   Handle( AIS_InteractiveContext ) aCont = v->getAISContext();
00083   if( aCont.IsNull() )
00084     return;
00085 
00086   QString txt;
00087   Handle( SelectMgr_EntityOwner ) owner = aCont->DetectedOwner();
00088   if( !owner.IsNull() )
00089     emit toolTipFor( owner, txt );
00090 
00091   Handle_AIS_InteractiveObject obj = aCont->DetectedInteractive();
00092   if( txt.isEmpty() && !obj.IsNull() )
00093     emit toolTipFor( obj, txt );
00094 
00095   if( txt.isEmpty() )
00096     return;
00097 
00098   str = txt;
00099   QFontMetrics m( myFont );
00100   int w = m.width( str ), h = m.height();
00101 
00102   txtRect = QRect( p.x()+4, p.y()-h, w, h );
00103   rect = txtRect;
00104 }