1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
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
19 // File: Plot2d_ToolTip.cxx
20 // Author: Alexandre SOLOVYOV
22 #include <Plot2d_ToolTip.h>
23 #include <Plot2d_ViewFrame.h>
24 #include <Plot2d_Curve.h>
26 #include <qfontmetrics.h>
29 #include <qwt_plot_canvas.h>
31 const int maxDist = 3, tip_margin = 10;
34 Plot2d_ToolTip::Plot2d_ToolTip( Plot2d_ViewFrame* frame, Plot2d_Plot2d* plot )
35 : QtxToolTip( plot->canvas() ),
39 connect( this, SIGNAL( maybeTip( QPoint, QString&, QFont&, QRect&, QRect& ) ),
40 this, SLOT( onToolTip( QPoint, QString&, QFont&, QRect&, QRect& ) ) );
43 Plot2d_ToolTip::~Plot2d_ToolTip()
47 void Plot2d_ToolTip::onToolTip( QPoint p, QString& str, QFont& f, QRect& txtRect, QRect& rect )
49 int curInd, pInd, dist;
51 curInd = myPlot->closestCurve( p.x(), p.y(), dist, x, y, pInd );
56 Plot2d_Curve* c = myFrame->getCurves().find( curInd );
60 str = c->text( pInd );
65 QStringList lst = QStringList::split( "\n", str );
66 QStringList::const_iterator anIt = lst.begin(), aLast = lst.end();
68 for( ; anIt!=aLast; anIt++ )
73 QRect r = m.boundingRect( *anIt );
79 txtRect = QRect( p.x(), p.y(), w, h );
83 bool Plot2d_ToolTip::eventFilter( QObject* o, QEvent* e )
85 bool res = QtxToolTip::eventFilter( o, e );
86 if( e && e->type() == QEvent::MouseMove )
88 QMouseEvent* me = ( QMouseEvent* )e;