1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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
23 // Author : OPEN CASCADE
24 // File: GLViewer_ToolTip.xx
25 // Created: March, 2005
26 //#include "GLViewerAfx.h"
28 #include "GLViewer_Context.h"
29 #include "GLViewer_ToolTip.h"
30 #include "GLViewer_Viewer2d.h"
31 #include "GLViewer_ViewPort2d.h"
32 #include "GLViewer_ViewFrame.h"
37 #include <QApplication>
39 #include <QMouseEvent>
44 GLViewer_ObjectTip::GLViewer_ObjectTip( GLViewer_ViewPort2d* theParent )
49 mypViewPort = theParent;
51 mypLabel = new QLabel( "Test", NULL,
52 Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::Tool | Qt::X11BypassWindowManagerHint );
53 mypLabel->setObjectName("ObjectTipText");
54 mypLabel->setMargin( 1 );
55 //mypLabel->setAutoMask( FALSE );
56 mypLabel->setFrameStyle( QFrame::Plain | QFrame::Box );
57 mypLabel->setLineWidth( 1 );
58 mypLabel->setAlignment( Qt::AlignAbsolute | Qt::AlignTop );
59 mypLabel->setIndent( 0 );
60 mypLabel->ensurePolished();
62 //mypLabel->setPalette( QToolTip::palette() );
64 mypTimer = new QTimer( this );
66 connect( mypTimer, SIGNAL( timeout() ), this, SLOT( showTip() ) );
72 GLViewer_ObjectTip::~GLViewer_ObjectTip()
87 It is called when there is a possibility that a tool tip should be shown
88 \param p - position of tooltip
90 bool GLViewer_ObjectTip::maybeTip( const QPoint &p )
94 GLViewer_Context* aContext = ((GLViewer_Viewer2d*)mypViewPort->getViewFrame()->getViewer())->getGLContext();
96 /*if( !aContext->currentObjectIsChanged() )
100 if( myPoint.x() == -1 && myPoint.y() == -1 || aContext->currentObjectIsChanged())
104 else/if( abs(myPoint.y() - p.y()) < 16 )
113 GLViewer_Object* anObj = aContext->getCurrentObject();
116 setText( anObj->getName() );
123 //GLViewer_Rect* aRect = anObj->getRect();
124 //QRect aWinRect = mypViewPort->GLV2win( *aRect );
125 tip( QRect( p.x(), p.y(), 1, 1 ), anObj->getName() );
126 //QFontMetrics aFM( font() );
127 //showTip( aWinRect, anObj->getName(), QRect( 0, 0, aFM.width( anObj->getName() + " " ), aFM.height()*1.5 ) );
128 //tip( aWinRect, anObj->getName(), aWinRect( aFM.width( anObj->getName() + " " ), aFM.height()*1.5 ) );
133 //tip( QRect( 0, 0, mypViewPort->getGLWidget()->width(),mypViewPort->getGLWidget()->height() ) , "test Tool tip" );
140 bool GLViewer_ObjectTip::eventFilter( QObject* theObj, QEvent* e )
145 /*case QEvent::MouseButtonPress:
146 case QEvent::MouseButtonRelease:
147 case QEvent::MouseButtonDblClick:
148 case QEvent::KeyPress:
149 case QEvent::KeyRelease:
150 // input - turn off tool tip mode
153 case QEvent::MouseMove:
156 /*if( mypTimer->isActive() )
161 QWidget* aWidget = (QWidget*) theObj;
162 if( aWidget == mypViewPort->getGLWidget() )
165 QMouseEvent* m = (QMouseEvent *)e;
167 // mypPoint = new QPoint();
169 myPoint.setX( m->x() );
170 myPoint.setY( m->y() );
178 Hides tooltip and stops timer
180 void GLViewer_ObjectTip::hideTipAndSleep()
198 void GLViewer_ObjectTip::showTip()
200 if( maybeTip( myPoint ) )
203 mypLabel->setText( myText );
204 mypLabel->adjustSize( );
206 QPoint pos = mypViewPort->getGLWidget()->mapToGlobal( myPoint );
210 QCursor* aCursor = QApplication::overrideCursor();
213 const QBitmap* aBitmap = aCursor->bitmap();
215 cur_height = aBitmap->height();
217 mypLabel->setGeometry( pos.x(), pos.y() + cur_height, mypLabel->width(), mypLabel->height() );
218 mypLabel->setPalette( QToolTip::palette() );
228 void GLViewer_ObjectTip::wakeup( int theTime )
230 if( mypTimer->isActive() )
232 mypTimer->start( theTime );