revert last commit

popups are done correctly now
(is necessary so show, set the flags and show again)
This commit is contained in:
Marco Martin 2011-06-07 19:12:04 +02:00
parent 230a15d475
commit d3868a8b65
2 changed files with 4 additions and 32 deletions

View File

@ -24,14 +24,14 @@
#include <QGraphicsObject> #include <QGraphicsObject>
#include <QGraphicsWidget> #include <QGraphicsWidget>
#include <QTimer> #include <QTimer>
#include <QLayout>
#include <Plasma/Corona> #include <Plasma/Corona>
#include <Plasma/Dialog> #include <Plasma/Dialog>
DialogProxy::DialogProxy(QObject *parent) DialogProxy::DialogProxy(QObject *parent)
: QObject(parent), : QObject(parent)
m_isPopupMenu(false)
{ {
m_dialog = new Plasma::Dialog(); m_dialog = new Plasma::Dialog();
m_dialog->installEventFilter(this); m_dialog->installEventFilter(this);
@ -117,22 +117,13 @@ void DialogProxy::setVisible(const bool visible)
m_dialog->setVisible(visible); m_dialog->setVisible(visible);
if (visible) { if (visible) {
m_dialog->setWindowFlags(m_flags); m_dialog->setWindowFlags(m_flags);
m_dialog->setVisible(visible);
m_dialog->raise(); m_dialog->raise();
if (m_isPopupMenu && QWidget::mouseGrabber() != m_dialog) {
QTimer::singleShot(200, this, SLOT(syncGrab()));
}
} }
emit visibleChanged(); emit visibleChanged();
} }
} }
void DialogProxy::syncGrab()
{
if (m_isPopupMenu) {
m_dialog->grabMouse();
}
}
QPoint DialogProxy::popupPosition(QGraphicsObject *item) const QPoint DialogProxy::popupPosition(QGraphicsObject *item) const
{ {
Plasma::Corona *corona = qobject_cast<Plasma::Corona *>(item->scene()); Plasma::Corona *corona = qobject_cast<Plasma::Corona *>(item->scene());
@ -203,30 +194,13 @@ bool DialogProxy::eventFilter(QObject *watched, QEvent *event)
if (re->oldSize().height() != re->size().height()) { if (re->oldSize().height() != re->size().height()) {
emit heightChanged(); emit heightChanged();
} }
} else if (watched == m_dialog && event->type() == QEvent::Hide) {
m_dialog->releaseMouse();
} else if (watched == m_dialog && event->type() == QEvent::MouseButtonPress) {
if (m_isPopupMenu) {
QMouseEvent *me = static_cast<QMouseEvent *>(event);
if (!m_dialog->geometry().contains(me->globalPos())) {
m_dialog->releaseMouse();
setVisible(false);
}
}
} }
return false; return false;
} }
void DialogProxy::setAttribute(int attribute, bool on) void DialogProxy::setAttribute(int attribute, bool on)
{ {
Qt::WidgetAttribute attr = (Qt::WidgetAttribute)attribute; m_dialog->setAttribute((Qt::WidgetAttribute)attribute, on);
if (attr == Qt::WA_X11NetWmWindowTypePopupMenu) {
m_isPopupMenu = on;
if (m_isPopupMenu && QWidget::mouseGrabber() != m_dialog) {
QTimer::singleShot(200, this, SLOT(syncGrab()));
}
}
m_dialog->setAttribute(attr, on);
} }
#include "dialog.moc" #include "dialog.moc"

View File

@ -86,7 +86,6 @@ Q_SIGNALS:
protected Q_SLOTS: protected Q_SLOTS:
void syncMainItem(); void syncMainItem();
void syncGrab();
protected: protected:
bool eventFilter(QObject *watched, QEvent *event); bool eventFilter(QObject *watched, QEvent *event);
@ -96,7 +95,6 @@ private:
Qt::WindowFlags m_flags; Qt::WindowFlags m_flags;
DeclarativeItemContainer *m_declarativeItemContainer; DeclarativeItemContainer *m_declarativeItemContainer;
QWeakPointer<QGraphicsObject> m_mainItem; QWeakPointer<QGraphicsObject> m_mainItem;
bool m_isPopupMenu;
}; };
#endif #endif