convert the function to a qgraphicswidget:
sceneeventfilter appears to eat events always and in this way i can remove elements from dragHandles when they get deleted svn path=/trunk/KDE/kdelibs/; revision=1045818
This commit is contained in:
parent
3639317617
commit
ca60a5a6cf
@ -213,6 +213,11 @@ public:
|
|||||||
(widget->pos() + delta).toPoint());
|
(widget->pos() + delta).toPoint());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cleanupDragHandles(QObject *destroyed)
|
||||||
|
{
|
||||||
|
dragHandles.remove(static_cast<QGraphicsWidget *>(destroyed));
|
||||||
|
}
|
||||||
|
|
||||||
ScrollWidget *q;
|
ScrollWidget *q;
|
||||||
QGraphicsWidget *scrollingWidget;
|
QGraphicsWidget *scrollingWidget;
|
||||||
QGraphicsWidget *widget;
|
QGraphicsWidget *widget;
|
||||||
@ -228,7 +233,7 @@ public:
|
|||||||
Qt::ScrollBarPolicy horizontalScrollBarPolicy;
|
Qt::ScrollBarPolicy horizontalScrollBarPolicy;
|
||||||
QString styleSheet;
|
QString styleSheet;
|
||||||
QRectF rectToBeVisible;
|
QRectF rectToBeVisible;
|
||||||
QSet<QGraphicsItem *>dragHandles;
|
QSet<QGraphicsWidget *>dragHandles;
|
||||||
bool dragging;
|
bool dragging;
|
||||||
int animId;
|
int animId;
|
||||||
static const int borderSize = 4;
|
static const int borderSize = 4;
|
||||||
@ -345,9 +350,9 @@ void ScrollWidget::ensureItemVisible(QGraphicsItem *item)
|
|||||||
QTimer::singleShot(0, this, SLOT(makeRectVisible()));
|
QTimer::singleShot(0, this, SLOT(makeRectVisible()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScrollWidget::registerAsDragHandle(QGraphicsItem *item)
|
void ScrollWidget::registerAsDragHandle(QGraphicsWidget *item)
|
||||||
{
|
{
|
||||||
if (!d->widget || !item) {
|
if (!d->widget || !item || d->dragHandles.contains(item)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -360,14 +365,15 @@ void ScrollWidget::registerAsDragHandle(QGraphicsItem *item)
|
|||||||
parentOfItem = parentOfItem->parentItem();
|
parentOfItem = parentOfItem->parentItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
item->installSceneEventFilter(this);
|
connect(item, SIGNAL(destroyed(QObject *)), this, SLOT(cleanupDragHandles(QObject *)));
|
||||||
|
item->installEventFilter(this);
|
||||||
d->dragHandles.insert(item);
|
d->dragHandles.insert(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScrollWidget::unregisterAsDragHandle(QGraphicsItem *item)
|
void ScrollWidget::unregisterAsDragHandle(QGraphicsWidget *item)
|
||||||
{
|
{
|
||||||
if (item) {
|
if (item) {
|
||||||
item->removeSceneEventFilter(this);
|
item->removeEventFilter(this);
|
||||||
d->dragHandles.remove(item);
|
d->dragHandles.remove(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -482,24 +488,6 @@ void ScrollWidget::wheelEvent(QGraphicsSceneWheelEvent *event)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScrollWidget::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
|
|
||||||
{
|
|
||||||
if (!d->widget && !scene()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (d->dragHandles.contains(watched)) {
|
|
||||||
if (event->type() == QEvent::GraphicsSceneMousePress ||
|
|
||||||
event->type() == QEvent::GraphicsSceneMouseMove ||
|
|
||||||
event->type() == QEvent::GraphicsSceneMouseRelease) {
|
|
||||||
if (scene()) {
|
|
||||||
scene()->sendEvent(d->widget, event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ScrollWidget::eventFilter(QObject *watched, QEvent *event)
|
bool ScrollWidget::eventFilter(QObject *watched, QEvent *event)
|
||||||
{
|
{
|
||||||
if (!d->widget) {
|
if (!d->widget) {
|
||||||
@ -518,6 +506,14 @@ bool ScrollWidget::eventFilter(QObject *watched, QEvent *event)
|
|||||||
d->verticalScrollBar->setValue(-d->widget->pos().y()/10);
|
d->verticalScrollBar->setValue(-d->widget->pos().y()/10);
|
||||||
d->horizontalScrollBar->blockSignals(false);
|
d->horizontalScrollBar->blockSignals(false);
|
||||||
d->verticalScrollBar->blockSignals(false);
|
d->verticalScrollBar->blockSignals(false);
|
||||||
|
} else if (d->dragHandles.contains(static_cast<QGraphicsWidget *>(watched))) {
|
||||||
|
if (event->type() == QEvent::GraphicsSceneMousePress ||
|
||||||
|
event->type() == QEvent::GraphicsSceneMouseMove ||
|
||||||
|
event->type() == QEvent::GraphicsSceneMouseRelease) {
|
||||||
|
if (scene()) {
|
||||||
|
scene()->sendEvent(this, event);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -129,13 +129,13 @@ public:
|
|||||||
* it's not necessary to call this function.
|
* it's not necessary to call this function.
|
||||||
* @since 4.4
|
* @since 4.4
|
||||||
*/
|
*/
|
||||||
void registerAsDragHandle(QGraphicsItem *item);
|
void registerAsDragHandle(QGraphicsWidget *item);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregister the given item as drag handle (if it was registered)
|
* Unregister the given item as drag handle (if it was registered)
|
||||||
* @since 4.4
|
* @since 4.4
|
||||||
*/
|
*/
|
||||||
void unregisterAsDragHandle(QGraphicsItem *item);
|
void unregisterAsDragHandle(QGraphicsWidget *item);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The geometry of the viewport.
|
* The geometry of the viewport.
|
||||||
@ -191,7 +191,6 @@ protected:
|
|||||||
bool eventFilter(QObject *watched, QEvent *event);
|
bool eventFilter(QObject *watched, QEvent *event);
|
||||||
void focusInEvent(QFocusEvent *event);
|
void focusInEvent(QFocusEvent *event);
|
||||||
QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint) const;
|
QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint) const;
|
||||||
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ScrollWidgetPrivate * const d;
|
ScrollWidgetPrivate * const d;
|
||||||
@ -199,6 +198,7 @@ private:
|
|||||||
Q_PRIVATE_SLOT(d, void verticalScroll(int value))
|
Q_PRIVATE_SLOT(d, void verticalScroll(int value))
|
||||||
Q_PRIVATE_SLOT(d, void horizontalScroll(int value))
|
Q_PRIVATE_SLOT(d, void horizontalScroll(int value))
|
||||||
Q_PRIVATE_SLOT(d, void makeRectVisible())
|
Q_PRIVATE_SLOT(d, void makeRectVisible())
|
||||||
|
Q_PRIVATE_SLOT(d, void cleanupDragHandles(QObject *destroyed))
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Plasma
|
} // namespace Plasma
|
||||||
|
Loading…
Reference in New Issue
Block a user