34 #include <config-kleopatra.h>
40 #include <QMouseEvent>
41 #include <QStringList>
43 #include <QApplication>
52 class MimeDataProxy :
public QMimeData {
55 explicit MimeDataProxy( QMimeData * source )
56 : QMimeData(), m_source( source )
61 QStringList formats()
const {
63 return m_source->formats();
68 bool hasFormat(
const QString & format )
const {
69 return m_source && m_source->hasFormat( format );
73 QVariant retrieveData(
const QString & format, QVariant::Type
type )
const {
80 case QVariant::String:
81 if ( format == QLatin1String(
"text/plain" ) )
82 return m_source->text();
83 if ( format == QLatin1String(
"text/html" ) )
84 return m_source->html();
87 if ( format == QLatin1String(
"application/x-color" ) )
88 return m_source->colorData();
91 if ( format == QLatin1String(
"application/x-qt-image" ) )
92 return m_source->imageData();
96 if ( format == QLatin1String(
"text/uri-list" ) ) {
98 if ( urls.size() == 1 )
101 std::copy( urls.begin(), urls.end(),
102 std::back_inserter( result ) );
110 QVariant v = m_source->data( format );
115 QPointer<QMimeData> m_source;
123 m_dragStartPosition()
131 m_dragStartPosition()
141 QMimeData * data =
new QMimeData;
143 urls.push_back( QUrl( url ) );
144 data->setUrls( urls );
149 if ( !m_data || !m_data->hasUrls() )
154 return urls.front().toString();
158 if ( data == m_data )
169 #ifndef QT_NO_DRAGANDDROP
170 if ( m_data && e->button() == Qt::LeftButton )
171 m_dragStartPosition = e->pos();
173 QLabel::mousePressEvent( e );
177 const Qt::Alignment align = label->alignment();
178 const int margin = label->margin();
179 const QRect cr = label->contentsRect().adjusted( margin, margin, -margin, -margin );
180 const QRect rect = QStyle::alignedRect( QApplication::layoutDirection(), align, pix, cr );
181 return mouse - rect.topLeft();
185 #ifndef QT_NO_DRAGANDDROP
187 (e->buttons() & Qt::LeftButton) &&
188 ( m_dragStartPosition - e->pos() ).manhattanLength() > QApplication::startDragDistance() ) {
189 QDrag * drag =
new QDrag(
this );
190 if (
const QPixmap *
const pix = pixmap() ) {
191 drag->setPixmap( *pix );
194 drag->setMimeData(
new MimeDataProxy( m_data ) );
198 QLabel::mouseMoveEvent( e );
199 #ifndef QT_NO_DRAGANDDROP
204 #include "moc_dragqueen.cpp"
205 #include "dragqueen.moc"
static QPoint calculate_hot_spot(const QPoint &mouse, const QSize &pix, const QLabel *label)
DragQueen(QWidget *p=0, Qt::WindowFlags f=0)
void setMimeData(QMimeData *md)
QMimeData * mimeData() const
void mouseMoveEvent(QMouseEvent *)
void mousePressEvent(QMouseEvent *)
void setUrl(const QString &url)