correctly manage popup menus
similar fix in the taskbar coming
This commit is contained in:
parent
f000f07b08
commit
230a15d475
@ -30,7 +30,8 @@
|
|||||||
|
|
||||||
|
|
||||||
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,11 +118,21 @@ void DialogProxy::setVisible(const bool visible)
|
|||||||
if (visible) {
|
if (visible) {
|
||||||
m_dialog->setWindowFlags(m_flags);
|
m_dialog->setWindowFlags(m_flags);
|
||||||
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());
|
||||||
@ -192,13 +203,30 @@ 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)
|
||||||
{
|
{
|
||||||
m_dialog->setAttribute((Qt::WidgetAttribute)attribute, on);
|
Qt::WidgetAttribute attr = (Qt::WidgetAttribute)attribute;
|
||||||
|
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"
|
||||||
|
@ -86,6 +86,7 @@ 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);
|
||||||
@ -95,6 +96,7 @@ 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
|
||||||
|
Loading…
Reference in New Issue
Block a user