File indexing completed on 2024-12-22 05:01:13

0001 /*
0002   This file is part of KDE Kontact.
0003 
0004   SPDX-FileCopyrightText: 2004 Tobias Koenig <tokoe@kde.org>
0005 
0006   SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #include "dropwidget.h"
0010 
0011 #include <QDragEnterEvent>
0012 #include <QDropEvent>
0013 #include <QMimeData>
0014 DropWidget::DropWidget(QWidget *parent)
0015     : QWidget(parent)
0016 {
0017     setAcceptDrops(true);
0018 }
0019 
0020 void DropWidget::dragEnterEvent(QDragEnterEvent *event)
0021 {
0022     if (event->mimeData()->hasFormat(QStringLiteral("application/x-kontact-summary"))) {
0023         event->acceptProposedAction();
0024     }
0025 }
0026 
0027 void DropWidget::dropEvent(QDropEvent *event)
0028 {
0029     int alignment = (event->position().toPoint().x() < (width() / 2) ? Qt::AlignLeft : Qt::AlignRight);
0030     alignment |= (event->position().toPoint().y() < (height() / 2) ? Qt::AlignTop : Qt::AlignBottom);
0031     Q_EMIT summaryWidgetDropped(this, event->source(), alignment);
0032 }
0033 
0034 #include "moc_dropwidget.cpp"