similar work around in mousePressEvent as we have in contextMenuEvent
This commit is contained in:
parent
bb026751dc
commit
bd3f840f3b
@ -44,7 +44,8 @@ public:
|
|||||||
LabelPrivate(Label *label)
|
LabelPrivate(Label *label)
|
||||||
: ThemedWidgetInterface<Label>(label),
|
: ThemedWidgetInterface<Label>(label),
|
||||||
svg(0),
|
svg(0),
|
||||||
textSelectable(false)
|
textSelectable(false),
|
||||||
|
hasLinks(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,6 +88,7 @@ public:
|
|||||||
QString absImagePath;
|
QString absImagePath;
|
||||||
Svg *svg;
|
Svg *svg;
|
||||||
bool textSelectable : 1;
|
bool textSelectable : 1;
|
||||||
|
bool hasLinks : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
Label::Label(QGraphicsWidget *parent)
|
Label::Label(QGraphicsWidget *parent)
|
||||||
@ -94,14 +96,16 @@ Label::Label(QGraphicsWidget *parent)
|
|||||||
d(new LabelPrivate(this))
|
d(new LabelPrivate(this))
|
||||||
{
|
{
|
||||||
QLabel *native = new QLabel;
|
QLabel *native = new QLabel;
|
||||||
|
|
||||||
native->setWindowFlags(native->windowFlags()|Qt::BypassGraphicsProxyWidget);
|
native->setWindowFlags(native->windowFlags()|Qt::BypassGraphicsProxyWidget);
|
||||||
|
native->setAttribute(Qt::WA_NoSystemBackground);
|
||||||
|
native->setWordWrap(true);
|
||||||
|
native->setWindowIcon(QIcon());
|
||||||
|
|
||||||
connect(native, SIGNAL(linkActivated(QString)), this, SIGNAL(linkActivated(QString)));
|
connect(native, SIGNAL(linkActivated(QString)), this, SIGNAL(linkActivated(QString)));
|
||||||
connect(native, SIGNAL(linkHovered(QString)), this, SIGNAL(linkHovered(QString)));
|
connect(native, SIGNAL(linkHovered(QString)), this, SIGNAL(linkHovered(QString)));
|
||||||
|
|
||||||
native->setAttribute(Qt::WA_NoSystemBackground);
|
|
||||||
native->setWordWrap(true);
|
|
||||||
setWidget(native);
|
setWidget(native);
|
||||||
native->setWindowIcon(QIcon());
|
|
||||||
d->initTheming();
|
d->initTheming();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,6 +116,7 @@ Label::~Label()
|
|||||||
|
|
||||||
void Label::setText(const QString &text)
|
void Label::setText(const QString &text)
|
||||||
{
|
{
|
||||||
|
d->hasLinks = text.contains("<a ", Qt::CaseInsensitive);
|
||||||
static_cast<QLabel*>(widget())->setText(text);
|
static_cast<QLabel*>(widget())->setText(text);
|
||||||
updateGeometry();
|
updateGeometry();
|
||||||
}
|
}
|
||||||
@ -169,7 +174,7 @@ void Label::setTextSelectable(bool enable)
|
|||||||
if (enable) {
|
if (enable) {
|
||||||
nativeWidget()->setTextInteractionFlags(Qt::TextBrowserInteraction);
|
nativeWidget()->setTextInteractionFlags(Qt::TextBrowserInteraction);
|
||||||
} else {
|
} else {
|
||||||
nativeWidget()->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
|
nativeWidget()->setTextInteractionFlags(Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
d->textSelectable = enable;
|
d->textSelectable = enable;
|
||||||
@ -231,9 +236,9 @@ void Label::dataUpdated(const QString &sourceName, const Plasma::DataEngine::Dat
|
|||||||
|
|
||||||
void Label::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
|
void Label::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
|
||||||
{
|
{
|
||||||
if (d->textSelectable || nativeWidget()->text().contains("<a ", Qt::CaseInsensitive)){
|
if (d->textSelectable || d->hasLinks){
|
||||||
QContextMenuEvent contextMenuEvent(QContextMenuEvent::Reason(event->reason()),
|
QContextMenuEvent contextMenuEvent(QContextMenuEvent::Reason(event->reason()),
|
||||||
event->pos().toPoint(), event->screenPos(), event->modifiers());
|
event->pos().toPoint(), event->screenPos(), event->modifiers());
|
||||||
QApplication::sendEvent(nativeWidget(), &contextMenuEvent);
|
QApplication::sendEvent(nativeWidget(), &contextMenuEvent);
|
||||||
}else{
|
}else{
|
||||||
event->ignore();
|
event->ignore();
|
||||||
@ -251,7 +256,7 @@ void Label::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
QGraphicsProxyWidget::mousePressEvent(event);
|
QGraphicsProxyWidget::mousePressEvent(event);
|
||||||
//FIXME: when QTextControl accept()s mouse press events (as of Qt 4.6.2, it processes them
|
//FIXME: when QTextControl accept()s mouse press events (as of Qt 4.6.2, it processes them
|
||||||
//but never marks them as accepted) the following event->accept() can be removed
|
//but never marks them as accepted) the following event->accept() can be removed
|
||||||
if (d->textSelectable) {
|
if (d->textSelectable || d->hasLinks) {
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user