put all context menus in a separate window, resolving cutting and z-order issues

BUG:207956

svn path=/trunk/KDE/kdelibs/; revision=1067048
This commit is contained in:
Marco Martin 2009-12-28 19:52:54 +00:00
parent eaa5b602be
commit 06341cfb73
8 changed files with 48 additions and 1 deletions

View File

@ -25,6 +25,7 @@
#include <QDir>
#include <QStyleOptionGraphicsItem>
#include <QGraphicsSceneMouseEvent>
#include <QMenu>
#include <kmimetype.h>
#include <kglobalsettings.h>
@ -113,6 +114,7 @@ Label::Label(QGraphicsWidget *parent)
d(new LabelPrivate(this))
{
QLabel *native = new QLabel;
native->setWindowFlags(native->windowFlags()|Qt::BypassGraphicsProxyWidget);
d->textSelectable = false;
connect(native, SIGNAL(linkActivated(QString)), this, SIGNAL(linkActivated(QString)));
connect(native, SIGNAL(linkHovered(QString)), this, SIGNAL(linkHovered(QString)));
@ -234,6 +236,13 @@ void Label::dataUpdated(const QString &sourceName, const Plasma::DataEngine::Dat
setText(texts.join(" "));
}
void Label::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
QContextMenuEvent contextMenuEvent(QContextMenuEvent::Reason(event->reason()),
event->pos().toPoint(), event->screenPos(), event->modifiers());
QApplication::sendEvent(nativeWidget(), &contextMenuEvent);
}
void Label::resizeEvent(QGraphicsSceneResizeEvent *event)
{
d->setPixmap();

View File

@ -152,6 +152,7 @@ protected:
QWidget *widget);
void changeEvent(QEvent *event);
bool event(QEvent *event);
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
private:
Q_PRIVATE_SLOT(d, void setPalette())

View File

@ -20,6 +20,10 @@
#include "scrollbar.h"
#include <QApplication>
#include <QContextMenuEvent>
#include <QGraphicsSceneContextMenuEvent>
#include <plasma/private/style_p.h>
namespace Plasma
@ -36,6 +40,7 @@ ScrollBar::ScrollBar(QGraphicsWidget *parent)
d(new ScrollBarPrivate)
{
QScrollBar *scrollbar = new QScrollBar();
scrollbar->setWindowFlags(scrollbar->windowFlags()|Qt::BypassGraphicsProxyWidget);
scrollbar->setAttribute(Qt::WA_NoSystemBackground);
setWidget(scrollbar);
d->style = Plasma::Style::sharedStyle();
@ -118,6 +123,13 @@ void ScrollBar::setOrientation(Qt::Orientation orientation)
resize(native->sizeHint());
}
void ScrollBar::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
QContextMenuEvent contextMenuEvent(QContextMenuEvent::Reason(event->reason()),
event->pos().toPoint(), event->screenPos(), event->modifiers());
QApplication::sendEvent(nativeWidget(), &contextMenuEvent);
}
}
#include <scrollbar.moc>

View File

@ -118,6 +118,9 @@ public:
*/
QScrollBar *nativeWidget() const;
protected:
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
public Q_SLOTS:
/**
* Sets the current value for the ScrollBar

View File

@ -22,6 +22,7 @@
#include <QPainter>
#include <QScrollBar>
#include <QGraphicsSceneWheelEvent>
#include <QMenu>
#include <kmimetype.h>
#include <ktextbrowser.h>
@ -101,6 +102,7 @@ TextBrowser::TextBrowser(QGraphicsWidget *parent)
d(new TextBrowserPrivate(this))
{
KTextBrowser *native = new KTextBrowser;
native->setWindowFlags(native->windowFlags()|Qt::BypassGraphicsProxyWidget);
connect(native, SIGNAL(textChanged()), this, SIGNAL(textChanged()));
connect(native, SIGNAL(textChanged()), this, SLOT(setFixedHeight()));
setWidget(native);
@ -171,6 +173,13 @@ void TextBrowser::dataUpdated(const QString &sourceName, const Plasma::DataEngin
}
}
void TextBrowser::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
QMenu *popup = nativeWidget()->createStandardContextMenu(event->screenPos());
popup->exec(event->screenPos());
delete popup;
}
void TextBrowser::resizeEvent(QGraphicsSceneResizeEvent *event)
{
d->setFixedHeight();

View File

@ -101,6 +101,7 @@ protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);
void wheelEvent(QGraphicsSceneWheelEvent *event);
void changeEvent(QEvent *event);
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
private:
TextBrowserPrivate * const d;

View File

@ -21,6 +21,8 @@
#include <QPainter>
#include <QScrollBar>
#include <QMenu>
#include <QGraphicsSceneContextMenuEvent>
#include <kmimetype.h>
#include <ktextedit.h>
@ -75,7 +77,9 @@ TextEdit::TextEdit(QGraphicsWidget *parent)
{
d->style = Plasma::Style::sharedStyle();
setNativeWidget(new KTextEdit);
KTextEdit *nativeWidget = new KTextEdit;
nativeWidget->setWindowFlags(nativeWidget->windowFlags()|Qt::BypassGraphicsProxyWidget);
setNativeWidget(nativeWidget);
connect(Theme::defaultTheme(), SIGNAL(themeChanged()),
this, SLOT(setPalette()));
}
@ -153,6 +157,13 @@ void TextEdit::dataUpdated(const QString &sourceName, const Plasma::DataEngine::
}
}
void TextEdit::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
QMenu *popup = nativeWidget()->mousePopupMenu();
popup->exec(event->screenPos());
delete popup;
}
void TextEdit::resizeEvent(QGraphicsSceneResizeEvent *event)
{
QGraphicsProxyWidget::resizeEvent(event);

View File

@ -109,6 +109,7 @@ Q_SIGNALS:
protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);
void changeEvent(QEvent *event);
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
private:
TextEditPrivate * const d;