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:
Marco Martin 2009-08-29 16:59:28 +00:00
parent 07f11ce056
commit d6eb165ee5
2 changed files with 37 additions and 0 deletions

View File

@ -23,6 +23,7 @@
#include <QPainter>
#include <QDir>
#include <QStyleOptionGraphicsItem>
#include <QGraphicsSceneMouseEvent>
#include <kmimetype.h>
#include <kglobalsettings.h>
@ -87,6 +88,7 @@ public:
QString imagePath;
QString absImagePath;
Svg *svg;
bool textSelectable;
};
Label::Label(QGraphicsWidget *parent)
@ -94,6 +96,7 @@ Label::Label(QGraphicsWidget *parent)
d(new LabelPrivate(this))
{
QLabel *native = new QLabel;
d->textSelectable = false;
connect(native, SIGNAL(linkActivated(QString)), this, SIGNAL(linkActivated(QString)));
connect(native, SIGNAL(linkHovered(QString)), this, SIGNAL(linkHovered(QString)));
@ -164,6 +167,16 @@ bool Label::hasScaledContents() const
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)
{
nativeWidget()->setAlignment(alignment);
@ -209,6 +222,15 @@ void Label::resizeEvent(QGraphicsSceneResizeEvent *event)
QGraphicsProxyWidget::resizeEvent(event);
}
void Label::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (!d->textSelectable) {
event->ignore();
} else {
QGraphicsProxyWidget::mousePressEvent(event);
}
}
void Label::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget)

View File

@ -106,6 +106,20 @@ public:
*/
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
*
@ -132,6 +146,7 @@ public Q_SLOTS:
protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget);