Fixed drag and drop in widget items.

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

@ -16,7 +16,7 @@
#define UBWIDGETAPI_H #define UBWIDGETAPI_H
#include <QtCore> #include <QtCore>
#include <QDropEvent> #include <QGraphicsSceneDragDropEvent>
#include "UBW3CWidgetAPI.h" #include "UBW3CWidgetAPI.h"
#include "core/UBDownloadManager.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. * 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 * 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; bool isDropableData(const QMimeData *pMimeData) const;
private slots: 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()); QGraphicsView::dragMoveEvent(event);
UBGraphicsWidgetItem* graphicsWidget = dynamic_cast<UBGraphicsWidgetItem*>(graphicsItemAtPos); event->acceptProposedAction();
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;
}
} }
void UBBoardView::dropEvent (QDropEvent *event) void UBBoardView::dropEvent (QDropEvent *event)
{ {
mOkOnWidget = false; if (!itemAt(event->pos().x(),event->pos().y())) {
QGraphicsItem* graphicsItemAtPos = 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())) {
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())) {
mController->processMimeData (event->mimeData (), mapToScene (event->pos ())); mController->processMimeData (event->mimeData (), mapToScene (event->pos ()));
event->acceptProposedAction(); event->acceptProposedAction();
} }
}
else
QGraphicsView::dropEvent(event);
} }
void void

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

@ -54,7 +54,7 @@ class UBGraphicsWebView: public QGraphicsWebView, public UBItem, public UBResiza
virtual void wheelEvent(QGraphicsSceneWheelEvent *event); virtual void wheelEvent(QGraphicsSceneWheelEvent *event);
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event); virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverLeaveEvent(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); virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
}; };

@ -97,7 +97,6 @@ UBGraphicsWidgetItem::~UBGraphicsWidgetItem()
void UBGraphicsWidgetItem::initialize() void UBGraphicsWidgetItem::initialize()
{ {
installEventFilter(this);
UBGraphicsWebView::setMinimumSize(nominalSize()); UBGraphicsWebView::setMinimumSize(nominalSize());
setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); // Necessary to set if we want z value to be assigned correctly 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();}"); 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 bool UBGraphicsWidgetItem::isDropableData(const QMimeData *data) const
{ {
@ -486,6 +485,31 @@ void UBGraphicsWidgetItem::unFreeze()
mIsFrozen = false; 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) void UBGraphicsWidgetItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{ {
UBGraphicsWebView::mousePressEvent(event); UBGraphicsWebView::mousePressEvent(event);
@ -522,30 +546,6 @@ void UBGraphicsWidgetItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
UBGraphicsWebView::hoverMoveEvent(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() void UBGraphicsWidgetItem::sendJSEnterEvent()
{ {
if (page() && page()->mainFrame()) if (page() && page()->mainFrame())

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

Loading…
Cancel
Save