Fixed drag and drop in widget items.

preferencesAboutTextFull
Yimgo 13 years ago
parent 58746c87e5
commit 7c14893b30
  1. 22
      src/api/UBWidgetUniboardAPI.cpp
  2. 4
      src/api/UBWidgetUniboardAPI.h
  3. 50
      src/board/UBBoardView.cpp
  4. 4
      src/domain/UBGraphicsWebView.cpp
  5. 2
      src/domain/UBGraphicsWebView.h
  6. 54
      src/domain/UBGraphicsWidgetItem.cpp
  7. 5
      src/domain/UBGraphicsWidgetItem.h

@ -476,7 +476,7 @@ void UBWidgetUniboardAPI::enableDropOnWidget(bool enable)
}
}
void UBWidgetUniboardAPI::ProcessDropEvent(QDropEvent *event)
void UBWidgetUniboardAPI::ProcessDropEvent(QGraphicsSceneDragDropEvent *event)
{
const QMimeData *pMimeData = event->mimeData();
@ -485,11 +485,12 @@ void UBWidgetUniboardAPI::ProcessDropEvent(QDropEvent *event)
bool downloaded = false;
QGraphicsView *tmpView = mGraphicsWidget->scene()->views().at(0);
QPoint dropPoint(mGraphicsWidget->mapFromScene(tmpView->mapToScene(event->pos())).toPoint());
Qt::DropActions dropActions = event->dropAction();
Qt::MouseButtons dropMouseButtons = event->mouseButtons();
Qt::KeyboardModifiers dropModifiers = event->keyboardModifiers();
QMimeData dropMimeData;
QPoint dropPoint(mGraphicsWidget->mapFromScene(tmpView->mapToScene(event->pos().toPoint())).toPoint());
Qt::DropActions dropActions = event->possibleActions();
Qt::MouseButtons dropMouseButtons = event->buttons();
Qt::KeyboardModifiers dropModifiers = event->modifiers();
QMimeData *dropMimeData = new QMimeData;
qDebug() << event->possibleActions();
if (pMimeData->hasHtml()) { //Dropping element from web browser
@ -510,7 +511,7 @@ void UBWidgetUniboardAPI::ProcessDropEvent(QDropEvent *event)
desc.name = QFileInfo(url).fileName();
desc.totalSize = 0; // The total size will be retrieved during the download
desc.dropPoint = event->pos(); //Passing pure event point. No modifications
desc.dropPoint = event->pos().toPoint(); //Passing pure event point. No modifications
desc.dropActions = dropActions;
desc.dropMouseButtons = dropMouseButtons;
desc.dropModifiers = dropModifiers;
@ -542,12 +543,9 @@ void UBWidgetUniboardAPI::ProcessDropEvent(QDropEvent *event)
}
qDebug() << destFileName;
QString mimeText = createMimeText(downloaded, contentType, destFileName);
dropMimeData.setData(tMimeText, mimeText.toAscii());
dropMimeData->setData(tMimeText, mimeText.toAscii());
QDropEvent readyEvent(dropPoint, dropActions, &dropMimeData, dropMouseButtons, dropModifiers);
//sending event to destination either it had been downloaded or not
QApplication::sendEvent(mGraphicsWidget,&readyEvent);
readyEvent.acceptProposedAction();
event->setMimeData(dropMimeData);
}
void UBWidgetUniboardAPI::onDownloadFinished(bool pSuccess, sDownloadFileDesc desc, QByteArray pData)

@ -16,7 +16,7 @@
#define UBWIDGETAPI_H
#include <QtCore>
#include <QDropEvent>
#include <QGraphicsSceneDragDropEvent>
#include "UBW3CWidgetAPI.h"
#include "core/UBDownloadManager.h"
@ -246,7 +246,7 @@ class UBWidgetUniboardAPI : public QObject
* When an object is dropped on a widget, this one send us the informations to download it locally.
* this method download the object on the widget directory and return the path of the downloaded object
*/
void ProcessDropEvent(QDropEvent *);
void ProcessDropEvent(QGraphicsSceneDragDropEvent *);
bool isDropableData(const QMimeData *pMimeData) const;
private slots:

@ -1202,56 +1202,22 @@ UBBoardView::drawItems (QPainter *painter, int numItems,
}
void UBBoardView::dragMoveEvent (QDragMoveEvent *event)
void UBBoardView::dragMoveEvent(QDragMoveEvent *event)
{
QGraphicsItem* graphicsItemAtPos = itemAt(event->pos().x(),event->pos().y());
UBGraphicsWidgetItem* graphicsWidget = dynamic_cast<UBGraphicsWidgetItem*>(graphicsItemAtPos);
if (graphicsWidget) {
if (graphicsWidget->acceptDrops()) {
if (!mOkOnWidget) {
if (!graphicsWidget->isDropableData(event->mimeData())) {
mOkOnWidget = false;
event->ignore();
return;
} else {
mOkOnWidget = true;
}
}
QPoint newPoint(graphicsWidget->mapFromScene(mapToScene(event->pos())).toPoint());
QDragMoveEvent newEvent(newPoint, event->dropAction(), event->mimeData(), event->mouseButtons(), event->keyboardModifiers());
QApplication::sendEvent(graphicsWidget,&newEvent);
} else {
mOkOnWidget = false;
event->ignore();
}
} else {
event->acceptProposedAction();
mOkOnWidget = false;
}
QGraphicsView::dragMoveEvent(event);
event->acceptProposedAction();
}
void UBBoardView::dropEvent (QDropEvent *event)
{
mOkOnWidget = false;
QGraphicsItem* graphicsItemAtPos = itemAt(event->pos().x(),event->pos().y());
UBGraphicsWidgetItem* graphicsWidget = dynamic_cast<UBGraphicsWidgetItem*>(graphicsItemAtPos);
if (graphicsWidget && graphicsWidget->acceptDrops()) {
graphicsWidget->processDropEvent(event);
event->acceptProposedAction();
} else if (!event->source()
|| dynamic_cast<UBThumbnailWidget *>(event->source())
|| dynamic_cast<QWebView*>(event->source())
|| dynamic_cast<UBTGMediaWidget*>(event->source())
|| dynamic_cast<QListView *>(event->source())
|| dynamic_cast<UBTGDraggableTreeItem*>(event->source())) {
if (!itemAt(event->pos().x(),event->pos().y())) {
if (!event->source() || dynamic_cast<UBThumbnailWidget *>(event->source()) || dynamic_cast<QWebView*>(event->source()) || dynamic_cast<UBTGMediaWidget*>(event->source()) || dynamic_cast<QListView *>(event->source()) || dynamic_cast<UBTGDraggableTreeItem*>(event->source())) {
mController->processMimeData (event->mimeData (), mapToScene (event->pos ()));
event->acceptProposedAction();
}
}
else
QGraphicsView::dropEvent(event);
}
void

@ -151,10 +151,10 @@ void UBGraphicsWebView::remove()
mDelegate->remove(true);
}
bool UBGraphicsWebView::event(QEvent *event)
/*bool UBGraphicsWebView::event(QEvent *event)
{
if (event->type() == QEvent::ShortcutOverride)
event->accept();
return QGraphicsWebView::event(event);
}
}*/

@ -54,7 +54,7 @@ class UBGraphicsWebView: public QGraphicsWebView, public UBItem, public UBResiza
virtual void wheelEvent(QGraphicsSceneWheelEvent *event);
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
virtual bool event(QEvent *event);
//virtual bool event(QEvent *event);
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
};

@ -97,7 +97,6 @@ UBGraphicsWidgetItem::~UBGraphicsWidgetItem()
void UBGraphicsWidgetItem::initialize()
{
installEventFilter(this);
UBGraphicsWebView::setMinimumSize(nominalSize());
setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); // Necessary to set if we want z value to be assigned correctly
@ -277,9 +276,9 @@ void UBGraphicsWidgetItem::removeScript()
page()->mainFrame()->evaluateJavaScript("if(widget && widget.onremove) { widget.onremove();}");
}
void UBGraphicsWidgetItem::processDropEvent(QDropEvent *event)
void UBGraphicsWidgetItem::processDropEvent(QGraphicsSceneDragDropEvent *event)
{
return mUniboardAPI->ProcessDropEvent(event);
mUniboardAPI->ProcessDropEvent(event);
}
bool UBGraphicsWidgetItem::isDropableData(const QMimeData *data) const
{
@ -486,6 +485,31 @@ void UBGraphicsWidgetItem::unFreeze()
mIsFrozen = false;
}
bool UBGraphicsWidgetItem::event(QEvent *event)
{
if (mShouldMoveWidget && event->type() == QEvent::MouseMove) {
QMouseEvent *mouseMoveEvent = static_cast<QMouseEvent*>(event);
if (mouseMoveEvent->buttons() & Qt::LeftButton) {
QPointF scenePos = mapToScene(mouseMoveEvent->pos());
QPointF newPos = pos() + scenePos - mLastMousePos;
setPos(newPos);
mLastMousePos = scenePos;
event->accept();
return true;
}
}
else if (event->type() == QEvent::ShortcutOverride)
event->accept();
return UBGraphicsWebView::event(event);
}
void UBGraphicsWidgetItem::dropEvent(QGraphicsSceneDragDropEvent *event)
{
processDropEvent(event);
QGraphicsWebView::dropEvent(event);
}
void UBGraphicsWidgetItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
UBGraphicsWebView::mousePressEvent(event);
@ -522,30 +546,6 @@ void UBGraphicsWidgetItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
UBGraphicsWebView::hoverMoveEvent(event);
}
bool UBGraphicsWidgetItem::eventFilter(QObject *obj, QEvent *event)
{
if (mShouldMoveWidget && obj == this && event->type() == QEvent::MouseMove) {
QMouseEvent *mouseMoveEvent = static_cast<QMouseEvent*>(event);
if (mouseMoveEvent->buttons() & Qt::LeftButton) {
QPointF scenePos = mapToScene(mouseMoveEvent->pos());
QPointF newPos = pos() + scenePos - mLastMousePos;
setPos(newPos);
mLastMousePos = scenePos;
event->accept();
return true;
}
}
/* standard event processing */
return QObject::eventFilter(obj, event);
}
void UBGraphicsWidgetItem::sendJSEnterEvent()
{
if (page() && page()->mainFrame())

@ -76,7 +76,7 @@ class UBGraphicsWidgetItem : public UBGraphicsWebView
virtual void remove();
void removeScript();
void processDropEvent(QDropEvent *event);
void processDropEvent(QGraphicsSceneDragDropEvent *event);
bool isDropableData(const QMimeData *data) const;
virtual QUrl getOwnFolder() const;
@ -136,12 +136,13 @@ class UBGraphicsWidgetItem : public UBGraphicsWebView
QMap<QString, QString> mDatastore;
QMap<QString, QString> mPreferences;
virtual bool event(QEvent *event);
virtual void dropEvent(QGraphicsSceneDragDropEvent *event);
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
virtual bool eventFilter(QObject *obj, QEvent *event);
virtual void sendJSEnterEvent();
virtual void sendJSLeaveEvent();
virtual void injectInlineJavaScript();

Loading…
Cancel
Save