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 // Author : OPEN CASCADE
23 // File: GLViewer_ToolTip.xx
24 // Created: March, 2005
25 //#include "GLViewerAfx.h"
27 #include "GLViewer_Context.h"
28 #include "GLViewer_ToolTip.h"
29 #include "GLViewer_Viewer2d.h"
30 #include "GLViewer_ViewPort2d.h"
31 #include "GLViewer_ViewFrame.h"
36 #include <QApplication>
38 #include <QMouseEvent>
43 GLViewer_ObjectTip::GLViewer_ObjectTip( GLViewer_ViewPort2d* theParent )
48 mypViewPort = theParent;
50 mypLabel = new QLabel( "Test", NULL,
51 Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::Tool | Qt::X11BypassWindowManagerHint );
52 mypLabel->setObjectName("ObjectTipText");
53 mypLabel->setMargin( 1 );
54 //mypLabel->setAutoMask( FALSE );
55 mypLabel->setFrameStyle( QFrame::Plain | QFrame::Box );
56 mypLabel->setLineWidth( 1 );
57 mypLabel->setAlignment( Qt::AlignAbsolute | Qt::AlignTop );
58 mypLabel->setIndent( 0 );
59 mypLabel->ensurePolished();
61 //mypLabel->setPalette( QToolTip::palette() );
63 mypTimer = new QTimer( this );
65 connect( mypTimer, SIGNAL( timeout() ), this, SLOT( showTip() ) );
71 GLViewer_ObjectTip::~GLViewer_ObjectTip()
86 It is called when there is a possibility that a tool tip should be shown
87 \param p - position of tooltip
89 bool GLViewer_ObjectTip::maybeTip( const QPoint &p )
93 GLViewer_Context* aContext = ((GLViewer_Viewer2d*)mypViewPort->getViewFrame()->getViewer())->getGLContext();
95 /*if( !aContext->currentObjectIsChanged() )
99 if( myPoint.x() == -1 && myPoint.y() == -1 || aContext->currentObjectIsChanged())
103 else/if( abs(myPoint.y() - p.y()) < 16 )
112 GLViewer_Object* anObj = aContext->getCurrentObject();
115 setText( anObj->getName() );
122 //GLViewer_Rect* aRect = anObj->getRect();
123 //QRect aWinRect = mypViewPort->GLV2win( *aRect );
124 tip( QRect( p.x(), p.y(), 1, 1 ), anObj->getName() );
125 //QFontMetrics aFM( font() );
126 //showTip( aWinRect, anObj->getName(), QRect( 0, 0, aFM.width( anObj->getName() + " " ), aFM.height()*1.5 ) );
127 //tip( aWinRect, anObj->getName(), aWinRect( aFM.width( anObj->getName() + " " ), aFM.height()*1.5 ) );
132 //tip( QRect( 0, 0, mypViewPort->getGLWidget()->width(),mypViewPort->getGLWidget()->height() ) , "test Tool tip" );
139 bool GLViewer_ObjectTip::eventFilter( QObject* theObj, QEvent* e )
144 /*case QEvent::MouseButtonPress:
145 case QEvent::MouseButtonRelease:
146 case QEvent::MouseButtonDblClick:
147 case QEvent::KeyPress:
148 case QEvent::KeyRelease:
149 // input - turn off tool tip mode
152 case QEvent::MouseMove:
155 /*if( mypTimer->isActive() )
160 QWidget* aWidget = (QWidget*) theObj;
161 if( aWidget == mypViewPort->getGLWidget() )
164 QMouseEvent* m = (QMouseEvent *)e;
166 // mypPoint = new QPoint();
168 myPoint.setX( m->x() );
169 myPoint.setY( m->y() );
177 Hides tooltip and stops timer
179 void GLViewer_ObjectTip::hideTipAndSleep()
197 void GLViewer_ObjectTip::showTip()
199 if( maybeTip( myPoint ) )
202 mypLabel->setText( myText );
203 mypLabel->adjustSize( );
205 QPoint pos = mypViewPort->getGLWidget()->mapToGlobal( myPoint );
209 QCursor* aCursor = QApplication::overrideCursor();
212 const QBitmap* aBitmap = aCursor->bitmap();
214 cur_height = aBitmap->height();
216 mypLabel->setGeometry( pos.x(), pos.y() + cur_height, mypLabel->width(), mypLabel->height() );
217 mypLabel->setPalette( QToolTip::palette() );
227 void GLViewer_ObjectTip::wakeup( int theTime )
229 if( mypTimer->isActive() )
231 mypTimer->start( theTime );