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: Plot2d_ToolTip.cxx
23 // Author: Alexandre SOLOVYOV
25 #include "Plot2d_ToolTip.h"
26 #include "Plot2d_ViewFrame.h"
27 #include "Plot2d_Curve.h"
29 #include <QFontMetrics>
31 #include <QMouseEvent>
34 #include <qwt_plot_canvas.h>
36 const int maxDist = 3, tip_margin = 10;
39 Plot2d_ToolTip::Plot2d_ToolTip( Plot2d_ViewFrame* frame, Plot2d_Plot2d* plot )
40 : QtxToolTip( plot->canvas() ),
44 connect( this, SIGNAL( maybeTip( QPoint, QString&, QFont&, QRect&, QRect& ) ),
45 this, SLOT( onToolTip( QPoint, QString&, QFont&, QRect&, QRect& ) ) );
48 Plot2d_ToolTip::~Plot2d_ToolTip()
52 void Plot2d_ToolTip::onToolTip( QPoint p, QString& str, QFont& f, QRect& txtRect, QRect& rect )
57 Plot2d_Curve* c = myPlot->getClosestCurve( p, dist, pInd );
58 if( !c || dist>maxDist )
61 str = c->text( pInd );
66 QStringList lst = str.split( "\n", QString::SkipEmptyParts );
67 QStringList::const_iterator anIt = lst.begin(), aLast = lst.end();
69 for( ; anIt!=aLast; anIt++ )
74 QRect r = m.boundingRect( *anIt );
80 txtRect = QRect( p.x(), p.y(), w, h );
84 bool Plot2d_ToolTip::eventFilter( QObject* o, QEvent* e )
86 bool res = QtxToolTip::eventFilter( o, e );
87 if( e && e->type() == QEvent::MouseMove )
89 QMouseEvent* me = ( QMouseEvent* )e;
90 if( me->modifiers()==0 )