1 /* 2 Copyright © 2011-13 Qtrac Ltd. All rights reserved. 3 This program or module is free software: you can redistribute it 4 and/or modify it under the terms of the GNU General Public License 5 as published by the Free Software Foundation, either version 2 of 6 the License, or (at your option) any later version. This program is 7 distributed in the hope that it will be useful, but WITHOUT ANY 8 WARRANTY; without even the implied warranty of MERCHANTABILITY or 9 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 10 for more details. 11 */ 12 13 #include "generic.hpp" 14 #include "label.hpp" 15 #include <QDragEnterEvent> 16 #include <QDragEnterEvent> 17 #include <QMouseEvent> 18 #include <QMimeData> 19 Label(QWidget * parent)20Label::Label(QWidget *parent) : QLabel(parent) 21 { 22 setAcceptDrops(true); 23 } 24 dragEnterEvent(QDragEnterEvent * event)25void Label::dragEnterEvent(QDragEnterEvent *event) 26 { 27 const QMimeData *mimeData = event->mimeData(); 28 if (mimeData->hasFormat("text/plain") || 29 mimeData->hasFormat("text/uri-list")) 30 event->acceptProposedAction(); 31 } 32 33 dropEvent(QDropEvent * event)34void Label::dropEvent(QDropEvent *event) 35 { 36 QStringList filenames = droppedFilenames(event->mimeData()); 37 if (!filenames.isEmpty()) 38 emit filenamesDropped(filenames); 39 event->acceptProposedAction(); 40 } 41 42 mousePressEvent(QMouseEvent * event)43void Label::mousePressEvent(QMouseEvent *event) 44 { 45 if (event->button() == Qt::LeftButton) 46 emit clicked(event->pos()); 47 QLabel::mousePressEvent(event); 48 } 49