[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-panel-devel
Subject: [PATCH] minor lineedit improvement
From: Chani <chanika () gmail ! com>
Date: 2008-03-29 22:00:45
Message-ID: 200803291500.53293.chanika () gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/signed)]
[Attachment #4 (multipart/mixed)]
-setDefaultText no longer clobbers regular text
-fewer string comparisons
anyone see any case where the new bool could get out of sync with reality? it
seems to work fine with the notes applet.
--
This message brought to you by evyl bananas, and the number 3.
www.chani3.com
["lineedit.diff" (text/x-diff)]
Index: lineedit.h
===================================================================
--- lineedit.h (revision 791548)
+++ lineedit.h (working copy)
@@ -75,11 +75,13 @@
/**
* Set text to be displayed when the LineEdit is empty and doesn't have focus.
- * Warning: this will overwrite any text currently in the item
*/
void setDefaultText(const QString &text);
+
const QString toHtml();
const QString toPlainText();
+ void setHtml(const QString &text);
+ void setPlainText(const QString &text);
/**
* Reimplented from QGraphicsItem
Index: lineedit.cpp
===================================================================
--- lineedit.cpp (revision 791548)
+++ lineedit.cpp (working copy)
@@ -41,12 +41,12 @@
{
public:
Private()
- : styled(true), multiline(false) {}
+ : showingDefaultText(true), styled(true), multiline(false) {}
QString defaultText;
QString oldText;
- QString defaultTextPlain;
+ bool showingDefaultText;
bool styled;
bool multiline;
@@ -212,15 +212,14 @@
d->defaultText = text.simplified();
//FIXME hardcoded colours aren't nice
d->defaultText = QString("<font color=\"gray\">") + d->defaultText + QString("</font>");
- QGraphicsTextItem::setHtml(d->defaultText);
- d->defaultTextPlain = QGraphicsTextItem::toPlainText();
+ if (d->showingDefaultText) {
+ QGraphicsTextItem::setHtml(d->defaultText);
+ }
}
const QString LineEdit::toHtml()
{
- //note: comparing html doesn't work because QGraphicsTextItem::toHtml() returns
- //unpredictable text with lots of added html
- if (QGraphicsTextItem::toPlainText() == d->defaultTextPlain) {
+ if (d->showingDefaultText) {
return QString();
} else {
return QGraphicsTextItem::toHtml();
@@ -229,13 +228,35 @@
const QString LineEdit::toPlainText()
{
- if (QGraphicsTextItem::toPlainText() == d->defaultTextPlain) {
+ if (d->showingDefaultText) {
return QString();
} else {
return QGraphicsTextItem::toPlainText();
}
}
+void LineEdit::setHtml(const QString &text)
+{
+ if (text.isEmpty()) {
+ d->showingDefaultText = true;
+ QGraphicsTextItem::setHtml(d->defaultText);
+ } else {
+ d->showingDefaultText = false;
+ QGraphicsTextItem::setHtml(text);
+ }
+}
+
+void LineEdit::setPlainText(const QString &text)
+{
+ if (text.isEmpty()) {
+ d->showingDefaultText = true;
+ QGraphicsTextItem::setHtml(d->defaultText);
+ } else {
+ d->showingDefaultText = false;
+ QGraphicsTextItem::setPlainText(text);
+ }
+}
+
void LineEdit::keyPressEvent(QKeyEvent *event)
{
if ( !d->multiline && (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return)) {
@@ -255,8 +276,9 @@
void LineEdit::focusInEvent(QFocusEvent *event)
{
- if (QGraphicsTextItem::toPlainText() == d->defaultTextPlain) {
+ if (d->showingDefaultText) {
QGraphicsTextItem::setHtml(QString());
+ d->showingDefaultText = false;
}
QGraphicsTextItem::focusInEvent(event);
}
@@ -265,6 +287,7 @@
{
if (QGraphicsTextItem::toPlainText().isEmpty()) {
QGraphicsTextItem::setHtml(d->defaultText);
+ d->showingDefaultText = true;
}
QGraphicsTextItem::focusOutEvent(event);
}
["signature.asc" (application/pgp-signature)]
_______________________________________________
Panel-devel mailing list
Panel-devel@kde.org
https://mail.kde.org/mailman/listinfo/panel-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic