make lineedit a LayoutItem. seems to basically work, though i don't think it is quite perfect yet =)

svn path=/trunk/KDE/kdebase/workspace/plasma/lib/; revision=668932
This commit is contained in:
Aaron J. Seigo 2007-05-28 05:52:56 +00:00
parent 3c690fea84
commit 6393ddd3ad
2 changed files with 77 additions and 5 deletions

View File

@ -19,6 +19,7 @@
#include "lineedit.h" #include "lineedit.h"
#include <QStyleOptionFrameV2> #include <QStyleOptionFrameV2>
#include <QTextDocument>
namespace Plasma namespace Plasma
{ {
@ -61,15 +62,69 @@ void LineEdit::updated(const QString&, const DataEngine::Data& data)
{ {
DataEngine::DataIterator it(data); DataEngine::DataIterator it(data);
//TODO: this only shows the first possible data item. QString text;
// should it do more?
while (it.hasNext()) { while (it.hasNext()) {
it.next(); it.next();
if (it.value().canConvert(QVariant::String)) { if (it.value().canConvert(QVariant::String)) {
setPlainText(it.value().toString()); text.append(QString("<p><b>%1</b>: %2</p>").arg(it.key(), it.value().toString()));
return;
} }
} }
setHtml(text);
}
Qt::Orientations LineEdit::expandingDirections() const
{
return Qt::Vertical;
}
QSizeF LineEdit::minimumSize() const
{
return boundingRect().size();
}
QSizeF LineEdit::maximumSize() const
{
return minimumSize();
}
bool LineEdit::hasHeightForWidth() const
{
return true;
}
qreal LineEdit::heightForWidth(qreal w) const
{
QTextDocument* doc = document();
doc->setTextWidth(w);
qreal height = doc->size().height();
kDebug() << "LineEdit::heightForWidth(" << w << ") is " << height << endl;
return height;
}
bool LineEdit::hasWidthForHeight() const
{
return false;
}
qreal LineEdit::widthForHeight(qreal h) const
{
return 0;
}
QRectF LineEdit::geometry() const
{
return boundingRect().toRect();
}
void LineEdit::setGeometry(const QRectF& geometry)
{
setTextWidth(geometry.width());
}
QSizeF LineEdit::sizeHint() const
{
kDebug() << "LineEdit::sizeeHint() " << document()->size() << endl;
return document()->size();
} }
} // namespace Plasma } // namespace Plasma

View File

@ -25,6 +25,7 @@
#include <kdemacros.h> #include <kdemacros.h>
#include <dataengine.h> #include <dataengine.h>
#include <widgets/layoutitem.h>
namespace Plasma namespace Plasma
{ {
@ -32,7 +33,7 @@ namespace Plasma
/** /**
* Class that emulates a QLineEdit inside plasma * Class that emulates a QLineEdit inside plasma
*/ */
class KDE_EXPORT LineEdit : public QGraphicsTextItem class KDE_EXPORT LineEdit : public QGraphicsTextItem, public LayoutItem
{ {
Q_OBJECT Q_OBJECT
@ -42,6 +43,22 @@ class KDE_EXPORT LineEdit : public QGraphicsTextItem
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
Qt::Orientations expandingDirections() const;
QSizeF minimumSize() const;
QSizeF maximumSize() const;
bool hasHeightForWidth() const;
qreal heightForWidth(qreal w) const;
bool hasWidthForHeight() const;
qreal widthForHeight(qreal h) const;
QRectF geometry() const;
void setGeometry(const QRectF& geometry);
QSizeF sizeHint() const;
public Q_SLOTS: public Q_SLOTS:
void updated(const QString&, const Plasma::DataEngine::Data&); void updated(const QString&, const Plasma::DataEngine::Data&);