Fix crash if key bindings specified in profile cannot be found. Improve
[personal-kdebase.git] / apps / konqueror / src / konqdraggablelabel.cpp
blob5dc1cae48e574f23ae5448d1f1d38ce255ca4284
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"
22 #include "konqview.h"
23 #include <QMouseEvent>
24 #include <QApplication>
27 KonqDraggableLabel::KonqDraggableLabel( KonqMainWindow* mw, const QString& text )
28 : QLabel( text )
29 , m_mw(mw)
31 setBackgroundRole( QPalette::Button );
32 setAlignment( (QApplication::isRightToLeft() ? Qt::AlignRight : Qt::AlignLeft) |
33 Qt::AlignVCenter );
34 setAcceptDrops(true);
35 adjustSize();
36 validDrag = false;
39 void KonqDraggableLabel::mousePressEvent( QMouseEvent * ev )
41 validDrag = true;
42 startDragPos = ev->pos();
45 void KonqDraggableLabel::mouseMoveEvent( QMouseEvent * ev )
47 if ((startDragPos - ev->pos()).manhattanLength() > QApplication::startDragDistance())
49 validDrag = false;
50 if ( m_mw->currentView() )
52 KUrl::List lst;
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));
62 drag->start();
67 void KonqDraggableLabel::mouseReleaseEvent( QMouseEvent * )
69 validDrag = false;
72 void KonqDraggableLabel::dragEnterEvent( QDragEnterEvent *ev )
74 if ( KUrl::List::canDecode( ev->mimeData() ) )
75 ev->accept();
78 void KonqDraggableLabel::dropEvent( QDropEvent* ev )
80 _savedLst.clear();
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() );
93 #include "konqdraggablelabel.moc"