2007-03-04 21:35:37 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 by Alexander Wiedenbruch <mail@wiedenbruch.de>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "lineedit.h"
|
|
|
|
|
2007-05-21 16:28:03 +02:00
|
|
|
#include <QStyleOptionFrameV2>
|
2007-05-28 07:52:56 +02:00
|
|
|
#include <QTextDocument>
|
2007-05-21 16:28:03 +02:00
|
|
|
|
2007-03-04 21:35:37 +01:00
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2007-05-24 21:36:05 +02:00
|
|
|
class LineEdit::Private
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2007-03-04 21:35:37 +01:00
|
|
|
LineEdit::LineEdit(QGraphicsItem *parent, QGraphicsScene *scene)
|
2007-05-24 21:36:05 +02:00
|
|
|
: QGraphicsTextItem(parent, scene),
|
|
|
|
d(new Private())
|
2007-03-04 21:35:37 +01:00
|
|
|
{
|
|
|
|
setTextInteractionFlags(Qt::TextEditorInteraction);
|
|
|
|
}
|
|
|
|
|
|
|
|
LineEdit::~LineEdit()
|
|
|
|
{
|
2007-06-07 22:57:18 +02:00
|
|
|
delete d;
|
2007-03-04 21:35:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LineEdit::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
|
|
|
{
|
|
|
|
QStyleOptionFrameV2 panel;
|
|
|
|
panel.initFrom(widget);
|
|
|
|
panel.state = option->state;
|
|
|
|
panel.rect = boundingRect().toRect();
|
|
|
|
|
|
|
|
widget->style()->drawPrimitive(QStyle::PE_PanelLineEdit, &panel, painter, widget);
|
|
|
|
widget->style()->drawPrimitive(QStyle::PE_FrameLineEdit, &panel, painter, widget);
|
|
|
|
|
|
|
|
// QGraphicsTextItem paints a black frame when it has focus
|
|
|
|
// and is selected. We want to use our own frame, so we
|
|
|
|
// clear these flags.
|
|
|
|
QStyleOptionGraphicsItem *style = const_cast<QStyleOptionGraphicsItem*>(option);
|
|
|
|
style->state &= ~(QStyle::State_Selected | QStyle::State_HasFocus);
|
|
|
|
|
|
|
|
QGraphicsTextItem::paint(painter, style, widget);
|
|
|
|
}
|
|
|
|
|
2007-05-22 04:49:54 +02:00
|
|
|
void LineEdit::updated(const QString&, const DataEngine::Data& data)
|
2007-03-04 21:35:37 +01:00
|
|
|
{
|
2007-05-21 06:29:00 +02:00
|
|
|
DataEngine::DataIterator it(data);
|
|
|
|
|
2007-05-28 07:52:56 +02:00
|
|
|
QString text;
|
2007-05-21 06:29:00 +02:00
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
|
|
|
if (it.value().canConvert(QVariant::String)) {
|
2007-05-28 07:52:56 +02:00
|
|
|
text.append(QString("<p><b>%1</b>: %2</p>").arg(it.key(), it.value().toString()));
|
2007-05-21 06:29:00 +02:00
|
|
|
}
|
|
|
|
}
|
2007-05-28 07:52:56 +02:00
|
|
|
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)
|
|
|
|
{
|
2007-05-29 09:58:05 +02:00
|
|
|
prepareGeometryChange();
|
2007-05-28 07:52:56 +02:00
|
|
|
setTextWidth(geometry.width());
|
2007-05-29 09:58:05 +02:00
|
|
|
update();
|
2007-05-28 07:52:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QSizeF LineEdit::sizeHint() const
|
|
|
|
{
|
|
|
|
kDebug() << "LineEdit::sizeeHint() " << document()->size() << endl;
|
|
|
|
return document()->size();
|
2007-03-04 21:35:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Plasma
|
2007-05-23 05:08:47 +02:00
|
|
|
|
|
|
|
#include "lineedit.moc"
|
|
|
|
|