setTextSelectable, to be able to select text XOR drag the widget with
the mouse svn path=/trunk/KDE/kdelibs/; revision=1017058
This commit is contained in:
parent
07f11ce056
commit
d6eb165ee5
@ -23,6 +23,7 @@
|
|||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QStyleOptionGraphicsItem>
|
#include <QStyleOptionGraphicsItem>
|
||||||
|
#include <QGraphicsSceneMouseEvent>
|
||||||
|
|
||||||
#include <kmimetype.h>
|
#include <kmimetype.h>
|
||||||
#include <kglobalsettings.h>
|
#include <kglobalsettings.h>
|
||||||
@ -87,6 +88,7 @@ public:
|
|||||||
QString imagePath;
|
QString imagePath;
|
||||||
QString absImagePath;
|
QString absImagePath;
|
||||||
Svg *svg;
|
Svg *svg;
|
||||||
|
bool textSelectable;
|
||||||
};
|
};
|
||||||
|
|
||||||
Label::Label(QGraphicsWidget *parent)
|
Label::Label(QGraphicsWidget *parent)
|
||||||
@ -94,6 +96,7 @@ Label::Label(QGraphicsWidget *parent)
|
|||||||
d(new LabelPrivate(this))
|
d(new LabelPrivate(this))
|
||||||
{
|
{
|
||||||
QLabel *native = new QLabel;
|
QLabel *native = new QLabel;
|
||||||
|
d->textSelectable = false;
|
||||||
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)));
|
||||||
|
|
||||||
@ -164,6 +167,16 @@ bool Label::hasScaledContents() const
|
|||||||
return static_cast<QLabel*>(widget())->hasScaledContents();
|
return static_cast<QLabel*>(widget())->hasScaledContents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Label::setTextSelectable(bool enable)
|
||||||
|
{
|
||||||
|
d->textSelectable = enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Label::textSelectable() const
|
||||||
|
{
|
||||||
|
return d->textSelectable;
|
||||||
|
}
|
||||||
|
|
||||||
void Label::setAlignment(Qt::Alignment alignment)
|
void Label::setAlignment(Qt::Alignment alignment)
|
||||||
{
|
{
|
||||||
nativeWidget()->setAlignment(alignment);
|
nativeWidget()->setAlignment(alignment);
|
||||||
@ -209,6 +222,15 @@ void Label::resizeEvent(QGraphicsSceneResizeEvent *event)
|
|||||||
QGraphicsProxyWidget::resizeEvent(event);
|
QGraphicsProxyWidget::resizeEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Label::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
|
{
|
||||||
|
if (!d->textSelectable) {
|
||||||
|
event->ignore();
|
||||||
|
} else {
|
||||||
|
QGraphicsProxyWidget::mousePressEvent(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Label::paint(QPainter *painter,
|
void Label::paint(QPainter *painter,
|
||||||
const QStyleOptionGraphicsItem *option,
|
const QStyleOptionGraphicsItem *option,
|
||||||
QWidget *widget)
|
QWidget *widget)
|
||||||
|
@ -106,6 +106,20 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool hasScaledContents() const;
|
bool hasScaledContents() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set if the text on the label can be selected with the mouse
|
||||||
|
*
|
||||||
|
* @arg enable true if we want to manage text selection with the mouse
|
||||||
|
* @since 4.4
|
||||||
|
*/
|
||||||
|
void setTextSelectable(bool enable);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if the text is selectable with the mouse
|
||||||
|
* @since 4.4
|
||||||
|
*/
|
||||||
|
bool textSelectable() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the stylesheet used to control the visual display of this Label
|
* Sets the stylesheet used to control the visual display of this Label
|
||||||
*
|
*
|
||||||
@ -132,6 +146,7 @@ public Q_SLOTS:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent(QGraphicsSceneResizeEvent *event);
|
void resizeEvent(QGraphicsSceneResizeEvent *event);
|
||||||
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
void paint(QPainter *painter,
|
void paint(QPainter *painter,
|
||||||
const QStyleOptionGraphicsItem *option,
|
const QStyleOptionGraphicsItem *option,
|
||||||
QWidget *widget);
|
QWidget *widget);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user