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

« back to all changes in this revision

Viewing changes to src/libUnicorn/imagebutton.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Devid Filoni
  • Date: 2008-07-14 16:46:20 UTC
  • mfrom: (1.1.7 upstream) (3.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080714164620-67hoz9fs177wpgmr
Tags: 1:1.5.1.31879.dfsg-1ubuntu1
* Merge from Debian unstable (LP: #248100), remaining changes:
  - debian/rules: add dh_icons call
  + debian/control:
    - switch iceweasel to firefox in Recommends field
    - modify debhelper version to >= 5.0.51~
    - modify Maintainer to Ubuntu MOTU Developers

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 ***************************************************************************/
21
21
 
22
22
#include "imagebutton.h"
 
23
 
23
24
#include <QDesktopServices>
24
25
#include <QIcon>
25
26
#include <QMouseEvent>
 
27
#include <QApplication>
26
28
 
27
29
 
28
30
ImageButton::ImageButton( QWidget *parent ) :
56
58
void
57
59
ImageButton::mousePressEvent( QMouseEvent* e )
58
60
{
59
 
    if ( e->button() == Qt::LeftButton && m_enabled && !m_down.isNull() )
60
 
        setPixmap( m_down );
61
 
    else
62
 
        setPixmap( m_normal );
 
61
    if ( e->button() == Qt::LeftButton && m_enabled )
 
62
    {
 
63
        if ( !m_down.isNull() )
 
64
            setPixmap( m_down );
 
65
 
 
66
        m_dragStartPosition = e->pos();
 
67
    }
 
68
 
 
69
    setPixmap( m_normal );
63
70
}
64
71
 
65
72
 
66
73
void
67
74
ImageButton::mouseReleaseEvent( QMouseEvent* e )
68
75
{
 
76
    if ( ( e->pos() - m_dragStartPosition ).manhattanLength() > QApplication::startDragDistance() )
 
77
        return;
 
78
 
69
79
    if ( e->button() == Qt::LeftButton && m_enabled && rect().contains( e->pos() ) )
70
80
    {
71
81
        setPixmap( m_normal );
91
101
        setPixmap( m_down );
92
102
    else
93
103
        setPixmap( m_normal );
 
104
 
 
105
    if ( !m_enabled )
 
106
        return;
 
107
    if ( ( e->pos() - m_dragStartPosition ).manhattanLength() < QApplication::startDragDistance() )
 
108
        return;
 
109
 
 
110
    if ( m_dragData.count() )
 
111
    {
 
112
        QDrag* drag = new QDrag( this );
 
113
        QMimeData *mimeData = new QMimeData();
 
114
        mimeData->setData( "item/type", QByteArray::number( itemType() ) );
 
115
 
 
116
        for ( int i = 0; i < m_dragData.count(); i++ )
 
117
        {
 
118
            //qDebug() << "Setting data" << m_dragData.keys().at( i ) << m_dragData.values().at( i );
 
119
            mimeData->setData( QString( "item/%1" ).arg( m_dragData.keys().at( i ) ), m_dragData.values().at( i ).toUtf8() );
 
120
        }
 
121
 
 
122
        drag->setMimeData( mimeData );
 
123
        drag->setPixmap( m_normal );
 
124
 
 
125
        Qt::DropAction dropAction = drag->start( Qt::CopyAction );
 
126
        Q_UNUSED( dropAction )
 
127
    }
94
128
}
95
129
 
96
130
 
104
138
        else
105
139
            setPixmap( m_normal );
106
140
 
107
 
        emit urlHovered( m_url.toString() );
 
141
        emit urlHovered( m_url );
108
142
    }
109
143
}
110
144
 
115
149
    if ( m_enabled )
116
150
    {
117
151
        setPixmap( m_normal );
118
 
        emit urlHovered( "" );
 
152
        emit urlHovered( QUrl() );
119
153
    }
120
154
}