1 // Copyright (C) 2007-2023 CEA, EDF, 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 #include "GLViewer_Context.h"
24 #include "GLViewer_ToolTip.h"
25 #include "GLViewer_Viewer2d.h"
26 #include "GLViewer_ViewPort2d.h"
27 #include "GLViewer_ViewFrame.h"
32 #include <QApplication>
34 #include <QMouseEvent>
39 GLViewer_ObjectTip::GLViewer_ObjectTip( GLViewer_ViewPort2d* theParent )
43 mypViewPort = theParent;
44 mypLabel = new QLabel( "Test", NULL,
45 Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::Tool | Qt::X11BypassWindowManagerHint );
46 mypLabel->setObjectName("ObjectTipText");
47 mypLabel->setMargin( 1 );
48 mypLabel->setFrameStyle( QFrame::Plain | QFrame::Box );
49 mypLabel->setLineWidth( 1 );
50 mypLabel->setAlignment( Qt::AlignAbsolute | Qt::AlignTop );
51 mypLabel->setIndent( 0 );
52 mypLabel->ensurePolished();
54 mypTimer = new QTimer( this );
56 connect( mypTimer, SIGNAL( timeout() ), this, SLOT( showTip() ) );
62 GLViewer_ObjectTip::~GLViewer_ObjectTip()
70 It is called when there is a possibility that a tool tip should be shown
71 \param p - position of tooltip
73 bool GLViewer_ObjectTip::maybeTip( const QPoint& /*p*/ )
75 GLViewer_Context* aContext = ((GLViewer_Viewer2d*)mypViewPort->getViewFrame()->getViewer())->getGLContext();
76 GLViewer_Object* anObj = aContext->getCurrentObject();
79 setText( anObj->getName() );
89 bool GLViewer_ObjectTip::eventFilter( QObject* theObj, QEvent* e )
94 case QEvent::MouseMove:
96 QWidget* aWidget = (QWidget*) theObj;
97 if( aWidget == mypViewPort->getGLWidget() )
100 QMouseEvent* m = (QMouseEvent *)e;
102 myPoint.setX( m->x() );
103 myPoint.setY( m->y() );
113 Hides tooltip and stops timer
115 void GLViewer_ObjectTip::hideTipAndSleep()
130 void GLViewer_ObjectTip::showTip()
132 if( maybeTip( myPoint ) )
135 mypLabel->setText( myText );
136 mypLabel->adjustSize( );
138 QPoint pos = mypViewPort->getGLWidget()->mapToGlobal( myPoint );
141 QCursor* aCursor = QApplication::overrideCursor();
144 const QBitmap* aBitmap = aCursor->bitmap();
146 cur_height = aBitmap->height();
148 mypLabel->setGeometry( pos.x(), pos.y() + cur_height, mypLabel->width(), mypLabel->height() );
149 mypLabel->setPalette( QToolTip::palette() );
159 void GLViewer_ObjectTip::wakeup( int theTime )
161 if( mypTimer->isActive() )
163 mypTimer->start( theTime );