~ubuntu-branches/ubuntu/lucid/lastfm/lucid

« back to all changes in this revision

Viewing changes to src/SideBarToolTipLabel.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Pedro Fragoso
  • Date: 2007-12-31 09:49:54 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20071231094954-ix1amvcsj9pk61ya
Tags: 1:1.4.1.57486.dfsg-1ubuntu1
* Merge from Debian unstable (LP: #180254), remaining changes:
  - debian/rules;
    - Added dh_icons
  - Modify Maintainer value to match Debian-Maintainer-Field Spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2005 - 2007 by                                          *
 
3
 *      Max Howell, Last.fm Ltd <max@last.fm>                              *
 
4
 *                                                                         *
 
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.                                   *
 
9
 *                                                                         *
 
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.                          *
 
14
 *                                                                         *
 
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
 ***************************************************************************/
 
20
 
 
21
#include "SideBarToolTipLabel.h"
 
22
#include <QApplication>
 
23
#include <QKeyEvent>
 
24
#include <QStyle>
 
25
#include <QStylePainter>
 
26
#include <QStyleOptionFrame>
 
27
#include <QToolTip>
 
28
 
 
29
 
 
30
ToolTipLabel::ToolTipLabel( QWidget* parent ) :
 
31
        QLabel( parent, Qt::ToolTip )
 
32
{
 
33
    setMargin( 1 + style()->pixelMetric(QStyle::PM_ToolTipLabelFrameWidth, 0, this) );
 
34
    setFrameStyle(QFrame::NoFrame);
 
35
    setAlignment(Qt::AlignLeft);
 
36
    setIndent(1);
 
37
    setPalette( QToolTip::palette() );
 
38
}
 
39
 
 
40
 
 
41
void
 
42
ToolTipLabel::paintEvent( QPaintEvent *e )
 
43
{
 
44
    QStylePainter p( this );
 
45
    QStyleOptionFrame opt;
 
46
    opt.init( this );
 
47
    p.drawPrimitive( QStyle::PE_PanelTipLabel, opt );
 
48
    p.end();
 
49
 
 
50
    QLabel::paintEvent( e );
 
51
}
 
52
 
 
53
 
 
54
bool
 
55
ToolTipLabel::event( QEvent *e )
 
56
{
 
57
    switch (e->type()) {
 
58
        case QEvent::Show:
 
59
            qApp->installEventFilter( this );
 
60
            break;
 
61
            
 
62
        case QEvent::Hide:
 
63
            qApp->removeEventFilter( this );
 
64
            break;
 
65
    
 
66
        default:
 
67
            break;
 
68
    }
 
69
    
 
70
    return QLabel::event( e );
 
71
}
 
72
 
 
73
    
 
74
bool
 
75
ToolTipLabel::eventFilter( QObject *o, QEvent *e )
 
76
{
 
77
    switch (e->type()) {
 
78
        case QEvent::KeyPress:
 
79
        case QEvent::KeyRelease: 
 
80
        {
 
81
            int key = static_cast<QKeyEvent *>(e)->key();
 
82
            Qt::KeyboardModifiers mody = static_cast<QKeyEvent *>(e)->modifiers();
 
83
    
 
84
            if ((mody & Qt::KeyboardModifierMask) || (key == Qt::Key_Shift || key == Qt::Key_Control || key == Qt::Key_Alt || key == Qt::Key_Meta))
 
85
                break;
 
86
            
 
87
            hide();
 
88
            break;
 
89
        }
 
90
 
 
91
        case QEvent::Enter:
 
92
        case QEvent::Leave:
 
93
        {
 
94
            QPoint p = parentWidget()->mapFromGlobal( QCursor::pos() );
 
95
            
 
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!
 
99
                return true;
 
100
        } 
 
101
            //fall through
 
102
        
 
103
        case QEvent::DragLeave:
 
104
        case QEvent::DragEnter:
 
105
        case QEvent::WindowActivate:
 
106
        case QEvent::WindowDeactivate:
 
107
        case QEvent::FocusIn:
 
108
        case QEvent::FocusOut:
 
109
        case QEvent::Wheel:
 
110
        case QEvent::MouseButtonPress:
 
111
        case QEvent::MouseButtonRelease:
 
112
        case QEvent::MouseButtonDblClick:
 
113
            hide();
 
114
            break;
 
115
    
 
116
        default:
 
117
            break;
 
118
    }
 
119
 
 
120
    return QLabel::eventFilter( o, e );
 
121
}