Support for using custom native widgets with ComboBox, LineEdit and TextEdit

svn path=/trunk/KDE/kdelibs/; revision=1027285
This commit is contained in:
Michał Dutkiewicz 2009-09-23 18:42:19 +00:00
parent 56ac584338
commit 034e5a4a62
6 changed files with 92 additions and 33 deletions

View File

@ -132,13 +132,6 @@ ComboBox::ComboBox(QGraphicsWidget *parent)
: QGraphicsProxyWidget(parent),
d(new ComboBoxPrivate(this))
{
KComboBox *native = new KComboBox;
connect(native, SIGNAL(activated(const QString &)), this, SIGNAL(activated(const QString &)));
connect(native, SIGNAL(currentIndexChanged(const QString &)),
this, SIGNAL(textChanged(const QString &)));
setWidget(native);
native->setAttribute(Qt::WA_NoSystemBackground);
d->background = new FrameSvg(this);
d->background->setImagePath("widgets/button");
d->background->setCacheAllRenderedFrames(true);
@ -147,12 +140,14 @@ ComboBox::ComboBox(QGraphicsWidget *parent)
d->lineEditBackground->setImagePath("widgets/lineedit");
d->lineEditBackground->setCacheAllRenderedFrames(true);
d->syncBorders();
setAcceptHoverEvents(true);
d->style = Style::sharedStyle();
setNativeWidget(new KComboBox);
connect(Theme::defaultTheme(), SIGNAL(themeChanged()), SLOT(syncBorders()));
connect(Plasma::Animator::self(), SIGNAL(customAnimationFinished(int)), this, SLOT(animationFinished(int)));
d->style = Style::sharedStyle();
native->setStyle(d->style.data());
}
ComboBox::~ComboBox()
@ -176,6 +171,24 @@ QString ComboBox::styleSheet()
return widget()->styleSheet();
}
void ComboBox::setNativeWidget(KComboBox *nativeWidget)
{
if (widget()) {
widget()->deleteLater();
}
connect(nativeWidget, SIGNAL(activated(const QString &)), this, SIGNAL(activated(const QString &)));
connect(nativeWidget, SIGNAL(currentIndexChanged(const QString &)),
this, SIGNAL(textChanged(const QString &)));
setWidget(nativeWidget);
nativeWidget->setAttribute(Qt::WA_NoSystemBackground);
nativeWidget->setStyle(d->style.data());
d->syncBorders();
}
KComboBox *ComboBox::nativeWidget() const
{
return static_cast<KComboBox*>(widget());

View File

@ -43,7 +43,7 @@ class PLASMA_EXPORT ComboBox : public QGraphicsProxyWidget
Q_PROPERTY(QGraphicsWidget *parentWidget READ parentWidget)
Q_PROPERTY(QString text READ text NOTIFY textChanged)
Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
Q_PROPERTY(KComboBox *nativeWidget READ nativeWidget)
Q_PROPERTY(KComboBox *nativeWidget READ nativeWidget WRITE setNativeWidget)
public:
explicit ComboBox(QGraphicsWidget *parent = 0);
@ -66,13 +66,21 @@ public:
*/
QString styleSheet();
/**
* Sets the combo box wrapped by this ComboBox (widget must inherit KComboBox), ownership is transferred to the ComboBox
*
* @arg combo box that will be wrapped by this ComboBox
* @since KDE4.4
*/
void setNativeWidget(KComboBox *nativeWidget);
/**
* @return the native widget wrapped by this ComboBox
*/
KComboBox *nativeWidget() const;
/**
* Adds an item to the combobox with the given text. The
* Adds an item to the combo box with the given text. The
* item is appended to the list of existing items.
*/
void addItem(const QString &text);

View File

@ -72,22 +72,13 @@ LineEdit::LineEdit(QGraphicsWidget *parent)
: QGraphicsProxyWidget(parent),
d(new LineEditPrivate(this))
{
KLineEdit *native = new KLineEdit;
d->style = Plasma::Style::sharedStyle();
d->background = new Plasma::FrameSvg(this);
d->background->setImagePath("widgets/lineedit");
d->background->setCacheAllRenderedFrames(true);
native->setStyle(d->style.data());
native->setAttribute(Qt::WA_NoSystemBackground);
setWidget(native);
setNativeWidget(new KLineEdit);
connect(native, SIGNAL(editingFinished()), this, SIGNAL(editingFinished()));
connect(native, SIGNAL(returnPressed()), this, SIGNAL(returnPressed()));
connect(native, SIGNAL(textEdited(const QString&)), this, SIGNAL(textEdited(const QString&)));
connect(native, SIGNAL(textChanged(const QString&)), this, SIGNAL(textChanged(const QString&)));
d->setPalette();
connect(Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(setPalette()));
}
@ -127,6 +118,26 @@ QString LineEdit::styleSheet()
return widget()->styleSheet();
}
void LineEdit::setNativeWidget(KLineEdit *nativeWidget)
{
if (widget()) {
widget()->deleteLater();
}
connect(nativeWidget, SIGNAL(editingFinished()), this, SIGNAL(editingFinished()));
connect(nativeWidget, SIGNAL(returnPressed()), this, SIGNAL(returnPressed()));
connect(nativeWidget, SIGNAL(textEdited(const QString&)), this, SIGNAL(textEdited(const QString&)));
connect(nativeWidget, SIGNAL(textChanged(const QString&)), this, SIGNAL(textChanged(const QString&)));
setWidget(nativeWidget);
nativeWidget->setAttribute(Qt::WA_NoSystemBackground);
nativeWidget->setStyle(d->style.data());
d->setPalette();
}
KLineEdit *LineEdit::nativeWidget() const
{
return static_cast<KLineEdit*>(widget());

View File

@ -44,7 +44,7 @@ class PLASMA_EXPORT LineEdit : public QGraphicsProxyWidget
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textEdited)
Q_PROPERTY(bool isClearButtonShown READ isClearButtonShown WRITE setClearButtonShown)
Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
Q_PROPERTY(KLineEdit *nativeWidget READ nativeWidget)
Q_PROPERTY(KLineEdit *nativeWidget READ nativeWidget WRITE setNativeWidget)
public:
explicit LineEdit(QGraphicsWidget *parent = 0);
@ -86,6 +86,14 @@ public:
*/
QString styleSheet();
/**
* Sets the line edit wrapped by this LineEdit (widget must inherit KLineEdit), ownership is transferred to the LineEdit
*
* @arg text edit that will be wrapped by this LineEdit
* @since KDE4.4
*/
void setNativeWidget(KLineEdit *nativeWidget);
/**
* @return the native widget wrapped by this LineEdit
*/

View File

@ -73,16 +73,9 @@ TextEdit::TextEdit(QGraphicsWidget *parent)
: QGraphicsProxyWidget(parent),
d(new TextEditPrivate(this))
{
KTextEdit *native = new KTextEdit;
connect(native, SIGNAL(textChanged()), this, SIGNAL(textChanged()));
setWidget(native);
native->setAttribute(Qt::WA_NoSystemBackground);
native->setFrameShape( QFrame::NoFrame );
native->setTextBackgroundColor( Qt::transparent );
native->viewport()->setAutoFillBackground( false );
d->style = Plasma::Style::sharedStyle();
native->verticalScrollBar()->setStyle(d->style.data());
native->horizontalScrollBar()->setStyle(d->style.data());
setNativeWidget(new KTextEdit);
connect(Theme::defaultTheme(), SIGNAL(themeChanged()),
this, SLOT(setPalette()));
}
@ -114,6 +107,24 @@ QString TextEdit::styleSheet()
return widget()->styleSheet();
}
void TextEdit::setNativeWidget(KTextEdit *nativeWidget)
{
if (widget()) {
widget()->deleteLater();
}
connect(nativeWidget, SIGNAL(textChanged()), this, SIGNAL(textChanged()));
setWidget(nativeWidget);
nativeWidget->setAttribute(Qt::WA_NoSystemBackground);
nativeWidget->setFrameShape(QFrame::NoFrame);
nativeWidget->setTextBackgroundColor(Qt::transparent);
nativeWidget->viewport()->setAutoFillBackground(false);
nativeWidget->verticalScrollBar()->setStyle(d->style.data());
nativeWidget->horizontalScrollBar()->setStyle(d->style.data());
}
KTextEdit *TextEdit::nativeWidget() const
{
return static_cast<KTextEdit*>(widget());

View File

@ -44,7 +44,7 @@ class PLASMA_EXPORT TextEdit : public QGraphicsProxyWidget
Q_PROPERTY(QGraphicsWidget *parentWidget READ parentWidget)
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
Q_PROPERTY(QString stylesheet READ styleSheet WRITE setStyleSheet)
Q_PROPERTY(KTextEdit *nativeWidget READ nativeWidget)
Q_PROPERTY(KTextEdit *nativeWidget READ nativeWidget WRITE setNativeWidget)
public:
explicit TextEdit(QGraphicsWidget *parent = 0);
@ -74,6 +74,14 @@ public:
*/
QString styleSheet();
/**
* Sets the text edit wrapped by this TextEdit (widget must inherit KTextEdit), ownership is transferred to the TextEdit
*
* @arg text edit that will be wrapped by this TextEdit
* @since KDE4.4
*/
void setNativeWidget(KTextEdit *nativeWidget);
/**
* @return the native widget wrapped by this TextEdit
*/