1 /* This file is part of the KDE project
2 Copyright 2002 John Firebaugh <jfirebaugh@kde.org>
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 #include "konqdraggablelabel.h"
21 #include "konqmainwindow.h"
23 #include <QMouseEvent>
24 #include <QApplication>
27 KonqDraggableLabel::KonqDraggableLabel( KonqMainWindow
* mw
, const QString
& text
)
31 setBackgroundRole( QPalette::Button
);
32 setAlignment( (QApplication::isRightToLeft() ? Qt::AlignRight
: Qt::AlignLeft
) |
39 void KonqDraggableLabel::mousePressEvent( QMouseEvent
* ev
)
42 startDragPos
= ev
->pos();
45 void KonqDraggableLabel::mouseMoveEvent( QMouseEvent
* ev
)
47 if ((startDragPos
- ev
->pos()).manhattanLength() > QApplication::startDragDistance())
50 if ( m_mw
->currentView() )
53 lst
.append( m_mw
->currentView()->url() );
54 QDrag
* drag
= new QDrag( m_mw
);
55 QMimeData
* md
= new QMimeData();
56 lst
.populateMimeData( md
);
57 drag
->setMimeData( md
);
58 QString iconName
= KMimeType::iconNameForUrl( lst
.first() );
60 drag
->setPixmap(KIconLoader::global()->loadMimeTypeIcon(iconName
, KIconLoader::Small
));
67 void KonqDraggableLabel::mouseReleaseEvent( QMouseEvent
* )
72 void KonqDraggableLabel::dragEnterEvent( QDragEnterEvent
*ev
)
74 if ( KUrl::List::canDecode( ev
->mimeData() ) )
78 void KonqDraggableLabel::dropEvent( QDropEvent
* ev
)
81 _savedLst
= KUrl::List::fromMimeData( ev
->mimeData() );
82 if ( !_savedLst
.isEmpty() ) {
83 QMetaObject::invokeMethod(this, "delayedOpenURL", Qt::QueuedConnection
);
87 void KonqDraggableLabel::delayedOpenURL()
89 m_mw
->openUrl( 0L, _savedLst
.first() );