1
/***************************************************************************
2
* Copyright (C) 2005 - 2007 by *
3
* Max Howell, Last.fm Ltd <max@last.fm> *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA. *
19
***************************************************************************/
21
#include "SideBarToolTipLabel.h"
22
#include <QApplication>
25
#include <QStylePainter>
26
#include <QStyleOptionFrame>
30
ToolTipLabel::ToolTipLabel( QWidget* parent ) :
31
QLabel( parent, Qt::ToolTip )
33
setMargin( 1 + style()->pixelMetric(QStyle::PM_ToolTipLabelFrameWidth, 0, this) );
34
setFrameStyle(QFrame::NoFrame);
35
setAlignment(Qt::AlignLeft);
37
setPalette( QToolTip::palette() );
42
ToolTipLabel::paintEvent( QPaintEvent *e )
44
QStylePainter p( this );
45
QStyleOptionFrame opt;
47
p.drawPrimitive( QStyle::PE_PanelTipLabel, opt );
50
QLabel::paintEvent( e );
55
ToolTipLabel::event( QEvent *e )
59
qApp->installEventFilter( this );
63
qApp->removeEventFilter( this );
70
return QLabel::event( e );
75
ToolTipLabel::eventFilter( QObject *o, QEvent *e )
78
case QEvent::KeyPress:
79
case QEvent::KeyRelease:
81
int key = static_cast<QKeyEvent *>(e)->key();
82
Qt::KeyboardModifiers mody = static_cast<QKeyEvent *>(e)->modifiers();
84
if ((mody & Qt::KeyboardModifierMask) || (key == Qt::Key_Shift || key == Qt::Key_Control || key == Qt::Key_Alt || key == Qt::Key_Meta))
94
QPoint p = parentWidget()->mapFromGlobal( QCursor::pos() );
96
if (parentWidget()->geometry().contains( p ))
97
// we get these enter events, but we shouldn't delete as
98
// then we'd dissappear when user is trying to read it!
103
case QEvent::DragLeave:
104
case QEvent::DragEnter:
105
case QEvent::WindowActivate:
106
case QEvent::WindowDeactivate:
107
case QEvent::FocusIn:
108
case QEvent::FocusOut:
110
case QEvent::MouseButtonPress:
111
case QEvent::MouseButtonRelease:
112
case QEvent::MouseButtonDblClick:
120
return QLabel::eventFilter( o, e );